Openlayers 3关闭平滑滚动
Openlayers 3 turn off smooth scroll
我目前有一个 Openlayers 3 集成,具有许多更新功能,这些使滚动变得卡顿,尤其是在使用 'kinetic' 移动(轻弹滚动)时。有没有办法关闭惯性的平滑滚动,以便用户必须拖动才能移动地图?
移除缩放时的动画也会有所帮助。
我一直在 ol.animation 区域寻找这些 - 那个地方对吗?
可以在 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)})]),
//...
});
}
我目前有一个 Openlayers 3 集成,具有许多更新功能,这些使滚动变得卡顿,尤其是在使用 'kinetic' 移动(轻弹滚动)时。有没有办法关闭惯性的平滑滚动,以便用户必须拖动才能移动地图?
移除缩放时的动画也会有所帮助。
我一直在 ol.animation 区域寻找这些 - 那个地方对吗?
可以在 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)})]),
//...
});
}