add addzone and update zone in map-adapter interface
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
Copyright (c) 2020, 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.
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
[](https://travis-ci.org/mapbox/geojson-rewind)
|
||||
|
||||
# geojson-rewind
|
||||
|
||||
The [GeoJSON](https://tools.ietf.org/html/rfc7946) specification is [picky about winding order](https://tools.ietf.org/html/rfc7946#section-3.1.6).
|
||||
|
||||
This helps you generate compliant Polygon and MultiPolygon geometries. Furthermore it lets you use [Canvas](http://www.bit-101.com/blog/?p=3702) and other drawing libraries's default behavior to color the interior rings of Polygon and MultiPolygon features.
|
||||
|
||||
## Usage
|
||||
|
||||
As NPM module:
|
||||
|
||||
npm install --save @mapbox/geojson-rewind
|
||||
|
||||
As a console utility:
|
||||
|
||||
# install
|
||||
npm install -g @mapbox/geojson-rewind
|
||||
# use
|
||||
geojson-rewind foo.geojson
|
||||
|
||||
As a browser library: [geojson-rewind.js](https://bundle.run/geojson-rewind)
|
||||
|
||||
## API
|
||||
|
||||
`rewind(geojson, clockwise)`
|
||||
|
||||
Given a GeoJSON FeatureCollection, Feature, or Geometry, return a version
|
||||
with inner and outer rings of different winding orders.
|
||||
|
||||
If `clockwise` is `true`, the outer ring is clockwise, otherwise
|
||||
it is counterclockwise.
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var rewind = require('./'),
|
||||
getStream = require('get-stream'),
|
||||
fs = require('fs'),
|
||||
argv = require('minimist')(process.argv.slice(2), {
|
||||
boolean: 'clockwise'
|
||||
});
|
||||
|
||||
const help = `
|
||||
usage:
|
||||
|
||||
geojson-rewind < foo.geojson > foo.geojson
|
||||
geojson-rewind foo.geojson > bar.geojson
|
||||
|
||||
options:
|
||||
|
||||
--clockwise
|
||||
|
||||
if specified, set outer ring to clockwise
|
||||
and inner rings to counterclockwise`.trim();
|
||||
|
||||
if (process.stdin.isTTY && !argv._[0]) {
|
||||
console.log(help);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
getStream(argv._.length ? fs.createReadStream(argv._[0]) : process.stdin)
|
||||
.then(convert);
|
||||
|
||||
function convert(data) {
|
||||
process.stdout.write(JSON.stringify(rewind(JSON.parse(data), argv.clockwise)));
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
|
||||
module.exports = rewind;
|
||||
|
||||
function rewind(gj, outer) {
|
||||
var type = gj && gj.type, i;
|
||||
|
||||
if (type === 'FeatureCollection') {
|
||||
for (i = 0; i < gj.features.length; i++) rewind(gj.features[i], outer);
|
||||
|
||||
} else if (type === 'GeometryCollection') {
|
||||
for (i = 0; i < gj.geometries.length; i++) rewind(gj.geometries[i], outer);
|
||||
|
||||
} else if (type === 'Feature') {
|
||||
rewind(gj.geometry, outer);
|
||||
|
||||
} else if (type === 'Polygon') {
|
||||
rewindRings(gj.coordinates, outer);
|
||||
|
||||
} else if (type === 'MultiPolygon') {
|
||||
for (i = 0; i < gj.coordinates.length; i++) rewindRings(gj.coordinates[i], outer);
|
||||
}
|
||||
|
||||
return gj;
|
||||
}
|
||||
|
||||
function rewindRings(rings, outer) {
|
||||
if (rings.length === 0) return;
|
||||
|
||||
rewindRing(rings[0], outer);
|
||||
for (var i = 1; i < rings.length; i++) {
|
||||
rewindRing(rings[i], !outer);
|
||||
}
|
||||
}
|
||||
|
||||
function rewindRing(ring, dir) {
|
||||
var area = 0, err = 0;
|
||||
for (var i = 0, len = ring.length, j = len - 1; i < len; j = i++) {
|
||||
var k = (ring[i][0] - ring[j][0]) * (ring[j][1] + ring[i][1]);
|
||||
var m = area + k;
|
||||
err += Math.abs(area) >= Math.abs(k) ? area - m + k : k - m + area;
|
||||
area = m;
|
||||
}
|
||||
if (area + err >= 0 !== !!dir) ring.reverse();
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "@mapbox/geojson-rewind",
|
||||
"version": "0.5.2",
|
||||
"description": "enforce winding order for geojson",
|
||||
"main": "index.js",
|
||||
"bin": "geojson-rewind",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test/rewind.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"geojson-rewind"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mapbox/geojson-rewind.git"
|
||||
},
|
||||
"keywords": [
|
||||
"geojson",
|
||||
"winding",
|
||||
"order",
|
||||
"rendering",
|
||||
"coordinates"
|
||||
],
|
||||
"author": "Tom MacWright",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mapbox/geojson-rewind/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mapbox/geojson-rewind",
|
||||
"dependencies": {
|
||||
"get-stream": "^6.0.1",
|
||||
"minimist": "^1.2.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tape": "^5.5.3"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user