![](/img/trans.png)
[英]Overwrite automatically calculated TileWMS request properties in Open Layers 3
[英]Selecting map objects using ol.source.TileWMS in open layers 3
我正在使用開放圖層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
});
我正在使用dragbox進行矩形選擇,當我進行shift + drag時,我無法在地圖中選擇對象。 有人可以幫我解決一下如何實現它嗎? 這是我用於矩形選擇的代碼。
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(', ');
}
}); `
您使用TileWMS源,它是在WMS服務器上呈現的圖像(圖塊)的集合。 OpenLayers不了解用於渲染圖像的功能。 因此, forEachFeatureIntersectingExtent
僅適用於矢量源。
您可以在boxend回調中創建WMS getFeatureInfo
-request,以從服務器加載功能信息。
或者,您可以創建包含所需功能的矢量源,並將其用於forEachFeatureIntersectingExtent
調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.