Flyer: update map

Here is my function that I am using to draw a Leaflet card on my website:

function drawTweetMap(points) {
    if (tweetMap != null)
        tweetMap.remove();  

    var london = [51.505, -0.09];
    tweetMap = L.map('tweetMap').setView(london, 5);

    var cloudmadeUrl = 'http://{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg';
    var subDomains = ['otile1','otile2','otile3','otile4'];
    var cloudmadeAttrib = 'Data, imagery and map information provided by <a href="http://open.mapquest.co.uk" target="_blank">MapQuest</a>, <a href="http://www.openstreetmap.org/" target="_blank">OpenStreetMap</a> and contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/" target="_blank">CC-BY-SA</a>';
    L.tileLayer(cloudmadeUrl, 
                  {attribution: cloudmadeAttrib, 
                   maxZoom: 18,
                   subdomains: subDomains})
    .addTo(tweetMap);

    var markers = L.markerClusterGroup();
    var points_rand = L.geoJson(points, {onEachFeature: onEachFeature});
    markers.addLayer(points_rand);
    tweetMap.addLayer(markers);
    tweetMap.fitBounds(markers.getBounds());
}

      

This function is called periodically:

mapWatch = setInterval(function() {
    retrieveCurrentTweetPositions()},
numMinutes*60*1000);

      

in this function:

function retrieveCurrentTweetPositions() {
    var points = retrieveCurrentPositions();
    var mapInput = translatePointsInMapFormat(points);
    drawTweetMap(mapInput);
}

      

Unfortunately, if the map is drawn this way, the result is the following: enter image description here

In other questions I found that it was possible to void the map size to fix this problem, so it was suggested to call this function on startup:

function updateTweetMapPosition() { 
    setTimeout(function(){
        tweetMap.invalidateSize(true);}
    ,500)
}

      

I did this and it solves the problem during the first drawing of the map. However, when I try to redraw the map a second time, the result looks like this:

enter image description here

Has anyone experienced this problem? How can I redraw the map with full load of its contents?

Thank.


EDIT

Here is a jsFiddle: http://jsfiddle.net/qzpwvqzk/

+3


source to share


1 answer


Take a look at the method redraw()

.



0


source







All Articles