Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Openlayers-在地图初始化后启用交互_Javascript_Openlayers - Fatal编程技术网

Javascript Openlayers-在地图初始化后启用交互

Javascript Openlayers-在地图初始化后启用交互,javascript,openlayers,Javascript,Openlayers,我使用的是openlayers 6.5 我是这样开始的: /*** Set the map ***/ map = new ol.Map({ target: map_element, layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }) ], view: new ol.View({ center: ol.proj.fromLon

我使用的是openlayers 6.5

我是这样开始的:

/*** Set the map ***/
map = new ol.Map({
    target: map_element,
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM()
        })
    ],
    view: new ol.View({
        center: ol.proj.fromLonLat([
            '24.6859225',
            '45.9852129',
        ]),
        zoom: 6,
    }),
    interactions: ol.interaction.defaults({
        'DragPan': false,
        'Keyboard': false,
        'PinchZoom': false,
        'ZoomDelta': false,
        'PinchRotate': false,
        'OnFocusOnly': false,
        'ZoomDuration': false,
        'ShiftDragZoom': false,
        'MouseWheelZoom': false,
        'DoubleClickZoom': false,
        'AltShiftDragRotate': false
    }),
    controls: [],
});
我希望在地图初始化后,能够启用和禁用每个交互

我在堆栈上找到了下一个代码(启用DragPan):

但下一个不起作用:

map.getInteractions().forEach((interaction) => {
    if (interaction instanceof ol.interaction.AltShiftDragRotate) {
        interaction.setActive(true);
    }
});
错误:
instanceof'右侧不是对象


一些帮助?

而不是使用
ol.interaction.defaults
false
选项(选项名称应为
camelCase
格式),您应该使用

var interactions = ol.interaction.defaults();
interactions.forEach((interaction) => {
    interaction.setActive(false);
});
因为将选项设置为false会排除某些交互,而不是将其设置为禁用

altShiftDragRotate
是用于禁用(或可能排除)DragRotate交互的选项名称,因此所需的交互类是
ol.interaction.DragRotate

interactions.forEach((interaction) => {
    if (interaction instanceof ol.interaction.DragRotate) {
        interaction.setActive(true);
    }
});

默认设置中的交互与options@Mike是的,这是真的,但这似乎不是问题。将
AltShiftDragRotate
替换为
AltShiftDragRotate
无效。我也犯了同样的错误。
interactions.forEach((interaction) => {
    if (interaction instanceof ol.interaction.DragRotate) {
        interaction.setActive(true);
    }
});