refresh leaflet map: map container is already initialized

后端 未结 17 1114
鱼传尺愫
鱼传尺愫 2020-11-27 04:16

I have a page where given a select to the user he can switch the leaflet map I show.

After a initial leaflet map load, my problem is when i want to refresh the map.

17条回答
  •  臣服心动
    2020-11-27 04:27

    Html:

    JavaScript:

    function buildMap(lat,lon)  {
        document.getElementById('weathermap').innerHTML = "
    "; var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', osmAttribution = 'Map data © OpenStreetMap contributors,' + ' CC-BY-SA', osmLayer = new L.TileLayer(osmUrl, {maxZoom: 18, attribution: osmAttribution}); var map = new L.Map('map'); map.setView(new L.LatLng(lat,lon), 9 ); map.addLayer(osmLayer); var validatorsLayer = new OsmJs.Weather.LeafletLayer({lang: 'en'}); map.addLayer(validatorsLayer); }

    I use this:

    document.getElementById('weathermap').innerHTML = "
    ";

    to reload content of div where render map.

提交回复
热议问题