【问题标题】:Openlayers 5 - Dynamically changing interactionsOpenlayers 5 - 动态变化的交互
【发布时间】:2019-03-05 04:22:03
【问题描述】:

有没有办法动态改变 Openlayers 中的交互?我设置交互

import {defaults as defaultInteractions} from 'ol/interaction.js';

var interactions = defaultInteractions({
       constrainResolution: true, 
       onFocusOnly: true, 
       doubleClickZoom: false, 
       altShiftDragRotate:false, 
       pinchRotate:false
    });

但是假设我想要一个用户按钮,他们可以在其中打开(或切换)pinchRotate?我已经尝试用一千种不同的方式搜索这个问题,但似乎无法在地图渲染后找到如何修改交互。

【问题讨论】:

    标签: openlayers-5


    【解决方案1】:

    需要将交互分配给变量名并添加到默认集合中,而不是包含在默认值中。如果您不立即需要它们,请将它们设置为非活动状态。然后,您的按钮可以切换交互活动设置。

    var dragRotate = new DragRotate();
    var pinchRotate = new PinchRotate();
    
    var interactions = defaultInteractions({
           constrainResolution: true, 
           onFocusOnly: true, 
           doubleClickZoom: false, 
           altShiftDragRotate:false, 
           pinchRotate:false
        }).extend([dragRotate, pinchRotate]);
    
    dragRotate.setActive(false);
    pinchRotate.setActive(false);
    
    myRotateButton.addEventListener('click', function() {
        // turn rotation on/off
        dragRotate.setActive(!dragRotate.getActive());
        pinchRotate.setActive(!pinchRotate.getActive());
    }, false);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多