-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapbox Vector Tiles loader #624
Merged
ibgreen
merged 6 commits into
visgl:master
from
jesusbotella:mapbox-vector-tiles-loader
Jan 13, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a088e60
Create mapbox-vector-tile and add @mapbox/vector-tile and pbf to depe…
jesusbotella a376ab2
Add source code
jesusbotella be81807
Add tests
jesusbotella f134804
Add docs
jesusbotella e2753c2
Fix paths, linting and add aliases for tests
jesusbotella e7a72fe
Add JSON results, and tile properties for tests
jesusbotella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo "commercial"