New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@2gis/geojson-vt

Package Overview
Dependencies
Maintainers
9
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@2gis/geojson-vt - npm Package Compare versions

Comparing version 3.2.3 to 3.3.0

262

geojson-vt-dev.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.geojsonvt = {}));
(global = global || self, factory(global.geojsonvt = {}));
}(this, (function (exports) { 'use strict';

@@ -9,3 +9,6 @@

function simplify(coords, first, last, sqTolerance) {
function simplify(coords, first, last, sqTolerance, dimensions) {
if ( dimensions === void 0 ) dimensions = 2;
var stride = dimensions + 1;
var maxSqDist = sqTolerance;

@@ -21,3 +24,3 @@ var mid = (last - first) >> 1;

for (var i = first + 3; i < last; i += 3) {
for (var i = first + stride; i < last; i += stride) {
var d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);

@@ -42,5 +45,5 @@

if (maxSqDist > sqTolerance) {
if (index - first > 3) { simplify(coords, first, index, sqTolerance); }
if (index - first > stride) { simplify(coords, first, index, sqTolerance, dimensions); }
coords[index + 2] = maxSqDist;
if (last - index > 3) { simplify(coords, index, last, sqTolerance); }
if (last - index > stride) { simplify(coords, index, last, sqTolerance, dimensions); }
}

@@ -75,3 +78,5 @@ }

function createFeature(id, type, geom, tags, index) {
function createFeature(id, type, geom, tags, index, stride) {
if ( stride === void 0 ) stride = 3;
var feature = {

@@ -90,7 +95,7 @@ id: id == null ? null : id,

if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
calcLineBBox(feature, geom);
calcLineBBox(feature, geom, stride);
} else if (type === 'Polygon') {
// the outer ring (ie [0]) contains all inner rings
calcLineBBox(feature, geom[0]);
calcLineBBox(feature, geom[0], stride);

@@ -101,3 +106,3 @@ } else if (type === 'MultiLineString') {

calcLineBBox(feature, line);
calcLineBBox(feature, line, stride);
}

@@ -110,3 +115,3 @@

calcLineBBox(feature, polygon[0]);
calcLineBBox(feature, polygon[0], stride);
}

@@ -118,4 +123,6 @@ }

function calcLineBBox(feature, geom) {
for (var i = 0; i < geom.length; i += 3) {
function calcLineBBox(feature, geom, stride) {
if ( stride === void 0 ) stride = 3;
for (var i = 0; i < geom.length; i += stride) {
feature.minX = Math.min(feature.minX, geom[i]);

@@ -162,3 +169,3 @@ feature.minY = Math.min(feature.minY, geom[i + 1]);

if (type === 'Point') {
convertPoint(coords, geometry);
convertPoint(coords, geometry, options.dimensions);

@@ -169,7 +176,7 @@ } else if (type === 'MultiPoint') {

convertPoint(p, geometry);
convertPoint(p, geometry, options.dimensions);
}
} else if (type === 'LineString') {
convertLine(coords, geometry, tolerance, false);
convertLine(coords, geometry, tolerance, false, options.dimensions);

@@ -183,12 +190,12 @@ } else if (type === 'MultiLineString') {

geometry = [];
convertLine(line, geometry, tolerance, false);
features.push(createFeature(id, 'LineString', geometry, geojson.properties, index));
convertLine(line, geometry, tolerance, false, options.dimensions);
features.push(createFeature(id, 'LineString', geometry, geojson.properties, index, options.dimensions + 1));
}
return;
} else {
convertLines(coords, geometry, tolerance, false);
convertLines(coords, geometry, tolerance, false, options.dimensions);
}
} else if (type === 'Polygon') {
convertLines(coords, geometry, tolerance, true);
convertLines(coords, geometry, tolerance, true, options.dimensions);

@@ -200,3 +207,3 @@ } else if (type === 'MultiPolygon') {

var newPolygon = [];
convertLines(polygon, newPolygon, tolerance, true);
convertLines(polygon, newPolygon, tolerance, true, options.dimensions);
geometry.push(newPolygon);

@@ -219,10 +226,17 @@ }

features.push(createFeature(id, type, geometry, geojson.properties, index));
features.push(createFeature(id, type, geometry, geojson.properties, index, options.dimensions + 1));
}
function convertPoint(coords, out) {
function convertPoint(coords, out, dimensions) {
if ( dimensions === void 0 ) dimensions = 2;
out.push(projectX(coords[0]), projectY(coords[1]), 0);
for (var i = 2; i < dimensions; i++) {
out.push(coords[i]);
}
}
function convertLine(ring, out, tolerance, isPolygon) {
function convertLine(ring, out, tolerance, isPolygon, dimensions) {
if ( dimensions === void 0 ) dimensions = 2;
var x0, y0;

@@ -236,3 +250,5 @@ var size = 0;

out.push(x, y, 0);
for (var i = 2; i < dimensions; i++) {
out.push(ring[j][i]);
}
if (j > 0) {

@@ -249,5 +265,5 @@ if (isPolygon) {

var last = out.length - 3;
var last = out.length - (dimensions + 1);
out[2] = 1;
simplify(out, 0, last, tolerance);
simplify(out, 0, last, tolerance, dimensions);
out[last + 2] = 1;

@@ -260,6 +276,8 @@

function convertLines(rings, out, tolerance, isPolygon) {
function convertLines(rings, out, tolerance, isPolygon, dimensions) {
if ( dimensions === void 0 ) dimensions = 2;
for (var i = 0; i < rings.length; i++) {
var geom = [];
convertLine(rings[i], geom, tolerance, isPolygon);
convertLine(rings[i], geom, tolerance, isPolygon, dimensions);
out.push(geom);

@@ -290,2 +308,3 @@ }

function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
var stride = (options.dimensions === undefined ? 2 : options.dimensions) + 1;
k1 /= scale;

@@ -318,12 +337,12 @@ k2 /= scale;

if (type === 'Point' || type === 'MultiPoint') {
clipPoints(geometry, newGeometry, k1, k2, axis);
clipPoints(geometry, newGeometry, k1, k2, axis, stride);
} else if (type === 'LineString') {
clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics, stride);
} else if (type === 'MultiLineString') {
clipLines(geometry, newGeometry, k1, k2, axis, false);
clipLines(geometry, newGeometry, k1, k2, axis, false, stride);
} else if (type === 'Polygon') {
clipLines(geometry, newGeometry, k1, k2, axis, true);
clipLines(geometry, newGeometry, k1, k2, axis, true, stride);

@@ -335,3 +354,3 @@ } else if (type === 'MultiPolygon') {

var newPolygon = [];
clipLines(polygon, newPolygon, k1, k2, axis, true);
clipLines(polygon, newPolygon, k1, k2, axis, true, stride);
if (newPolygon.length) {

@@ -348,3 +367,3 @@ newGeometry.push(newPolygon);

clipped.push(createFeature(feature.id, type, line, feature.tags, feature.index));
clipped.push(createFeature(feature.id, type, line, feature.tags, feature.index, stride));
}

@@ -363,6 +382,6 @@ continue;

if (type === 'Point' || type === 'MultiPoint') {
type = newGeometry.length === 3 ? 'Point' : 'MultiPoint';
type = newGeometry.length === stride ? 'Point' : 'MultiPoint';
}
clipped.push(createFeature(feature.id, type, newGeometry, feature.tags, feature.index));
clipped.push(createFeature(feature.id, type, newGeometry, feature.tags, feature.index, stride));
}

@@ -374,4 +393,6 @@ }

function clipPoints(geom, newGeom, k1, k2, axis) {
for (var i = 0; i < geom.length; i += 3) {
function clipPoints(geom, newGeom, k1, k2, axis, stride) {
if ( stride === void 0 ) stride = 3;
for (var i = 0; i < geom.length; i += stride) {
var a = geom[i + axis];

@@ -381,2 +402,5 @@

addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
for (var j = 3; j < stride; j++) {
newGeom.push(geom[i + j]);
}
}

@@ -386,4 +410,6 @@ }

function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics, stride) {
if ( stride === void 0 ) stride = 3;
var slice = newSlice(geom);

@@ -394,8 +420,8 @@ var intersect = axis === 0 ? intersectX : intersectY;

for (var i = 0; i < geom.length - 3; i += 3) {
for (var i = 0; i < geom.length - stride; i += stride) {
var ax$1 = geom[i];
var ay$1 = geom[i + 1];
var az$1 = geom[i + 2];
var bx = geom[i + 3];
var by = geom[i + 4];
var bx = geom[i + stride];
var by = geom[i + stride + 1];
var a$1 = axis === 0 ? ax$1 : ay$1;

@@ -411,2 +437,6 @@ var b = axis === 0 ? bx : by;

t = intersect(slice, ax$1, ay$1, bx, by, k1);
for (var j = 3; j < stride; j++) {
var aj = geom[i + j];
slice.push((geom[i + stride + j] - aj) * t + aj);
}
if (trackMetrics) { slice.start = len + segLen * t; }

@@ -418,2 +448,6 @@ }

t = intersect(slice, ax$1, ay$1, bx, by, k2);
for (var j$1 = 3; j$1 < stride; j$1++) {
var aj$1 = geom[i + j$1];
slice.push((geom[i + stride + j$1] - aj$1) * t + aj$1);
}
if (trackMetrics) { slice.start = len + segLen * t; }

@@ -423,2 +457,5 @@ }

addPoint(slice, ax$1, ay$1, az$1);
for (var j$2 = 3; j$2 < stride; j$2++) {
slice.push(geom[i + j$2]);
}
}

@@ -428,2 +465,6 @@ if (b < k1 && a$1 >= k1) {

t = intersect(slice, ax$1, ay$1, bx, by, k1);
for (var j$3 = 3; j$3 < stride; j$3++) {
var aj$2 = geom[i + j$3];
slice.push((geom[i + stride + j$3] - aj$2) * t + aj$2);
}
exited = true;

@@ -434,2 +475,6 @@ }

t = intersect(slice, ax$1, ay$1, bx, by, k2);
for (var j$4 = 3; j$4 < stride; j$4++) {
var aj$3 = geom[i + j$4];
slice.push((geom[i + stride + j$4] - aj$3) * t + aj$3);
}
exited = true;

@@ -448,3 +493,3 @@ }

// add the last point
var last = geom.length - 3;
var last = geom.length - stride;
var ax = geom[last];

@@ -454,8 +499,16 @@ var ay = geom[last + 1];

var a = axis === 0 ? ax : ay;
if (a >= k1 && a <= k2) { addPoint(slice, ax, ay, az); }
if (a >= k1 && a <= k2) {
addPoint(slice, ax, ay, az);
for (var j$5 = 3; j$5 < stride; j$5++) {
slice.push(geom[last + j$5]);
}
}
// close the polygon if its endpoints are not the same after clipping
last = slice.length - 3;
last = slice.length - stride;
if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
addPoint(slice, slice[0], slice[1], slice[2]);
for (var j$6 = 3; j$6 < stride; j$6++) {
slice.push(slice[j$6]);
}
}

@@ -477,7 +530,7 @@

function clipLines(geom, newGeom, k1, k2, axis, isPolygon) {
function clipLines(geom, newGeom, k1, k2, axis, isPolygon, stride) {
for (var i = 0, list = geom; i < list.length; i += 1) {
var line = list[i];
clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
clipLine(line, newGeom, k1, k2, axis, isPolygon, false, stride);
}

@@ -504,2 +557,3 @@ }

var buffer = options.buffer / options.extent;
var stride = options.dimensions + 1;
var merged = features;

@@ -512,4 +566,4 @@ var left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options); // left world copy

if (left) { merged = shiftFeatureCoords(left, 1).concat(merged); } // merge left into center
if (right) { merged = merged.concat(shiftFeatureCoords(right, -1)); } // merge right into center
if (left) { merged = shiftFeatureCoords(left, 1, stride).concat(merged); } // merge left into center
if (right) { merged = merged.concat(shiftFeatureCoords(right, -1, stride)); } // merge right into center
}

@@ -520,3 +574,5 @@

function shiftFeatureCoords(features, offset) {
function shiftFeatureCoords(features, offset, stride) {
if ( stride === void 0 ) stride = 3;
var newFeatures = [];

@@ -531,3 +587,3 @@

if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
newGeometry = shiftCoords(feature.geometry, offset);
newGeometry = shiftCoords(feature.geometry, offset, stride);

@@ -539,3 +595,3 @@ } else if (type === 'MultiLineString' || type === 'Polygon') {

newGeometry.push(shiftCoords(line, offset));
newGeometry.push(shiftCoords(line, offset, stride));
}

@@ -551,3 +607,3 @@ } else if (type === 'MultiPolygon') {

newPolygon.push(shiftCoords(line$1, offset));
newPolygon.push(shiftCoords(line$1, offset, stride));
}

@@ -558,3 +614,3 @@ newGeometry.push(newPolygon);

newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags, feature.index));
newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags, feature.index, stride));
}

@@ -565,3 +621,5 @@

function shiftCoords(points, offset) {
function shiftCoords(points, offset, stride) {
if ( stride === void 0 ) stride = 3;
var newPoints = [];

@@ -575,4 +633,7 @@ newPoints.size = points.size;

for (var i = 0; i < points.length; i += 3) {
for (var i = 0; i < points.length; i += stride) {
newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
for (var j = 3; j < stride; j++) {
newPoints.push(points[i + j]);
}
}

@@ -584,3 +645,5 @@ return newPoints;

// mercator-projected space into (extent x extent) tile space.
function transformTile(tile, extent) {
function transformTile(tile, extent, dimensions) {
if ( dimensions === void 0 ) dimensions = 2;
if (tile.transformed) { return tile; }

@@ -601,10 +664,10 @@

if (type === 1) {
for (var j = 0; j < geom.length; j += 2) {
feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
for (var j = 0; j < geom.length; j += dimensions) {
feature.geometry.push(transformPoint(geom, j, dimensions, extent, z2, tx, ty));
}
} else if (type === 2) {
feature.geometry = transformRings(geom, extent, z2, tx, ty);
feature.geometry = transformRings(geom, extent, z2, tx, ty, dimensions);
} else {
for (var j$1 = 0; j$1 < geom.length; j$1++) {
feature.geometry.push(transformRings(geom[j$1], extent, z2, tx, ty));
feature.geometry.push(transformRings(geom[j$1], extent, z2, tx, ty, dimensions));
}

@@ -619,8 +682,10 @@ }

function transformRings(sourceRings, extent, z2, tx, ty) {
function transformRings(sourceRings, extent, z2, tx, ty, dimensions) {
if ( dimensions === void 0 ) dimensions = 2;
var rings = [];
for (var j = 0; j < sourceRings.length; j++) {
var ring = [];
for (var k = 0; k < sourceRings[j].length; k += 2) {
ring.push(transformPoint(sourceRings[j][k], sourceRings[j][k + 1], extent, z2, tx, ty));
for (var k = 0; k < sourceRings[j].length; k += dimensions) {
ring.push(transformPoint(sourceRings[j], k, dimensions, extent, z2, tx, ty));
}

@@ -632,6 +697,14 @@ rings.push(ring);

function transformPoint(x, y, extent, z2, tx, ty) {
return [
Math.round(extent * (x * z2 - tx)),
Math.round(extent * (y * z2 - ty))];
function transformPoint(geom, index, dimensions, extent, z2, tx, ty) {
var result = [
Math.round(extent * (geom[index] * z2 - tx)),
Math.round(extent * (geom[index + 1] * z2 - ty))
];
for (var i = 2; i < dimensions; i++) {
result.push(geom[index + i]);
}
return result;
}

@@ -667,2 +740,3 @@

var type = feature.type;
var stride = options.dimensions + 1;
var simplified = [];

@@ -676,4 +750,7 @@

if (type === 'Point' || type === 'MultiPoint') {
for (var i = 0; i < geom.length; i += 3) {
for (var i = 0; i < geom.length; i += stride) {
simplified.push(geom[i], geom[i + 1]);
for (var j = 3; j < stride; j++) {
simplified.push(geom[i + j]);
}
tile.numPoints++;

@@ -684,7 +761,7 @@ tile.numSimplified++;

} else if (type === 'LineString') {
addLine(simplified, geom, tile, tolerance, false, false);
addLine(simplified, geom, tile, tolerance, false, false, stride);
} else if (type === 'MultiLineString' || type === 'Polygon') {
for (var i$1 = 0; i$1 < geom.length; i$1++) {
addLine(simplified, geom[i$1], tile, tolerance, type === 'Polygon', i$1 === 0);
addLine(simplified, geom[i$1], tile, tolerance, type === 'Polygon', i$1 === 0, stride);
}

@@ -702,3 +779,3 @@

for (var i$2 = 0; i$2 < polygon.length; i$2++) {
addLine(simplifiedPolygon, polygon[i$2], tile, tolerance, true, i$2 === 0);
addLine(simplifiedPolygon, polygon[i$2], tile, tolerance, true, i$2 === 0, stride);
}

@@ -737,7 +814,9 @@ if (simplifiedPolygon.length) {

function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
function addLine(result, geom, tile, tolerance, isPolygon, isOuter, stride) {
if ( stride === void 0 ) stride = 3;
var sqTolerance = tolerance * tolerance;
if (tolerance > 0 && (geom.size < (isPolygon ? sqTolerance : tolerance))) {
tile.numPoints += geom.length / 3;
tile.numPoints += geom.length / stride;
return;

@@ -748,6 +827,9 @@ }

for (var i = 0; i < geom.length; i += 3) {
for (var i = 0; i < geom.length; i += stride) {
if (tolerance === 0 || geom[i + 2] > sqTolerance) {
tile.numSimplified++;
ring.push(geom[i], geom[i + 1]);
for (var j = 3; j < stride; j++) {
ring.push(geom[i + j]);
}
}

@@ -757,3 +839,3 @@ tile.numPoints++;

if (isPolygon) { rewind(ring, isOuter); }
if (isPolygon) { rewind(ring, isOuter, stride - 1); }

@@ -763,17 +845,20 @@ result.push(ring);

function rewind(ring, clockwise) {
function rewind(ring, clockwise, dimensions) {
if ( dimensions === void 0 ) dimensions = 2;
var area = 0;
for (var i = 0, len = ring.length, j = len - 2; i < len; j = i, i += 2) {
for (var i = 0, len = ring.length, j = len - dimensions; i < len; j = i, i += dimensions) {
area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
}
if (area > 0 === clockwise) {
for (var i$1 = 0, len$1 = ring.length; i$1 < len$1 / 2; i$1 += 2) {
var x = ring[i$1];
var y = ring[i$1 + 1];
ring[i$1] = ring[len$1 - 2 - i$1];
ring[i$1 + 1] = ring[len$1 - 1 - i$1];
ring[len$1 - 2 - i$1] = x;
ring[len$1 - 1 - i$1] = y;
for (var i$1 = 0, len$1 = ring.length; i$1 < len$1 / 2; i$1 += dimensions) {
for (var j$1 = 0; j$1 < dimensions; j$1++) {
var a = ring[i$1 + j$1];
var rewIndex = len$1 - i$1 - (dimensions - j$1);
ring[i$1 + j$1] = ring[rewIndex];
ring[rewIndex] = a;
}
}
}
return ring;
}

@@ -798,3 +883,4 @@

generateIndex: false, // whether to generate feature indexes
debug: 0 // logging level (0, 1 or 2)
debug: 0, // logging level (0, 1 or 2)
dimensions: 2 // number of coordinates per vertex in the input array (2 by default)
};

@@ -956,3 +1042,3 @@

var id = toID(z, x, y);
if (this.tiles[id]) { return transformTile(this.tiles[id], extent); }
if (this.tiles[id]) { return transformTile(this.tiles[id], extent, options.dimensions); }

@@ -983,3 +1069,3 @@ if (debug > 1) { console.log('drilling down to z%d-%d-%d', z, x, y); }

return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
return this.tiles[id] ? transformTile(this.tiles[id], extent, options.dimensions) : null;
};

@@ -986,0 +1072,0 @@

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).geojsonvt={})}(this,(function(e){"use strict";function t(e,t,n,i,o,r){var l=o-n,a=r-i;if(0!==l||0!==a){var s=((e-n)*l+(t-i)*a)/(l*l+a*a);s>1?(n=o,i=r):s>0&&(n+=l*s,i+=a*s)}return(l=e-n)*l+(a=t-i)*a}function n(e,t,n,o,r){var l={id:null==e?null:e,index:r,type:t,geometry:n,tags:o,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};if("Point"===t||"MultiPoint"===t||"LineString"===t)i(l,n);else if("Polygon"===t)i(l,n[0]);else if("MultiLineString"===t)for(var a=0,s=n;a<s.length;a+=1){i(l,s[a])}else if("MultiPolygon"===t)for(var u=0,f=n;u<f.length;u+=1){i(l,f[u][0])}return l}function i(e,t){for(var n=0;n<t.length;n+=3)e.minX=Math.min(e.minX,t[n]),e.minY=Math.min(e.minY,t[n+1]),e.maxX=Math.max(e.maxX,t[n]),e.maxY=Math.max(e.maxY,t[n+1])}function o(e,t,i,s){if(t.geometry){var u=t.geometry.coordinates,f=t.geometry.type,g=Math.pow(i.tolerance/((1<<i.maxZoom)*i.extent),2),h=[],m=t.id;if(i.promoteId?m=t.properties[i.promoteId]:i.generateId&&(m=s||0),"Point"===f)r(u,h);else if("MultiPoint"===f)for(var p=0,d=u;p<d.length;p+=1){r(d[p],h)}else if("LineString"===f)l(u,h,g,!1);else if("MultiLineString"===f){if(i.lineMetrics){for(var c=0,v=u;c<v.length;c+=1){l(v[c],h=[],g,!1),e.push(n(m,"LineString",h,t.properties,s))}return}a(u,h,g,!1)}else if("Polygon"===f)a(u,h,g,!0);else{if("MultiPolygon"!==f){if("GeometryCollection"===f){for(var x=0,M=t.geometry.geometries;x<M.length;x+=1){o(e,{id:m,geometry:M[x],properties:t.properties},i,s)}return}throw new Error("Input data is not a valid GeoJSON object.")}for(var y=0,P=u;y<P.length;y+=1){var S=[];a(P[y],S,g,!0),h.push(S)}}e.push(n(m,f,h,t.properties,s))}}function r(e,t){t.push(s(e[0]),u(e[1]),0)}function l(e,n,i,o){for(var r,l,a=0,f=0;f<e.length;f++){var g=s(e[f][0]),h=u(e[f][1]);n.push(g,h,0),f>0&&(a+=o?(r*h-g*l)/2:Math.sqrt(Math.pow(g-r,2)+Math.pow(h-l,2))),r=g,l=h}var m=n.length-3;n[2]=1,function e(n,i,o,r){for(var l,a=r,s=o-i>>1,u=o-i,f=n[i],g=n[i+1],h=n[o],m=n[o+1],p=i+3;p<o;p+=3){var d=t(n[p],n[p+1],f,g,h,m);if(d>a)l=p,a=d;else if(d===a){var c=Math.abs(p-s);c<u&&(l=p,u=c)}}a>r&&(l-i>3&&e(n,i,l,r),n[l+2]=a,o-l>3&&e(n,l,o,r))}(n,0,m,i),n[m+2]=1,n.size=Math.abs(a),n.start=0,n.end=n.size}function a(e,t,n,i){for(var o=0;o<e.length;o++){var r=[];l(e[o],r,n,i),t.push(r)}}function s(e){return e/360+.5}function u(e){var t=Math.sin(e*Math.PI/180),n=.5-.25*Math.log((1+t)/(1-t))/Math.PI;return n<0?0:n>1?1:n}function f(e,t,i,o,r,l,a,s){if(o/=t,l>=(i/=t)&&a<o)return e;if(a<i||l>=o)return null;for(var u=[],f=0,m=e;f<m.length;f+=1){var d=m[f],c=d.geometry,v=d.type,x=0===r?d.minX:d.minY,M=0===r?d.maxX:d.maxY;if(x>=i&&M<o)u.push(d);else if(!(M<i||x>=o)){var y=[];if("Point"===v||"MultiPoint"===v)g(c,y,i,o,r);else if("LineString"===v)h(c,y,i,o,r,!1,s.lineMetrics);else if("MultiLineString"===v)p(c,y,i,o,r,!1);else if("Polygon"===v)p(c,y,i,o,r,!0);else if("MultiPolygon"===v)for(var P=0,S=c;P<S.length;P+=1){var Y=[];p(S[P],Y,i,o,r,!0),Y.length&&y.push(Y)}if(y.length){if(s.lineMetrics&&"LineString"===v){for(var L=0,X=y;L<X.length;L+=1){var b=X[L];u.push(n(d.id,v,b,d.tags,d.index))}continue}"LineString"!==v&&"MultiLineString"!==v||(1===y.length?(v="LineString",y=y[0]):v="MultiLineString"),"Point"!==v&&"MultiPoint"!==v||(v=3===y.length?"Point":"MultiPoint"),u.push(n(d.id,v,y,d.tags,d.index))}}}return u.length?u:null}function g(e,t,n,i,o){for(var r=0;r<e.length;r+=3){var l=e[r+o];l>=n&&l<=i&&d(t,e[r],e[r+1],e[r+2])}}function h(e,t,n,i,o,r,l){for(var a,s,u=m(e),f=0===o?c:v,g=e.start,h=0;h<e.length-3;h+=3){var p=e[h],x=e[h+1],M=e[h+2],y=e[h+3],P=e[h+4],S=0===o?p:x,Y=0===o?y:P,L=!1;l&&(a=Math.sqrt(Math.pow(p-y,2)+Math.pow(x-P,2))),S<n?Y>n&&(s=f(u,p,x,y,P,n),l&&(u.start=g+a*s)):S>i?Y<i&&(s=f(u,p,x,y,P,i),l&&(u.start=g+a*s)):d(u,p,x,M),Y<n&&S>=n&&(s=f(u,p,x,y,P,n),L=!0),Y>i&&S<=i&&(s=f(u,p,x,y,P,i),L=!0),!r&&L&&(l&&(u.end=g+a*s),t.push(u),u=m(e)),l&&(g+=a)}var X=e.length-3,b=e[X],z=e[X+1],w=e[X+2],I=0===o?b:z;I>=n&&I<=i&&d(u,b,z,w),X=u.length-3,r&&X>=3&&(u[X]!==u[0]||u[X+1]!==u[1])&&d(u,u[0],u[1],u[2]),u.length&&t.push(u)}function m(e){var t=[];return t.size=e.size,t.start=e.start,t.end=e.end,t}function p(e,t,n,i,o,r){for(var l=0,a=e;l<a.length;l+=1){h(a[l],t,n,i,o,r,!1)}}function d(e,t,n,i){e.push(t,n,i)}function c(e,t,n,i,o,r){var l=(r-t)/(i-t);return d(e,r,n+(o-n)*l,1),l}function v(e,t,n,i,o,r){var l=(r-n)/(o-n);return d(e,t+(i-t)*l,r,1),l}function x(e,t){for(var i=[],o=0;o<e.length;o++){var r=e[o],l=r.type,a=void 0;if("Point"===l||"MultiPoint"===l||"LineString"===l)a=M(r.geometry,t);else if("MultiLineString"===l||"Polygon"===l){a=[];for(var s=0,u=r.geometry;s<u.length;s+=1){var f=u[s];a.push(M(f,t))}}else if("MultiPolygon"===l){a=[];for(var g=0,h=r.geometry;g<h.length;g+=1){for(var m=[],p=0,d=h[g];p<d.length;p+=1){var c=d[p];m.push(M(c,t))}a.push(m)}}i.push(n(r.id,l,a,r.tags,r.index))}return i}function M(e,t){var n=[];n.size=e.size,void 0!==e.start&&(n.start=e.start,n.end=e.end);for(var i=0;i<e.length;i+=3)n.push(e[i]+t,e[i+1],e[i+2]);return n}function y(e,t){if(e.transformed)return e;for(var n=1<<e.z,i=e.x,o=e.y,r=0,l=e.features;r<l.length;r+=1){var a=l[r],s=a.geometry,u=a.type;if(a.geometry=[],1===u)for(var f=0;f<s.length;f+=2)a.geometry.push(S(s[f],s[f+1],t,n,i,o));else if(2===u)a.geometry=P(s,t,n,i,o);else for(var g=0;g<s.length;g++)a.geometry.push(P(s[g],t,n,i,o))}return e.transformed=!0,e}function P(e,t,n,i,o){for(var r=[],l=0;l<e.length;l++){for(var a=[],s=0;s<e[l].length;s+=2)a.push(S(e[l][s],e[l][s+1],t,n,i,o));r.push(a)}return r}function S(e,t,n,i,o,r){return[Math.round(n*(e*i-o)),Math.round(n*(t*i-r))]}function Y(e,t,n,i,o){for(var r=t===o.maxZoom?0:o.tolerance/((1<<t)*o.extent),l={features:[],numPoints:0,numSimplified:0,numFeatures:e.length,source:null,x:n,y:i,z:t,transformed:!1,minX:2,minY:1,maxX:-1,maxY:0},a=0,s=e;a<s.length;a+=1){L(l,s[a],r,o)}return l}function L(e,t,n,i){var o=t.geometry,r=t.type,l=[];if(e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),"Point"===r||"MultiPoint"===r)for(var a=0;a<o.length;a+=3)l.push(o[a],o[a+1]),e.numPoints++,e.numSimplified++;else if("LineString"===r)X(l,o,e,n,!1,!1);else if("MultiLineString"===r||"Polygon"===r){for(var s=0;s<o.length;s++)X(l,o[s],e,n,"Polygon"===r,0===s);"Polygon"===r&&l.length&&(l=[l])}else if("MultiPolygon"===r)for(var u=0;u<o.length;u++){for(var f=o[u],g=[],h=0;h<f.length;h++)X(g,f[h],e,n,!0,0===h);g.length&&l.push(g)}if(l.length){var m=t.tags||null;if("LineString"===r&&i.lineMetrics){for(var p in m={},t.tags)m[p]=t.tags[p];m.mapbox_clip_start=o.start/o.size,m.mapbox_clip_end=o.end/o.size}var d={geometry:l,type:"Polygon"===r||"MultiPolygon"===r?3:"LineString"===r||"MultiLineString"===r?2:1,tags:m};null!==t.id&&(d.id=t.id),i.generateIndex&&(d.index=t.index),e.features.push(d)}}function X(e,t,n,i,o,r){var l=i*i;if(i>0&&t.size<(o?l:i))n.numPoints+=t.length/3;else{for(var a=[],s=0;s<t.length;s+=3)(0===i||t[s+2]>l)&&(n.numSimplified++,a.push(t[s],t[s+1])),n.numPoints++;o&&function(e,t){for(var n=0,i=0,o=e.length,r=o-2;i<o;r=i,i+=2)n+=(e[i]-e[r])*(e[i+1]+e[r+1]);if(n>0===t)for(var l=0,a=e.length;l<a/2;l+=2){var s=e[l],u=e[l+1];e[l]=e[a-2-l],e[l+1]=e[a-1-l],e[a-2-l]=s,e[a-1-l]=u}}(a,r),e.push(a)}}var b={maxZoom:14,indexMaxZoom:5,indexMaxPoints:1e5,tolerance:3,extent:4096,buffer:64,lineMetrics:!1,promoteId:null,generateId:!1,generateIndex:!1,debug:0},z=function(e,t){var n=(t=this.options=function(e,t){for(var n in t)e[n]=t[n];return e}(Object.create(b),t)).debug;if(n&&console.time("preprocess data"),t.maxZoom<0||t.maxZoom>24)throw new Error("maxZoom should be in the 0-24 range");if(t.promoteId&&t.generateId)throw new Error("promoteId and generateId cannot be used together.");var i=function(e,t){var n=[];if("FeatureCollection"===e.type)for(var i=0;i<e.features.length;i++)o(n,e.features[i],t,i);else"Feature"===e.type?o(n,e,t,0):o(n,{geometry:e},t,0);return n}(e,t);this.tiles={},this.tileCoords=[],n&&(console.timeEnd("preprocess data"),console.log("index: maxZoom: %d, maxPoints: %d",t.indexMaxZoom,t.indexMaxPoints),console.time("generate tiles"),this.stats={},this.total=0),(i=function(e,t){var n=t.buffer/t.extent,i=e,o=f(e,1,-1-n,n,0,-1,2,t),r=f(e,1,1-n,2+n,0,-1,2,t);return(o||r)&&(i=f(e,1,-n,1+n,0,-1,2,t)||[],o&&(i=x(o,1).concat(i)),r&&(i=i.concat(x(r,-1)))),i}(i,t)).length&&this.splitTile(i,0,0,0),n&&(i.length&&console.log("features: %d, points: %d",this.tiles[0].numFeatures,this.tiles[0].numPoints),console.timeEnd("generate tiles"),console.log("tiles generated:",this.total,JSON.stringify(this.stats)))};function w(e,t,n){return 32*((1<<e)*n+t)+e}z.prototype.splitTile=function(e,t,n,i,o,r,l){for(var a=[e,t,n,i],s=this.options,u=s.debug;a.length;){i=a.pop(),n=a.pop(),t=a.pop(),e=a.pop();var g=1<<t,h=w(t,n,i),m=this.tiles[h];if(!m&&(u>1&&console.time("creation"),m=this.tiles[h]=Y(e,t,n,i,s),this.tileCoords.push({z:t,x:n,y:i}),u)){u>1&&(console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",t,n,i,m.numFeatures,m.numPoints,m.numSimplified),console.timeEnd("creation"));var p="z"+t;this.stats[p]=(this.stats[p]||0)+1,this.total++}if(m.source=e,null==o){if(t===s.indexMaxZoom||m.numPoints<=s.indexMaxPoints)continue}else{if(t===s.maxZoom||t===o)continue;if(null!=o){var d=o-t;if(n!==r>>d||i!==l>>d)continue}}if(m.source=null,0!==e.length){u>1&&console.time("clipping");var c=.5*s.buffer/s.extent,v=.5-c,x=.5+c,M=1+c,y=null,P=null,S=null,L=null,X=f(e,g,n-c,n+x,0,m.minX,m.maxX,s),b=f(e,g,n+v,n+M,0,m.minX,m.maxX,s);e=null,X&&(y=f(X,g,i-c,i+x,1,m.minY,m.maxY,s),P=f(X,g,i+v,i+M,1,m.minY,m.maxY,s),X=null),b&&(S=f(b,g,i-c,i+x,1,m.minY,m.maxY,s),L=f(b,g,i+v,i+M,1,m.minY,m.maxY,s),b=null),u>1&&console.timeEnd("clipping"),a.push(y||[],t+1,2*n,2*i),a.push(P||[],t+1,2*n,2*i+1),a.push(S||[],t+1,2*n+1,2*i),a.push(L||[],t+1,2*n+1,2*i+1)}}},z.prototype.getTile=function(e,t,n){e=+e,t=+t,n=+n;var i=this.options,o=i.extent,r=i.debug;if(e<0||e>24)return null;var l=1<<e,a=w(e,t=t+l&l-1,n);if(this.tiles[a])return y(this.tiles[a],o);r>1&&console.log("drilling down to z%d-%d-%d",e,t,n);for(var s,u=e,f=t,g=n;!s&&u>0;)u--,f>>=1,g>>=1,s=this.tiles[w(u,f,g)];return s&&s.source?(r>1&&(console.log("found parent tile z%d-%d-%d",u,f,g),console.time("drilling down")),this.splitTile(s.source,u,f,g,e,t,n),r>1&&console.timeEnd("drilling down"),this.tiles[a]?y(this.tiles[a],o):null):null},e.GeoJsonFeatureType={Points:1,Lines:2,Polygons:3},e.default=function(e,t){return new z(e,t)},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).geojsonvt={})}(this,(function(e){"use strict";function n(e,n,t,i,o,r){var s=o-t,a=r-i;if(0!==s||0!==a){var l=((e-t)*s+(n-i)*a)/(s*s+a*a);l>1?(t=o,i=r):l>0&&(t+=s*l,i+=a*l)}return(s=e-t)*s+(a=n-i)*a}function t(e,n,t,o,r,s){void 0===s&&(s=3);var a={id:null==e?null:e,index:r,type:n,geometry:t,tags:o,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};if("Point"===n||"MultiPoint"===n||"LineString"===n)i(a,t,s);else if("Polygon"===n)i(a,t[0],s);else if("MultiLineString"===n)for(var l=0,u=t;l<u.length;l+=1){i(a,u[l],s)}else if("MultiPolygon"===n)for(var f=0,h=t;f<h.length;f+=1){i(a,h[f][0],s)}return a}function i(e,n,t){void 0===t&&(t=3);for(var i=0;i<n.length;i+=t)e.minX=Math.min(e.minX,n[i]),e.minY=Math.min(e.minY,n[i+1]),e.maxX=Math.max(e.maxX,n[i]),e.maxY=Math.max(e.maxY,n[i+1])}function o(e,n,i,l){if(n.geometry){var u=n.geometry.coordinates,f=n.geometry.type,h=Math.pow(i.tolerance/((1<<i.maxZoom)*i.extent),2),m=[],g=n.id;if(i.promoteId?g=n.properties[i.promoteId]:i.generateId&&(g=l||0),"Point"===f)r(u,m,i.dimensions);else if("MultiPoint"===f)for(var d=0,p=u;d<p.length;d+=1){r(p[d],m,i.dimensions)}else if("LineString"===f)s(u,m,h,!1,i.dimensions);else if("MultiLineString"===f){if(i.lineMetrics){for(var v=0,c=u;v<c.length;v+=1){s(c[v],m=[],h,!1,i.dimensions),e.push(t(g,"LineString",m,n.properties,l,i.dimensions+1))}return}a(u,m,h,!1,i.dimensions)}else if("Polygon"===f)a(u,m,h,!0,i.dimensions);else{if("MultiPolygon"!==f){if("GeometryCollection"===f){for(var x=0,M=n.geometry.geometries;x<M.length;x+=1){o(e,{id:g,geometry:M[x],properties:n.properties},i,l)}return}throw new Error("Input data is not a valid GeoJSON object.")}for(var y=0,P=u;y<P.length;y+=1){var S=[];a(P[y],S,h,!0,i.dimensions),m.push(S)}}e.push(t(g,f,m,n.properties,l,i.dimensions+1))}}function r(e,n,t){void 0===t&&(t=2),n.push(l(e[0]),u(e[1]),0);for(var i=2;i<t;i++)n.push(e[i])}function s(e,t,i,o,r){var s,a;void 0===r&&(r=2);for(var f=0,h=0;h<e.length;h++){var m=l(e[h][0]),g=u(e[h][1]);t.push(m,g,0);for(var d=2;d<r;d++)t.push(e[h][d]);h>0&&(f+=o?(s*g-m*a)/2:Math.sqrt(Math.pow(m-s,2)+Math.pow(g-a,2))),s=m,a=g}var p=t.length-(r+1);t[2]=1,function e(t,i,o,r,s){void 0===s&&(s=2);for(var a,l=s+1,u=r,f=o-i>>1,h=o-i,m=t[i],g=t[i+1],d=t[o],p=t[o+1],v=i+l;v<o;v+=l){var c=n(t[v],t[v+1],m,g,d,p);if(c>u)a=v,u=c;else if(c===u){var x=Math.abs(v-f);x<h&&(a=v,h=x)}}u>r&&(a-i>l&&e(t,i,a,r,s),t[a+2]=u,o-a>l&&e(t,a,o,r,s))}(t,0,p,i,r),t[p+2]=1,t.size=Math.abs(f),t.start=0,t.end=t.size}function a(e,n,t,i,o){void 0===o&&(o=2);for(var r=0;r<e.length;r++){var a=[];s(e[r],a,t,i,o),n.push(a)}}function l(e){return e/360+.5}function u(e){var n=Math.sin(e*Math.PI/180),t=.5-.25*Math.log((1+n)/(1-n))/Math.PI;return t<0?0:t>1?1:t}function f(e,n,i,o,r,s,a,l){var u=(void 0===l.dimensions?2:l.dimensions)+1;if(o/=n,s>=(i/=n)&&a<o)return e;if(a<i||s>=o)return null;for(var f=[],g=0,p=e;g<p.length;g+=1){var v=p[g],c=v.geometry,x=v.type,M=0===r?v.minX:v.minY,y=0===r?v.maxX:v.maxY;if(M>=i&&y<o)f.push(v);else if(!(y<i||M>=o)){var P=[];if("Point"===x||"MultiPoint"===x)h(c,P,i,o,r,u);else if("LineString"===x)m(c,P,i,o,r,!1,l.lineMetrics,u);else if("MultiLineString"===x)d(c,P,i,o,r,!1,u);else if("Polygon"===x)d(c,P,i,o,r,!0,u);else if("MultiPolygon"===x)for(var S=0,Y=c;S<Y.length;S+=1){var L=[];d(Y[S],L,i,o,r,!0,u),L.length&&P.push(L)}if(P.length){if(l.lineMetrics&&"LineString"===x){for(var X=0,b=P;X<b.length;X+=1){var z=b[X];f.push(t(v.id,x,z,v.tags,v.index,u))}continue}"LineString"!==x&&"MultiLineString"!==x||(1===P.length?(x="LineString",P=P[0]):x="MultiLineString"),"Point"!==x&&"MultiPoint"!==x||(x=P.length===u?"Point":"MultiPoint"),f.push(t(v.id,x,P,v.tags,v.index,u))}}}return f.length?f:null}function h(e,n,t,i,o,r){void 0===r&&(r=3);for(var s=0;s<e.length;s+=r){var a=e[s+o];if(a>=t&&a<=i){p(n,e[s],e[s+1],e[s+2]);for(var l=3;l<r;l++)n.push(e[s+l])}}}function m(e,n,t,i,o,r,s,a){void 0===a&&(a=3);for(var l,u,f=g(e),h=0===o?v:c,m=e.start,d=0;d<e.length-a;d+=a){var x=e[d],M=e[d+1],y=e[d+2],P=e[d+a],S=e[d+a+1],Y=0===o?x:M,L=0===o?P:S,X=!1;if(s&&(l=Math.sqrt(Math.pow(x-P,2)+Math.pow(M-S,2))),Y<t){if(L>t){u=h(f,x,M,P,S,t);for(var b=3;b<a;b++){var z=e[d+b];f.push((e[d+a+b]-z)*u+z)}s&&(f.start=m+l*u)}}else if(Y>i){if(L<i){u=h(f,x,M,P,S,i);for(var w=3;w<a;w++){var I=e[d+w];f.push((e[d+a+w]-I)*u+I)}s&&(f.start=m+l*u)}}else{p(f,x,M,y);for(var Z=3;Z<a;Z++)f.push(e[d+Z])}if(L<t&&Y>=t){u=h(f,x,M,P,S,t);for(var E=3;E<a;E++){var F=e[d+E];f.push((e[d+a+E]-F)*u+F)}X=!0}if(L>i&&Y<=i){u=h(f,x,M,P,S,i);for(var _=3;_<a;_++){var j=e[d+_];f.push((e[d+a+_]-j)*u+j)}X=!0}!r&&X&&(s&&(f.end=m+l*u),n.push(f),f=g(e)),s&&(m+=l)}var T=e.length-a,C=e[T],O=e[T+1],G=e[T+2],J=0===o?C:O;if(J>=t&&J<=i){p(f,C,O,G);for(var q=3;q<a;q++)f.push(e[T+q])}if(T=f.length-a,r&&T>=3&&(f[T]!==f[0]||f[T+1]!==f[1])){p(f,f[0],f[1],f[2]);for(var N=3;N<a;N++)f.push(f[N])}f.length&&n.push(f)}function g(e){var n=[];return n.size=e.size,n.start=e.start,n.end=e.end,n}function d(e,n,t,i,o,r,s){for(var a=0,l=e;a<l.length;a+=1){m(l[a],n,t,i,o,r,!1,s)}}function p(e,n,t,i){e.push(n,t,i)}function v(e,n,t,i,o,r){var s=(r-n)/(i-n);return p(e,r,t+(o-t)*s,1),s}function c(e,n,t,i,o,r){var s=(r-t)/(o-t);return p(e,n+(i-n)*s,r,1),s}function x(e,n,i){void 0===i&&(i=3);for(var o=[],r=0;r<e.length;r++){var s=e[r],a=s.type,l=void 0;if("Point"===a||"MultiPoint"===a||"LineString"===a)l=M(s.geometry,n,i);else if("MultiLineString"===a||"Polygon"===a){l=[];for(var u=0,f=s.geometry;u<f.length;u+=1){var h=f[u];l.push(M(h,n,i))}}else if("MultiPolygon"===a){l=[];for(var m=0,g=s.geometry;m<g.length;m+=1){for(var d=[],p=0,v=g[m];p<v.length;p+=1){var c=v[p];d.push(M(c,n,i))}l.push(d)}}o.push(t(s.id,a,l,s.tags,s.index,i))}return o}function M(e,n,t){void 0===t&&(t=3);var i=[];i.size=e.size,void 0!==e.start&&(i.start=e.start,i.end=e.end);for(var o=0;o<e.length;o+=t){i.push(e[o]+n,e[o+1],e[o+2]);for(var r=3;r<t;r++)i.push(e[o+r])}return i}function y(e,n,t){if(void 0===t&&(t=2),e.transformed)return e;for(var i=1<<e.z,o=e.x,r=e.y,s=0,a=e.features;s<a.length;s+=1){var l=a[s],u=l.geometry,f=l.type;if(l.geometry=[],1===f)for(var h=0;h<u.length;h+=t)l.geometry.push(S(u,h,t,n,i,o,r));else if(2===f)l.geometry=P(u,n,i,o,r,t);else for(var m=0;m<u.length;m++)l.geometry.push(P(u[m],n,i,o,r,t))}return e.transformed=!0,e}function P(e,n,t,i,o,r){void 0===r&&(r=2);for(var s=[],a=0;a<e.length;a++){for(var l=[],u=0;u<e[a].length;u+=r)l.push(S(e[a],u,r,n,t,i,o));s.push(l)}return s}function S(e,n,t,i,o,r,s){for(var a=[Math.round(i*(e[n]*o-r)),Math.round(i*(e[n+1]*o-s))],l=2;l<t;l++)a.push(e[n+l]);return a}function Y(e,n,t,i,o){for(var r=n===o.maxZoom?0:o.tolerance/((1<<n)*o.extent),s={features:[],numPoints:0,numSimplified:0,numFeatures:e.length,source:null,x:t,y:i,z:n,transformed:!1,minX:2,minY:1,maxX:-1,maxY:0},a=0,l=e;a<l.length;a+=1){L(s,l[a],r,o)}return s}function L(e,n,t,i){var o=n.geometry,r=n.type,s=i.dimensions+1,a=[];if(e.minX=Math.min(e.minX,n.minX),e.minY=Math.min(e.minY,n.minY),e.maxX=Math.max(e.maxX,n.maxX),e.maxY=Math.max(e.maxY,n.maxY),"Point"===r||"MultiPoint"===r)for(var l=0;l<o.length;l+=s){a.push(o[l],o[l+1]);for(var u=3;u<s;u++)a.push(o[l+u]);e.numPoints++,e.numSimplified++}else if("LineString"===r)X(a,o,e,t,!1,!1,s);else if("MultiLineString"===r||"Polygon"===r){for(var f=0;f<o.length;f++)X(a,o[f],e,t,"Polygon"===r,0===f,s);"Polygon"===r&&a.length&&(a=[a])}else if("MultiPolygon"===r)for(var h=0;h<o.length;h++){for(var m=o[h],g=[],d=0;d<m.length;d++)X(g,m[d],e,t,!0,0===d,s);g.length&&a.push(g)}if(a.length){var p=n.tags||null;if("LineString"===r&&i.lineMetrics){for(var v in p={},n.tags)p[v]=n.tags[v];p.mapbox_clip_start=o.start/o.size,p.mapbox_clip_end=o.end/o.size}var c={geometry:a,type:"Polygon"===r||"MultiPolygon"===r?3:"LineString"===r||"MultiLineString"===r?2:1,tags:p};null!==n.id&&(c.id=n.id),i.generateIndex&&(c.index=n.index),e.features.push(c)}}function X(e,n,t,i,o,r,s){void 0===s&&(s=3);var a=i*i;if(i>0&&n.size<(o?a:i))t.numPoints+=n.length/s;else{for(var l=[],u=0;u<n.length;u+=s){if(0===i||n[u+2]>a){t.numSimplified++,l.push(n[u],n[u+1]);for(var f=3;f<s;f++)l.push(n[u+f])}t.numPoints++}o&&function(e,n,t){void 0===t&&(t=2);for(var i=0,o=0,r=e.length,s=r-t;o<r;s=o,o+=t)i+=(e[o]-e[s])*(e[o+1]+e[s+1]);if(i>0===n)for(var a=0,l=e.length;a<l/2;a+=t)for(var u=0;u<t;u++){var f=e[a+u],h=l-a-(t-u);e[a+u]=e[h],e[h]=f}}(l,r,s-1),e.push(l)}}var b={maxZoom:14,indexMaxZoom:5,indexMaxPoints:1e5,tolerance:3,extent:4096,buffer:64,lineMetrics:!1,promoteId:null,generateId:!1,generateIndex:!1,debug:0,dimensions:2},z=function(e,n){var t=(n=this.options=function(e,n){for(var t in n)e[t]=n[t];return e}(Object.create(b),n)).debug;if(t&&console.time("preprocess data"),n.maxZoom<0||n.maxZoom>24)throw new Error("maxZoom should be in the 0-24 range");if(n.promoteId&&n.generateId)throw new Error("promoteId and generateId cannot be used together.");var i=function(e,n){var t=[];if("FeatureCollection"===e.type)for(var i=0;i<e.features.length;i++)o(t,e.features[i],n,i);else"Feature"===e.type?o(t,e,n,0):o(t,{geometry:e},n,0);return t}(e,n);this.tiles={},this.tileCoords=[],t&&(console.timeEnd("preprocess data"),console.log("index: maxZoom: %d, maxPoints: %d",n.indexMaxZoom,n.indexMaxPoints),console.time("generate tiles"),this.stats={},this.total=0),(i=function(e,n){var t=n.buffer/n.extent,i=n.dimensions+1,o=e,r=f(e,1,-1-t,t,0,-1,2,n),s=f(e,1,1-t,2+t,0,-1,2,n);return(r||s)&&(o=f(e,1,-t,1+t,0,-1,2,n)||[],r&&(o=x(r,1,i).concat(o)),s&&(o=o.concat(x(s,-1,i)))),o}(i,n)).length&&this.splitTile(i,0,0,0),t&&(i.length&&console.log("features: %d, points: %d",this.tiles[0].numFeatures,this.tiles[0].numPoints),console.timeEnd("generate tiles"),console.log("tiles generated:",this.total,JSON.stringify(this.stats)))};function w(e,n,t){return 32*((1<<e)*t+n)+e}z.prototype.splitTile=function(e,n,t,i,o,r,s){for(var a=[e,n,t,i],l=this.options,u=l.debug;a.length;){i=a.pop(),t=a.pop(),n=a.pop(),e=a.pop();var h=1<<n,m=w(n,t,i),g=this.tiles[m];if(!g&&(u>1&&console.time("creation"),g=this.tiles[m]=Y(e,n,t,i,l),this.tileCoords.push({z:n,x:t,y:i}),u)){u>1&&(console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",n,t,i,g.numFeatures,g.numPoints,g.numSimplified),console.timeEnd("creation"));var d="z"+n;this.stats[d]=(this.stats[d]||0)+1,this.total++}if(g.source=e,null==o){if(n===l.indexMaxZoom||g.numPoints<=l.indexMaxPoints)continue}else{if(n===l.maxZoom||n===o)continue;if(null!=o){var p=o-n;if(t!==r>>p||i!==s>>p)continue}}if(g.source=null,0!==e.length){u>1&&console.time("clipping");var v=.5*l.buffer/l.extent,c=.5-v,x=.5+v,M=1+v,y=null,P=null,S=null,L=null,X=f(e,h,t-v,t+x,0,g.minX,g.maxX,l),b=f(e,h,t+c,t+M,0,g.minX,g.maxX,l);e=null,X&&(y=f(X,h,i-v,i+x,1,g.minY,g.maxY,l),P=f(X,h,i+c,i+M,1,g.minY,g.maxY,l),X=null),b&&(S=f(b,h,i-v,i+x,1,g.minY,g.maxY,l),L=f(b,h,i+c,i+M,1,g.minY,g.maxY,l),b=null),u>1&&console.timeEnd("clipping"),a.push(y||[],n+1,2*t,2*i),a.push(P||[],n+1,2*t,2*i+1),a.push(S||[],n+1,2*t+1,2*i),a.push(L||[],n+1,2*t+1,2*i+1)}}},z.prototype.getTile=function(e,n,t){e=+e,n=+n,t=+t;var i=this.options,o=i.extent,r=i.debug;if(e<0||e>24)return null;var s=1<<e,a=w(e,n=n+s&s-1,t);if(this.tiles[a])return y(this.tiles[a],o,i.dimensions);r>1&&console.log("drilling down to z%d-%d-%d",e,n,t);for(var l,u=e,f=n,h=t;!l&&u>0;)u--,f>>=1,h>>=1,l=this.tiles[w(u,f,h)];return l&&l.source?(r>1&&(console.log("found parent tile z%d-%d-%d",u,f,h),console.time("drilling down")),this.splitTile(l.source,u,f,h,e,n,t),r>1&&console.timeEnd("drilling down"),this.tiles[a]?y(this.tiles[a],o,i.dimensions):null):null},e.GeoJsonFeatureType={Points:1,Lines:2,Polygons:3},e.default=function(e,n){return new z(e,n)},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@2gis/geojson-vt",
"version": "3.2.3",
"version": "3.3.0",
"description": "Slice GeoJSON data into vector tiles efficiently",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/2gis/geojson-vt",

@@ -56,12 +56,13 @@ ## geojson-vt &mdash; GeoJSON Vector Tiles

var tileIndex = geojsonvt(data, {
maxZoom: 14, // max zoom to preserve detail on; can't be higher than 24
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)
lineMetrics: false, // whether to enable line metrics tracking for LineString/MultiLineString features
promoteId: null, // name of a feature property to promote to feature.id. Cannot be used with `generateId`
generateId: false, // whether to generate feature ids. Cannot be used with `promoteId`
indexMaxZoom: 5, // max zoom in the initial tile index
indexMaxPoints: 100000 // max number of points per tile in the index
maxZoom: 14, // max zoom to preserve detail on; can't be higher than 24
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)
lineMetrics: false, // whether to enable line metrics tracking for LineString/MultiLineString features
promoteId: null, // name of a feature property to promote to feature.id. Cannot be used with `generateId`
generateId: false, // whether to generate feature ids. Cannot be used with `promoteId`
indexMaxZoom: 5, // max zoom in the initial tile index
indexMaxPoints: 100000, // max number of points per tile in the index
dimensions: 2, // number of coordinates per vertex in the input array (2 by default)
});

@@ -82,6 +83,6 @@ ```

// import as a ES module
import geojsonvt from 'geojson-vt';
import geojsonvt from "geojson-vt";
// or require in Node / Browserify
const geojsonvt = require('geojson-vt');
const geojsonvt = require("geojson-vt");
```

@@ -88,0 +89,0 @@

@@ -15,2 +15,3 @@

export default function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
const stride = (options.dimensions === undefined ? 2 : options.dimensions) + 1;
k1 /= scale;

@@ -41,12 +42,12 @@ k2 /= scale;

if (type === 'Point' || type === 'MultiPoint') {
clipPoints(geometry, newGeometry, k1, k2, axis);
clipPoints(geometry, newGeometry, k1, k2, axis, stride);
} else if (type === 'LineString') {
clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics, stride);
} else if (type === 'MultiLineString') {
clipLines(geometry, newGeometry, k1, k2, axis, false);
clipLines(geometry, newGeometry, k1, k2, axis, false, stride);
} else if (type === 'Polygon') {
clipLines(geometry, newGeometry, k1, k2, axis, true);
clipLines(geometry, newGeometry, k1, k2, axis, true, stride);

@@ -56,3 +57,3 @@ } else if (type === 'MultiPolygon') {

const newPolygon = [];
clipLines(polygon, newPolygon, k1, k2, axis, true);
clipLines(polygon, newPolygon, k1, k2, axis, true, stride);
if (newPolygon.length) {

@@ -67,3 +68,3 @@ newGeometry.push(newPolygon);

for (const line of newGeometry) {
clipped.push(createFeature(feature.id, type, line, feature.tags, feature.index));
clipped.push(createFeature(feature.id, type, line, feature.tags, feature.index, stride));
}

@@ -82,6 +83,6 @@ continue;

if (type === 'Point' || type === 'MultiPoint') {
type = newGeometry.length === 3 ? 'Point' : 'MultiPoint';
type = newGeometry.length === stride ? 'Point' : 'MultiPoint';
}
clipped.push(createFeature(feature.id, type, newGeometry, feature.tags, feature.index));
clipped.push(createFeature(feature.id, type, newGeometry, feature.tags, feature.index, stride));
}

@@ -93,4 +94,4 @@ }

function clipPoints(geom, newGeom, k1, k2, axis) {
for (let i = 0; i < geom.length; i += 3) {
function clipPoints(geom, newGeom, k1, k2, axis, stride = 3) {
for (let i = 0; i < geom.length; i += stride) {
const a = geom[i + axis];

@@ -100,2 +101,5 @@

addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
for (let j = 3; j < stride; j++) {
newGeom.push(geom[i + j]);
}
}

@@ -105,3 +109,3 @@ }

function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics, stride = 3) {

@@ -113,8 +117,8 @@ let slice = newSlice(geom);

for (let i = 0; i < geom.length - 3; i += 3) {
for (let i = 0; i < geom.length - stride; i += stride) {
const ax = geom[i];
const ay = geom[i + 1];
const az = geom[i + 2];
const bx = geom[i + 3];
const by = geom[i + 4];
const bx = geom[i + stride];
const by = geom[i + stride + 1];
const a = axis === 0 ? ax : ay;

@@ -130,2 +134,6 @@ const b = axis === 0 ? bx : by;

t = intersect(slice, ax, ay, bx, by, k1);
for (let j = 3; j < stride; j++) {
const aj = geom[i + j];
slice.push((geom[i + stride + j] - aj) * t + aj);
}
if (trackMetrics) slice.start = len + segLen * t;

@@ -137,2 +145,6 @@ }

t = intersect(slice, ax, ay, bx, by, k2);
for (let j = 3; j < stride; j++) {
const aj = geom[i + j];
slice.push((geom[i + stride + j] - aj) * t + aj);
}
if (trackMetrics) slice.start = len + segLen * t;

@@ -142,2 +154,5 @@ }

addPoint(slice, ax, ay, az);
for (let j = 3; j < stride; j++) {
slice.push(geom[i + j]);
}
}

@@ -147,2 +162,6 @@ if (b < k1 && a >= k1) {

t = intersect(slice, ax, ay, bx, by, k1);
for (let j = 3; j < stride; j++) {
const aj = geom[i + j];
slice.push((geom[i + stride + j] - aj) * t + aj);
}
exited = true;

@@ -153,2 +172,6 @@ }

t = intersect(slice, ax, ay, bx, by, k2);
for (let j = 3; j < stride; j++) {
const aj = geom[i + j];
slice.push((geom[i + stride + j] - aj) * t + aj);
}
exited = true;

@@ -167,3 +190,3 @@ }

// add the last point
let last = geom.length - 3;
let last = geom.length - stride;
const ax = geom[last];

@@ -173,8 +196,16 @@ const ay = geom[last + 1];

const a = axis === 0 ? ax : ay;
if (a >= k1 && a <= k2) addPoint(slice, ax, ay, az);
if (a >= k1 && a <= k2) {
addPoint(slice, ax, ay, az);
for (let j = 3; j < stride; j++) {
slice.push(geom[last + j]);
}
}
// close the polygon if its endpoints are not the same after clipping
last = slice.length - 3;
last = slice.length - stride;
if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
addPoint(slice, slice[0], slice[1], slice[2]);
for (let j = 3; j < stride; j++) {
slice.push(slice[j]);
}
}

@@ -196,5 +227,5 @@

function clipLines(geom, newGeom, k1, k2, axis, isPolygon) {
function clipLines(geom, newGeom, k1, k2, axis, isPolygon, stride) {
for (const line of geom) {
clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
clipLine(line, newGeom, k1, k2, axis, isPolygon, false, stride);
}

@@ -201,0 +232,0 @@ }

@@ -39,11 +39,11 @@

if (type === 'Point') {
convertPoint(coords, geometry);
convertPoint(coords, geometry, options.dimensions);
} else if (type === 'MultiPoint') {
for (const p of coords) {
convertPoint(p, geometry);
convertPoint(p, geometry, options.dimensions);
}
} else if (type === 'LineString') {
convertLine(coords, geometry, tolerance, false);
convertLine(coords, geometry, tolerance, false, options.dimensions);

@@ -55,12 +55,12 @@ } else if (type === 'MultiLineString') {

geometry = [];
convertLine(line, geometry, tolerance, false);
features.push(createFeature(id, 'LineString', geometry, geojson.properties, index));
convertLine(line, geometry, tolerance, false, options.dimensions);
features.push(createFeature(id, 'LineString', geometry, geojson.properties, index, options.dimensions + 1));
}
return;
} else {
convertLines(coords, geometry, tolerance, false);
convertLines(coords, geometry, tolerance, false, options.dimensions);
}
} else if (type === 'Polygon') {
convertLines(coords, geometry, tolerance, true);
convertLines(coords, geometry, tolerance, true, options.dimensions);

@@ -70,3 +70,3 @@ } else if (type === 'MultiPolygon') {

const newPolygon = [];
convertLines(polygon, newPolygon, tolerance, true);
convertLines(polygon, newPolygon, tolerance, true, options.dimensions);
geometry.push(newPolygon);

@@ -87,10 +87,13 @@ }

features.push(createFeature(id, type, geometry, geojson.properties, index));
features.push(createFeature(id, type, geometry, geojson.properties, index, options.dimensions + 1));
}
function convertPoint(coords, out) {
function convertPoint(coords, out, dimensions = 2) {
out.push(projectX(coords[0]), projectY(coords[1]), 0);
for (let i = 2; i < dimensions; i++) {
out.push(coords[i]);
}
}
function convertLine(ring, out, tolerance, isPolygon) {
function convertLine(ring, out, tolerance, isPolygon, dimensions = 2) {
let x0, y0;

@@ -104,3 +107,5 @@ let size = 0;

out.push(x, y, 0);
for (let i = 2; i < dimensions; i++) {
out.push(ring[j][i]);
}
if (j > 0) {

@@ -117,5 +122,5 @@ if (isPolygon) {

const last = out.length - 3;
const last = out.length - (dimensions + 1);
out[2] = 1;
simplify(out, 0, last, tolerance);
simplify(out, 0, last, tolerance, dimensions);
out[last + 2] = 1;

@@ -128,6 +133,6 @@

function convertLines(rings, out, tolerance, isPolygon) {
function convertLines(rings, out, tolerance, isPolygon, dimensions = 2) {
for (let i = 0; i < rings.length; i++) {
const geom = [];
convertLine(rings[i], geom, tolerance, isPolygon);
convertLine(rings[i], geom, tolerance, isPolygon, dimensions);
out.push(geom);

@@ -134,0 +139,0 @@ }

export default function createFeature(id, type, geom, tags, index) {
export default function createFeature(id, type, geom, tags, index, stride = 3) {
const feature = {

@@ -16,11 +16,11 @@ id: id == null ? null : id,

if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
calcLineBBox(feature, geom);
calcLineBBox(feature, geom, stride);
} else if (type === 'Polygon') {
// the outer ring (ie [0]) contains all inner rings
calcLineBBox(feature, geom[0]);
calcLineBBox(feature, geom[0], stride);
} else if (type === 'MultiLineString') {
for (const line of geom) {
calcLineBBox(feature, line);
calcLineBBox(feature, line, stride);
}

@@ -31,3 +31,3 @@

// the outer ring (ie [0]) contains all inner rings
calcLineBBox(feature, polygon[0]);
calcLineBBox(feature, polygon[0], stride);
}

@@ -39,4 +39,4 @@ }

function calcLineBBox(feature, geom) {
for (let i = 0; i < geom.length; i += 3) {
function calcLineBBox(feature, geom, stride = 3) {
for (let i = 0; i < geom.length; i += stride) {
feature.minX = Math.min(feature.minX, geom[i]);

@@ -43,0 +43,0 @@ feature.minY = Math.min(feature.minY, geom[i + 1]);

@@ -25,3 +25,4 @@

generateIndex: false, // whether to generate feature indexes
debug: 0 // logging level (0, 1 or 2)
debug: 0, // logging level (0, 1 or 2)
dimensions: 2 // number of coordinates per vertex in the input array (2 by default)
};

@@ -183,3 +184,3 @@

const id = toID(z, x, y);
if (this.tiles[id]) return transform(this.tiles[id], extent);
if (this.tiles[id]) return transform(this.tiles[id], extent, options.dimensions);

@@ -210,3 +211,3 @@ if (debug > 1) console.log('drilling down to z%d-%d-%d', z, x, y);

return this.tiles[id] ? transform(this.tiles[id], extent) : null;
return this.tiles[id] ? transform(this.tiles[id], extent, options.dimensions) : null;
}

@@ -213,0 +214,0 @@ }

// calculate simplification data using optimized Douglas-Peucker algorithm
export default function simplify(coords, first, last, sqTolerance) {
export default function simplify(coords, first, last, sqTolerance, dimensions = 2) {
const stride = dimensions + 1;
let maxSqDist = sqTolerance;

@@ -15,3 +16,3 @@ const mid = (last - first) >> 1;

for (let i = first + 3; i < last; i += 3) {
for (let i = first + stride; i < last; i += stride) {
const d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);

@@ -36,5 +37,5 @@

if (maxSqDist > sqTolerance) {
if (index - first > 3) simplify(coords, first, index, sqTolerance);
if (index - first > stride) simplify(coords, first, index, sqTolerance, dimensions);
coords[index + 2] = maxSqDist;
if (last - index > 3) simplify(coords, index, last, sqTolerance);
if (last - index > stride) simplify(coords, index, last, sqTolerance, dimensions);
}

@@ -41,0 +42,0 @@ }

@@ -28,2 +28,3 @@

const type = feature.type;
const stride = options.dimensions + 1;
let simplified = [];

@@ -37,4 +38,7 @@

if (type === 'Point' || type === 'MultiPoint') {
for (let i = 0; i < geom.length; i += 3) {
for (let i = 0; i < geom.length; i += stride) {
simplified.push(geom[i], geom[i + 1]);
for (let j = 3; j < stride; j++) {
simplified.push(geom[i + j]);
}
tile.numPoints++;

@@ -45,7 +49,7 @@ tile.numSimplified++;

} else if (type === 'LineString') {
addLine(simplified, geom, tile, tolerance, false, false);
addLine(simplified, geom, tile, tolerance, false, false, stride);
} else if (type === 'MultiLineString' || type === 'Polygon') {
for (let i = 0; i < geom.length; i++) {
addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0);
addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0, stride);
}

@@ -63,3 +67,3 @@

for (let i = 0; i < polygon.length; i++) {
addLine(simplifiedPolygon, polygon[i], tile, tolerance, true, i === 0);
addLine(simplifiedPolygon, polygon[i], tile, tolerance, true, i === 0, stride);
}

@@ -98,7 +102,7 @@ if (simplifiedPolygon.length) {

function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
function addLine(result, geom, tile, tolerance, isPolygon, isOuter, stride = 3) {
const sqTolerance = tolerance * tolerance;
if (tolerance > 0 && (geom.size < (isPolygon ? sqTolerance : tolerance))) {
tile.numPoints += geom.length / 3;
tile.numPoints += geom.length / stride;
return;

@@ -109,6 +113,9 @@ }

for (let i = 0; i < geom.length; i += 3) {
for (let i = 0; i < geom.length; i += stride) {
if (tolerance === 0 || geom[i + 2] > sqTolerance) {
tile.numSimplified++;
ring.push(geom[i], geom[i + 1]);
for (let j = 3; j < stride; j++) {
ring.push(geom[i + j]);
}
}

@@ -118,3 +125,3 @@ tile.numPoints++;

if (isPolygon) rewind(ring, isOuter);
if (isPolygon) rewind(ring, isOuter, stride - 1);

@@ -124,17 +131,18 @@ result.push(ring);

function rewind(ring, clockwise) {
function rewind(ring, clockwise, dimensions = 2) {
let area = 0;
for (let i = 0, len = ring.length, j = len - 2; i < len; j = i, i += 2) {
for (let i = 0, len = ring.length, j = len - dimensions; i < len; j = i, i += dimensions) {
area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
}
if (area > 0 === clockwise) {
for (let i = 0, len = ring.length; i < len / 2; i += 2) {
const x = ring[i];
const y = ring[i + 1];
ring[i] = ring[len - 2 - i];
ring[i + 1] = ring[len - 1 - i];
ring[len - 2 - i] = x;
ring[len - 1 - i] = y;
for (let i = 0, len = ring.length; i < len / 2; i += dimensions) {
for (let j = 0; j < dimensions; j++) {
const a = ring[i + j];
const rewIndex = len - i - (dimensions - j);
ring[i + j] = ring[rewIndex];
ring[rewIndex] = a;
}
}
}
return ring;
}
// Transforms the coordinates of each feature in the given tile from
// mercator-projected space into (extent x extent) tile space.
export default function transformTile(tile, extent) {
export default function transformTile(tile, extent, dimensions = 2) {
if (tile.transformed) return tile;

@@ -18,10 +18,10 @@

if (type === 1) {
for (let j = 0; j < geom.length; j += 2) {
feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
for (let j = 0; j < geom.length; j += dimensions) {
feature.geometry.push(transformPoint(geom, j, dimensions, extent, z2, tx, ty));
}
} else if (type === 2) {
feature.geometry = transformRings(geom, extent, z2, tx, ty);
feature.geometry = transformRings(geom, extent, z2, tx, ty, dimensions);
} else {
for (let j = 0; j < geom.length; j++) {
feature.geometry.push(transformRings(geom[j], extent, z2, tx, ty));
feature.geometry.push(transformRings(geom[j], extent, z2, tx, ty, dimensions));
}

@@ -36,8 +36,8 @@ }

function transformRings(sourceRings, extent, z2, tx, ty) {
function transformRings(sourceRings, extent, z2, tx, ty, dimensions = 2) {
const rings = [];
for (let j = 0; j < sourceRings.length; j++) {
const ring = [];
for (let k = 0; k < sourceRings[j].length; k += 2) {
ring.push(transformPoint(sourceRings[j][k], sourceRings[j][k + 1], extent, z2, tx, ty));
for (let k = 0; k < sourceRings[j].length; k += dimensions) {
ring.push(transformPoint(sourceRings[j], k, dimensions, extent, z2, tx, ty));
}

@@ -49,6 +49,14 @@ rings.push(ring);

function transformPoint(x, y, extent, z2, tx, ty) {
return [
Math.round(extent * (x * z2 - tx)),
Math.round(extent * (y * z2 - ty))];
function transformPoint(geom, index, dimensions, extent, z2, tx, ty) {
const result = [
Math.round(extent * (geom[index] * z2 - tx)),
Math.round(extent * (geom[index + 1] * z2 - ty))
];
for (let i = 2; i < dimensions; i++) {
result.push(geom[index + i]);
}
return result;
}

@@ -7,2 +7,3 @@

const buffer = options.buffer / options.extent;
const stride = options.dimensions + 1;
let merged = features;

@@ -15,4 +16,4 @@ const left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options); // left world copy

if (left) merged = shiftFeatureCoords(left, 1).concat(merged); // merge left into center
if (right) merged = merged.concat(shiftFeatureCoords(right, -1)); // merge right into center
if (left) merged = shiftFeatureCoords(left, 1, stride).concat(merged); // merge left into center
if (right) merged = merged.concat(shiftFeatureCoords(right, -1, stride)); // merge right into center
}

@@ -23,3 +24,3 @@

function shiftFeatureCoords(features, offset) {
function shiftFeatureCoords(features, offset, stride = 3) {
const newFeatures = [];

@@ -34,3 +35,3 @@

if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
newGeometry = shiftCoords(feature.geometry, offset);
newGeometry = shiftCoords(feature.geometry, offset, stride);

@@ -40,3 +41,3 @@ } else if (type === 'MultiLineString' || type === 'Polygon') {

for (const line of feature.geometry) {
newGeometry.push(shiftCoords(line, offset));
newGeometry.push(shiftCoords(line, offset, stride));
}

@@ -48,3 +49,3 @@ } else if (type === 'MultiPolygon') {

for (const line of polygon) {
newPolygon.push(shiftCoords(line, offset));
newPolygon.push(shiftCoords(line, offset, stride));
}

@@ -55,3 +56,3 @@ newGeometry.push(newPolygon);

newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags, feature.index));
newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags, feature.index, stride));
}

@@ -62,3 +63,3 @@

function shiftCoords(points, offset) {
function shiftCoords(points, offset, stride = 3) {
const newPoints = [];

@@ -72,6 +73,9 @@ newPoints.size = points.size;

for (let i = 0; i < points.length; i += 3) {
for (let i = 0; i < points.length; i += stride) {
newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
for (let j = 3; j < stride; j++) {
newPoints.push(points[i + j]);
}
}
return newPoints;
}

@@ -89,2 +89,7 @@ import { GeoJSON } from 'geojson';

debug?: number;
/**
* number of coordinates per vertex in the input array (2 by default)
*/
dimensions?: number;
}

@@ -91,0 +96,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc