refresh leaflet map: map container is already initialized

后端 未结 17 1053
鱼传尺愫
鱼传尺愫 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:28

    I had the same problem on angular when switching page. I had to add this code before leaving the page to make it works:

        $scope.$on('$locationChangeStart', function( event ) {
        if(map != undefined)
        {
          map.remove();
          map = undefined
          document.getElementById('mapLayer').innerHTML = "";
        }
    });
    

    Without document.getElementById('mapLayer').innerHTML = "" the map was not displayed on the next page.

提交回复
热议问题