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

我按照这个官方示例尝试加载带有栅格和WFS图层的 Map :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中显示 Map :2169 .

当我将新投影设置为WFS图层(vectorSource)时,它不会再在 Map 上显示它 . 当我将新投影设置为 Map 视图本身时,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网页中没有?我错过了什么吗?

非常感谢 !