【问题标题】:HERE maps JS, disable mouse zoom but not panningHERE 映射 JS,禁用鼠标缩放但不平移
【发布时间】:2020-03-08 20:13:21
【问题描述】:

我希望用户能够用鼠标/手指平移地图。但是,我想将缩放限制为仅使用 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,则会重新打开缩放功能。

如何在不禁用平移的情况下禁用缩放?

【问题讨论】:

    标签: javascript here-api


    【解决方案1】:

    禁用拖动的问题是您尝试禁用 Behavior 对象中不存在的功能 (PINCH_ZOOM & 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.PANNINGH.mapevents.Behavior.Feature.PINCH_ZOOMH.mapevents.Behavior.Feature.WHEEL_ZOOMH.mapevents.Behavior.Feature.DBL_TAP_ZOOMH.mapevents.Behavior.Feature.FRACTIONAL_ZOOMH.mapevents.Behavior.Feature.HEADINGH.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 的缩放。

    【讨论】:

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

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

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 2011-08-28
      • 1970-01-01
      • 2018-03-20
      • 2014-09-13
      • 2023-02-11
      相关资源
      最近更新 更多