数据显示在错误的位置-OpenLayers

问题描述 投票:0回答:1

我已经在HTML页面中定义了此脚本:

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

    var vector = new ol.layer.Vector({
        source: new ol.source.Vector({
            format: new ol.format.GeoJSON(),
            url: function(extent) {
                return 'http://localhost:8080/geoserver/population/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=population:ne_10m_populated_places&outputFormat=application/json'
            },
            serverType: 'geoserver'
        })
    });

    var map = new ol.Map({ 
        layers: [raster,vector], 
        target: 'map', 
        view: new ol.View({ 
            center: [0, 0], 
            zoom: 5
        }) 
    });

    map.addControl(new ol.control.ZoomSlider()); 
</script>

但是数据正在加纳附近的所有海域中显示。

这是从GeoServer检索到的我的GeoJSON数据的示例:

{"type":"Feature","id":"ne_10m_populated_places.2","geometry":{"type":"Point","coordinates":[-56.90099656,-33.54399894]},"geometry_name":"the_geom","properties":{}}

当我在GeoServer中单击图层页面时,它说我的数据文件的本地SRS是EPSG:404000。

javascript openlayers geojson geoserver
1个回答
0
投票

我认为您的问题是,您没有在其中指定要使用功能的空间参考系统。您正在使用OSM作为使用事实上的EPSG:3857 Web Mercator的底图。您的要素位于地理坐标EPSG:4286中,这可能是几何位置错误的原因。

因此,向WFS请求添加参数srsName="EPSG:3857",以指定您希望几何位于该空间参考系统中。

© www.soinside.com 2019 - 2024. All rights reserved.