Permalink
Browse files

enabled pyramid loading (optional), fixed Coordinate.toKey()

  • Loading branch information...
1 parent 6c1b212 commit 1b3a646c082fee42851f22ba5ed77f92bbcac461 @RandomEtc RandomEtc committed Feb 8, 2011
Showing with 76 additions and 77 deletions.
  1. +4 −0 CHANGELOG
  2. +4 −1 examples/zoompan/index.html
  3. +33 −37 modestmaps.js
  4. +2 −2 modestmaps.min.js
  5. +3 −15 src/coordinate.js
  6. +29 −21 src/map.js
  7. +1 −1 src/start.js
View
@@ -8,6 +8,10 @@ Following the semantic versioning recommendation best we can:
minor version, and backwards incompatible API changes increment
the major version." -- http://semver.org/
+v0.14.0
+ - added map.enablePyramidLoading flag for pyramid loading (off by default)
+ - fixed Coordinate.prototype.toKey (back to string join to avoid collisions)
+
v0.13.5
- changed the order of initialization so that event handlers go last
(this is so that attributes like layerParent are in place for complex
@@ -14,6 +14,7 @@
var provider = new com.modestmaps.TemplatedMapProvider(template, subdomains);
map = new com.modestmaps.Map('map', provider);
+ map.enablePyramidLoading = true;
map.setCenterZoom(new com.modestmaps.Location(37.811530, -122.2666097), 14);
@@ -117,6 +118,7 @@
var t0 = Date.now();
var interval = setInterval(function() {
var t1 = Date.now();
+ var frameInterval = t1;
var t = (t1 - t0) / 1000.0;
var s = V * t;
if (s > S) {
@@ -126,7 +128,8 @@
var us = u(s);
var pos = lerp2(c0,c1,(us-u0)/(u1-u0));
applyPos(pos, w(s));
- }, 40);
+ console.log(Date.now() - frameInterval);
+ }, 100);
}
View
@@ -1,5 +1,5 @@
/*!
- * Modest Maps JS v0.13.5
+ * Modest Maps JS v0.14.0
* http://modestmaps.com/
*
* Copyright (c) 2010 Stamen Design, All Rights Reserved.
@@ -130,22 +130,10 @@ if (!com) {
+ this.zoom.toFixed(3) + ")";
},
- /* hopfully/somewhat optimized because firebug
- said we were spending a lot of time in toString() */
toKey: function() {
- var a = Math.floor(this.row);
- var b = Math.floor(this.column);
- var c = Math.floor(this.zoom);
- a=a-b; a=a-c; a=a^(c >>> 13);
- b=b-c; b=b-a; b=b^(a << 8);
- c=c-a; c=c-b; c=c^(b >>> 13);
- a=a-b; a=a-c; a=a^(c >>> 12);
- b=b-c; b=b-a; b=b^(a << 16);
- c=c-a; c=c-b; c=c^(b >>> 5);
- a=a-b; a=a-c; a=a^(c >>> 3);
- b=b-c; b=b-a; b=b^(a << 10);
- c=c-a; c=c-b; c=c^(b >>> 15);
- return c;
+ /* there used to be a clever hash function here but there were collisions.
+ TODO: optimize, but test for collisions properly :) */
+ return [ Math.floor(this.zoom), Math.floor(this.column), Math.floor(this.row) ].join(',');
},
copy: function() {
@@ -1019,6 +1007,8 @@ if (!com) {
this.setProvider(provider);
+ this.enablePyramidLoading = false;
+
this.callbackManager = new MM.CallbackManager(this, [ 'zoomed', 'panned', 'centered', 'extentset', 'resized', 'drawn' ]);
// set up handlers last so that all required attributes/functions are in place if needed
@@ -1414,35 +1404,41 @@ if (!com) {
}
// look for a parent tile in our image cache
var tileCovered = false;
- for (var pz = 1; pz <= 5; pz++) {
+ var maxStepsOut = tileCoord.zoom;
+ for (var pz = 1; pz <= maxStepsOut; pz++) {
var parentCoord = tileCoord.zoomBy(-pz).container();
var parentKey = parentCoord.toKey();
-
- // only mark it valid if we have it already
- if (parentKey in this.tiles) {
+
+ if (this.enablePyramidLoading) {
+ // mark all parent tiles valid
validTileKeys[parentKey] = true;
tileCovered = true;
- break;
+ var parentLayer = this.createOrGetLayer(parentCoord.zoom);
+ //parentLayer.coordinate = parentCoord.copy();
+ if (parentKey in this.tiles) {
+ var parentTile = this.tiles[parentKey];
+ if (parentTile.parentNode != parentLayer) {
+ parentLayer.appendChild(parentTile);
+ }
+ }
+ else if (!this.requestManager.hasRequest(parentKey)) {
+ // force load of parent tiles we don't already have
+ var tileURL = this.provider.getTileUrl(parentCoord);
+ this.requestManager.requestTile(parentKey, parentCoord, tileURL);
+ }
}
-
- /* pyramid load would look like this:
- validTileKeys[parentKey] = true;
- var parentLayer = this.createOrGetLayer(parentCoord.zoom);
- parentLayer.coordinate = parentCoord.copy();
- if (parentKey in this.tiles) {
- var parentTile = this.tiles[parentKey];
- if (parentTile.parentNode != parentLayer) {
- parentLayer.appendChild(parentTile);
- }
+ else {
+ // only mark it valid if we have it already
+ if (parentKey in this.tiles) {
+ validTileKeys[parentKey] = true;
+ tileCovered = true;
+ break;
+ }
}
- else if (!this.requestManager.hasRequest(parentKey)) {
- var tileURL = this.provider.getTileUrl(tileCoord);
- this.requestManager.requestTile(parentKey, parentCoord, tileURL);
- }//*/
}
// if we didn't find a parent, look at the children:
- if (!tileCovered) {
+ /*if (!tileCovered) {
var childCoord = tileCoord.zoomBy(1);
// mark everything valid whether or not we have it:
validTileKeys[childCoord.toKey()] = true;
@@ -1452,7 +1448,7 @@ if (!com) {
validTileKeys[childCoord.toKey()] = true;
childCoord.column -= 1;
validTileKeys[childCoord.toKey()] = true;
- }
+ }*/
}
}
}
View
Oops, something went wrong.
View
@@ -17,22 +17,10 @@
+ this.zoom.toFixed(3) + ")";
},
- /* hopfully/somewhat optimized because firebug
- said we were spending a lot of time in toString() */
toKey: function() {
- var a = Math.floor(this.row);
- var b = Math.floor(this.column);
- var c = Math.floor(this.zoom);
- a=a-b; a=a-c; a=a^(c >>> 13);
- b=b-c; b=b-a; b=b^(a << 8);
- c=c-a; c=c-b; c=c^(b >>> 13);
- a=a-b; a=a-c; a=a^(c >>> 12);
- b=b-c; b=b-a; b=b^(a << 16);
- c=c-a; c=c-b; c=c^(b >>> 5);
- a=a-b; a=a-c; a=a^(c >>> 3);
- b=b-c; b=b-a; b=b^(a << 10);
- c=c-a; c=c-b; c=c^(b >>> 15);
- return c;
+ /* there used to be a clever hash function here but there were collisions.
+ TODO: optimize, but test for collisions properly :) */
+ return [ Math.floor(this.zoom), Math.floor(this.column), Math.floor(this.row) ].join(',');
},
copy: function() {
View
@@ -104,6 +104,8 @@
this.setProvider(provider);
+ this.enablePyramidLoading = false;
+
this.callbackManager = new MM.CallbackManager(this, [ 'zoomed', 'panned', 'centered', 'extentset', 'resized', 'drawn' ]);
// set up handlers last so that all required attributes/functions are in place if needed
@@ -499,35 +501,41 @@
}
// look for a parent tile in our image cache
var tileCovered = false;
- for (var pz = 1; pz <= 5; pz++) {
+ var maxStepsOut = tileCoord.zoom;
+ for (var pz = 1; pz <= maxStepsOut; pz++) {
var parentCoord = tileCoord.zoomBy(-pz).container();
var parentKey = parentCoord.toKey();
-
- // only mark it valid if we have it already
- if (parentKey in this.tiles) {
+
+ if (this.enablePyramidLoading) {
+ // mark all parent tiles valid
validTileKeys[parentKey] = true;
tileCovered = true;
- break;
+ var parentLayer = this.createOrGetLayer(parentCoord.zoom);
+ //parentLayer.coordinate = parentCoord.copy();
+ if (parentKey in this.tiles) {
+ var parentTile = this.tiles[parentKey];
+ if (parentTile.parentNode != parentLayer) {
+ parentLayer.appendChild(parentTile);
+ }
+ }
+ else if (!this.requestManager.hasRequest(parentKey)) {
+ // force load of parent tiles we don't already have
+ var tileURL = this.provider.getTileUrl(parentCoord);
+ this.requestManager.requestTile(parentKey, parentCoord, tileURL);
+ }
}
-
- /* pyramid load would look like this:
- validTileKeys[parentKey] = true;
- var parentLayer = this.createOrGetLayer(parentCoord.zoom);
- parentLayer.coordinate = parentCoord.copy();
- if (parentKey in this.tiles) {
- var parentTile = this.tiles[parentKey];
- if (parentTile.parentNode != parentLayer) {
- parentLayer.appendChild(parentTile);
- }
+ else {
+ // only mark it valid if we have it already
+ if (parentKey in this.tiles) {
+ validTileKeys[parentKey] = true;
+ tileCovered = true;
+ break;
+ }
}
- else if (!this.requestManager.hasRequest(parentKey)) {
- var tileURL = this.provider.getTileUrl(tileCoord);
- this.requestManager.requestTile(parentKey, parentCoord, tileURL);
- }//*/
}
// if we didn't find a parent, look at the children:
- if (!tileCovered) {
+ /*if (!tileCovered) {
var childCoord = tileCoord.zoomBy(1);
// mark everything valid whether or not we have it:
validTileKeys[childCoord.toKey()] = true;
@@ -537,7 +545,7 @@
validTileKeys[childCoord.toKey()] = true;
childCoord.column -= 1;
validTileKeys[childCoord.toKey()] = true;
- }
+ }*/
}
}
}
View
@@ -1,5 +1,5 @@
/*!
- * Modest Maps JS v0.13.5
+ * Modest Maps JS v0.14.0
* http://modestmaps.com/
*
* Copyright (c) 2010 Stamen Design, All Rights Reserved.

0 comments on commit 1b3a646

Please sign in to comment.