Openlayers 3 从DragBox选择的图层-openlayers 3

Openlayers 3 从DragBox选择的图层-openlayers 3,openlayers-3,Openlayers 3,有没有办法从DragBox选择创建新图层 以下是我的DragBox交互: /* create drag box */ this.dragBox = new ol.interaction.DragBox({ /* dragbox interaction is active only if alt key is pressed */ condition: ol.events.condition.altKeyOnly, /* style the box */ style

有没有办法从DragBox选择创建新图层

以下是我的DragBox交互:

/* create drag box */
this.dragBox = new ol.interaction.DragBox({
    /* dragbox interaction is active only if alt key is pressed */
    condition: ol.events.condition.altKeyOnly,
    /* style the box */
    style: new ol.style.Style({
        stroke: new ol.style.Stroke({
            color: [0, 0, 255, 1]
        })
    })
});
/* add the DragBox interaction to the map */
this.map.addInteraction(this.dragBox);

在boxend事件中,我想使用边界框中的数据创建一个新层。我怎样才能做到这一点?

我认为这是一个相当简单的方法

  • 您可以获得如下边界(在openlayer的术语中称为“范围”):

     var extent = this.dragBox.getGeometry().getExtent(); // you can use this inside the boxend event
    
  • 使用此边界,可以使用任何方法过滤贴图。例如,使用openlayers geometry intersect,检查图层中与范围相交的要素:

    var isIntersect=feature.getGeometry().intersectsExtent(extent);
    
  • 然后创建一个图层,并用过滤的要素填充它