刚接触openlayer,多有不熟悉。报了如下的错误。
检查了一下代码,原来是直接矢量的资源给加载进去了。
var wfsVectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
projection: 'EPSG:4326',
url: function(extent) {
return 'http://localhost:8080/geoserver/sde/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=sde:lianhua &outputFormat=application%2Fjson&srsname=EPSG:4326';
},
strategy: ol.loadingstrategy.bbox
});
map.addLayer(wfsVectorSource)
正确的方式应该是下面的方式。
var wfsVectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
projection: 'EPSG:4326',
url: function(extent) {
return 'http://localhost:8080/geoserver/sde/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=sde:lianhua &outputFormat=application%2Fjson&srsname=EPSG:4326';
},
strategy: ol.loadingstrategy.bbox
});
var wfsVectorLayer = new ol.layer.Vector({
source: wfsVectorSource,
style: new ol.style.Style({
image:new ol.style.Circle({
radius: 5,
fill: new ol.style.Fill({
color: "#3885ff",
opacity: 0.5
})
})
})
});
map.addLayer(wfsVectorLayer)