I use classic JS to display a LeaFlet MAP into a ```
function getMap(latitude,longitude){
var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osm = new L.TileLayer(osmUrl, {minZoom:2, maxZoom:19});
var googleStreets = new L.tileLayer('https://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{minZoom:1, maxZoom:19, subdomains:['mt0','mt1','mt2','mt3']});
var googleSat = new L.tileLayer('https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',{minZoom:1, maxZoom: 21,subdomains:['mt0','mt1','mt2','mt3']});
var map = new L.Map('mapDiv', { doubleClickZoom:false, zoomControl:false, maxBounds:([[90,-270],[-90,270]]) });
L.control.layers({"OSM (Mapnik)": osm, "Google Street": googleStreets, "Google Earth": googleSat}).addTo(map);
map.addLayer(osm);
var map_set = "osm";
map.setView(new L.LatLng(latitude,longitude),zoom);
}
on a button I call getMap(latitude,longitude)
and it works fine
But if I call again (with new coordinates) than I get the Error Map container is already initialized.
Now I understand I need a new function with map.setView(new L.LatLng(latitude,longitude),zoom);
but then I get map not defined. I need a prod to define the map "global" and final initializing by function and a separate function to display a point on map. Thank's for help!