[gnome-maps] Import geojson-vt v2.1.8



commit cc5096f600986405e23df251b2bd5450dd642a44
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Sun Jan 31 17:26:16 2016 +0100

    Import geojson-vt v2.1.8
    
    From:
    https://github.com/mapbox/geojson-vt

 src/geojson-vt/convert.js |    7 ++++++-
 src/geojson-vt/index.js   |   37 +++++++++++++++++++++++--------------
 2 files changed, 29 insertions(+), 15 deletions(-)
---
diff --git a/src/geojson-vt/convert.js b/src/geojson-vt/convert.js
index 8a58c70..eda26c7 100644
--- a/src/geojson-vt/convert.js
+++ b/src/geojson-vt/convert.js
@@ -22,6 +22,11 @@ function convert(data, tolerance) {
 }
 
 function convertFeature(features, feature, tolerance) {
+    if (feature.geometry === null) {
+        // ignore features with null geometry
+        return;
+    }
+
     var geom = feature.geometry,
         type = geom.type,
         coords = geom.coordinates,
@@ -95,7 +100,7 @@ function projectPoint(p) {
         x = (p[0] / 360 + 0.5),
         y = (0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI);
 
-    y = y < -1 ? -1 :
+    y = y < 0 ? 0 :
         y > 1 ? 1 : y;
 
     return [x, y, 0];
diff --git a/src/geojson-vt/index.js b/src/geojson-vt/index.js
index b4330fe..bd0c6e5 100644
--- a/src/geojson-vt/index.js
+++ b/src/geojson-vt/index.js
@@ -59,7 +59,8 @@ GeoJSONVT.prototype.splitTile = function (features, z, x, y, cz, cx, cy) {
 
     var stack = [features, z, x, y],
         options = this.options,
-        debug = options.debug;
+        debug = options.debug,
+        solid = null;
 
     // avoid recursion by using a processing queue
     while (stack.length) {
@@ -94,9 +95,6 @@ GeoJSONVT.prototype.splitTile = function (features, z, x, y, cz, cx, cy) {
         // save reference to original geometry in tile so that we can drill down later if we stop now
         tile.source = features;
 
-        // stop tiling if the tile is solid clipped square
-        if (!options.solidChildren && isClippedSquare(tile, options.extent, options.buffer)) continue;
-
         // if it's the first-pass tiling
         if (!cz) {
             // stop tiling if we reached max zoom, or if the tile is too simple
@@ -112,6 +110,12 @@ GeoJSONVT.prototype.splitTile = function (features, z, x, y, cz, cx, cy) {
             if (x !== Math.floor(cx / m) || y !== Math.floor(cy / m)) continue;
         }
 
+        // stop tiling if the tile is solid clipped square
+        if (!options.solidChildren && isClippedSquare(tile, options.extent, options.buffer)) {
+            if (cz) solid = z; // and remember the zoom if we're drilling down
+            continue;
+        }
+
         // if we slice further down, no need to keep source geometry
         tile.source = null;
 
@@ -146,6 +150,8 @@ GeoJSONVT.prototype.splitTile = function (features, z, x, y, cz, cx, cy) {
         if (tr) stack.push(tr, z + 1, x * 2 + 1, y * 2);
         if (br) stack.push(br, z + 1, x * 2 + 1, y * 2 + 1);
     }
+
+    return solid;
 };
 
 GeoJSONVT.prototype.getTile = function (z, x, y) {
@@ -173,22 +179,25 @@ GeoJSONVT.prototype.getTile = function (z, x, y) {
         parent = this.tiles[toID(z0, x0, y0)];
     }
 
-    if (!parent) return null;
+    if (!parent || !parent.source) return null;
 
+    // if we found a parent tile containing the original geometry, we can drill down from it
     if (debug > 1) console.log('found parent tile z%d-%d-%d', z0, x0, y0);
 
-    // if we found a parent tile containing the original geometry, we can drill down from it
-    if (parent.source) {
-        if (isClippedSquare(parent, extent, options.buffer)) return transform.tile(parent, extent);
+    // it parent tile is a solid clipped square, return it instead since it's identical
+    if (isClippedSquare(parent, extent, options.buffer)) return transform.tile(parent, extent);
 
-        if (debug > 1) console.time('drilling down');
-        this.splitTile(parent.source, z0, x0, y0, z, x, y);
-        if (debug > 1) console.timeEnd('drilling down');
-    }
+    if (debug > 1) console.time('drilling down');
+    var solid = this.splitTile(parent.source, z0, x0, y0, z, x, y);
+    if (debug > 1) console.timeEnd('drilling down');
 
-    if (!this.tiles[id]) return null;
+    // one of the parent tiles was a solid clipped square
+    if (solid !== null) {
+        var m = 1 << (z - solid);
+        id = toID(solid, Math.floor(x / m), Math.floor(y / m));
+    }
 
-    return transform.tile(this.tiles[id], extent);
+    return this.tiles[id] ? transform.tile(this.tiles[id], extent) : null;
 };
 
 function toID(z, x, y) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]