在打开的图层中使用ol.source.TileWMS选择地图对象3 [英] Selecting map objects using ol.source.TileWMS in open layers 3

查看:796
本文介绍了在打开的图层中使用ol.source.TileWMS选择地图对象3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用开放图层3,
我正在使用此代码显示地图:

I am using open layers 3, and I am using this code for displaying the map:

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时我无法进行选择地图中的对象。有人可以帮我解决一下如何实现它吗?
这是我用于矩形选择的代码。

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. 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(', ');
 }
});   `


推荐答案

您使用的是TileWMS源,这是一个集合在WMS服务器上呈现的图像(图块)。 OpenLayers不了解用于渲染图像的功能。因此, forEachFeatureIntersectingExtent 仅适用于矢量源。

You use a TileWMS source, which is a collection of images (tiles) rendered on the WMS server. OpenLayers does not know about the features used to render the images. Because of this, forEachFeatureIntersectingExtent is only available on vector sources.

您可以创建一个WMS boxFend回调中的getFeatureInfo -request,用于从服务器加载功能信息。

You could create a WMS getFeatureInfo-request in the boxend callback, to load the feature information from the server.

或者,您可以创建一个包含所需功能的矢量源,并用于 forEachFeatureIntersectingExtent 调用。

Alternatively, you could create a vector source containing the features you want and use for the forEachFeatureIntersectingExtent call.

这篇关于在打开的图层中使用ol.source.TileWMS选择地图对象3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