如何使 Mapbox 地图(directions.js)只读? -(并防止用户移动标记)

How to make Mapbox maps (with directions.js) read only? - (and prevent users from moving markers)

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

我提到了图层选项

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

并添加:

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

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

有什么建议吗?

Fiddle: https://jsfiddle.net/q9grgbt0/

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

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

I've updated your fiddle with this code fix。我还清理了一些代码并去掉了不必要的变量 Layer.