使用leaflet+graphhopper进行路径规划

 $("#go").click(function(){
        $.ajax({

            url:"/findPath?idS="+idS+"&&idE="+idE,
            success:function(data){
                /**
                 * 后台返回的路径规划数据
                 * 可以console.log看一下
                 * 包括路径信息,指令信息等
                 * 重点:以下为同一层数据
                 **/

                var path=data.paths;
                var coordinates=[];
                for(var i =0 ; i < path.points.length;i++){
                    // coordinates.push({latLng: L.latLng(path.points[i][0],path.points[i][1])});
                    coordinates.push({lat:path.points[i][0],lng:path.points[i][1]});
                }
                var inputWaypoints=[];
                inputWaypoints.push({latLng: L.latLng(path.points[1][0],path.points[1][1])});
                inputWaypoints.push({latLng: L.latLng(path.points[(path.points.length)-1][0],path.points[(path.points.length)-1][1])});
                inputWaypoints.push({latLng: L.latLng(path.points[1][0],path.points[1][1])});
                var routes={
                    name:"",
                    coordinates:coordinates,
                    inputWaypoints:inputWaypoints,
                    instructions: _convertInstructions(path.instructions),
                    summary: {
                        totalDistance: path.distance,
                        totalTime: path.time / 1000,
                    },
                    waypoints:inputWaypoints
                };
                console.log(routes);
                L.Routing.line(routes).addTo(mymap);

            }

        })

    })

 

你可能感兴趣的:(使用leaflet+graphhopper进行路径规划)