无法使用来自 OpenLayers 3 站点的 WFS 示例作为基础加载另一个 WFS
Failing to load another WFS using the WFS example from the site of OpenLayers 3 as base
我是 OpenLayers3 的初学者,我是这个网站的新手,所以这是我的第一个问题,希望我把它正确地放在这里。对我不起作用的是在 OpenLayers3 中打开一个(不是平铺的?)WFS 层。我使用开放层站点的 WFS 示例作为基础(也是因为它似乎是一个相对简单的代码)。我试图在我的教科书 OpenLayers3 中找到解决方案,在开放层的网站上,Google 和在这个网站上,但没有成功。
在我用 OpenLayers 的例子制作的代码下面,但现在是另一个 WFS,因为我认为应该打开这个 WFS。我做错了什么?
// working example from: http://openlayers.org/en/v3.13.1/examples/vector-wfs.html
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://demo.boundlessgeo.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';
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
maxZoom: 19
}))
});
var vector1 = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 255, 255, 1.0)',
width: 2
})
})
});
// 基于上面示例代码的无效代码
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'https://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=bestuurlijkegrenzen:gemeenten&' +
'outputFormat=application/json&srsname=EPSG:28992&' +
'bbox=' + extent.join(',') + ',EPSG:28992';
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
maxZoom: 19
}))
});
var vector = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 255, 255, 1.0)',
width: 2
})
})
});
除非你提供完整的代码,否则我只能做一些猜测。
你的两层有不同的投影。我猜您使用 epsg:3857
进行视图投影,因此使用此范围内的坐标将 return 0 个特征。首先要尝试的是使用视图的投影从地理服务器请求图层。
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'https://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=bestuurlijkegrenzen:gemeenten&' +
'outputFormat=application/json&srsname=EPSG:3857&' +
'bbox=' + extent.join(',') + ',EPSG:3857';
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
maxZoom: 19
}))
});
这将强制地理服务器在服务器端进行重新投影。
我建议首先尝试上述方法,以确保这是您的情况。然后你必须考虑是否要在客户端或服务器端进行重新投影。
我是 OpenLayers3 的初学者,我是这个网站的新手,所以这是我的第一个问题,希望我把它正确地放在这里。对我不起作用的是在 OpenLayers3 中打开一个(不是平铺的?)WFS 层。我使用开放层站点的 WFS 示例作为基础(也是因为它似乎是一个相对简单的代码)。我试图在我的教科书 OpenLayers3 中找到解决方案,在开放层的网站上,Google 和在这个网站上,但没有成功。 在我用 OpenLayers 的例子制作的代码下面,但现在是另一个 WFS,因为我认为应该打开这个 WFS。我做错了什么?
// working example from: http://openlayers.org/en/v3.13.1/examples/vector-wfs.html
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://demo.boundlessgeo.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';
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
maxZoom: 19
}))
});
var vector1 = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 255, 255, 1.0)',
width: 2
})
})
});
// 基于上面示例代码的无效代码
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'https://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=bestuurlijkegrenzen:gemeenten&' +
'outputFormat=application/json&srsname=EPSG:28992&' +
'bbox=' + extent.join(',') + ',EPSG:28992';
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
maxZoom: 19
}))
});
var vector = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 255, 255, 1.0)',
width: 2
})
})
});
除非你提供完整的代码,否则我只能做一些猜测。
你的两层有不同的投影。我猜您使用 epsg:3857
进行视图投影,因此使用此范围内的坐标将 return 0 个特征。首先要尝试的是使用视图的投影从地理服务器请求图层。
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'https://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=bestuurlijkegrenzen:gemeenten&' +
'outputFormat=application/json&srsname=EPSG:3857&' +
'bbox=' + extent.join(',') + ',EPSG:3857';
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
maxZoom: 19
}))
});
这将强制地理服务器在服务器端进行重新投影。 我建议首先尝试上述方法,以确保这是您的情况。然后你必须考虑是否要在客户端或服务器端进行重新投影。