geojson-vt
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -151,4 +151,4 @@ (function (global, factory) { | ||
features.push(createFeature(geojson.id, 'LineString', geometry, geojson.properties)); | ||
return; | ||
} | ||
return; | ||
} else { | ||
@@ -155,0 +155,0 @@ convertLines(coords, geometry, tolerance, false); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.geojsonvt=e()}(this,function(){"use strict";function t(t,e,n,i,o,r){var s=o-n,l=r-i;if(0!==s||0!==l){var u=((t-n)*s+(e-i)*l)/(s*s+l*l);u>1?(n=o,i=r):u>0&&(n+=s*u,i+=l*u)}return(s=t-n)*s+(l=e-i)*l}function e(t,e,i,o){var r={id:t||null,type:e,geometry:i,tags:o,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};return function(t){var e=t.geometry,i=t.type;if("Point"===i||"MultiPoint"===i||"LineString"===i)n(t,e);else if("Polygon"===i||"MultiLineString"===i)for(var o=0;o<e.length;o++)n(t,e[o]);else if("MultiPolygon"===i)for(o=0;o<e.length;o++)for(var r=0;r<e[o].length;r++)n(t,e[o][r])}(r),r}function n(t,e){for(var n=0;n<e.length;n+=3)t.minX=Math.min(t.minX,e[n]),t.minY=Math.min(t.minY,e[n+1]),t.maxX=Math.max(t.maxX,e[n]),t.maxY=Math.max(t.maxY,e[n+1])}function i(t,n,l){if(n.geometry){var u=n.geometry.coordinates,a=n.geometry.type,f=Math.pow(l.tolerance/((1<<l.maxZoom)*l.extent),2),h=[];if("Point"===a)o(u,h);else if("MultiPoint"===a)for(var g=0;g<u.length;g++)o(u[g],h);else if("LineString"===a)r(u,h,f,!1);else if("MultiLineString"===a)if(l.lineMetrics)for(g=0;g<u.length;g++)return h=[],r(u[g],h,f,!1),void t.push(e(n.id,"LineString",h,n.properties));else s(u,h,f,!1);else if("Polygon"===a)s(u,h,f,!0);else{if("MultiPolygon"!==a){if("GeometryCollection"===a){for(g=0;g<n.geometry.geometries.length;g++)i(t,{id:n.id,geometry:n.geometry.geometries[g],properties:n.properties},l);return}throw new Error("Input data is not a valid GeoJSON object.")}for(g=0;g<u.length;g++){var m=[];s(u[g],m,f,!0),h.push(m)}}t.push(e(n.id,a,h,n.properties))}}function o(t,e){e.push(l(t[0])),e.push(u(t[1])),e.push(0)}function r(e,n,i,o){for(var r,s,a=0,f=0;f<e.length;f++){var h=l(e[f][0]),g=u(e[f][1]);n.push(h),n.push(g),n.push(0),f>0&&(a+=o?(r*g-h*s)/2:Math.sqrt(Math.pow(h-r,2)+Math.pow(g-s,2))),r=h,s=g}var m=n.length-3;n[2]=1,function e(n,i,o,r){for(var s,l=r,u=n[i],a=n[i+1],f=n[o],h=n[o+1],g=i+3;g<o;g+=3){var m=t(n[g],n[g+1],u,a,f,h);m>l&&(s=g,l=m)}l>r&&(s-i>3&&e(n,i,s,r),n[s+2]=l,o-s>3&&e(n,s,o,r))}(n,0,m,i),n[m+2]=1,n.size=Math.abs(a),n.start=0,n.end=n.size}function s(t,e,n,i){for(var o=0;o<t.length;o++){var s=[];r(t[o],s,n,i),e.push(s)}}function l(t){return t/360+.5}function u(t){var e=Math.sin(t*Math.PI/180),n=.5-.25*Math.log((1+e)/(1-e))/Math.PI;return n<0?0:n>1?1:n}function a(t,n,i,o,r,s,l,u){if(o/=n,s>=(i/=n)&&l<o)return t;if(l<i||s>=o)return null;for(var a=[],g=0;g<t.length;g++){var p=t[g],c=p.geometry,d=p.type,v=0===r?p.minX:p.minY,x=0===r?p.maxX:p.maxY;if(v>=i&&x<o)a.push(p);else if(!(x<i||v>=o)){var y=[];if("Point"===d||"MultiPoint"===d)f(c,y,i,o,r);else if("LineString"===d)h(c,y,i,o,r,!1,u.lineMetrics);else if("MultiLineString"===d)m(c,y,i,o,r,!1);else if("Polygon"===d)m(c,y,i,o,r,!0);else if("MultiPolygon"===d)for(var M=0;M<c.length;M++){var P=[];m(c[M],P,i,o,r,!0),P.length&&y.push(P)}if(y.length){if(u.lineMetrics&&"LineString"===d){for(M=0;M<y.length;M++)a.push(e(p.id,d,y[M],p.tags));continue}"LineString"!==d&&"MultiLineString"!==d||(1===y.length?(d="LineString",y=y[0]):d="MultiLineString"),"Point"!==d&&"MultiPoint"!==d||(d=3===y.length?"Point":"MultiPoint"),a.push(e(p.id,d,y,p.tags))}}}return a.length?a:null}function f(t,e,n,i,o){for(var r=0;r<t.length;r+=3){var s=t[r+o];s>=n&&s<=i&&(e.push(t[r]),e.push(t[r+1]),e.push(t[r+2]))}}function h(t,e,n,i,o,r,s){for(var l,u,a=g(t),f=0===o?c:d,h=t.start,m=0;m<t.length-3;m+=3){var v=t[m],x=t[m+1],y=t[m+2],M=t[m+3],P=t[m+4],S=0===o?v:x,Y=0===o?M:P,X=!1;s&&(l=Math.sqrt(Math.pow(v-M,2)+Math.pow(x-P,2))),S<n?Y>=n&&(u=f(a,v,x,M,P,n),s&&(a.start=h+l*u)):S>=i?Y<i&&(u=f(a,v,x,M,P,i),s&&(a.start=h+l*u)):p(a,v,x,y),Y<n&&S>=n&&(u=f(a,v,x,M,P,n),X=!0),Y>i&&S<=i&&(u=f(a,v,x,M,P,i),X=!0),!r&&X&&(s&&(a.end=h+l*u),e.push(a),a=g(t)),s&&(h+=l)}var L=t.length-3;v=t[L],x=t[L+1],y=t[L+2],(S=0===o?v:x)>=n&&S<=i&&p(a,v,x,y),L=a.length-3,r&&L>=3&&(a[L]!==a[0]||a[L+1]!==a[1])&&p(a,a[0],a[1],a[2]),a.length&&e.push(a)}function g(t){var e=[];return e.size=t.size,e.start=t.start,e.end=t.end,e}function m(t,e,n,i,o,r){for(var s=0;s<t.length;s++)h(t[s],e,n,i,o,r,!1)}function p(t,e,n,i){t.push(e),t.push(n),t.push(i)}function c(t,e,n,i,o,r){var s=(r-e)/(i-e);return t.push(r),t.push(n+(o-n)*s),t.push(1),s}function d(t,e,n,i,o,r){var s=(r-n)/(o-n);return t.push(e+(i-e)*s),t.push(r),t.push(1),s}function v(t,n){for(var i=[],o=0;o<t.length;o++){var r,s=t[o],l=s.type;if("Point"===l||"MultiPoint"===l||"LineString"===l)r=x(s.geometry,n);else if("MultiLineString"===l||"Polygon"===l){r=[];for(var u=0;u<s.geometry.length;u++)r.push(x(s.geometry[u],n))}else if("MultiPolygon"===l)for(r=[],u=0;u<s.geometry.length;u++){for(var a=[],f=0;f<s.geometry[u].length;f++)a.push(x(s.geometry[u][f],n));r.push(a)}i.push(e(s.id,l,r,s.tags))}return i}function x(t,e){var n=[];n.size=t.size,void 0!==t.start&&(n.start=t.start,n.end=t.end);for(var i=0;i<t.length;i+=3)n.push(t[i]+e,t[i+1],t[i+2]);return n}function y(t,e){if(t.transformed)return t;var n,i,o,r=1<<t.z,s=t.x,l=t.y;for(n=0;n<t.features.length;n++){var u=t.features[n],a=u.geometry,f=u.type;if(u.geometry=[],1===f)for(i=0;i<a.length;i+=2)u.geometry.push(M(a[i],a[i+1],e,r,s,l));else for(i=0;i<a.length;i++){var h=[];for(o=0;o<a[i].length;o+=2)h.push(M(a[i][o],a[i][o+1],e,r,s,l));u.geometry.push(h)}}return t.transformed=!0,t}function M(t,e,n,i,o,r){return[Math.round(n*(t*i-o)),Math.round(n*(e*i-r))]}function P(t,e,n,i,o){for(var r=e===o.maxZoom?0:o.tolerance/((1<<e)*o.extent),s={features:[],numPoints:0,numSimplified:0,numFeatures:0,source:null,x:n,y:i,z:e,transformed:!1,minX:2,minY:1,maxX:-1,maxY:0},l=0;l<t.length;l++){s.numFeatures++,S(s,t[l],r,o);var u=t[l].minX,a=t[l].minY,f=t[l].maxX,h=t[l].maxY;u<s.minX&&(s.minX=u),a<s.minY&&(s.minY=a),f>s.maxX&&(s.maxX=f),h>s.maxY&&(s.maxY=h)}return s}function S(t,e,n,i){var o=e.geometry,r=e.type,s=[];if("Point"===r||"MultiPoint"===r)for(var l=0;l<o.length;l+=3)s.push(o[l]),s.push(o[l+1]),t.numPoints++,t.numSimplified++;else if("LineString"===r)Y(s,o,t,n,!1,!1);else if("MultiLineString"===r||"Polygon"===r)for(l=0;l<o.length;l++)Y(s,o[l],t,n,"Polygon"===r,0===l);else if("MultiPolygon"===r)for(var u=0;u<o.length;u++){var a=o[u];for(l=0;l<a.length;l++)Y(s,a[l],t,n,!0,0===l)}if(s.length){var f=e.tags||null;if("LineString"===r&&i.lineMetrics){for(var h in f={},e.tags)f[h]=e.tags[h];f.mapbox_clip_start=o.start/o.size,f.mapbox_clip_end=o.end/o.size}var g={geometry:s,type:"Polygon"===r||"MultiPolygon"===r?3:"LineString"===r||"MultiLineString"===r?2:1,tags:f};null!==e.id&&(g.id=e.id),t.features.push(g)}}function Y(t,e,n,i,o,r){var s=i*i;if(i>0&&e.size<(o?s:i))n.numPoints+=e.length/3;else{for(var l=[],u=0;u<e.length;u+=3)(0===i||e[u+2]>s)&&(n.numSimplified++,l.push(e[u]),l.push(e[u+1])),n.numPoints++;o&&function(t,e){for(var n=0,i=0,o=t.length,r=o-2;i<o;r=i,i+=2)n+=(t[i]-t[r])*(t[i+1]+t[r+1]);if(n>0===e)for(i=0,o=t.length;i<o/2;i+=2){var s=t[i],l=t[i+1];t[i]=t[o-2-i],t[i+1]=t[o-1-i],t[o-2-i]=s,t[o-1-i]=l}}(l,r),t.push(l)}}function X(t,e){var n=(e=this.options=function(t,e){for(var n in e)t[n]=e[n];return t}(Object.create(this.options),e)).debug;if(n&&console.time("preprocess data"),e.maxZoom<0||e.maxZoom>24)throw new Error("maxZoom should be in the 0-24 range");var o=function(t,e){var n=[];if("FeatureCollection"===t.type)for(var o=0;o<t.features.length;o++)i(n,t.features[o],e);else"Feature"===t.type?i(n,t,e):i(n,{geometry:t},e);return n}(t,e);this.tiles={},this.tileCoords=[],n&&(console.timeEnd("preprocess data"),console.log("index: maxZoom: %d, maxPoints: %d",e.indexMaxZoom,e.indexMaxPoints),console.time("generate tiles"),this.stats={},this.total=0),(o=function(t,e){var n=e.buffer/e.extent,i=t,o=a(t,1,-1-n,n,0,-1,2,e),r=a(t,1,1-n,2+n,0,-1,2,e);return(o||r)&&(i=a(t,1,-n,1+n,0,-1,2,e)||[],o&&(i=v(o,1).concat(i)),r&&(i=i.concat(v(r,-1)))),i}(o,e)).length&&this.splitTile(o,0,0,0),n&&(o.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 L(t,e,n){return 32*((1<<t)*n+e)+t}return X.prototype.options={maxZoom:14,indexMaxZoom:5,indexMaxPoints:1e5,tolerance:3,extent:4096,buffer:64,lineMetrics:!1,debug:0},X.prototype.splitTile=function(t,e,n,i,o,r,s){for(var l=[t,e,n,i],u=this.options,f=u.debug;l.length;){i=l.pop(),n=l.pop(),e=l.pop(),t=l.pop();var h=1<<e,g=L(e,n,i),m=this.tiles[g];if(!m&&(f>1&&console.time("creation"),m=this.tiles[g]=P(t,e,n,i,u),this.tileCoords.push({z:e,x:n,y:i}),f)){f>1&&(console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",e,n,i,m.numFeatures,m.numPoints,m.numSimplified),console.timeEnd("creation"));var p="z"+e;this.stats[p]=(this.stats[p]||0)+1,this.total++}if(m.source=t,o){if(e===u.maxZoom||e===o)continue;var c=1<<o-e;if(n!==Math.floor(r/c)||i!==Math.floor(s/c))continue}else if(e===u.indexMaxZoom||m.numPoints<=u.indexMaxPoints)continue;if(m.source=null,0!==t.length){f>1&&console.time("clipping");var d,v,x,y,M,S,Y=.5*u.buffer/u.extent,X=.5-Y,z=.5+Y,b=1+Y;d=v=x=y=null,M=a(t,h,n-Y,n+z,0,m.minX,m.maxX,u),S=a(t,h,n+X,n+b,0,m.minX,m.maxX,u),t=null,M&&(d=a(M,h,i-Y,i+z,1,m.minY,m.maxY,u),v=a(M,h,i+X,i+b,1,m.minY,m.maxY,u),M=null),S&&(x=a(S,h,i-Y,i+z,1,m.minY,m.maxY,u),y=a(S,h,i+X,i+b,1,m.minY,m.maxY,u),S=null),f>1&&console.timeEnd("clipping"),l.push(d||[],e+1,2*n,2*i),l.push(v||[],e+1,2*n,2*i+1),l.push(x||[],e+1,2*n+1,2*i),l.push(y||[],e+1,2*n+1,2*i+1)}}},X.prototype.getTile=function(t,e,n){var i=this.options,o=i.extent,r=i.debug;if(t<0||t>24)return null;var s=1<<t,l=L(t,e=(e%s+s)%s,n);if(this.tiles[l])return y(this.tiles[l],o);r>1&&console.log("drilling down to z%d-%d-%d",t,e,n);for(var u,a=t,f=e,h=n;!u&&a>0;)a--,f=Math.floor(f/2),h=Math.floor(h/2),u=this.tiles[L(a,f,h)];return u&&u.source?(r>1&&console.log("found parent tile z%d-%d-%d",a,f,h),r>1&&console.time("drilling down"),this.splitTile(u.source,a,f,h,t,e,n),r>1&&console.timeEnd("drilling down"),this.tiles[l]?y(this.tiles[l],o):null):null},function(t,e){return new X(t,e)}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.geojsonvt=e()}(this,function(){"use strict";function t(t,e,n,i,o,r){var s=o-n,l=r-i;if(0!==s||0!==l){var u=((t-n)*s+(e-i)*l)/(s*s+l*l);u>1?(n=o,i=r):u>0&&(n+=s*u,i+=l*u)}return(s=t-n)*s+(l=e-i)*l}function e(t,e,i,o){var r={id:t||null,type:e,geometry:i,tags:o,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};return function(t){var e=t.geometry,i=t.type;if("Point"===i||"MultiPoint"===i||"LineString"===i)n(t,e);else if("Polygon"===i||"MultiLineString"===i)for(var o=0;o<e.length;o++)n(t,e[o]);else if("MultiPolygon"===i)for(o=0;o<e.length;o++)for(var r=0;r<e[o].length;r++)n(t,e[o][r])}(r),r}function n(t,e){for(var n=0;n<e.length;n+=3)t.minX=Math.min(t.minX,e[n]),t.minY=Math.min(t.minY,e[n+1]),t.maxX=Math.max(t.maxX,e[n]),t.maxY=Math.max(t.maxY,e[n+1])}function i(t,n,l){if(n.geometry){var u=n.geometry.coordinates,a=n.geometry.type,f=Math.pow(l.tolerance/((1<<l.maxZoom)*l.extent),2),h=[];if("Point"===a)o(u,h);else if("MultiPoint"===a)for(var g=0;g<u.length;g++)o(u[g],h);else if("LineString"===a)r(u,h,f,!1);else if("MultiLineString"===a){if(l.lineMetrics){for(g=0;g<u.length;g++)h=[],r(u[g],h,f,!1),t.push(e(n.id,"LineString",h,n.properties));return}s(u,h,f,!1)}else if("Polygon"===a)s(u,h,f,!0);else{if("MultiPolygon"!==a){if("GeometryCollection"===a){for(g=0;g<n.geometry.geometries.length;g++)i(t,{id:n.id,geometry:n.geometry.geometries[g],properties:n.properties},l);return}throw new Error("Input data is not a valid GeoJSON object.")}for(g=0;g<u.length;g++){var m=[];s(u[g],m,f,!0),h.push(m)}}t.push(e(n.id,a,h,n.properties))}}function o(t,e){e.push(l(t[0])),e.push(u(t[1])),e.push(0)}function r(e,n,i,o){for(var r,s,a=0,f=0;f<e.length;f++){var h=l(e[f][0]),g=u(e[f][1]);n.push(h),n.push(g),n.push(0),f>0&&(a+=o?(r*g-h*s)/2:Math.sqrt(Math.pow(h-r,2)+Math.pow(g-s,2))),r=h,s=g}var m=n.length-3;n[2]=1,function e(n,i,o,r){for(var s,l=r,u=n[i],a=n[i+1],f=n[o],h=n[o+1],g=i+3;g<o;g+=3){var m=t(n[g],n[g+1],u,a,f,h);m>l&&(s=g,l=m)}l>r&&(s-i>3&&e(n,i,s,r),n[s+2]=l,o-s>3&&e(n,s,o,r))}(n,0,m,i),n[m+2]=1,n.size=Math.abs(a),n.start=0,n.end=n.size}function s(t,e,n,i){for(var o=0;o<t.length;o++){var s=[];r(t[o],s,n,i),e.push(s)}}function l(t){return t/360+.5}function u(t){var e=Math.sin(t*Math.PI/180),n=.5-.25*Math.log((1+e)/(1-e))/Math.PI;return n<0?0:n>1?1:n}function a(t,n,i,o,r,s,l,u){if(o/=n,s>=(i/=n)&&l<o)return t;if(l<i||s>=o)return null;for(var a=[],g=0;g<t.length;g++){var p=t[g],c=p.geometry,d=p.type,v=0===r?p.minX:p.minY,x=0===r?p.maxX:p.maxY;if(v>=i&&x<o)a.push(p);else if(!(x<i||v>=o)){var y=[];if("Point"===d||"MultiPoint"===d)f(c,y,i,o,r);else if("LineString"===d)h(c,y,i,o,r,!1,u.lineMetrics);else if("MultiLineString"===d)m(c,y,i,o,r,!1);else if("Polygon"===d)m(c,y,i,o,r,!0);else if("MultiPolygon"===d)for(var M=0;M<c.length;M++){var P=[];m(c[M],P,i,o,r,!0),P.length&&y.push(P)}if(y.length){if(u.lineMetrics&&"LineString"===d){for(M=0;M<y.length;M++)a.push(e(p.id,d,y[M],p.tags));continue}"LineString"!==d&&"MultiLineString"!==d||(1===y.length?(d="LineString",y=y[0]):d="MultiLineString"),"Point"!==d&&"MultiPoint"!==d||(d=3===y.length?"Point":"MultiPoint"),a.push(e(p.id,d,y,p.tags))}}}return a.length?a:null}function f(t,e,n,i,o){for(var r=0;r<t.length;r+=3){var s=t[r+o];s>=n&&s<=i&&(e.push(t[r]),e.push(t[r+1]),e.push(t[r+2]))}}function h(t,e,n,i,o,r,s){for(var l,u,a=g(t),f=0===o?c:d,h=t.start,m=0;m<t.length-3;m+=3){var v=t[m],x=t[m+1],y=t[m+2],M=t[m+3],P=t[m+4],S=0===o?v:x,Y=0===o?M:P,X=!1;s&&(l=Math.sqrt(Math.pow(v-M,2)+Math.pow(x-P,2))),S<n?Y>=n&&(u=f(a,v,x,M,P,n),s&&(a.start=h+l*u)):S>=i?Y<i&&(u=f(a,v,x,M,P,i),s&&(a.start=h+l*u)):p(a,v,x,y),Y<n&&S>=n&&(u=f(a,v,x,M,P,n),X=!0),Y>i&&S<=i&&(u=f(a,v,x,M,P,i),X=!0),!r&&X&&(s&&(a.end=h+l*u),e.push(a),a=g(t)),s&&(h+=l)}var L=t.length-3;v=t[L],x=t[L+1],y=t[L+2],(S=0===o?v:x)>=n&&S<=i&&p(a,v,x,y),L=a.length-3,r&&L>=3&&(a[L]!==a[0]||a[L+1]!==a[1])&&p(a,a[0],a[1],a[2]),a.length&&e.push(a)}function g(t){var e=[];return e.size=t.size,e.start=t.start,e.end=t.end,e}function m(t,e,n,i,o,r){for(var s=0;s<t.length;s++)h(t[s],e,n,i,o,r,!1)}function p(t,e,n,i){t.push(e),t.push(n),t.push(i)}function c(t,e,n,i,o,r){var s=(r-e)/(i-e);return t.push(r),t.push(n+(o-n)*s),t.push(1),s}function d(t,e,n,i,o,r){var s=(r-n)/(o-n);return t.push(e+(i-e)*s),t.push(r),t.push(1),s}function v(t,n){for(var i=[],o=0;o<t.length;o++){var r,s=t[o],l=s.type;if("Point"===l||"MultiPoint"===l||"LineString"===l)r=x(s.geometry,n);else if("MultiLineString"===l||"Polygon"===l){r=[];for(var u=0;u<s.geometry.length;u++)r.push(x(s.geometry[u],n))}else if("MultiPolygon"===l)for(r=[],u=0;u<s.geometry.length;u++){for(var a=[],f=0;f<s.geometry[u].length;f++)a.push(x(s.geometry[u][f],n));r.push(a)}i.push(e(s.id,l,r,s.tags))}return i}function x(t,e){var n=[];n.size=t.size,void 0!==t.start&&(n.start=t.start,n.end=t.end);for(var i=0;i<t.length;i+=3)n.push(t[i]+e,t[i+1],t[i+2]);return n}function y(t,e){if(t.transformed)return t;var n,i,o,r=1<<t.z,s=t.x,l=t.y;for(n=0;n<t.features.length;n++){var u=t.features[n],a=u.geometry,f=u.type;if(u.geometry=[],1===f)for(i=0;i<a.length;i+=2)u.geometry.push(M(a[i],a[i+1],e,r,s,l));else for(i=0;i<a.length;i++){var h=[];for(o=0;o<a[i].length;o+=2)h.push(M(a[i][o],a[i][o+1],e,r,s,l));u.geometry.push(h)}}return t.transformed=!0,t}function M(t,e,n,i,o,r){return[Math.round(n*(t*i-o)),Math.round(n*(e*i-r))]}function P(t,e,n,i,o){for(var r=e===o.maxZoom?0:o.tolerance/((1<<e)*o.extent),s={features:[],numPoints:0,numSimplified:0,numFeatures:0,source:null,x:n,y:i,z:e,transformed:!1,minX:2,minY:1,maxX:-1,maxY:0},l=0;l<t.length;l++){s.numFeatures++,S(s,t[l],r,o);var u=t[l].minX,a=t[l].minY,f=t[l].maxX,h=t[l].maxY;u<s.minX&&(s.minX=u),a<s.minY&&(s.minY=a),f>s.maxX&&(s.maxX=f),h>s.maxY&&(s.maxY=h)}return s}function S(t,e,n,i){var o=e.geometry,r=e.type,s=[];if("Point"===r||"MultiPoint"===r)for(var l=0;l<o.length;l+=3)s.push(o[l]),s.push(o[l+1]),t.numPoints++,t.numSimplified++;else if("LineString"===r)Y(s,o,t,n,!1,!1);else if("MultiLineString"===r||"Polygon"===r)for(l=0;l<o.length;l++)Y(s,o[l],t,n,"Polygon"===r,0===l);else if("MultiPolygon"===r)for(var u=0;u<o.length;u++){var a=o[u];for(l=0;l<a.length;l++)Y(s,a[l],t,n,!0,0===l)}if(s.length){var f=e.tags||null;if("LineString"===r&&i.lineMetrics){for(var h in f={},e.tags)f[h]=e.tags[h];f.mapbox_clip_start=o.start/o.size,f.mapbox_clip_end=o.end/o.size}var g={geometry:s,type:"Polygon"===r||"MultiPolygon"===r?3:"LineString"===r||"MultiLineString"===r?2:1,tags:f};null!==e.id&&(g.id=e.id),t.features.push(g)}}function Y(t,e,n,i,o,r){var s=i*i;if(i>0&&e.size<(o?s:i))n.numPoints+=e.length/3;else{for(var l=[],u=0;u<e.length;u+=3)(0===i||e[u+2]>s)&&(n.numSimplified++,l.push(e[u]),l.push(e[u+1])),n.numPoints++;o&&function(t,e){for(var n=0,i=0,o=t.length,r=o-2;i<o;r=i,i+=2)n+=(t[i]-t[r])*(t[i+1]+t[r+1]);if(n>0===e)for(i=0,o=t.length;i<o/2;i+=2){var s=t[i],l=t[i+1];t[i]=t[o-2-i],t[i+1]=t[o-1-i],t[o-2-i]=s,t[o-1-i]=l}}(l,r),t.push(l)}}function X(t,e){var n=(e=this.options=function(t,e){for(var n in e)t[n]=e[n];return t}(Object.create(this.options),e)).debug;if(n&&console.time("preprocess data"),e.maxZoom<0||e.maxZoom>24)throw new Error("maxZoom should be in the 0-24 range");var o=function(t,e){var n=[];if("FeatureCollection"===t.type)for(var o=0;o<t.features.length;o++)i(n,t.features[o],e);else"Feature"===t.type?i(n,t,e):i(n,{geometry:t},e);return n}(t,e);this.tiles={},this.tileCoords=[],n&&(console.timeEnd("preprocess data"),console.log("index: maxZoom: %d, maxPoints: %d",e.indexMaxZoom,e.indexMaxPoints),console.time("generate tiles"),this.stats={},this.total=0),(o=function(t,e){var n=e.buffer/e.extent,i=t,o=a(t,1,-1-n,n,0,-1,2,e),r=a(t,1,1-n,2+n,0,-1,2,e);return(o||r)&&(i=a(t,1,-n,1+n,0,-1,2,e)||[],o&&(i=v(o,1).concat(i)),r&&(i=i.concat(v(r,-1)))),i}(o,e)).length&&this.splitTile(o,0,0,0),n&&(o.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 L(t,e,n){return 32*((1<<t)*n+e)+t}return X.prototype.options={maxZoom:14,indexMaxZoom:5,indexMaxPoints:1e5,tolerance:3,extent:4096,buffer:64,lineMetrics:!1,debug:0},X.prototype.splitTile=function(t,e,n,i,o,r,s){for(var l=[t,e,n,i],u=this.options,f=u.debug;l.length;){i=l.pop(),n=l.pop(),e=l.pop(),t=l.pop();var h=1<<e,g=L(e,n,i),m=this.tiles[g];if(!m&&(f>1&&console.time("creation"),m=this.tiles[g]=P(t,e,n,i,u),this.tileCoords.push({z:e,x:n,y:i}),f)){f>1&&(console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",e,n,i,m.numFeatures,m.numPoints,m.numSimplified),console.timeEnd("creation"));var p="z"+e;this.stats[p]=(this.stats[p]||0)+1,this.total++}if(m.source=t,o){if(e===u.maxZoom||e===o)continue;var c=1<<o-e;if(n!==Math.floor(r/c)||i!==Math.floor(s/c))continue}else if(e===u.indexMaxZoom||m.numPoints<=u.indexMaxPoints)continue;if(m.source=null,0!==t.length){f>1&&console.time("clipping");var d,v,x,y,M,S,Y=.5*u.buffer/u.extent,X=.5-Y,z=.5+Y,b=1+Y;d=v=x=y=null,M=a(t,h,n-Y,n+z,0,m.minX,m.maxX,u),S=a(t,h,n+X,n+b,0,m.minX,m.maxX,u),t=null,M&&(d=a(M,h,i-Y,i+z,1,m.minY,m.maxY,u),v=a(M,h,i+X,i+b,1,m.minY,m.maxY,u),M=null),S&&(x=a(S,h,i-Y,i+z,1,m.minY,m.maxY,u),y=a(S,h,i+X,i+b,1,m.minY,m.maxY,u),S=null),f>1&&console.timeEnd("clipping"),l.push(d||[],e+1,2*n,2*i),l.push(v||[],e+1,2*n,2*i+1),l.push(x||[],e+1,2*n+1,2*i),l.push(y||[],e+1,2*n+1,2*i+1)}}},X.prototype.getTile=function(t,e,n){var i=this.options,o=i.extent,r=i.debug;if(t<0||t>24)return null;var s=1<<t,l=L(t,e=(e%s+s)%s,n);if(this.tiles[l])return y(this.tiles[l],o);r>1&&console.log("drilling down to z%d-%d-%d",t,e,n);for(var u,a=t,f=e,h=n;!u&&a>0;)a--,f=Math.floor(f/2),h=Math.floor(h/2),u=this.tiles[L(a,f,h)];return u&&u.source?(r>1&&console.log("found parent tile z%d-%d-%d",a,f,h),r>1&&console.time("drilling down"),this.splitTile(u.source,a,f,h,t,e,n),r>1&&console.timeEnd("drilling down"),this.tiles[l]?y(this.tiles[l],o):null):null},function(t,e){return new X(t,e)}}); |
{ | ||
"name": "geojson-vt", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "Slice GeoJSON data into vector tiles efficiently", | ||
@@ -23,8 +23,8 @@ "homepage": "https://github.com/mapbox/geojson-vt", | ||
"benchmark": "^2.1.4", | ||
"coveralls": "^3.0.0", | ||
"eslint": "^4.18.2", | ||
"coveralls": "^3.0.1", | ||
"eslint": "^4.19.1", | ||
"eslint-config-mourner": "^2.0.3", | ||
"esm": "^3.0.19", | ||
"nyc": "^11.4.1", | ||
"rollup": "^0.57.1", | ||
"esm": "^3.0.33", | ||
"nyc": "^11.7.3", | ||
"rollup": "^0.58.2", | ||
"rollup-plugin-uglify": "^3.0.0", | ||
@@ -31,0 +31,0 @@ "tape": "^4.9.0", |
@@ -62,2 +62,3 @@ ## geojson-vt — GeoJSON Vector Tiles | ||
debug: 0, // logging level (0 to disable, 1 or 2) | ||
lineMetrics: false, // whether to enable line metrics tracking for LineString/MultiLineString features | ||
@@ -64,0 +65,0 @@ indexMaxZoom: 5, // max zoom in the initial tile index |
@@ -52,4 +52,4 @@ | ||
features.push(createFeature(geojson.id, 'LineString', geometry, geojson.properties)); | ||
return; | ||
} | ||
return; | ||
} else { | ||
@@ -56,0 +56,0 @@ convertLines(coords, geometry, tolerance, false); |
68443
79