Skip to content
Permalink
Browse files

integrated geojson-vt

  • Loading branch information...
kilsedar
kilsedar committed Aug 13, 2017
1 parent 482d18f commit 99145152504ee1e9816cd7f08594c93af07804a6
Showing with 2,067 additions and 56 deletions.
  1. +0 −2 README.md
  2. +8 −0 libraries/geojson-vt-master/.gitignore
  3. +4 −0 libraries/geojson-vt-master/.npmignore
  4. +7 −0 libraries/geojson-vt-master/.travis.yml
  5. +15 −0 libraries/geojson-vt-master/LICENSE
  6. +149 −0 libraries/geojson-vt-master/README.md
  7. +1 −0 libraries/geojson-vt-master/debug/data/route.json
  8. +1 −0 libraries/geojson-vt-master/debug/data/tiles.json
  9. +35 −0 libraries/geojson-vt-master/debug/debug.js
  10. +24 −0 libraries/geojson-vt-master/debug/index.html
  11. +211 −0 libraries/geojson-vt-master/debug/viz.js
  12. +46 −0 libraries/geojson-vt-master/package.json
  13. +149 −0 libraries/geojson-vt-master/src/clip.js
  14. +121 −0 libraries/geojson-vt-master/src/convert.js
  15. +43 −0 libraries/geojson-vt-master/src/feature.js
  16. +242 −0 libraries/geojson-vt-master/src/index.js
  17. +74 −0 libraries/geojson-vt-master/src/simplify.js
  18. +106 −0 libraries/geojson-vt-master/src/tile.js
  19. +41 −0 libraries/geojson-vt-master/src/transform.js
  20. +56 −0 libraries/geojson-vt-master/src/wrap.js
  21. +1 −0 libraries/geojson-vt-master/test/fixtures/collection-tiles.json
  22. +10 −0 libraries/geojson-vt-master/test/fixtures/collection.json
  23. +1 −0 libraries/geojson-vt-master/test/fixtures/dateline-tiles.json
  24. +257 −0 libraries/geojson-vt-master/test/fixtures/dateline.json
  25. +4 −0 libraries/geojson-vt-master/test/fixtures/empty.json
  26. +7 −0 libraries/geojson-vt-master/test/fixtures/feature-null-geometry.json
  27. +1 −0 libraries/geojson-vt-master/test/fixtures/feature-tiles.json
  28. +13 −0 libraries/geojson-vt-master/test/fixtures/feature.json
  29. +1 −0 libraries/geojson-vt-master/test/fixtures/single-geom-tiles.json
  30. +12 −0 libraries/geojson-vt-master/test/fixtures/single-geom.json
  31. +1 −0 libraries/geojson-vt-master/test/fixtures/us-states-tiles.json
  32. +1 −0 libraries/geojson-vt-master/test/fixtures/us-states-z7-37-48.json
  33. +54 −0 libraries/geojson-vt-master/test/fixtures/us-states.json
  34. +28 −0 libraries/geojson-vt-master/test/gen-tiles.js
  35. +79 −0 libraries/geojson-vt-master/test/test-clip.js
  36. +42 −0 libraries/geojson-vt-master/test/test-full.js
  37. +38 −0 libraries/geojson-vt-master/test/test-get-tile.js
  38. +62 −0 libraries/geojson-vt-master/test/test-multi-world.js
  39. +59 −0 libraries/geojson-vt-master/test/test-simplify.js
  40. +1 −1 out/BuildingShape.html
  41. +1 −1 out/BuildingShape.js.html
  42. +1 −1 out/GeoJSONParserTriangulation.html
  43. +1 −1 out/GeoJSONParserTriangulation.js.html
  44. +1 −1 out/GeoJSONParserTriangulationOSM.html
  45. +1 −1 out/GeoJSONParserTriangulationOSM.js.html
  46. +1 −1 out/OSMBuildingLayer.html
  47. +2 −2 out/OSMBuildingLayer.js.html
  48. +1 −1 out/OSMLayer.html
  49. +3 −3 out/OSMLayer.js.html
  50. +7 −7 out/OSMTBuildingLayer.html
  51. +27 −23 out/OSMTBuildingLayer.js.html
  52. +1 −1 out/index.html
  53. +2 −1 require.conf.js
  54. +13 −9 src/OSMTBuildingLayer.js
