Reputation: 27
How to set the marker exactly to the center of the map div block the marker moves to the right side and is not visible.
<div id="map" #map >
</div>
this.map = L.map('map', {
center: [20.5937, 78.9629],
zoom: 5,
zoomControl: true,
trackResize: true,
});
const that = this;
this.map.flyTo(new L.LatLng(20.5937, 78.9629), 15, { animation: true });
how to center exactly to center of the screen
Upvotes: 0
Views: 1752
Reputation: 11338
You can read out the center of the map. map.getCenter()
var marker = L.marker(map.getCenter()).addTo(map)
If you want that you marker is always centered, also after moving:
map.on('move',function(e){
marker .setLatLng(map.getCenter());
map._renderer._update();
});
http://jsfiddle.net/falkedesign/f0p5rj89/
Upvotes: 3