【发布时间】:2015-04-17 09:46:58
【问题描述】:
我目前有一个带有许多更新功能的 Openlayers 3 集成,这些功能会使滚动卡顿,尤其是在使用“动力学”运动(轻弹滚动)时。有没有办法在关闭惯性的情况下关闭平滑滚动,以便用户必须拖动才能移动地图?
删除缩放动画也会有所帮助。
我一直在 ol.animation 区域寻找这些 - 这是正确的地方吗?
【问题讨论】:
标签: scroll openlayers-3
我目前有一个带有许多更新功能的 Openlayers 3 集成,这些功能会使滚动卡顿,尤其是在使用“动力学”运动(轻弹滚动)时。有没有办法在关闭惯性的情况下关闭平滑滚动,以便用户必须拖动才能移动地图?
删除缩放动画也会有所帮助。
我一直在 ol.animation 区域寻找这些 - 这是正确的地方吗?
【问题讨论】:
标签: scroll openlayers-3
可以在ol.interaction.DragPan 交互中关闭动力学。可以通过将duration: 0 传递给ol.interaction.MouseWheelZoom 来在缩放时移除动画。
在此处查看实时示例:http://jsfiddle.net/9v6fd6as/1/
这是示例源代码:
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
interactions: ol.interaction.defaults({
dragPan: false,
mouseWheelZoom: false
}).extend([
new ol.interaction.DragPan({kinetic: false}),
new ol.interaction.MouseWheelZoom({duration: 0})
]),
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
【讨论】:
Alexandre Dube 的上述回答对于 旧版本的 openlayers 是正确的。
如果您使用 OpenLayers 6+ 和 TypeScript,您可以通过以下方式禁用动画平移:
import Interaction from "ol/interaction/Interaction";
import DragPan from "ol/interaction/DragPan";
import {defaults as defaultInteractions} from 'ol/interaction.js';
import {Kinetic} from "ol";
// ...
ngOnInit() {
this.map = new Map({
//...
interactions: defaultInteractions({
dragPan: false
}).extend([new DragPan({kinetic: new Kinetic(0, 0, 0)})]),
//...
});
}
【讨论】: