Маршрутизатор листовки

1

Я пытаюсь использовать Machine Routing Machine для отображения маршрута между двумя точками. Я реализовал эти функции точно так же, как в примере на веб-сайте поставщика плагинов. Я получаю два маркера, но путь не отображается.

<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
  <head profile="http://gmpg.org/xfn/11">
    <title>Wanderrouten24</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css"   href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
    <link rel="stylesheet" href="leaflet-routing-machine-3.2.7/dist/leaflet-routing-machine.css" />
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js'></script>
    <script type='text/javascript' src='http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js'></script>
    <script src="leaflet-routing-machine-3.2.7/dist/leaflet-routing-machine.js"></script>
  </head>
  <body>
  <div id="map" style="width: 800px; height: 440px; border: 1px solid #AAA;"></div>
    <script type='text/javascript' src='maps/createRoute.js'></script>
  </body>
</html>

JS:

var map = L.map( 'map', {
  center: [20.0, 5.0],
  minZoom: 2,
  zoom: 2
});

L.Routing.control({
  waypoints: [
      L.latLng(49.47748, 8.42216),
      L.latLng(49.47648, 8.32216)
  ],
  routeWhileDragging: true
}).addTo(map);

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

map.setView([49.47748, 8.42216], 15);

map.locate({setView: true, watch: true}) /* This will return map so you can do chaining */
.on('locationfound', function(e){})
.on('locationerror', function(e){
    console.log(e);
    alert("Location access denied.");
});
Теги:
leaflet
web
routing

1 ответ

0
Лучший ответ

Скорее всего, вы получите эту ошибку:

TypeError: Невозможно прочитать "маневр" свойств неопределенного

поскольку библиотека leaflet-routing-machine не совместима с leaflet v0.7.7, здесь приведена аналогичная проблема.

Таким образом, решение будет заключаться в том, чтобы обновить leaflet до версии 1.0.0 или выше, после того, как обновление маршрута должно быть напечатано, как ожидается, вот демонстрационная версия

Ещё вопросы

Сообщество Overcoder
Наверх
Меню