How to add Leaflet Routing Machine control outside the map div

拥有回忆 提交于 2019-12-07 19:05:56

问题


Leaflet routing machine container div is displayed on the map by default and I want to put this div below the map. Any clue to do this ?


回答1:


So, you need to add a leaflet control outside the map div. Here is a solution to it.

  • Create a Div where you want to add your control and position it on page where ever you want
  • Initiate your control and add it in a variable, like in this case I did

    var control = L.Routing.control({
      waypoints: [
        L.latLng(57.74, 11.94),
        L.latLng(57.6792, 11.949)
      ]
    });
    
  • Add your control to map like below

    control._map = map;
    var controlDiv = control.onAdd(map);
    
  • Finally add your control to initially defined html div

    document.getElementById('controls').appendChild(controlDiv);
    

Here is a working fiddle




回答2:


I modified muzaffar solution, now it working much better. Thank you muzaffar!

var control = L.Routing.control({
    waypoints: [
        L.latLng(32.78186, -96.76612),
        L.latLng(32.77602, -96.80766)
    ],
    geocoder: L.Control.Geocoder.nominatim(),
    routeWhileDragging: true,
    reverseWaypoints: true,
    fitSelectedRoutes: true
});

var routeBlock = control.onAdd(map);    
document.getElementById('controls').appendChild(routeBlock);

Here if a fiddle



来源:https://stackoverflow.com/questions/32881423/how-to-add-leaflet-routing-machine-control-outside-the-map-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!