Skip to content

Instantly share code, notes, and snippets.

@FranckErnewein
Created October 1, 2015 08:31
Show Gist options
  • Save FranckErnewein/60e420d99ec1d7aa55d9 to your computer and use it in GitHub Desktop.
Save FranckErnewein/60e420d99ec1d7aa55d9 to your computer and use it in GitHub Desktop.
var L = window.L;
var addressPoints = window.addressPoints;
var tiles = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors, Points &copy 2012 LINZ'
}),
latlng = L.latLng(-37.82, 175.24);
var map = L.map('map', {
center: latlng,
zoom: 13,
layers: [tiles]
});
console.log(L.DivIcon.prototype);
var markers = L.markerClusterGroup({
iconCreateFunction: function createMarker(cluster) {
var markers = cluster.getAllChildMarkers();
var title = '';
for (var i = 0; i < markers.length; i++) {
title += markers[i].options.data[2] + ',';
}
return new L.DivIcon({
html: '<div class="marker">' + title + '</div>'
});
}
});
var CustomMarker = L.Marker.extend({
options: {
data: {}
}
});
function loop(i) {
var a = addressPoints[i];
var title = a[2];
var marker = new CustomMarker(new L.LatLng(a[0], a[1]), {
title: title,
data: a
});
marker.bindPopup(title);
markers.addLayer(marker);
if (addressPoints[i]) {
setTimeout(function() {
loop(i + 1);
}, 300);
}
}
loop(0);
map.addLayer(markers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment