From 5ed66d22c43e310126d80e4cfff98ba356daa69f Mon Sep 17 00:00:00 2001 From: Eric Kuehne Date: Tue, 26 May 2015 14:11:13 -0700 Subject: [PATCH 1/4] added relative scaling --- src/GeoJson.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/GeoJson.js b/src/GeoJson.js index 391ddef..c3fdc27 100644 --- a/src/GeoJson.js +++ b/src/GeoJson.js @@ -12,7 +12,8 @@ ms.geoJson = function(fetch) { pointRadius = 4.5, features, tileBackground = false, - selection; + selection, + zoomWhenLoaded; container.setAttribute("fill-rule", "evenodd"); clipPath.setAttribute("id", clipId); @@ -159,7 +160,14 @@ ms.geoJson = function(fetch) { var initialScale = ""; if (scale == "fixed") { + tile.scale = geoJson.map().zoom(); initialScale = "scale(" + Math.pow(2, tile.zoom - (tile.scale = geoJson.map().zoom())) + ")"; + // console.log("setting initialScale to " + initialScale); + } + else if (scale == "relative") { + if(! zoomWhenLoaded) zoomWhenLoaded = tile.zoom; + tile.scale = geoJson.map().zoom(); + initialScale = "scale(" + Math.pow(.5, zoomWhenLoaded - tile.zoom) + ")"; } var pointUpdate = d3.select(g) @@ -199,6 +207,7 @@ ms.geoJson = function(fetch) { for (key in tiles) { if ((tile = tiles[key]).scale != zoom) { k = "scale(" + Math.pow(2, tile.zoom - zoom) + ")"; + console.log("tile.zoom = " + tile.zoom + ", zoom = " + zoom + ", scale = " + k); i = -1; n = (features = tile.features).length; while (++i < n) rescale((feature = features[i]).data, feature.element, k); @@ -206,6 +215,18 @@ ms.geoJson = function(fetch) { } } } + // else if(scale == "relative") { + // // console.log("moving"); + // for (key in tiles) { + // if ((tile = tiles[key]).scale != zoom) { + // k = "scale(" + Math.pow(2, tile.zoom - zoom) + ")"; + // i = -1; + // n = (features = tile.features).length; + // while (++i < n) rescale((feature = features[i]).data, feature.element, k); + // tile.scale = zoom; + // } + // } + // } } geoJson.tileBackground = function(x) { From aeb2cac506b9015942a500f9cd8b4800efe153bb Mon Sep 17 00:00:00 2001 From: Eric Kuehne Date: Tue, 26 May 2015 14:14:28 -0700 Subject: [PATCH 2/4] added relative scale --- src/GeoJson.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/GeoJson.js b/src/GeoJson.js index c3fdc27..435194f 100644 --- a/src/GeoJson.js +++ b/src/GeoJson.js @@ -160,9 +160,7 @@ ms.geoJson = function(fetch) { var initialScale = ""; if (scale == "fixed") { - tile.scale = geoJson.map().zoom(); initialScale = "scale(" + Math.pow(2, tile.zoom - (tile.scale = geoJson.map().zoom())) + ")"; - // console.log("setting initialScale to " + initialScale); } else if (scale == "relative") { if(! zoomWhenLoaded) zoomWhenLoaded = tile.zoom; @@ -215,18 +213,6 @@ ms.geoJson = function(fetch) { } } } - // else if(scale == "relative") { - // // console.log("moving"); - // for (key in tiles) { - // if ((tile = tiles[key]).scale != zoom) { - // k = "scale(" + Math.pow(2, tile.zoom - zoom) + ")"; - // i = -1; - // n = (features = tile.features).length; - // while (++i < n) rescale((feature = features[i]).data, feature.element, k); - // tile.scale = zoom; - // } - // } - // } } geoJson.tileBackground = function(x) { From 2e86c3023ebdaad8b21c03d5f4bcaf210009d137 Mon Sep 17 00:00:00 2001 From: Eric Kuehne Date: Tue, 26 May 2015 14:14:56 -0700 Subject: [PATCH 3/4] added relative scale --- src/GeoJson.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GeoJson.js b/src/GeoJson.js index 435194f..fddc62a 100644 --- a/src/GeoJson.js +++ b/src/GeoJson.js @@ -205,7 +205,6 @@ ms.geoJson = function(fetch) { for (key in tiles) { if ((tile = tiles[key]).scale != zoom) { k = "scale(" + Math.pow(2, tile.zoom - zoom) + ")"; - console.log("tile.zoom = " + tile.zoom + ", zoom = " + zoom + ", scale = " + k); i = -1; n = (features = tile.features).length; while (++i < n) rescale((feature = features[i]).data, feature.element, k); From 14cbcaa06f51034e4aaf693919d15e13b9777a38 Mon Sep 17 00:00:00 2001 From: Eric Kuehne Date: Tue, 26 May 2015 15:20:46 -0700 Subject: [PATCH 4/4] test typeof zoomWhenLoaded rather than compare to 0 --- mapsense.js | 8 +++++++- src/GeoJson.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mapsense.js b/mapsense.js index 7ed53fd..78db79b 100644 --- a/mapsense.js +++ b/mapsense.js @@ -1232,7 +1232,8 @@ ms.geoJson = function(fetch) { pointRadius = 4.5, features, tileBackground = false, - selection; + selection, + zoomWhenLoaded; container.setAttribute("fill-rule", "evenodd"); clipPath.setAttribute("id", clipId); @@ -1381,6 +1382,11 @@ ms.geoJson = function(fetch) { if (scale == "fixed") { initialScale = "scale(" + Math.pow(2, tile.zoom - (tile.scale = geoJson.map().zoom())) + ")"; } + else if (scale == "relative") { + if (typeof zoomWhenLoaded == 'undefined') zoomWhenLoaded = tile.zoom; + tile.scale = geoJson.map().zoom(); + initialScale = "scale(" + Math.pow(.5, zoomWhenLoaded - tile.zoom) + ")"; + } var pointUpdate = d3.select(g) .selectAll("circle") diff --git a/src/GeoJson.js b/src/GeoJson.js index fddc62a..cc6dc76 100644 --- a/src/GeoJson.js +++ b/src/GeoJson.js @@ -163,7 +163,7 @@ ms.geoJson = function(fetch) { initialScale = "scale(" + Math.pow(2, tile.zoom - (tile.scale = geoJson.map().zoom())) + ")"; } else if (scale == "relative") { - if(! zoomWhenLoaded) zoomWhenLoaded = tile.zoom; + if (typeof zoomWhenLoaded == 'undefined') zoomWhenLoaded = tile.zoom; tile.scale = geoJson.map().zoom(); initialScale = "scale(" + Math.pow(.5, zoomWhenLoaded - tile.zoom) + ")"; }