我想使用以下代码在开放图层中显示我的地理服务器图层,但是我无法获得正确的url格式以输入以下图层的url- localhost:8080/geoserver/itachi/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=itachi%3Awfs_geom&maxFeatures=50
var sourceWFS = new ol.source.Vector({
loader: function (extent) {
$.ajax('https://gsx.geolytix.net/geoserver/geolytix_wfs/ows', {
type: 'GET',
data: {
service: 'WFS',
version: '1.1.0',
request: 'GetFeature',
typename: 'wfs_geom',
srsname: 'EPSG:3857',
bbox: extent.join(',') + ',EPSG:3857'
}
}).done(function (response) {
sourceWFS.addFeatures(formatWFS.readFeatures(response));
});
},发布于 2019-04-10 18:40:00
您可以使用完整的url来完成此操作。
var sourceWFS = new ol.source.Vector({
url: 'http://localhost:8080/geoserver/itachi/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=itachi%3Awfs_geom&maxFeatures=50',
format: formatWFS
});但如果您需要更改投影(例如,数据在EPSG:4326中返回,视图在EPSG:3857中返回),则需要使用加载器
var sourceWFS = new ol.source.Vector({
loader: function () {
$.ajax('http://localhost:8080/geoserver/itachi/ows', {
type: 'GET',
data: {
service: 'WFS',
version: '1.0.0',
request: 'GetFeature',
typename: 'itachi:wfs_geom',
maxFeatures: '50'
}
}).done(function (response) {
sourceWFS.addFeatures(formatWFS.readFeatures(response),{
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
});
});
},
strategy: ol.loadingstrategy.all
});如果数据可以更新,则需要调用sourceWFS.refresh();来重新加载
https://stackoverflow.com/questions/55599801
复制相似问题