加载地图后打开第 3 层禁用捏合旋转
Open Layers 3 disable pinch rotate after map is loaded
我想要我的应用程序中的一个选项,允许在用户需要时禁用捏合旋转。
我有一张地图:
map_object = new ol.Map({
target: 'map',
controls: controls_list,
interactions: interactions_list,
overlays: [overlay],
layers: vector_layers,
view: view
});
您会注意到我在地图定义中以通常的方式定义了交互。我的interactions_list如下:
var interactions_list = ol.interaction.defaults({altShiftDragRotate:false, pinchRotate:true, dragPan:true});
如何在创建地图对象后禁用收缩旋转,以便在加载和显示地图后禁用地图旋转。
如果您使用 OpenLayers v3.1.1,您可以通过在交互中调用 setActive(true)
/setActive(false)
来 enable/disable 交互。
首先您需要在交互集合中找到 PinchRotate
交互:
var interactions = map.getInteractions().getArray();
var pinchRotateInteraction = interactions.filter(function(interaction) {
return interaction instanceof ol.interaction.PinchRotate;
})[0];
然后您可以根据需要启用和禁用交互:
pinchRotateInteraction.setActive(false);
pinchRotateInteraction.setActive(true);
我想要我的应用程序中的一个选项,允许在用户需要时禁用捏合旋转。
我有一张地图:
map_object = new ol.Map({
target: 'map',
controls: controls_list,
interactions: interactions_list,
overlays: [overlay],
layers: vector_layers,
view: view
});
您会注意到我在地图定义中以通常的方式定义了交互。我的interactions_list如下:
var interactions_list = ol.interaction.defaults({altShiftDragRotate:false, pinchRotate:true, dragPan:true});
如何在创建地图对象后禁用收缩旋转,以便在加载和显示地图后禁用地图旋转。
如果您使用 OpenLayers v3.1.1,您可以通过在交互中调用 setActive(true)
/setActive(false)
来 enable/disable 交互。
首先您需要在交互集合中找到 PinchRotate
交互:
var interactions = map.getInteractions().getArray();
var pinchRotateInteraction = interactions.filter(function(interaction) {
return interaction instanceof ol.interaction.PinchRotate;
})[0];
然后您可以根据需要启用和禁用交互:
pinchRotateInteraction.setActive(false);
pinchRotateInteraction.setActive(true);