add a simple progress bar to the 50K sample

This commit is contained in:
Rasmus Schultz
2013-12-24 16:48:01 -05:00
parent 8732cb4f0a
commit 8d53c8a7c2
2 changed files with 43 additions and 3 deletions
+19 -2
View File
@@ -18,6 +18,7 @@
</head>
<body>
<div id="progress"><div id="progress-bar"></div></div>
<div id="map"></div>
<span>Mouse over a cluster to see the bounds of its children and click a cluster to zoom to those bounds</span>
<script type="text/javascript">
@@ -28,12 +29,28 @@
var map = L.map('map', { center: latlng, zoom: 13, layers: [cloudmade] });
var markers = L.markerClusterGroup({ chunkedLoading: true });
var progress = document.getElementById('progress');
var progressBar = document.getElementById('progress-bar');
function updateProgressBar(processed, total, elapsed, layersArray) {
if (elapsed > 1000) {
// if it takes more than a second to load, display the progress bar:
progress.style.display = 'block';
progressBar.style.width = Math.round(processed/total*100) + '%';
}
if (processed === total) {
// all markers processed - hide the progress bar:
progress.style.display = 'none';
}
}
var markers = L.markerClusterGroup({ chunkedLoading: true, chunkProgress: updateProgressBar });
var markerList = [];
//console.log('start creating markers: ' + window.performance.now());
for (var i = 0; i < addressPoints.length; i++) {
var a = addressPoints[i];
var title = a[2];
+24 -1
View File
@@ -2,4 +2,27 @@
width: 800px;
height: 600px;
border: 1px solid #ccc;
}
}
#progress {
display: none;
position: absolute;
z-index: 1000;
left: 400px;
top: 300px;
width: 200px;
height: 20px;
margin-top: -20px;
margin-left: -100px;
background-color: #fff;
background-color: rgba(255, 255, 255, 0.7);
border-radius: 4px;
padding: 2px;
}
#progress-bar {
width: 0;
height: 100%;
background-color: #76A6FC;
border-radius: 4px;
}