Openlayers 如何将鼠标滚轮缩放级别限制为View.resolutions中指定的级别?
我想将鼠标滚轮缩放级别限制为View.resolutions中指定的级别 我能做些什么来实现它 在视图选项中使用constraintresolution:true (c) 迈克 编辑: 如果您只想将ConstraintResolution用于鼠标滚轮缩放,则应在创建地图之前覆盖原型鼠标滚轮缩放中的handleWheelZoom_u函数:Openlayers 如何将鼠标滚轮缩放级别限制为View.resolutions中指定的级别?,openlayers,openlayers-6,Openlayers,Openlayers 6,我想将鼠标滚轮缩放级别限制为View.resolutions中指定的级别 我能做些什么来实现它 在视图选项中使用constraintresolution:true (c) 迈克 编辑: 如果您只想将ConstraintResolution用于鼠标滚轮缩放,则应在创建地图之前覆盖原型鼠标滚轮缩放中的handleWheelZoom_u函数: import { clamp } from 'ol/math.js'; import { zoomByDelta } from 'ol/interaction/
import { clamp } from 'ol/math.js';
import { zoomByDelta } from 'ol/interaction/Interaction';
import { MouseWheelZoom } from "ol/interaction";
const mouseWheelZoomContrainResolution = true;
MouseWheelZoom.prototype.handleWheelZoom_ = function (map) {
var view = map.getView();
if (view.getAnimating()) {
view.cancelAnimations();
}
var delta = -clamp(this.totalDelta_, -this.maxDelta_ * this.deltaPerZoom_, this.maxDelta_ * this.deltaPerZoom_) / this.deltaPerZoom_;
if (view.getConstrainResolution() || mouseWheelZoomContrainResolution) {
// view has a zoom constraint, zoom by 1
delta = delta ? delta > 0 ? 1 : -1 : 0;
}
zoomByDelta(view, delta, this.lastAnchor_, this.duration_);
this.mode_ = undefined;
this.totalDelta_ = 0;
this.lastAnchor_ = null;
this.startTime_ = undefined;
this.timeoutId_ = undefined;
};
EDIT2:
该视图具有SetConstraintResolution方法,因此您可以打开 约束打开和关闭。可以在设置缩放之前将其关闭 手动,并在对系统进行任何进一步更改时将其重新打开 决议 (c) 迈克
请参阅下面的注释,在视图选项中使用
constraintresolution:true
。视图有一个setconstraintresolution方法,因此您可以打开和关闭约束。您可以在手动设置缩放之前将其关闭,如果对分辨率@Mike good hit进行了任何进一步更改,则可以将其重新打开,但对我不起作用,当我再次将Constraint resolution设置为true时,分辨率将移到预定义的Yes,但在鼠标滚轮动作触发<代码>更改:分辨率event@Mike仍然不起作用,当在一行中设置两次分辨率而不使用鼠标滚轮时,如果要重复执行,请创建一个函数