OpenLayers选择具有多边形的要素 [英] OpenLayers select features with polygon

查看:528
本文介绍了OpenLayers选择具有多边形的要素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用它- http://openlayers.org/dev/examples/SLDSelect.html 例如: 我有选择要素(框),可以选择图层上的要素.但是是箱型. 现在,我尝试进行相同的选择,但使用多边形样式.就像绘制新的多边形一样,但是将选择该多边形内的内容. 我在尝试使用此SLD选择的正确路径上找到了,还是还有其他更好的方法?

Trying to use this - http://openlayers.org/dev/examples/SLDSelect.html For example: I have select feature ( box ) which allow me to select features on layer. But it is box type. Now i am trying to make same selection but with polygon style. Like drawing new polygon but what are inside that polygon will select. did i look on right path trying to use this SLD selection or there is other better way?

打开任何解决方案.

谢谢.

推荐答案

在此插件中,我使用了interact.Draw来创建多边形.多边形完成后,它将找到多边形范围内的所有特征点并选择它们.

In this plunker I have used interaction.Draw to create a polygon. Once the polygon is finished, it finds all feature points in the polygon's extent and selects them.

此处是指向矮人的链接

这是draw.on('drawend',...侦听器的摘录:

draw.on('drawend', function(e) {

  e.preventDefault();
  //stop a click select from overriding selection made by polygon
  setTimeout(function(){
    select.setActive(true)
  },300);

  // features that intersect the box are added to the collection of
  // selected features, and their names are displayed in the "info"
  // div
  var extent = e.feature.getGeometry().getExtent();

  //pointsLayer is the vector layer with the point features
  pointsLayer.getSource().forEachFeatureIntersectingExtent(extent, function(feature) {
    selectedFeatures.push(feature);
  });

});

这篇关于OpenLayers选择具有多边形的要素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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