I am bringing in leaflet routing control into my map and I would like to have the route icons show up in the center of the current view. using the code below I can get the icons to show up at the center of the inital view but I cannot find a way to get the center to update
Javascript:
var route = L.Routing.control({
waypoints: [
L.latLng(map.getCenter()),
L.latLng(map.getCenter())
]
});
JQuery:
$("#route-btn").click(function(event) {
event.preventDefault();
$('.leaflet-routing-container').is(':visible') ? route.removeFrom(map) : route.addTo(map);l
});
like most of the mistakes I make it is probably something simple, any help would be welcomed.
Best Answer
Use
map.getBounds()
to obtain anLatLngBounds
Object. This object has the methodgetCenter()
, which will eventually give you anLatLng
Object, which you can use for your purpose.