0

尝试在传单地图上显示路线时遇到问题:

  L.Routing.control({
  router: L.Routing.mapbox(''),
  profile:"mapbox/driving",
  addWaypoints:false,
  waypointMode:'snap',
  routeWhileDragging: true,
  show:false,
  fitSelectedRoutes:false,
  plan:false,
  draggableWaypoints:false,
  lineOptions:{
    styles:[ {color: 'black', opacity: 0.8, weight: 6}, {color: 'red', opacity: 1, weight: 2}]
      },
  waypoints: [
    L.Routing.waypoint(L.latLng(28.6114741,77.2112497),"New Dehli"),
    L.Routing.waypoint(L.latLng(30.7304186,76.7789926),"Chandigarh"),
    L.Routing.waypoint(L.latLng(31.1047637,77.1717752),"Shimla"),
    L.Routing.waypoint(L.latLng(31.4493988,77.629702),"Rampur"),
    L.Routing.waypoint(L.latLng(31.9755409,78.5961753),"Changoa"),
    L.Routing.waypoint(L.latLng(32.2251899,78.0610693),"Kaza"),
    L.Routing.waypoint(L.latLng(32.4513357,77.860656),"Hanse"),
    L.Routing.waypoint(L.latLng(32.4386919,77.7497997),"losar gompa"),
  ],

}).addTo(map);

在第 7 个航路点(Hanse),路线正在掉头,增加一千公里到达距离只有几公里的第 8 个航路点。

这里发生了什么?我想不通。欢迎任何帮助!

4

1 回答 1

2

欢迎来到 SO!

这可以通过 OSMR 服务而不是 Mapbox 重现:

var map = L.map("map").setView([32.4513357, 77.860656], 10);

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

L.Routing.control({
  //router: L.Routing.mapbox(''),
  //profile: "mapbox/driving",
  addWaypoints: false,
  waypointMode: 'snap',
  routeWhileDragging: true,
  show: false,
  fitSelectedRoutes: false,
  plan: false,
  draggableWaypoints: false,
  lineOptions: {
    styles: [{
      color: 'black',
      opacity: 0.8,
      weight: 6
    }, {
      color: 'red',
      opacity: 1,
      weight: 2
    }]
  },
  waypoints: [
    /*L.Routing.waypoint(L.latLng(28.6114741, 77.2112497), "New Dehli"),
    L.Routing.waypoint(L.latLng(30.7304186, 76.7789926), "Chandigarh"),
    L.Routing.waypoint(L.latLng(31.1047637, 77.1717752), "Shimla"),
    L.Routing.waypoint(L.latLng(31.4493988, 77.629702), "Rampur"),
    L.Routing.waypoint(L.latLng(31.9755409, 78.5961753), "Changoa"),
    L.Routing.waypoint(L.latLng(32.2251899, 78.0610693), "Kaza"),*/
    L.Routing.waypoint(L.latLng(32.4513357, 77.860656), "Hanse"),
    L.Routing.waypoint(L.latLng(32.4386919, 77.7497997), "losar gompa"),
  ],

}).addTo(map);
#map {
  height: 200px;
}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.2.0/dist/leaflet.css">
<script src="https://unpkg.com/leaflet@1.2.0/dist/leaflet-src.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet-routing-machine@3.2.7/dist/leaflet-routing-machine.css">
<script src="https://unpkg.com/leaflet-routing-machine@3.2.7/dist/leaflet-routing-machine.js"></script>

<div id="map"></div>

看起来 OSM 数据库认为您的到达点附近有一个“障碍”障碍物(“losar gompa”):

在到达点附近捕获 OSM 编辑网站

如果这种类型的障碍物不能被汽车穿越,那就可以解释为什么路由器会选择另一条(很长的……)路线。

如果您认为这个障碍不再存在,请随时在 OpenStreetMap 上创建一个帐户并编辑地图!Mapbox 路由器很有可能使用 OSM 数据,因此您的修改将在一段时间后反映在 Mapbox 中。

于 2017-11-08T16:32:05.403 回答