-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2e4054
commit 95fe0f5
Showing
20 changed files
with
282 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# @loaders.gl/mapbox-vector-tile | ||
|
||
This module contains a geometry loader for Mapbox Vector Tiles (MVT). | ||
|
||
[loaders.gl](https://loaders.gl/docs) is a collection of framework independent visualization-focused loaders (parsers). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# @loaders.gl/mapbox-vector-tile | ||
|
||
The `@loaders.gl/mapbox-vector-tile` module handles the [Mapbox Vector Tile](https://github.com/mapbox/vector-tile-spec) format, a protobuf encoded format that defines geospatial geometries. | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @loaders.gl/mapbox-vector-tile | ||
npm install @loaders.gl/core | ||
``` | ||
|
||
## Loaders and Writers | ||
|
||
| Loader | | ||
| ---------------------------------------------------------------------------------------------------- | | ||
| [`MapboxVectorTileLoader`](modules/mapbox-vector-tiles/docs/api-reference/mapbox-vector-tile-loader) | | ||
|
||
## Attribution | ||
|
||
The `MapboxVectorTileLoader` uses [`@mapbox/vector-tile`](https://github.com/mapbox/vector-tile-js) module under the BSD-3-Clause. |
28 changes: 28 additions & 0 deletions
28
modules/mapbox-vector-tile/docs/api-reference/mapbox-vector-tile-loader.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# MapboxVectorTileLoader | ||
|
||
Loader for the [Mapbox Vector Tile](https://docs.mapbox.com/vector-tiles/specification/) format for representation of geometry. | ||
|
||
| Loader | Characteristic | | ||
| -------------- | ------------------------------------------------------------------------- | | ||
| File Extension | `.mvt`, | | ||
| File Type | Binary | | ||
| File Format | [Mapbox Vector Tile](https://docs.mapbox.com/vector-tiles/specification/) | | ||
| Data Format | [Geometry](/docs/specifications/category-gis) | | ||
| Supported APIs | `load`, `parse`, `parseSync` | | ||
|
||
## Usage | ||
|
||
```js | ||
import {MapboxVectorTileLoader} from '@loaders.gl/mapbox-vector-tile'; | ||
import {load} from '@loaders.gl/core'; | ||
|
||
const data = await load(url, MapboxVectorTileLoader); | ||
``` | ||
|
||
## Options | ||
|
||
N/A | ||
|
||
## Attribution | ||
|
||
The `MapboxVectorTileLoader` uses [`@mapbox/vector-tile`](https://github.com/mapbox/vector-tile-js) module under the BSD-3-Clause. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@loaders.gl/mapbox-vector-tile", | ||
"description": "Loader for Mapbox Vector Tiles", | ||
"version": "2.1.0-alpha.1", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/uber-web/loaders.gl" | ||
}, | ||
"keywords": [ | ||
"geometry", | ||
"loader", | ||
"parser", | ||
"MVT", | ||
"Mapbox Vector Tiles" | ||
], | ||
"main": "dist/es5/index.js", | ||
"module": "dist/esm/index.js", | ||
"esnext": "dist/es6/index.js", | ||
"sideEffects": false, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"pre-build": "npm run build-bundle && npm run build-bundle -- --env.dev", | ||
"build-bundle": "webpack --display=minimal --config ../../scripts/bundle.config.js" | ||
}, | ||
"devDependencies": { | ||
"@mapbox/vector-tile": "^1.3.1", | ||
"pbf": "^3.2.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* global window, global */ | ||
const moduleExports = require('./index'); | ||
|
||
const _global = typeof window === 'undefined' ? global : window; | ||
_global.loaders = _global.loaders || {}; | ||
|
||
module.exports = Object.assign(_global.loaders, moduleExports); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {MapboxVectorTileLoader} from './mvt-loader'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {VectorTile} from '@mapbox/vector-tile'; | ||
import Protobuf from 'pbf'; | ||
|
||
/* | ||
* Parse MVT arrayBuffer and return GeoJSON. | ||
* | ||
* @param {arrayBuffer} _ A MVT arrayBuffer | ||
* @return {?Object} A GeoJSON geometry object | ||
*/ | ||
export default function parseMVT(input, options) { | ||
if (input.byteLength === 0) { | ||
return []; | ||
} | ||
|
||
const tile = new VectorTile(new Protobuf(input)); | ||
const features = []; | ||
|
||
for (const layerName in tile.layers) { | ||
const vectorTileLayer = tile.layers[layerName]; | ||
|
||
for (let i = 0; i < vectorTileLayer.length; i++) { | ||
const vectorTileFeature = vectorTileLayer.feature(i); | ||
|
||
const feature = vectorTileFeature.toGeoJSON( | ||
options.tileProperties.x, | ||
options.tileProperties.y, | ||
options.tileProperties.z | ||
); | ||
|
||
features.push(feature); | ||
} | ||
} | ||
|
||
return features; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* global __VERSION__ */ // __VERSION__ is injected by babel-plugin-version-inline | ||
import parseMVT from './lib/parse-mvt'; | ||
|
||
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest'; | ||
|
||
export const MapboxVectorTileLoader = { | ||
id: 'mvt', | ||
name: 'Mapbox Vector Tile', | ||
version: VERSION, | ||
extensions: ['mvt'], | ||
mimeType: 'application/x-protobuf', | ||
category: 'geometry', | ||
parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options), | ||
parseSync: parseMVT, | ||
binary: true, | ||
testText: null, | ||
options: { | ||
mvt: { | ||
tileProperties: {} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Data Attribution | ||
|
||
- gadm_usa_3-0-3.mvt from GADM which is free for non-comercial use |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './mvt/mvt-points.spec'; | ||
import './mvt/mvt-lines.spec'; | ||
import './mvt/mvt-polygons.spec'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* eslint-disable */ | ||
|
||
import test from 'tape-promise/tape'; | ||
import {MVTLoader} from '@loaders.gl/mapbox-vector-tile'; | ||
import {fetchFile, parse} from '@loaders.gl/core'; | ||
|
||
import decodedGeoJSON from '../results/decoded_mvt_lines.json'; | ||
|
||
const MVT_LINES_DATA_URL = '@loaders.gl/mapbox-vector-tile/test/data/lines_generated_5-16-11.mvt'; | ||
|
||
test('Lines MVT', async t => { | ||
const response = await fetchFile(MVT_LINES_DATA_URL); | ||
const mvtArrayBuffer = await response.arrayBuffer(); | ||
|
||
const loaderOptions = { | ||
tileProperties: { | ||
x: 16, | ||
y: 11, | ||
z: 5 | ||
} | ||
}; | ||
|
||
t.deepEqual(parse(mvtArrayBuffer, MVTLoader, loaderOptions), decodedGeoJSON); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* eslint-disable */ | ||
|
||
import test from 'tape-promise/tape'; | ||
import {MVTLoader} from '@loaders.gl/mapbox-vector-tile'; | ||
import {fetchFile, parse} from '@loaders.gl/core'; | ||
|
||
import decodedGeoJSON from '../results/decoded_mvt_points.json'; | ||
|
||
const MVT_POINTS_DATA_URL = '@loaders.gl/mapbox-vector-tile/test/data/points_generated_2-0-1.mvt'; | ||
|
||
test('Point MVT', async t => { | ||
const response = await fetchFile(MVT_POINTS_DATA_URL); | ||
const mvtArrayBuffer = await response.arrayBuffer(); | ||
|
||
const loaderOptions = { | ||
tileProperties: { | ||
x: 0, | ||
y: 1, | ||
z: 2 | ||
} | ||
}; | ||
|
||
t.deepEqual(parse(mvtArrayBuffer, MVTLoader, loaderOptions), decodedGeoJSON); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* eslint-disable */ | ||
|
||
import test from 'tape-promise/tape'; | ||
import {MVTLoader} from '@loaders.gl/mapbox-vector-tile'; | ||
import {fetchFile, parse} from '@loaders.gl/core'; | ||
|
||
import decodedGeoJSON from '../results/decoded_mvt_polygons.json'; | ||
|
||
const MVT_POLYGONS_DATA_URL = '@loaders.gl/mapbox-vector-tile/test/data/gadm_usa_3-0-3.mvt'; | ||
|
||
test('Polygons MVT', async t => { | ||
const response = await fetchFile(MVT_POLYGONS_DATA_URL); | ||
const mvtArrayBuffer = await response.arrayBuffer(); | ||
|
||
const loaderOptions = { | ||
tileProperties: { | ||
x: 0, | ||
y: 3, | ||
z: 3 | ||
} | ||
}; | ||
|
||
t.deepEqual(parse(mvtArrayBuffer, MVTLoader, loaderOptions), decodedGeoJSON); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters