OpenLayers 3:使用EPSG时地图不显示任何内容:2169而不是EPSG:4326

时间:2016-07-12 13:50:30

标签: javascript openlayers-3 epsg

我目前正在进行涉及OpenLayers的概念证明,我正面临一个问题。

我按照此官方示例尝试加载包含栅格和WFS图层的地图:http://openlayers.org/en/latest/examples/vector-wfs.html

我可以通过EPSG使这个示例正常工作:4326,我采用完全相同的代码,只有改变的地方是:

  • vectorSource.url =参加我的WFS
  • raster.Source = OMS而不是BingMaps
  • EPSG:4326而非EPSG:来自样本的3857

以下是JavaScript代码:

    var vectorSource = new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: function (extent) {
            return 'http://localhost:8090/geoserver/ANF/ows?service=WFS&' +
                'version=1.1.0&request=GetFeature&typename=ANF:PARC_BIODEM_SP&' +
                'outputFormat=application/json&srsname=EPSG:4326&' +
                'bbox=' + extent.join(',') + ',EPSG:4326';
        },
        strategy: ol.loadingstrategy.bbox
    });


    var vector = new ol.layer.Vector({
        source: vectorSource,
        style: new ol.style.Style({
            stroke: new ol.style.Stroke({
                color: 'rgba(0, 0, 255, 1.0)',
                width: 2
            })
        })
    });

    var raster = new ol.layer.Tile({
        source: new ol.source.OSM()
    });

    var map = new ol.Map({
        layers: [raster, vector],
        target: document.getElementById('map'),
        view: new ol.View({
            center: [6.13, 49.845],
            projection: 'EPSG:4326',
            minZoom: 10,
            maxZoom: 28,
            zoom: 10
        })
    });

现在,我想在EPSG中显示地图:2169。

当我将新投影设置为WFS图层(vectorSource)时,它不会再在地图上显示它。当我将新投影设置为地图视图本身时,HTML页面保持白色,调试器显示错误:“ol.js:68 Uncaught TypeError:无法读取未定义的属性'H'”

这是我想要的JavaScript代码,但这不起作用:

    var vectorSource = new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: function (extent) {
            return 'http://localhost:8090/geoserver/ANF/ows?service=WFS&' +
                'version=1.1.0&request=GetFeature&typename=ANF:PARC_BIODEM_SP&' +
                'outputFormat=application/json&srsname=EPSG:2169&' +
                'bbox=' + extent.join(',') + ',EPSG:2169';
        },
        strategy: ol.loadingstrategy.bbox
    });


    var vector = new ol.layer.Vector({
        source: vectorSource,
        style: new ol.style.Style({
            stroke: new ol.style.Stroke({
                color: 'rgba(0, 0, 255, 1.0)',
                width: 2
            })
        })
    });

    var raster = new ol.layer.Tile({
        source: new ol.source.OSM()
    });

    var map = new ol.Map({
        layers: [raster, vector],
        target: document.getElementById('map'),
        view: new ol.View({
            center: [6.13, 49.845],
            projection: 'EPSG:2169',
            minZoom: 10,
            maxZoom: 28,
            zoom: 10
        })
    });

我的WFS层来自GeoServer,来自Oracle数据库的数据,我确信这些数据在EPSG:2169中可用。 GeoServer说原生SRC是EPSG:2169,OpenLayers预览(总是来自GeoServer)显示该层。

为什么我的WFS在EPSG:2169(OpenLayers预览版)中从GeoServer工作得很好,但不在我的OpenLayers网页中? 我错过了什么吗?

非常感谢!

0 个答案:

没有答案