如何使地图框地图(带有方向.js)只读?-(并防止用户移动标记)



我在 Mapbox 中带有步行路线的地图不是只读的。用户可以移动标记的原始位置。

我提到了图层选项

https://github.com/mapbox/mapbox-directions.js/blob/mb-pages/API.md#layer-options

并补充说:

var Layer = L.LayerGroup.extend({
    options: {
        readonly: true
    }
});

地图保持交互,用户可以移动标记。

有什么建议吗?

小提琴:https://jsfiddle.net/q9grgbt0/

您将options添加到名为 Layer 的东西中,但您从不使用Layer 。您应该将其添加到directionsLayer。它应该看起来像这样:

var directionsLayer = L.mapbox.directions.layer(directions, {readonly: true}).addTo(map);

我已经用这个代码修复更新了你的小提琴。我还清理了一些代码并删除了不必要的变量Layer

最新更新