1

All of the examples of Leaflet routing control display the result (iterenary) inside the map area. enter image description here

I want to display it outside in a div or table element. There is ItineraryBuilder in the API but no example on how to use it.

My code

routing = L.Routing.control({
        waypoints: [
            L.latLng(37.56569, 22.8),
            L.latLng(37.56569, 22.7)
        ],
        routeWhileDragging: true,
        itineraryFormatter: "test"
    }).addTo(map);

I want the iterenary to be displayed in textarea below Path Data

<div class="form-group">
    <label for="path-results">Path data</label>
    <textarea class="form-control form-control-sm test" readonly id="path-results" rows="8"></textarea>
</div>
1
  • 1
    Coding questions on GIS SE site require relevant existing code to be included in the question, otherwise you are risking it to be closed as not compliant with the site policy.
    – TomazicM
    Jan 2, 2021 at 19:32

1 Answer 1

0

There is no straightforward 'official' method to achieve this, but it can be done with a little bit of hacking.

L.Routing.control is extension of standard Leaflet L.control, which has .getContainer() method to retrieve HTML element containing control. With the help of DOM standard methods .removeChild() and .appendChild(), this control element can be then moved inside desired HTML element.

Code could then look something like this:

var routing = L.Routing.control({
  waypoints: [
    L.latLng(37.56569, 22.8),
    L.latLng(37.56569, 22.7)
  ],
  routeWhileDragging: true,
  itineraryFormatter: "test"
}).addTo(map);

var routingControlContainer = routing.getContainer();
var controlContainerParent = routingControlContainer.parentNode;
controlContainerParent.removeChild(routingControlContainer);
var itineraryDiv = document.getElementById('path-results');
itineraryDiv.appendChild(routingControlContainer);
3
  • It worked but the size of my div did not match with the routing container
    – neogeomat
    Jan 3, 2021 at 9:56
  • Since you didn't gave info about form-control, form-control-sm and test CSS classes, I couldn't check output on your actual situation. Since this is pure HTML CSS problem, I deem that on the basis of the info given in the question, you question was answered.
    – TomazicM
    Jan 3, 2021 at 10:20
  • i removed 'leaflet-routing-container' class and it worked. routingControlContainer.removeAttribute('class', 'leaflet-routing-container');
    – neogeomat
    Jan 3, 2021 at 13:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.