简体   繁体   中英

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:

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.

First you need to find the PinchRotate interaction in the interactions collection:

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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