javascript - HERE 映射 JS,禁用鼠标缩放但不平移
问题描述
我希望用户能够用鼠标/手指平移地图。但是我想将缩放限制为仅使用 HERE ui 控件。
我尝试了以下方法:
// Since our marker is in the center of the map we need to make sure zooming occurs at center of map only
// The user can zoom to their mouse position which may not be center, so we need to disable and allow zooming
// via the +/- buttons only :(
this.mapBehavior.disable(window.H.mapevents.Behavior.WHEELZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.PINCH_ZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.DBL_TAP_ZOOM)
this.mapBehavior.enable(window.H.mapevents.Behavior.PANNING) <-- this renables zoom
不幸的是,如果我禁用 WHEELZOOM,我也会失去平移的能力。如果我重新启用平移,缩放将重新打开。
如何在不禁用平移的情况下禁用缩放?
解决方案
PINCH_ZOOM
禁用拖动的问题是您尝试禁用 Behavior 对象 ( & DBL_TAP_ZOOM
)中不存在的功能。此外,在 API 3.0 版和 API 3.1 版(最新)中禁用功能的方式也不同。从上面的代码中,我看到您使用的是旧版本 3.0,因此:
在 3.0 版中,您只能禁用/启用 3 个功能:
H.mapevents.Behavior.DBLTAPZOOM
、H.mapevents.Behavior.DRAGGING
、H.mapevents.Behavior.WHEELZOOM
因此,禁用缩放的代码应如下所示:
this.mapBehavior.disable(window.H.mapevents.Behavior.WHEELZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.DBLTAPZOOM)
在 3.1 版中,您可以禁用/启用更多功能:
H.mapevents.Behavior.Feature.PANNING
, H.mapevents.Behavior.Feature.PINCH_ZOOM
, H.mapevents.Behavior.Feature.WHEEL_ZOOM
, H.mapevents.Behavior.Feature.DBL_TAP_ZOOM
, H.mapevents.Behavior.Feature.FRACTIONAL_ZOOM
, H.mapevents.Behavior.Feature.HEADING
, H.mapevents.Behavior.Feature.TILT
,
因此,禁用缩放的代码(如果您使用 3.1 版)如下所示:
this.mapBehavior.disable(window.H.mapevents.Behavior.Feature.WHEEL_ZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.Feature.PINCH_ZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.Feature.DBL_TAP_ZOOM)
请参阅简单的jsfiddle示例以禁用 API 版本 3.1 的缩放。
推荐阅读
- django - Django rest 框架更新 Put 不允许
- css - 旋转圆圈 CSS
- php - 表单操作发生时 Laravel 回显自定义错误消息
- css - 导入 Materialize 源代码时的 Sass CompileError:Sass 映射“不是有效的 CSS 值”
- javascript - 如何添加过渡我的滑块?
- c - 为二维数组分配内存出错时如何正确释放
- javascript - Google Analytics API 为更大的日期范围删除日期
- java - 播放 sbt dist 命令卡住
- python - 从数组中获取整数作为python中的单独变量
- node.js - 如何在 puppeteer 中将 URL 添加到 Flash 白名单