移动设备上的 OpenLayers 3 dragBox

标签 openlayers openlayers-3 angular-openlayers

我目前正在实现一个 dragBox 以一次选择多个向量。 由于 dragBox 对象需要一个“条件:”并且在官方示例中它是一个按键,我认为是“shift”,我已经在 Angular 中设置了一个单例 bool 变量,它将条件设置为“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 = [];
                });
            }

        };

最佳答案

在移动设备上“拖动”的能力在 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});            

关于移动设备上的 OpenLayers 3 dragBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47839779/

相关文章:

javascript - 如何使用 OpenLayers 创建圆形图标图像?

css - 无法以 Angular 获取 openlayers css

javascript - 我需要使用 NodeJS 在页面内显示 OpenLayers 3 map 吗?

javascript - 如何在openlayers中获取当前的缩放

openlayers - 使用 Nominatim 进行简单的反向地理编码

vue.js - OL 功能在缩小/放大时移动

styles - OpenLayers 3笔触样式

javascript - 加载源向量(特征不会显示?)

openlayers - 如何在 OpenLayers 3 Map 上放置静态图像叠加层

javascript - OpenLayers getFeatures() 访问属性