public VectorTile GetTile(int z, int x, int y) { var options = this.Options; var extent = options.Extent; var debug = options.Debug; var z2 = 1 << z; x = ((x % z2) + z2) % z2; // wrap tile x coordinate var id = VectorTileCoord.ToID(z, x, y); if (Tiles.Contains(id)) { return(Transformer.TransformTile(Tiles.Get(id), extent)); } // if (debug > 1) console.log('drilling down to z%d-%d-%d', z, x, y); var z0 = z; var x0 = x; var y0 = y; VectorTile parent = null; while (parent.IsNull() && z0 > 0) { z0--; x0 = (int)Math.Floor(x0 / 2.0); y0 = (int)Math.Floor(y0 / 2.0); var tileId = VectorTileCoord.ToID(z0, x0, y0); parent = Tiles.Contains(tileId) ? Tiles.Get(tileId) : null; } if (parent.NoSource()) { 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); // it parent tile is a solid clipped square, return it instead since it's identical if (IsClippedSquare(parent, extent, options.Buffer)) { return(Transformer.TransformTile(parent, extent)); } // if (debug > 1) console.time('drilling down'); var solid = SplitTile(parent.Source, new VectorTileCoord(z0, x0, y0), z, x, y); // if (debug > 1) console.timeEnd('drilling down'); // one of the parent tiles was a solid clipped square if (solid.HasValue) { double m = 1 << (z - solid.Value); id = VectorTileCoord.ToID(solid.Value, (int)Math.Floor(x / m), (int)Math.Floor(y / m)); } return(Tiles.Contains(id) ? Transformer.TransformTile(this.Tiles.Get(id), extent) : null); }
public static bool NoSource(this VectorTile tile) { return(tile.IsNull() || tile.Source == null); }