add addzone and update zone in map-adapter interface
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2025 MapLibre contributors
|
||||
|
||||
Copyright (c) 2015 Anand Thakker
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Contains geojson_wrapper.js from https://github.com/mapbox/mapbox-gl-js
|
||||
|
||||
Copyright (c) 2014, Mapbox
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of Mapbox GL JS nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
[](https://maplibre.org/)
|
||||
|
||||
# vt-pbf
|
||||
[](https://www.npmjs.com/package/@maplibre/vt-pbf)
|
||||
|
||||
Serialize [Mapbox vector tiles](https://github.com/mapbox/vector-tile-spec) to binary protobufs in javascript.
|
||||
|
||||
## Installation
|
||||
Using NPM: `npm install @maplibre/vt-pbf`
|
||||
|
||||
Or `npm run build` and find build artifacts in `dist/`
|
||||
|
||||
## Usage
|
||||
|
||||
As far as I know, the two places you might get a JS representation of a vector
|
||||
tile are [geojson-vt](https://github.com/mapbox/geojson-vt) and
|
||||
[vector-tile-js](https://github.com/mapbox/vector-tile-js). These both use
|
||||
slightly different internal representations, so serializing each looks slightly
|
||||
different:
|
||||
|
||||
## From vector-tile-js
|
||||
|
||||
```javascript
|
||||
import {fromVectorTileJs} from 'vt-pbf'
|
||||
import {VectorTile} = from '@mapbox/vector-tile'
|
||||
import Protobuf from 'pbf'
|
||||
|
||||
var data = fs.readFileSync(__dirname + '/fixtures/rectangle-1.0.0.pbf')
|
||||
var tile = new VectorTile(new Protobuf(data))
|
||||
var orig = tile.layers['geojsonLayer'].feature(0).toGeoJSON(0, 0, 1)
|
||||
|
||||
var buff = fromVectorTileJs(tile)
|
||||
fs.writeFileSync('my-tile.pbf', buff)
|
||||
```
|
||||
|
||||
## From geojson-vt
|
||||
|
||||
```javascript
|
||||
import {fromGeojsonVt} from 'vt-pbf'
|
||||
import geojsonVt from 'geojson-vt'
|
||||
|
||||
var orig = JSON.parse(fs.readFileSync(__dirname + '/fixtures/rectangle.geojson'))
|
||||
var tileindex = geojsonVt(orig)
|
||||
var tile = tileindex.getTile(1, 0, 0)
|
||||
|
||||
// pass in an object mapping layername -> tile object
|
||||
var buff = fromGeojsonVt({ 'geojsonLayer': tile })
|
||||
fs.writeFileSync('my-tile.pbf', buff)
|
||||
```
|
||||
|
||||
`fromGeojsonVt` takes two arguments:
|
||||
- `layerMap` is an object where keys are layer names and values are a geojson-vt tile,
|
||||
- `options` is an object (optional argument). There are 2 supported keys: `version` to define the version of the mvt spec used and `extent` to define the extent of the tile. `version` defaults to 1 and `extent` to 4096.
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import { type GeoJSONOptions, type Feature, GeoJSONWrapper } from './lib/geojson_wrapper';
|
||||
import geojsonvt from 'geojson-vt';
|
||||
import { type VectorTile } from '@mapbox/vector-tile';
|
||||
/**
|
||||
* Serialize a vector-tile-js-created tile to pbf
|
||||
*
|
||||
* @param tile
|
||||
* @return uncompressed, pbf-serialized tile data
|
||||
*/
|
||||
export declare function fromVectorTileJs(tile: VectorTile): Uint8Array;
|
||||
/**
|
||||
* Serialized a geojson-vt-created tile to pbf.
|
||||
*
|
||||
* @param layers - An object mapping layer names to geojson-vt-created vector tile objects
|
||||
* @param options - An object specifying the vector-tile specification version and extent that were used to create `layers`.
|
||||
* @return uncompressed, pbf-serialized tile data
|
||||
*/
|
||||
export declare function fromGeojsonVt(layers: geojsonvt.Tile[], options?: GeoJSONOptions): Uint8Array;
|
||||
export { GeoJSONWrapper, GeoJSONOptions, Feature };
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import e from"pbf";import t from"@mapbox/point-geometry";import{VectorTileLayer as r,VectorTileFeature as i}from"@mapbox/vector-tile";class n extends i{constructor(t,r){super(new e,0,r,[],[]),this.feature=t,this.type=t.type,this.properties=t.tags?t.tags:{},"id"in t&&("string"==typeof t.id?this.id=parseInt(t.id,10):"number"!=typeof t.id||isNaN(t.id)||(this.id=t.id))}loadGeometry(){const e=[],r=1===this.feature.type?[this.feature.geometry]:this.feature.geometry;for(const i of r){const r=[];for(const e of i)r.push(new t(e[0],e[1]));e.push(r)}return e}}class o extends r{constructor(t,r){super(new e),this.layers={_geojsonTileLayer:this},this.name="_geojsonTileLayer",this.version=r?r.version:1,this.extent=r?r.extent:4096,this.length=t.length,this.features=t}feature(e){return new n(this.features[e],this.extent)}}function s(t){const r=new e;return function(e,t){for(const r in e.layers)t.writeMessage(3,f,e.layers[r])}(t,r),r.finish()}function a(e,t){const r={};for(const i in e)r[i]=new o(e[i].features,t),r[i].name=i,r[i].version=t?t.version:1,r[i].extent=t?t.extent:4096;return s({layers:r})}function f(e,t){t.writeVarintField(15,e.version||1),t.writeStringField(1,e.name||""),t.writeVarintField(5,e.extent||4096);const r={keys:[],values:[],keycache:{},valuecache:{}};for(let i=0;i<e.length;i++)r.feature=e.feature(i),t.writeMessage(2,u,r);const i=r.keys;for(const e of i)t.writeStringField(3,e);const n=r.values;for(const e of n)t.writeMessage(4,y,e)}function u(e,t){if(!e.feature)return;const r=e.feature;void 0!==r.id&&t.writeVarintField(1,r.id),t.writeMessage(2,c,e),t.writeVarintField(3,r.type),t.writeMessage(4,p,r)}function c(e,t){for(const r in e.feature?.properties){let i=e.feature.properties[r],n=e.keycache[r];if(null===i)continue;void 0===n&&(e.keys.push(r),n=e.keys.length-1,e.keycache[r]=n),t.writeVarint(n),"string"!=typeof i&&"boolean"!=typeof i&&"number"!=typeof i&&(i=JSON.stringify(i));const o=typeof i+":"+i;let s=e.valuecache[o];void 0===s&&(e.values.push(i),s=e.values.length-1,e.valuecache[o]=s),t.writeVarint(s)}}function l(e,t){return(t<<3)+(7&e)}function h(e){return e<<1^e>>31}function p(e,t){const r=e.loadGeometry(),i=e.type;let n=0,o=0;for(const s of r){let r=1;1===i&&(r=s.length),t.writeVarint(l(1,r));const a=3===i?s.length-1:s.length;for(let e=0;e<a;e++){1===e&&1!==i&&t.writeVarint(l(2,a-1));const r=s[e].x-n,f=s[e].y-o;t.writeVarint(h(r)),t.writeVarint(h(f)),n+=r,o+=f}3===e.type&&t.writeVarint(l(7,1))}}function y(e,t){const r=typeof e;"string"===r?t.writeStringField(1,e):"boolean"===r?t.writeBooleanField(7,e):"number"===r&&(e%1!=0?t.writeDoubleField(3,e):e<0?t.writeSVarintField(6,e):t.writeVarintField(5,e))}export{o as GeoJSONWrapper,a as fromGeojsonVt,s as fromVectorTileJs};
|
||||
//# sourceMappingURL=index.es.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+18
@@ -0,0 +1,18 @@
|
||||
import { VectorTileFeature, VectorTileLayer, type VectorTile } from '@mapbox/vector-tile';
|
||||
import type { TileFeature, AnyProps } from 'supercluster';
|
||||
import { type Feature as GeoJSONVTFeature } from 'geojson-vt';
|
||||
export type Feature = TileFeature<AnyProps, AnyProps> | GeoJSONVTFeature;
|
||||
export interface GeoJSONOptions {
|
||||
version: number;
|
||||
extent: number;
|
||||
}
|
||||
export declare class GeoJSONWrapper extends VectorTileLayer implements VectorTile {
|
||||
layers: Record<string, VectorTileLayer>;
|
||||
name: string;
|
||||
extent: number;
|
||||
length: number;
|
||||
version: number;
|
||||
features: Feature[];
|
||||
constructor(features: Feature[], options?: GeoJSONOptions);
|
||||
feature(i: number): VectorTileFeature;
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"name": "@maplibre/vt-pbf",
|
||||
"version": "4.0.3",
|
||||
"description": "Serialize mapbox vector tiles to binary protobufs in javascript.",
|
||||
"main": "dist/index.es.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "eslint index.ts lib/*.ts",
|
||||
"test-unit": "vitest run --config vitest.config.unit.ts",
|
||||
"test-unit-ci": "vitest run --config vitest.config.unit.ts --coverage",
|
||||
"build": "rollup --config rollup.config.ts --configPlugin typescript && tsc"
|
||||
},
|
||||
"author": "Anand Thakker <vestibule@anandthakker.net> (http://anandthakker.net/)",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/maplibre/vt-pbf.git"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@mapbox/point-geometry": "^1.1.0",
|
||||
"@mapbox/vector-tile": "^2.0.4",
|
||||
"@types/geojson-vt": "3.2.5",
|
||||
"@types/supercluster": "^7.1.3",
|
||||
"geojson-vt": "^4.0.2",
|
||||
"pbf": "^4.0.1",
|
||||
"supercluster": "^8.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.30.0",
|
||||
"@mapbox/geojson-fixtures": "^1.0.0",
|
||||
"@mapbox/mvt-fixtures": "^3.10.0",
|
||||
"@maplibre/vtvalidate": "^0.3.2",
|
||||
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||
"@rollup/plugin-replace": "^6.0.2",
|
||||
"@rollup/plugin-strip": "^3.0.4",
|
||||
"@rollup/plugin-terser": "^0.4.4",
|
||||
"@rollup/plugin-typescript": "^12.1.4",
|
||||
"@types/node": "^24.0.3",
|
||||
"@vitest/coverage-v8": "^3.2.4",
|
||||
"benchmark": "^2.1.4",
|
||||
"eslint": "^8.57.1",
|
||||
"eslint-config-standard": "^17.1.0",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-promise": "^6.0.0",
|
||||
"geojson-equality": "^0.2.1",
|
||||
"geojson-vt": "^4.0.2",
|
||||
"rollup": "^4.44.1",
|
||||
"standard": "^17.1.2",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.8.3",
|
||||
"typescript-eslint": "^8.35.1",
|
||||
"vite-tsconfig-paths": "^5.1.4",
|
||||
"vitest": "^3.2.4"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user