@2gis/geojson-vt
Advanced tools
Comparing version 3.3.0 to 3.4.1
@@ -12,3 +12,3 @@ (function (global, factory) { | ||
var stride = dimensions + 1; | ||
var stride = dimensions + 2; | ||
var maxSqDist = sqTolerance; | ||
@@ -77,3 +77,3 @@ var mid = (last - first) >> 1; | ||
function createFeature(id, type, geom, tags, index, stride) { | ||
if ( stride === void 0 ) stride = 3; | ||
if ( stride === void 0 ) stride = 4; | ||
@@ -119,3 +119,3 @@ var feature = { | ||
function calcLineBBox(feature, geom, stride) { | ||
if ( stride === void 0 ) stride = 3; | ||
if ( stride === void 0 ) stride = 4; | ||
@@ -184,3 +184,3 @@ for (var i = 0; i < geom.length; i += stride) { | ||
convertLine(line, geometry, tolerance, false, options.dimensions); | ||
features.push(createFeature(id, 'LineString', geometry, geojson.properties, index, options.dimensions + 1)); | ||
features.push(createFeature(id, 'LineString', geometry, geojson.properties, index, options.dimensions + 2)); | ||
} | ||
@@ -218,3 +218,3 @@ return; | ||
features.push(createFeature(id, type, geometry, geojson.properties, index, options.dimensions + 1)); | ||
features.push(createFeature(id, type, geometry, geojson.properties, index, options.dimensions + 2)); | ||
} | ||
@@ -225,3 +225,3 @@ | ||
out.push(projectX(coords[0]), projectY(coords[1]), 0); | ||
out.push(projectX(coords[0]), projectY(coords[1]), 0, 1); | ||
for (var i = 2; i < dimensions; i++) { | ||
@@ -242,3 +242,3 @@ out.push(coords[i]); | ||
out.push(x, y, 0); | ||
out.push(x, y, 0, 1); | ||
for (var i = 2; i < dimensions; i++) { | ||
@@ -258,3 +258,3 @@ out.push(ring[j][i]); | ||
var last = out.length - (dimensions + 1); | ||
var last = out.length - (dimensions + 2); | ||
out[2] = 1; | ||
@@ -300,3 +300,3 @@ simplify(out, 0, last, tolerance, dimensions); | ||
function clip(features, scale, k1, k2, axis, minAll, maxAll, options) { | ||
var stride = (options.dimensions === undefined ? 2 : options.dimensions) + 1; | ||
var stride = (options.dimensions === undefined ? 2 : options.dimensions) + 2; | ||
k1 /= scale; | ||
@@ -382,3 +382,3 @@ k2 /= scale; | ||
function clipPoints(geom, newGeom, k1, k2, axis, stride) { | ||
if ( stride === void 0 ) stride = 3; | ||
if ( stride === void 0 ) stride = 4; | ||
@@ -398,3 +398,3 @@ for (var i = 0; i < geom.length; i += stride) { | ||
function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics, stride) { | ||
if ( stride === void 0 ) stride = 3; | ||
if ( stride === void 0 ) stride = 4; | ||
@@ -423,3 +423,4 @@ | ||
t = intersect(slice, ax$1, ay$1, bx, by, k1); | ||
for (var j = 3; j < stride; j++) { | ||
slice.push(0); | ||
for (var j = 4; j < stride; j++) { | ||
var aj = geom[i + j]; | ||
@@ -434,3 +435,4 @@ slice.push((geom[i + stride + j] - aj) * t + aj); | ||
t = intersect(slice, ax$1, ay$1, bx, by, k2); | ||
for (var j$1 = 3; j$1 < stride; j$1++) { | ||
slice.push(0); | ||
for (var j$1 = 4; j$1 < stride; j$1++) { | ||
var aj$1 = geom[i + j$1]; | ||
@@ -450,3 +452,4 @@ slice.push((geom[i + stride + j$1] - aj$1) * t + aj$1); | ||
t = intersect(slice, ax$1, ay$1, bx, by, k1); | ||
for (var j$3 = 3; j$3 < stride; j$3++) { | ||
slice.push(0); | ||
for (var j$3 = 4; j$3 < stride; j$3++) { | ||
var aj$2 = geom[i + j$3]; | ||
@@ -460,3 +463,4 @@ slice.push((geom[i + stride + j$3] - aj$2) * t + aj$2); | ||
t = intersect(slice, ax$1, ay$1, bx, by, k2); | ||
for (var j$4 = 3; j$4 < stride; j$4++) { | ||
slice.push(0); | ||
for (var j$4 = 4; j$4 < stride; j$4++) { | ||
var aj$3 = geom[i + j$4]; | ||
@@ -539,3 +543,3 @@ slice.push((geom[i + stride + j$4] - aj$3) * t + aj$3); | ||
var buffer = options.buffer / options.extent; | ||
var stride = options.dimensions + 1; | ||
var stride = options.dimensions + 2; | ||
var merged = features; | ||
@@ -556,3 +560,3 @@ var left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options); // left world copy | ||
function shiftFeatureCoords(features, offset, stride) { | ||
if ( stride === void 0 ) stride = 3; | ||
if ( stride === void 0 ) stride = 4; | ||
@@ -599,3 +603,3 @@ var newFeatures = []; | ||
function shiftCoords(points, offset, stride) { | ||
if ( stride === void 0 ) stride = 3; | ||
if ( stride === void 0 ) stride = 4; | ||
@@ -611,4 +615,4 @@ var newPoints = []; | ||
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] + offset, points[i + 1], points[i + 2], points[i + 3]); | ||
for (var j = 4; j < stride; j++) { | ||
newPoints.push(points[i + j]); | ||
@@ -622,5 +626,3 @@ } | ||
// mercator-projected space into (extent x extent) tile space. | ||
function transformTile(tile, extent, dimensions) { | ||
if ( dimensions === void 0 ) dimensions = 2; | ||
function transformTile(tile, extent, options) { | ||
if (tile.transformed) { return tile; } | ||
@@ -640,11 +642,14 @@ | ||
var delta = options.cuts && type !== 1 ? 1 : 0; | ||
var stride = options.dimensions + delta; | ||
if (type === 1) { | ||
for (var j = 0; j < geom.length; j += dimensions) { | ||
feature.geometry.push(transformPoint(geom, j, dimensions, extent, z2, tx, ty)); | ||
for (var j = 0; j < geom.length; j += stride) { | ||
feature.geometry.push(transformPoint(geom, j, stride, extent, z2, tx, ty)); | ||
} | ||
} else if (type === 2) { | ||
feature.geometry = transformRings(geom, extent, z2, tx, ty, dimensions); | ||
feature.geometry = transformRings(geom, extent, z2, tx, ty, stride); | ||
} else { | ||
for (var j$1 = 0; j$1 < geom.length; j$1++) { | ||
feature.geometry.push(transformRings(geom[j$1], extent, z2, tx, ty, dimensions)); | ||
feature.geometry.push(transformRings(geom[j$1], extent, z2, tx, ty, stride)); | ||
} | ||
@@ -660,3 +665,3 @@ } | ||
function transformRings(sourceRings, extent, z2, tx, ty, dimensions) { | ||
if ( dimensions === void 0 ) dimensions = 2; | ||
if ( dimensions === void 0 ) dimensions = 3; | ||
@@ -716,3 +721,3 @@ var rings = []; | ||
var type = feature.type; | ||
var stride = options.dimensions + 1; | ||
var stride = options.dimensions + 2; | ||
var simplified = []; | ||
@@ -728,3 +733,3 @@ | ||
simplified.push(geom[i], geom[i + 1]); | ||
for (var j = 3; j < stride; j++) { | ||
for (var j = 4; j < stride; j++) { | ||
simplified.push(geom[i + j]); | ||
@@ -737,7 +742,7 @@ } | ||
} else if (type === 'LineString') { | ||
addLine(simplified, geom, tile, tolerance, false, false, stride); | ||
addLine(simplified, geom, tile, tolerance, false, false, options); | ||
} 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, stride); | ||
addLine(simplified, geom[i$1], tile, tolerance, type === 'Polygon', i$1 === 0, options); | ||
} | ||
@@ -755,3 +760,3 @@ | ||
for (var i$2 = 0; i$2 < polygon.length; i$2++) { | ||
addLine(simplifiedPolygon, polygon[i$2], tile, tolerance, true, i$2 === 0, stride); | ||
addLine(simplifiedPolygon, polygon[i$2], tile, tolerance, true, i$2 === 0, options); | ||
} | ||
@@ -790,7 +795,7 @@ if (simplifiedPolygon.length) { | ||
function addLine(result, geom, tile, tolerance, isPolygon, isOuter, stride) { | ||
if ( stride === void 0 ) stride = 3; | ||
function addLine(result, geom, tile, tolerance, isPolygon, isOuter, options) { | ||
var sqTolerance = tolerance * tolerance; | ||
var cuts = options && !!options.cuts; | ||
var stride = options.dimensions + 2; | ||
if (tolerance > 0 && (geom.size < (isPolygon ? sqTolerance : tolerance))) { | ||
@@ -807,5 +812,9 @@ tile.numPoints += geom.length / stride; | ||
ring.push(geom[i], geom[i + 1]); | ||
for (var j = 3; j < stride; j++) { | ||
for (var j = 4; j < stride; j++) { | ||
ring.push(geom[i + j]); | ||
} | ||
if (cuts) { | ||
// сохраняем признак резки самым последним компонентом | ||
ring.push(geom[i + 3]); | ||
} | ||
} | ||
@@ -815,3 +824,6 @@ tile.numPoints++; | ||
if (isPolygon) { rewind(ring, isOuter, stride - 1); } | ||
if (isPolygon) { | ||
var delta = cuts ? 1 : 2; | ||
rewind(ring, isOuter, stride - delta); | ||
} | ||
@@ -822,3 +834,3 @@ result.push(ring); | ||
function rewind(ring, clockwise, dimensions) { | ||
if ( dimensions === void 0 ) dimensions = 2; | ||
if ( dimensions === void 0 ) dimensions = 3; | ||
@@ -860,3 +872,4 @@ var area = 0; | ||
debug: 0, // logging level (0, 1 or 2) | ||
dimensions: 2 // number of coordinates per vertex in the input array (2 by default) | ||
dimensions: 2, // number of coordinates per vertex in the input array (2 by default) | ||
cuts: false // need to generate cuts for polygons | ||
}; | ||
@@ -1018,3 +1031,3 @@ | ||
var id = toID(z, x, y); | ||
if (this.tiles[id]) { return transformTile(this.tiles[id], extent, options.dimensions); } | ||
if (this.tiles[id]) { return transformTile(this.tiles[id], extent, options); } | ||
@@ -1045,3 +1058,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, options.dimensions) : null; | ||
return this.tiles[id] ? transformTile(this.tiles[id], extent, options) : null; | ||
}; | ||
@@ -1048,0 +1061,0 @@ |
@@ -1,1 +0,1 @@ | ||
!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})})); | ||
!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=4);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=4);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+2))}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+2))}}function r(e,n,t){void 0===t&&(t=2),n.push(l(e[0]),u(e[1]),0,1);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,1);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+2);t[2]=1,function e(t,i,o,r,s){void 0===s&&(s=2);for(var a,l=s+2,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)+2;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=4);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=4);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),f.push(0);for(var b=4;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),f.push(0);for(var w=4;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),f.push(0);for(var E=4;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),f.push(0);for(var _=4;_<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=4);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=4);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],e[o+3]);for(var r=4;r<t;r++)i.push(e[o+r])}return i}function y(e,n,t){if(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;l.geometry=[];var h=t.cuts&&1!==f?1:0,m=t.dimensions+h;if(1===f)for(var g=0;g<u.length;g+=m)l.geometry.push(S(u,g,m,n,i,o,r));else if(2===f)l.geometry=P(u,n,i,o,r,m);else for(var d=0;d<u.length;d++)l.geometry.push(P(u[d],n,i,o,r,m))}return e.transformed=!0,e}function P(e,n,t,i,o,r){void 0===r&&(r=3);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+2,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=4;u<s;u++)a.push(o[l+u]);e.numPoints++,e.numSimplified++}else if("LineString"===r)X(a,o,e,t,!1,!1,i);else if("MultiLineString"===r||"Polygon"===r){for(var f=0;f<o.length;f++)X(a,o[f],e,t,"Polygon"===r,0===f,i);"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,i);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){var a=i*i,l=s&&!!s.cuts,u=s.dimensions+2;if(i>0&&n.size<(o?a:i))t.numPoints+=n.length/u;else{for(var f=[],h=0;h<n.length;h+=u){if(0===i||n[h+2]>a){t.numSimplified++,f.push(n[h],n[h+1]);for(var m=4;m<u;m++)f.push(n[h+m]);l&&f.push(n[h+3])}t.numPoints++}if(o)!function(e,n,t){void 0===t&&(t=3);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}}(f,r,u-(l?1:2));e.push(f)}}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,cuts:!1},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+2,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);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):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.3.0", | ||
"version": "3.4.1", | ||
"description": "Slice GeoJSON data into vector tiles efficiently", | ||
@@ -45,3 +45,3 @@ "homepage": "https://github.com/2gis/geojson-vt", | ||
"prepublishOnly": "npm run test && npm run build", | ||
"pub": "npm run build && npm publish" | ||
"pub": "npm run build && npm publish --verbose" | ||
}, | ||
@@ -48,0 +48,0 @@ "files": [ |
@@ -15,3 +15,3 @@ | ||
export default function clip(features, scale, k1, k2, axis, minAll, maxAll, options) { | ||
const stride = (options.dimensions === undefined ? 2 : options.dimensions) + 1; | ||
const stride = (options.dimensions === undefined ? 2 : options.dimensions) + 2; | ||
k1 /= scale; | ||
@@ -90,3 +90,3 @@ k2 /= scale; | ||
function clipPoints(geom, newGeom, k1, k2, axis, stride = 3) { | ||
function clipPoints(geom, newGeom, k1, k2, axis, stride = 4) { | ||
for (let i = 0; i < geom.length; i += stride) { | ||
@@ -104,3 +104,3 @@ const a = geom[i + axis]; | ||
function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics, stride = 3) { | ||
function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics, stride = 4) { | ||
@@ -128,3 +128,4 @@ let slice = newSlice(geom); | ||
t = intersect(slice, ax, ay, bx, by, k1); | ||
for (let j = 3; j < stride; j++) { | ||
slice.push(0); | ||
for (let j = 4; j < stride; j++) { | ||
const aj = geom[i + j]; | ||
@@ -139,3 +140,4 @@ slice.push((geom[i + stride + j] - aj) * t + aj); | ||
t = intersect(slice, ax, ay, bx, by, k2); | ||
for (let j = 3; j < stride; j++) { | ||
slice.push(0); | ||
for (let j = 4; j < stride; j++) { | ||
const aj = geom[i + j]; | ||
@@ -155,3 +157,4 @@ slice.push((geom[i + stride + j] - aj) * t + aj); | ||
t = intersect(slice, ax, ay, bx, by, k1); | ||
for (let j = 3; j < stride; j++) { | ||
slice.push(0); | ||
for (let j = 4; j < stride; j++) { | ||
const aj = geom[i + j]; | ||
@@ -165,3 +168,4 @@ slice.push((geom[i + stride + j] - aj) * t + aj); | ||
t = intersect(slice, ax, ay, bx, by, k2); | ||
for (let j = 3; j < stride; j++) { | ||
slice.push(0); | ||
for (let j = 4; j < stride; j++) { | ||
const aj = geom[i + j]; | ||
@@ -168,0 +172,0 @@ slice.push((geom[i + stride + j] - aj) * t + aj); |
@@ -55,3 +55,3 @@ | ||
convertLine(line, geometry, tolerance, false, options.dimensions); | ||
features.push(createFeature(id, 'LineString', geometry, geojson.properties, index, options.dimensions + 1)); | ||
features.push(createFeature(id, 'LineString', geometry, geojson.properties, index, options.dimensions + 2)); | ||
} | ||
@@ -85,7 +85,7 @@ return; | ||
features.push(createFeature(id, type, geometry, geojson.properties, index, options.dimensions + 1)); | ||
features.push(createFeature(id, type, geometry, geojson.properties, index, options.dimensions + 2)); | ||
} | ||
function convertPoint(coords, out, dimensions = 2) { | ||
out.push(projectX(coords[0]), projectY(coords[1]), 0); | ||
out.push(projectX(coords[0]), projectY(coords[1]), 0, 1); | ||
for (let i = 2; i < dimensions; i++) { | ||
@@ -104,3 +104,3 @@ out.push(coords[i]); | ||
out.push(x, y, 0); | ||
out.push(x, y, 0, 1); | ||
for (let i = 2; i < dimensions; i++) { | ||
@@ -120,3 +120,3 @@ out.push(ring[j][i]); | ||
const last = out.length - (dimensions + 1); | ||
const last = out.length - (dimensions + 2); | ||
out[2] = 1; | ||
@@ -123,0 +123,0 @@ simplify(out, 0, last, tolerance, dimensions); |
export default function createFeature(id, type, geom, tags, index, stride = 3) { | ||
export default function createFeature(id, type, geom, tags, index, stride = 4) { | ||
const feature = { | ||
@@ -37,3 +37,3 @@ id: id == null ? null : id, | ||
function calcLineBBox(feature, geom, stride = 3) { | ||
function calcLineBBox(feature, geom, stride = 4) { | ||
for (let i = 0; i < geom.length; i += stride) { | ||
@@ -40,0 +40,0 @@ feature.minX = Math.min(feature.minX, geom[i]); |
@@ -26,3 +26,4 @@ | ||
debug: 0, // logging level (0, 1 or 2) | ||
dimensions: 2 // number of coordinates per vertex in the input array (2 by default) | ||
dimensions: 2, // number of coordinates per vertex in the input array (2 by default) | ||
cuts: false // need to generate cuts for polygons | ||
}; | ||
@@ -184,3 +185,3 @@ | ||
const id = toID(z, x, y); | ||
if (this.tiles[id]) return transform(this.tiles[id], extent, options.dimensions); | ||
if (this.tiles[id]) return transform(this.tiles[id], extent, options); | ||
@@ -211,3 +212,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, options.dimensions) : null; | ||
return this.tiles[id] ? transform(this.tiles[id], extent, options) : null; | ||
} | ||
@@ -214,0 +215,0 @@ } |
@@ -5,3 +5,3 @@ | ||
export default function simplify(coords, first, last, sqTolerance, dimensions = 2) { | ||
const stride = dimensions + 1; | ||
const stride = dimensions + 2; | ||
let maxSqDist = sqTolerance; | ||
@@ -8,0 +8,0 @@ const mid = (last - first) >> 1; |
@@ -28,3 +28,3 @@ | ||
const type = feature.type; | ||
const stride = options.dimensions + 1; | ||
const stride = options.dimensions + 2; | ||
let simplified = []; | ||
@@ -40,3 +40,3 @@ | ||
simplified.push(geom[i], geom[i + 1]); | ||
for (let j = 3; j < stride; j++) { | ||
for (let j = 4; j < stride; j++) { | ||
simplified.push(geom[i + j]); | ||
@@ -49,7 +49,7 @@ } | ||
} else if (type === 'LineString') { | ||
addLine(simplified, geom, tile, tolerance, false, false, stride); | ||
addLine(simplified, geom, tile, tolerance, false, false, options); | ||
} else if (type === 'MultiLineString' || type === 'Polygon') { | ||
for (let i = 0; i < geom.length; i++) { | ||
addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0, stride); | ||
addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0, options); | ||
} | ||
@@ -67,3 +67,3 @@ | ||
for (let i = 0; i < polygon.length; i++) { | ||
addLine(simplifiedPolygon, polygon[i], tile, tolerance, true, i === 0, stride); | ||
addLine(simplifiedPolygon, polygon[i], tile, tolerance, true, i === 0, options); | ||
} | ||
@@ -102,5 +102,7 @@ if (simplifiedPolygon.length) { | ||
function addLine(result, geom, tile, tolerance, isPolygon, isOuter, stride = 3) { | ||
function addLine(result, geom, tile, tolerance, isPolygon, isOuter, options) { | ||
const sqTolerance = tolerance * tolerance; | ||
const cuts = options && !!options.cuts; | ||
const stride = options.dimensions + 2; | ||
if (tolerance > 0 && (geom.size < (isPolygon ? sqTolerance : tolerance))) { | ||
@@ -117,5 +119,9 @@ tile.numPoints += geom.length / stride; | ||
ring.push(geom[i], geom[i + 1]); | ||
for (let j = 3; j < stride; j++) { | ||
for (let j = 4; j < stride; j++) { | ||
ring.push(geom[i + j]); | ||
} | ||
if (cuts) { | ||
// сохраняем признак резки самым последним компонентом | ||
ring.push(geom[i + 3]); | ||
} | ||
} | ||
@@ -125,3 +131,6 @@ tile.numPoints++; | ||
if (isPolygon) rewind(ring, isOuter, stride - 1); | ||
if (isPolygon) { | ||
const delta = cuts ? 1 : 2; | ||
rewind(ring, isOuter, stride - delta); | ||
} | ||
@@ -131,3 +140,3 @@ result.push(ring); | ||
function rewind(ring, clockwise, dimensions = 2) { | ||
function rewind(ring, clockwise, dimensions = 3) { | ||
let area = 0; | ||
@@ -134,0 +143,0 @@ for (let i = 0, len = ring.length, j = len - dimensions; i < len; j = i, i += dimensions) { |
// 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, dimensions = 2) { | ||
export default function transformTile(tile, extent, options) { | ||
if (tile.transformed) return tile; | ||
@@ -17,11 +17,14 @@ | ||
const delta = options.cuts && type !== 1 ? 1 : 0; | ||
const stride = options.dimensions + delta; | ||
if (type === 1) { | ||
for (let j = 0; j < geom.length; j += dimensions) { | ||
feature.geometry.push(transformPoint(geom, j, dimensions, extent, z2, tx, ty)); | ||
for (let j = 0; j < geom.length; j += stride) { | ||
feature.geometry.push(transformPoint(geom, j, stride, extent, z2, tx, ty)); | ||
} | ||
} else if (type === 2) { | ||
feature.geometry = transformRings(geom, extent, z2, tx, ty, dimensions); | ||
feature.geometry = transformRings(geom, extent, z2, tx, ty, stride); | ||
} else { | ||
for (let j = 0; j < geom.length; j++) { | ||
feature.geometry.push(transformRings(geom[j], extent, z2, tx, ty, dimensions)); | ||
feature.geometry.push(transformRings(geom[j], extent, z2, tx, ty, stride)); | ||
} | ||
@@ -36,3 +39,3 @@ } | ||
function transformRings(sourceRings, extent, z2, tx, ty, dimensions = 2) { | ||
function transformRings(sourceRings, extent, z2, tx, ty, dimensions = 3) { | ||
const rings = []; | ||
@@ -39,0 +42,0 @@ for (let j = 0; j < sourceRings.length; j++) { |
@@ -7,3 +7,3 @@ | ||
const buffer = options.buffer / options.extent; | ||
const stride = options.dimensions + 1; | ||
const stride = options.dimensions + 2; | ||
let merged = features; | ||
@@ -23,3 +23,3 @@ const left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options); // left world copy | ||
function shiftFeatureCoords(features, offset, stride = 3) { | ||
function shiftFeatureCoords(features, offset, stride = 4) { | ||
const newFeatures = []; | ||
@@ -58,3 +58,3 @@ | ||
function shiftCoords(points, offset, stride = 3) { | ||
function shiftCoords(points, offset, stride = 4) { | ||
const newPoints = []; | ||
@@ -69,4 +69,4 @@ newPoints.size = points.size; | ||
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] + offset, points[i + 1], points[i + 2], points[i + 3]); | ||
for (let j = 4; j < stride; j++) { | ||
newPoints.push(points[i + j]); | ||
@@ -73,0 +73,0 @@ } |
@@ -73,3 +73,3 @@ import { GeoJSON } from 'geojson'; | ||
*/ | ||
promoteId?: number | null; | ||
promoteId?: string | null; | ||
@@ -95,2 +95,7 @@ /** | ||
dimensions?: number; | ||
/** | ||
* whether to generate cuts in last component of polygon and line points (false by default) | ||
*/ | ||
cuts?: boolean; | ||
} | ||
@@ -97,0 +102,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
87016
1819
1