[Pkg-javascript-commits] [leaflet-markercluster] 08/219: instrument time elapsed and report progress
Jonas Smedegaard
dr at jones.dk
Sat May 7 09:39:06 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository leaflet-markercluster.
commit 8732cb4f0a416c220084912a7a4e0b287532a3e1
Author: Rasmus Schultz <rasmus at mindplay.dk>
Date: Tue Dec 24 16:47:21 2013 -0500
instrument time elapsed and report progress
---
dist/leaflet.markercluster-src.js | 37 ++++++++++++++++++++++++++-----------
dist/leaflet.markercluster.js | 2 +-
src/MarkerClusterGroup.js | 37 ++++++++++++++++++++++++++-----------
3 files changed, 53 insertions(+), 23 deletions(-)
diff --git a/dist/leaflet.markercluster-src.js b/dist/leaflet.markercluster-src.js
index 2993348..c1c930c 100644
--- a/dist/leaflet.markercluster-src.js
+++ b/dist/leaflet.markercluster-src.js
@@ -32,9 +32,11 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
//Increase to increase the distance away that spiderfied markers appear from the center
spiderfyDistanceMultiplier: 1,
- //When bulk adding layers, runs chunks at a time. Means addLayers may not add all the layers in the call, others will be loaded during setTimeouts
+ // When bulk adding layers, adds markers in chunks. Means addLayers may not add all the layers in the call, others will be loaded during setTimeouts
chunkedLoading: false,
- chunkSize: 500,
+ chunkInterval: 200, // process markers for a maximum of ~ n milliseconds (then trigger the chunkProgress callback)
+ chunkDelay: 50, // at the end of each interval, give n milliseconds back to system/browser
+ chunkProgress: null, // progress callback: function(processed, total, elapsed) (e.g. for a progress indicator)
//Options to pass to the L.Polygon constructor
polygonOptions: {}
@@ -164,15 +166,25 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
addLayers: function (layersArray) {
var fg = this._featureGroup,
npg = this._nonPointGroup,
- chunkSize = this.options.chunkSize,
+ chunkInterval = this.options.chunkInterval,
+ chunkProgress = this.options.chunkProgress,
newMarkers, i, l, m;
if (this._map) {
- var start = 0;
- var end = this.options.chunkedLoading && chunkSize < layersArray.length ? chunkSize : layersArray.length;
+ var offset = 0,
+ started = (new Date()).getTime();
var process = L.bind(function () {
- for (i = start; i < end; i++) {
- m = layersArray[i];
+ var start = (new Date()).getTime();
+ for (; offset < layersArray.length; offset++) {
+ if (offset % 200 === 0) {
+ // every couple hundred markers, instrument the time elapsed since processing started:
+ var elapsed = (new Date()).getTime() - start;
+ if (elapsed > chunkInterval) {
+ break; // been working too hard, time to take a break :-)
+ }
+ }
+
+ m = layersArray[offset];
//Not point data, can't be clustered
if (!m.getLatLng) {
@@ -196,7 +208,12 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
}
}
- if (end === layersArray.length) {
+ if (chunkProgress) {
+ // report progress and time elapsed:
+ chunkProgress(offset, layersArray.length, (new Date()).getTime() - started);
+ }
+
+ if (offset === layersArray.length) {
//Update the icons of all those visible clusters that were affected
this._featureGroup.eachLayer(function (c) {
if (c instanceof L.MarkerCluster && c._iconNeedsUpdate) {
@@ -206,9 +223,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds);
} else {
- start = end;
- end = Math.min(end + chunkSize, layersArray.length);
- setTimeout(process, 0);
+ setTimeout(process, this.options.chunkDelay);
}
}, this);
diff --git a/dist/leaflet.markercluster.js b/dist/leaflet.markercluster.js
index 3ff065f..541a968 100644
--- a/dist/leaflet.markercluster.js
+++ b/dist/leaflet.markercluster.js
@@ -3,4 +3,4 @@
https://github.com/Leaflet/Leaflet.markercluster
(c) 2012-2013, Dave Leaver, smartrak
*/
-!function(t,e){L.MarkerClusterGroup=L.FeatureGroup.extend({options:{maxClusterRadius:80,iconCreateFunction:null,spiderfyOnMaxZoom:!0,showCoverageOnHover:!0,zoomToBoundsOnClick:!0,singleMarkerMode:!1,disableClusteringAtZoom:null,removeOutsideVisibleBounds:!0,animateAddingMarkers:!1,spiderfyDistanceMultiplier:1,chunkedLoading:!1,chunkSize:500,polygonOptions:{}},initialize:function(t){L.Util.setOptions(this,t),this.options.iconCreateFunction||(this.options.iconCreateFunction=this._defaultIc [...]
\ No newline at end of file
+!function(t,e){L.MarkerClusterGroup=L.FeatureGroup.extend({options:{maxClusterRadius:80,iconCreateFunction:null,spiderfyOnMaxZoom:!0,showCoverageOnHover:!0,zoomToBoundsOnClick:!0,singleMarkerMode:!1,disableClusteringAtZoom:null,removeOutsideVisibleBounds:!0,animateAddingMarkers:!1,spiderfyDistanceMultiplier:1,chunkedLoading:!1,chunkInterval:200,chunkDelay:50,chunkProgress:null,polygonOptions:{}},initialize:function(t){L.Util.setOptions(this,t),this.options.iconCreateFunction||(this.optio [...]
\ No newline at end of file
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index dfa0bd0..a647c47 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -27,9 +27,11 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
//Increase to increase the distance away that spiderfied markers appear from the center
spiderfyDistanceMultiplier: 1,
- //When bulk adding layers, runs chunks at a time. Means addLayers may not add all the layers in the call, others will be loaded during setTimeouts
+ // When bulk adding layers, adds markers in chunks. Means addLayers may not add all the layers in the call, others will be loaded during setTimeouts
chunkedLoading: false,
- chunkSize: 500,
+ chunkInterval: 200, // process markers for a maximum of ~ n milliseconds (then trigger the chunkProgress callback)
+ chunkDelay: 50, // at the end of each interval, give n milliseconds back to system/browser
+ chunkProgress: null, // progress callback: function(processed, total, elapsed) (e.g. for a progress indicator)
//Options to pass to the L.Polygon constructor
polygonOptions: {}
@@ -159,15 +161,25 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
addLayers: function (layersArray) {
var fg = this._featureGroup,
npg = this._nonPointGroup,
- chunkSize = this.options.chunkSize,
+ chunkInterval = this.options.chunkInterval,
+ chunkProgress = this.options.chunkProgress,
newMarkers, i, l, m;
if (this._map) {
- var start = 0;
- var end = this.options.chunkedLoading && chunkSize < layersArray.length ? chunkSize : layersArray.length;
+ var offset = 0,
+ started = (new Date()).getTime();
var process = L.bind(function () {
- for (i = start; i < end; i++) {
- m = layersArray[i];
+ var start = (new Date()).getTime();
+ for (; offset < layersArray.length; offset++) {
+ if (offset % 200 === 0) {
+ // every couple hundred markers, instrument the time elapsed since processing started:
+ var elapsed = (new Date()).getTime() - start;
+ if (elapsed > chunkInterval) {
+ break; // been working too hard, time to take a break :-)
+ }
+ }
+
+ m = layersArray[offset];
//Not point data, can't be clustered
if (!m.getLatLng) {
@@ -191,7 +203,12 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
}
}
- if (end === layersArray.length) {
+ if (chunkProgress) {
+ // report progress and time elapsed:
+ chunkProgress(offset, layersArray.length, (new Date()).getTime() - started);
+ }
+
+ if (offset === layersArray.length) {
//Update the icons of all those visible clusters that were affected
this._featureGroup.eachLayer(function (c) {
if (c instanceof L.MarkerCluster && c._iconNeedsUpdate) {
@@ -201,9 +218,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds);
} else {
- start = end;
- end = Math.min(end + chunkSize, layersArray.length);
- setTimeout(process, 0);
+ setTimeout(process, this.options.chunkDelay);
}
}, this);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet-markercluster.git
More information about the Pkg-javascript-commits
mailing list