@@ -28,8 +28,6 @@ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install nodejs
sudo npm install
sudo npm install -g karma-cli
karma start
@@ -0,0 +1,8 @@
debug/data/hrr.json
debug/data/hsa.json
debug/data/idaho.json
debug/data/zips.json
geojson-vt-dev.js
geojson-vt.js
node_modules
coverage
@@ -0,0 +1,4 @@
debug
coverage
test
.travis.yml
@@ -0,0 +1,7 @@
sudo: false
language: node_js
node_js:
- "0.12"
script:
- npm test
- npm run coveralls
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2015, Mapbox

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
@@ -0,0 +1,149 @@
## geojson-vt — GeoJSON Vector Tiles

[![Build Status](https://travis-ci.org/mapbox/geojson-vt.svg?branch=master)](https://travis-ci.org/mapbox/geojson-vt)
[![Coverage Status](https://coveralls.io/repos/mapbox/geojson-vt/badge.svg)](https://coveralls.io/r/mapbox/geojson-vt)

A highly efficient JavaScript library for **slicing GeoJSON data into vector tiles on the fly**,
primarily designed to enable rendering and interacting with large geospatial datasets
on the browser side (without a server).

Created to power GeoJSON in [Mapbox GL JS](https://github.com/mapbox/mapbox-gl-js),
but can be useful in other visualization platforms
like [Leaflet](https://github.com/Leaflet/Leaflet) and [d3](https://github.com/mbostock/d3),
as well as Node.js server applications.

Resulting tiles conform to the JSON equivalent
of the [vector tile specification](https://github.com/mapbox/vector-tile-spec/).
To make data rendering and interaction fast, the tiles are simplified,
retaining the minimum level of detail appropriate for each zoom level
(simplifying shapes, filtering out tiny polygons and polylines).

Read more on how the library works [on the Mapbox blog](https://www.mapbox.com/blog/introducing-geojson-vt/).

There's a C++11 port: [geojson-vt-cpp](https://github.com/mapbox/geojson-vt-cpp)

### Demo

Here's **geojson-vt** action in [Mapbox GL JS](https://github.com/mapbox/mapbox-gl-js),
dynamically loading a 100Mb US zip codes GeoJSON with 5.4 million points:

![](https://cloud.githubusercontent.com/assets/25395/5360312/86028d8e-7f91-11e4-811f-87f24acb09ca.gif)

There's a convenient [debug page](http://mapbox.github.io/geojson-vt/debug/) to test out **geojson-vt** on different data.
Just drag any GeoJSON on the page, watching the console.

![](https://cloud.githubusercontent.com/assets/25395/5363235/41955c6e-7fa8-11e4-9575-a66ef54cb6d9.gif)

### Usage

```js
// build an initial index of tiles
var tileIndex = geojsonvt(geoJSON);
// request a particular tile
var features = tileIndex.getTile(z, x, y).features;
// show an array of tile coordinates created so far
console.log(tileIndex.tileCoords); // [{z: 0, x: 0, y: 0}, ...]
```

### Options

You can fine-tune the results with an options object,
although the defaults are sensible and work well for most use cases.

```js
var tileIndex = geojsonvt(data, {
maxZoom: 14, // max zoom to preserve detail on
tolerance: 3, // simplification tolerance (higher means simpler)
extent: 4096, // tile extent (both width and height)
buffer: 64, // tile buffer on each side
debug: 0 // logging level (0 to disable, 1 or 2)
indexMaxZoom: 4, // max zoom in the initial tile index
indexMaxPoints: 100000, // max number of points per tile in the index
solidChildren: false // whether to include solid tile children in the index
});
```

By default, tiles at zoom levels above `indexMaxZoom` are generated on the fly, but you can pre-generate all possible tiles for `data` by setting `indexMaxZoom` and `maxZoom` to the same value, setting `indexMaxPoints` to `0`, and then accessing the resulting tile coordinates from the `tileCoords` property of `tileIndex`.

### Browser builds

```bash
npm install
npm run build-dev # development build, used by the debug page
npm run build-min # minified production build
```

### Changelog

##### 2.3.0 (Jul 29, 2016)

- Improved tiling algorithm to avoid redundant clipping when tiles are requested in an empty area.
- Fixed issues with GeoJSON that only has data above 180 or below -180 longitude.

##### 2.2.0 (Jun 9, 2016)

- Fixed ring winding order for polygons and multipolygons in accordance with vector tile specification 2.0.
- Fixed handling of features with null geometry (now ignored instead of throwing an error).

##### 2.1.8 (Nov 9, 2015)

- Fixed a bug where `getTile` would initially return `null` when requesting a child of a solid clipped square tile.

##### 2.1.7 (Oct 16, 2015)

- Expose transform methods in a separate file (`transform.js`).

##### 2.1.6 (Sep 22, 2015)

- Fixed a bug where `getTile` could generate a lot of unnecessary tiles.
- Fixed a bug where an empty GeoJSON generated tiles.

##### 2.1.5 (Aug 14, 2015)

- Added `tileCoords` property with an array of coordinates of all tiles created so far.

##### 2.1.4 (Aug 14, 2015)

- Improved `getTile` to always return `null` on non-existing or invalid tiles.

##### 2.1.3 (Aug 13, 2015)

- Added `solidChildren` option that includes children of solid filled square tiles in the index (off by default).
- Added back solid tile heuristics (not tiling solid filled square tiles further).

##### 2.1.2 (Aug 13, 2015)

- Fixed a crazy slowdown (~30x) when generating a huge number of tiles on the first run.
- Removed clipped solid square heuristics (that actually didn't work since 2.0.0).

##### 2.1.1 (June 18, 2015)

- Fixed duplicate points in polygons.

##### 2.1.0 (June 15, 2015)

- Added proper handling for features crossing or near the date line.

##### 2.0.1 (June 9, 2015)

- 10-20% faster tile indexing.
- Fixed latitude extremes not being clamped.

##### 2.0.0 (Mar 20, 2015)

- **Breaking**: `maxZoom` renamed to `indexMaxZoom`, `maxPoints` to `indexMaxPoints`, `baseZoom` to `maxZoom`.
- Improved performance of both indexing and on-demand tile requests.
- Improved memory footprint.
- Better indexing defaults.
- Fixed a bug where unnecessary memory was retained in some cases.

##### 1.1.0 (Mar 2, 2015)

- Add `buffer` and `extent` options.

##### 1.0.0 (Dec 8, 2014)

- Initial release.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,35 @@

var geojsonvt = require('../src/index.js');

console.time('load data');
var data = require('./data/hrr.json');
console.timeEnd('load data');

var tileIndex = geojsonvt(data, {
debug: 1
});

console.time('drill down');
for (var i = 0; i < 10; i++) {
for (var j = 0; j < 10; j++) {
tileIndex.getTile(7, 30 + i, 45 + j);
}
}
for (var i = 0; i < 10; i++) {
for (var j = 0; j < 10; j++) {
tileIndex.getTile(8, 60 + i, 90 + j);
}
}
for (var i = 0; i < 10; i++) {
for (var j = 0; j < 10; j++) {
tileIndex.getTile(10, 240 + i, 360 + j);
}
}
console.timeEnd('drill down');

console.log('tiles generated:', tileIndex.total, JSON.stringify(tileIndex.stats));


// tileIndex.maxZoom = 14;
// tileIndex.getTile(14, 4100, 6200);
// tileIndex.getTile(14, 4100, 6000);
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>debug page</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body { padding: 0; margin: 0; }
#canvas { border-right: 1px dotted #aaa; border-bottom: 1px dotted #aaa;}
#canvas.hover { background: #cfc; }
button { font-size: 16px; background: white; border: 1px solid #ccc;
position: absolute; top: 5px; left: 5px;}
button:hover { border-color: black; }
</style>
</head>

<body>
<script src='../geojson-vt-dev.js'></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<canvas id="canvas"></canvas>
<button id="back">&larr;</button>
<script src="viz.js"></script>
</body>
</html>
Oops, something went wrong.

0 comments on commit 9914515

Please sign in to comment.
You can’t perform that action at this time.