HERE 映射 JS,禁用鼠标缩放但不平移
HERE maps JS, disable mouse zoom but not panning
我希望用户能够使用他们的 mouse/finger 平移地图。但是我想将缩放限制为仅使用 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,我也会失去平移的能力。
如果我重新启用 PANNING,缩放将重新打开。
如何在不禁用平移的情况下禁用缩放?
拖动被禁用的问题是您试图禁用 Behavior 对象中不存在的功能 (PINCH_ZOOM
& DBL_TAP_ZOOM
)。此外,API 3.0 版和 API 3.1 版(最新)中禁用功能的方式也不同。从上面的代码我看到你使用的是旧版本 3.0,因此:
在 3.0 版中只有 3 个功能可以使用 disable/enable:
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 版中,您可以使用更多功能disable/enable:
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 的缩放。
尝试以下操作(注意最后一行):
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.DRAGGING)
我希望用户能够使用他们的 mouse/finger 平移地图。但是我想将缩放限制为仅使用 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,我也会失去平移的能力。 如果我重新启用 PANNING,缩放将重新打开。
如何在不禁用平移的情况下禁用缩放?
拖动被禁用的问题是您试图禁用 Behavior 对象中不存在的功能 (PINCH_ZOOM
& DBL_TAP_ZOOM
)。此外,API 3.0 版和 API 3.1 版(最新)中禁用功能的方式也不同。从上面的代码我看到你使用的是旧版本 3.0,因此:
在 3.0 版中只有 3 个功能可以使用 disable/enable:
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 版中,您可以使用更多功能disable/enable:
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 的缩放。
尝试以下操作(注意最后一行):
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.DRAGGING)