[英]Selecting map objects using ol.source.TileWMS in open layers 3
I am using open layers 3, and I am using this code for displaying the map: 我正在使用开放图层3,我使用此代码显示地图:
wmsSource = new ol.source.TileWMS({
url: 'http://demo.boundlessgeo.com/geoserver/wms',
params: { 'LAYERS': 'ne:ne' },
serverType: 'geoserver',
crossOrigin: ''
});
var wmsLayer = new ol.layer.Tile({
source: wmsSource
});
I am using dragbox to make the rectangular selection and when I do the shift + drag I am not able to select the objects in map. 我正在使用dragbox进行矩形选择,当我进行shift + drag时,我无法在地图中选择对象。 Can somebody please help me on how to achieve it? 有人可以帮我解决一下如何实现它吗? This is the code I am using for rectangular selection. 这是我用于矩形选择的代码。
dragBox.on('boxend', function(e) {
// features that intersect the box are added to the collection of
// selected features, and their names are displayed in the "info"
// div
var info = [];
var extent = dragBox.getGeometry().getExtent();
wmsSource .forEachFeatureIntersectingExtent(extent, function(feature) {
selectedFeatures.push(feature);
info.push(feature.get('name'));
});
if (info.length > 0) {
infoBox.innerHTML = info.join(', ');
}
}); `
You use a TileWMS source, which is a collection of images (tiles) rendered on the WMS server. 您使用TileWMS源,它是在WMS服务器上呈现的图像(图块)的集合。 OpenLayers does not know about the features used to render the images. OpenLayers不了解用于渲染图像的功能。 Because of this, forEachFeatureIntersectingExtent
is only available on vector sources. 因此, forEachFeatureIntersectingExtent
仅适用于矢量源。
You could create a WMS getFeatureInfo
-request in the boxend callback, to load the feature information from the server. 您可以在boxend回调中创建WMS getFeatureInfo
-request,以从服务器加载功能信息。
Alternatively, you could create a vector source containing the features you want and use for the forEachFeatureIntersectingExtent
call. 或者,您可以创建包含所需功能的矢量源,并将其用于forEachFeatureIntersectingExtent
调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.