Skip to content

Commit

Permalink
promise delay for issue #131
Browse files Browse the repository at this point in the history
  • Loading branch information
David Cooley committed Feb 15, 2018
1 parent b897d56 commit b5d1ab6
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions inst/htmlwidgets/lib/markers.js
@@ -1,3 +1,9 @@
function delay(t, v) {
return new Promise(function(resolve) {
setTimeout(resolve.bind(null, v), t)
});
}

/**
* Add markers
*
Expand All @@ -16,7 +22,7 @@ function add_markers(map_id, data_markers, cluster, update_map_view, layer_id, u

createWindowObject(map_id, 'googleMarkers', layer_id);

promise_to_add_markers(map_id, data_markers, cluster, update_map_view, layer_id, use_polyline, interval).then(function() {
promise_to_add_markers(map_id, data_markers, cluster, update_map_view, layer_id, use_polyline, interval).then(function(i) {

console.log("resolving promise");

Expand All @@ -26,13 +32,9 @@ function add_markers(map_id, data_markers, cluster, update_map_view, layer_id, u
// need a delay after a setTimeout inside a promise chain
// https://stackoverflow.com/q/39538473/5977215

console.log("cluster is true, need to cluster");
console.log(layer_id);
console.log(window[map_id + 'googleMarkers' + layer_id].length);
//cluster_markers(map_id, layer_id);
window[map_id + 'googleMarkerClusterer' + layer_id] = new MarkerClusterer(window[map_id + 'map'], window[map_id + 'googleMarkers' + layer_id], {
imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});
return delay(interval * i).then(function(){
return cluster_markers(map_id, layer_id);
});
}
})
}
Expand All @@ -49,14 +51,16 @@ function promise_to_add_markers(map_id, data_markers, cluster, update_map_view,
}

if(i == Object.keys(data_markers).length) {
resolve();
resolve(i);
}

});
}


function cluster_markers(map_id, layer_id) {


window[map_id + 'googleMarkerClusterer' + layer_id] = new MarkerClusterer(window[map_id + 'map'], window[map_id + 'googleMarkers' + layer_id], {
imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});
Expand Down

0 comments on commit b5d1ab6

Please sign in to comment.