我尝试从OpenLayers 6.3.1中的本地GeoServer将矢量层显示为WFS。当我尝试添加新的矢量层时,在地图上我只能看到基本地图。但是,GeoServer上的所有数据的投影均为EPSG:3857。
如何解决这个问题?
我的代码:
var vectorSource = new VectorSource({
format: new GeoJSON(),
url: function(extent) {
return 'http://localhost:8080/geoserver/geodata/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=geodata%3Amlink&maxFeatures=50&outputFormat=application%2Fjson';
},
strategy: bboxStrategy,
});
var vector = new VectorLayer({
source: vectorSource
});
var map = new Map({
layers: [
new TileLayer({
source: new OSM(), //projection: 'EPSG:3857',
opacity: 0.7
}),
vector],
target: document.getElementById('map'),
view: new View({
//projection: 'EPSG:3857',
center: [6181942.5743,7443423.3883],
zoom: 11
//maxZoom: 19,
//zoom: 12
})
});