简体   繁体   English

加载地图后,打开第3层禁用捏旋转

[英]Open Layers 3 disable pinch rotate after map is loaded

I would like an option in my application which allows pinch rotate to be disabled when the user desires it. 我想在我的应用程序中使用一个选项,该选项允许在用户需要时禁用捏旋转。

I have a map: 我有一张地图:

map_object = new ol.Map({
target: 'map',
controls: controls_list,
interactions: interactions_list,
overlays: [overlay],
layers: vector_layers,
view: view
});

You'll notice that I have defined interactions in the usual way in the map definition. 您会注意到,我已经在地图定义中以通常的方式定义了交互。 My interactions_list is as follows: 我的interacts_list如下:

var interactions_list = ol.interaction.defaults({altShiftDragRotate:false, pinchRotate:true, dragPan:true}); 

How do I disable pinch rotate after the map object has been created so that map rotation is disabled after the map is loaded and displayed. 创建地图对象后如何禁用捏合旋转,以便加载和显示地图禁用地图旋转。

If you use OpenLayers v3.1.1 you can enable/disable an interaction by calling setActive(true) / setActive(false) on the interaction. 如果使用OpenLayers v3.1.1,则可以通过在交互上调用setActive(true) / setActive(false)来启用/禁用交互。

First you need to find the PinchRotate interaction in the interactions collection: 首先,您需要在交互集合中找到PinchRotate交互:

var interactions = map.getInteractions().getArray();
var pinchRotateInteraction = interactions.filter(function(interaction) {
  return interaction instanceof ol.interaction.PinchRotate;
})[0];

You can then enable and disable the interaction as needed: 然后,您可以根据需要启用和禁用交互:

pinchRotateInteraction.setActive(false);
pinchRotateInteraction.setActive(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM