Javascript 此处映射JS,禁用鼠标缩放但不平移

Javascript 此处映射JS,禁用鼠标缩放但不平移,javascript,here-api,Javascript,Here Api,我希望用户能够用鼠标/手指平移地图。但是,我想限制缩放仅使用此处的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 disa

我希望用户能够用鼠标/手指平移地图。但是,我想限制缩放仅使用此处的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
//由于我们的标记位于地图的中心,我们需要确保缩放只发生在地图的中心
//用户可以缩放到可能不在中心的鼠标位置,因此我们需要禁用并允许缩放
//仅通过+/-按钮:(
this.mapBehavior.disable(window.H.mapevents.Behavior.WHEELZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.PINCH\u ZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.DBL\u TAP\u ZOOM)

this.mappbehavior.enable(window.H.mappevents.Behavior.PANNING)禁用拖动的原因是您试图禁用行为对象中不存在的功能(
PINCH\u ZOOM
&
DBL\u TAP\u ZOOM
)。此外,在API版本3.0和API版本3.1(最新版本)中禁用功能的方式也不同.从上面的代码中,我看到您使用的是旧版本3.0,因此:

在3.0版中,只有3个功能可以禁用/启用:
H.mapevents.Behavior.DBLTAPZOOM
H.mapevents.Behavior.Draging
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\u ZOOM
H.mapevents.Behavior.Feature.DBL\u TAP\u ZOOM
H.mapevents.Behavior.Feature.particial\u ZOOM
H.mapevents.Behavior.HEADING
H或.Feature.TILT

因此,禁用缩放的代码(如果使用版本3.1)如下所示:

this.mapBehavior.disable(window.H.mapevents.Behavior.Feature.WHEEL\u ZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.Feature.PINCH\u ZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.Feature.DBL\u TAP\u ZOOM)

请参阅API 3.1版禁用缩放的简单示例。

禁用拖动的原因是您试图禁用行为对象中不存在的功能(
PINCH\u zoom
&
DBL\u TAP\u zoom
)。此外,API 3.0版和API 3.1版(最新版本)中禁用功能的方式不同.从上面的代码中,我看到您使用的是旧版本3.0,因此:

在3.0版中,只有3个功能可以禁用/启用:
H.mapevents.Behavior.DBLTAPZOOM
H.mapevents.Behavior.Draging
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\u ZOOM
H.mapevents.Behavior.Feature.DBL\u TAP\u ZOOM
H.mapevents.Behavior.Feature.particial\u ZOOM
H.mapevents.Behavior.HEADING
H或.Feature.TILT

因此,禁用缩放的代码(如果使用版本3.1)如下所示:

this.mapBehavior.disable(window.H.mapevents.Behavior.Feature.WHEEL\u ZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.Feature.PINCH\u ZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.Feature.DBL\u TAP\u ZOOM)
请参阅使用API 3.1版禁用缩放的简单示例。

尝试以下操作(注意最后一行):

this.mapBehavior.disable(window.H.mapevents.Behavior.WHEELZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.PINCH\u ZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.DBL\u TAP\u ZOOM)
this.mapBehavior.enable(window.H.mapevents.Behavior.Draging)
尝试以下操作(注意最后一行):

this.mapBehavior.disable(window.H.mapevents.Behavior.WHEELZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.PINCH\u ZOOM)
this.mapBehavior.disable(window.H.mapevents.Behavior.DBL\u TAP\u ZOOM)
this.mapBehavior.enable(window.H.mapevents.Behavior.Draging)

这对我不起作用,功能未定义。我相信我必须运行较旧版本的HERE maps。谢谢您,我看到您使用较旧版本的HERE maps API。我更新了答案,以涵盖两个版本(较旧的3.0和最新的3.1)的解决方案API的版本。这对我不起作用,功能未定义。我相信我必须运行较旧版本的HERE maps。谢谢您。我看到您使用较旧版本的HERE maps API。我更新了答案,以涵盖两个版本(较旧的3.0和最新的3.1)的API的解决方案。