手机上的OpenLayers 3 dragBox

时间:2017-12-15 20:58:18

标签: openlayers openlayers-3 angular-openlayers

我目前正在实施一个dragBox来一次选择多个向量。 由于dragBox对象需要"条件:"在官方的例子中,它是一个关键的新闻,"转移"我想,我已经在Angular中设置了一个单例布尔变量,它将条件设置为" ol.events.condition.always"或者" ol.events.condition.never"该对象在计算机上接受并正常工作...但是在移动设备上不起作用,我认为这可能适用于移动设备,比如绘制圆形而不是。

有没有办法让这项功能在移动设备上运行?

这是我的代码。

 mapFeature.addDragBox = function () {

            webMapValues.dragBox = new ol.interaction.DragBox({
                /* dragbox interaction is active only if "multi select" 
check box is checked is pressed */
                condition: ((webMapValues.multiSelect == true) ? 
ol.events.condition.always : ol.events.condition.never),
                /* 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 */
            webMapValues.mapObj.addInteraction(webMapValues.dragBox);

            if (webMapValues.multiSelect == true) {
                webMapValues.vectorMultiSelect = new 
ol.interaction.Select();

webMapValues.mapObj.addInteraction(webMapValues.vectorMultiSelect);

                webMapValues.multiSelectFeatures = 
webMapValues.vectorMultiSelect.getFeatures();
                webMapValues.dragBox.on('boxend', function () {
                    // features that intersect the box are added to the 
collection of
                    // selected features
                    webMapValues.clickedCoordinates = 
webMapValues.dragBox.getGeometry().getCoordinates();
                    var extent = 
webMapValues.dragBox.getGeometry().getExtent();
                    var layer = rcisMapService.getLayer("vector");
                    angular.forEach(layer, function (Layer, key) {
                        var source = Layer.getSource();
                        source.forEachFeatureIntersectingExtent(extent, 
function (feature) {

webMapValues.multiSelectedFeatures.push(vector);
                        });
                    });
                    mapFeature.Highlight();

                });

                webMapValues.dragBox.on('boxstart', function () {
                    webMapValues.popup.setPosition(undefined);
                    webMapValues.multiSelectedFeatures = [];
                });
            }

        };

2 个答案:

答案 0 :(得分:0)

OpenLayers 3中不存在在移动设备上“拖动”的能力......最接近它的是使用“绘制”功能绘制正方形,然后获取与该正方形相交的所有内容。

 if (selectionToolsSelection == "Box") {
                var geometryFunction = ol.interaction.Draw.createBox();
                drawObj = new ol.interaction.Draw({
                    features: features,
                    type: "Circle",
                    geometryFunction: geometryFunction
                });
                mapObj.addInteraction(drawObj);

            }  

然后你可以抓住“drawend”事件并做你需要的事情......

  drawObj.on('drawend', function (e) {Do magic stuff here});            

答案 1 :(得分:0)

通过将条件选项设置为mouseActionButton(请参阅:Pull Request: Support touch events for DragBox interaction),为拖动框支持触摸设备

import {mouseActionButton} from 'ol/events/condition';

const dragBox = new DragBox({
  condition: mouseActionButton,
});