【问题标题】:Leaflet Routing Machine - How to set line not draggable?Leaflet Routing Machine - 如何设置不可拖动的线?
【发布时间】:2015-12-18 15:01:46
【问题描述】:

我需要使用 Leaflet-routing-machine 将路由线设置为“不可拖动”。 谁能帮帮我?

编辑:

对不起,我用下面的代码创建了一条路线:

        var routerMap = new L.Routing.OSRM({
            serviceUrl: "http://192.168.20.26:5000/viaroute",
            timeout: 60000
        });

        if (routeControl != undefined) routeControl.getPlan().setWaypoints([]);

        routeControl = L.Routing.control({
            waypoints: novasCoord,
            router: routerMap,
            routeWhileDragging: true
        });

        routeControl.on("routefound", function (e) {
            routeCoordinates = e.route.coordinates;
        });

        //routeControl.on("routeselected", function (e) {
        //    routeCoordinates = e.route.coordinates;
        //});

        routeControl.addTo(map);

但我不想让客户端拖动L.Routing生成的线...

【问题讨论】:

  • 我们需要更多信息,例如代码或小提琴创意来帮助您
  • 对不起,我用上面的代码创建了一个路由: var routerMap = new L.Routing.OSRM({ serviceUrl: "192.168.20.26:5000/viaroute", timeout: 60000 }); if (routeControl != undefined) routeControl.getPlan().setWaypoints([]); routeControl = L.Routing.control({ waypoints: novasCoord, router: routerMap, routeWhileDragging: true }); routeControl.addTo(map);
  • 你的意思是L.Routing生成了一条线之后,你不希望用户点击地图上的另一个点从而重新生成路由?

标签: javascript routing leaflet


【解决方案1】:

查看此插件的docsL.Routing.Line 可以选择启用/禁用(默认启用)通过拖动线条添加新航点的可能性。

选项称为addWaypoints

只需将其设置为 false,例如,您可以扩展 L.Routing.Line 以默认禁用添加航点的可能性。

    L.Routing.Line = L.Routing.Line.extend({
        options: {
            styles: [
                {color: 'black', opacity: 0.15, weight: 9},
                {color: 'white', opacity: 0.8, weight: 6},
                {color: 'red', opacity: 1, weight: 2}
            ],
            missingRouteStyles: [
                {color: 'black', opacity: 0.15, weight: 7},
                {color: 'white', opacity: 0.6, weight: 4},
                {color: 'gray', opacity: 0.8, weight: 2, dashArray: '7,12'}
            ],
            addWaypoints: false,
            extendToWaypoints: true,
            missingRouteTolerance: 10
        },
    });

或者通过传递lineOptions 属性在实例化L.Routing.Control 时即时执行。

routeControl = L.Routing.control({
    /* your config */
    lineOptions : {
        addWaypoints: false
    }
});

这将满足您的需求。

兄弟。

【讨论】:

  • 如果您还想禁用航点拖动,请使用自定义计划,例如const planOptions = { addWaypoints: false, draggableWaypoints: false }; const plan = L.Routing.Plan(initialWayPoints, planOptions); L.Routing.control({ plan, //.. });liedman.net/leaflet-routing-machine/api/#l-routing-plan
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-23
  • 1970-01-01
  • 1970-01-01
  • 2022-08-20
  • 1970-01-01
  • 2016-11-25
  • 2020-04-24
相关资源
最近更新 更多