我目前正在将WFS与Openlayers一起使用,但是这些层位于错误的位置,如果我没错,问题出在srsName上,但是如何更改呢?
这是我的WFS代码:
var WFSSource = new VectorSource({
format: new GeoJSON(),
url: function(extent) {
return 'http://localhost:8081/geoserver/occi/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=occi%3Aocci&maxFeatures=5&outputFormat=application%2Fjson';
},
strategy: bboxStrategy,
});
var WFSLayer = new VectorLayer({
source: WFSSource
});
我在WMS上也遇到了同样的问题,但是我只是更改了Geoserver(EPSG:2154)上的SRC natif,一切正常。现在我遇到了同样的问题,请给我以下结果
几何图形应位于国家/地区的底部。我认为VectorSource具有默认的srsname,但我不知道如何更改它。顺便说一句在此链接上:https://openlayers.org/en/latest/examples/vector-wfs.html他们展示了如何使用WFS,他有以下代码行:
url: function(extent) {
return 'https://ahocevar.com/geoserver/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=osm:water_areas&' +
'outputFormat=application/json&srsname=EPSG:3857&' +
'bbox=' + extent.join(',') + ',EPSG:3857';
},
他在其中定义srsName,但对我不起作用。
ol / Source和ol / View具有投影。默认投影为EPSG:3857。如果您的数据或底图不同,则应定义EPSG:3857。
import Map from 'ol/Map';
import View from 'ol/View';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
const map = new Map({
layers: [
new VectorLayer({
source: new VectorSource({
projection: 'EPSG:3857',
})
})
],
target: 'map',
view: new View({
projection: 'EPSG:3857',
})
});