UNPKG

leaflet-mapbox-vector-tile

Version:

A Leaflet Plugin that renders Mapbox Vector Tiles on HTML5 Canvas.

2 lines 46 kB
!function t(e,r,i){function n(o,a){if(!r[o]){if(!e[o]){var h="function"==typeof require&&require;if(!a&&h)return h(o,!0);if(s)return s(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var l=r[o]={exports:{}};e[o][0].call(l.exports,function(t){var r=e[o][1][t];return n(r?r:t)},l,l.exports,t,e,r,i)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;o<i.length;o++)n(i[o]);return n}({1:[function(t,e){(function(r){"use strict";function i(t){this.buf=t,this.pos=0}var n=t("ieee754");e.exports=i,i.prototype={get length(){return this.buf.length}},i.Varint=0,i.Int64=1,i.Message=2,i.String=2,i.Packed=2,i.Int32=5,i.prototype.destroy=function(){this.buf=null},i.prototype.readUInt32=function(){var t=this.buf.readUInt32LE(this.pos);return this.pos+=4,t},i.prototype.readUInt64=function(){var t=this.buf.readUInt64LE(this.pos);return this.pos+=8,t},i.prototype.readDouble=function(){var t=n.read(this.buf,this.pos,!0,52,8);return this.pos+=8,t},i.prototype.readVarint=function(){var t=this.pos;return this.buf[t]<=127?(this.pos++,this.buf[t]):this.buf[t+1]<=127?(this.pos+=2,127&this.buf[t]|this.buf[t+1]<<7):this.buf[t+2]<=127?(this.pos+=3,127&this.buf[t]|(127&this.buf[t+1])<<7|this.buf[t+2]<<14):this.buf[t+3]<=127?(this.pos+=4,127&this.buf[t]|(127&this.buf[t+1])<<7|(127&this.buf[t+2])<<14|this.buf[t+3]<<21):this.buf[t+4]<=127?(this.pos+=5,(127&this.buf[t]|(127&this.buf[t+1])<<7|(127&this.buf[t+2])<<14|this.buf[t+3]<<21)+268435456*this.buf[t+4]):(this.skip(i.Varint),0)},i.prototype.readSVarint=function(){var t=this.readVarint();if(t>2147483647)throw new Error("TODO: Handle numbers >= 2^30");return t>>1^-(1&t)},i.prototype.readString=function(){for(var t=this.readVarint(),e=String.fromCharCode,r=this.buf,i=this.pos,n=this.pos+t,s="";n>i;)if(r[i]<=127)s+=e(r[i++]);else{if(r[i]<=191)throw new Error("Invalid UTF-8 codepoint: "+r[i]);if(r[i]<=223)s+=e((31&r[i++])<<6|63&r[i++]);else if(r[i]<=239)s+=e((31&r[i++])<<12|(63&r[i++])<<6|63&r[i++]);else if(r[i]<=247)i+=4;else if(r[i]<=251)i+=5;else{if(!(r[i]<=253))throw new Error("Invalid UTF-8 codepoint: "+r[i]);i+=6}}return this.pos+=t,s},i.prototype.readBuffer=function(){var t=this.readVarint(),e=this.buf.subarray(this.pos,this.pos+t);return this.pos+=t,e},i.prototype.readPacked=function(t){for(var e=this.readVarint(),r=this.pos+e,i=[];this.pos<r;)i.push(this["read"+t]());return i},i.prototype.skip=function(t){var e=7&t;switch(e){case i.Varint:for(;this.buf[this.pos++]>127;);break;case i.Int64:this.pos+=8;break;case i.Message:var r=this.readVarint();this.pos+=r;break;case i.Int32:this.pos+=4;break;default:throw new Error("Unimplemented type: "+e)}},i.prototype.writeTag=function(t,e){this.writeVarint(t<<3|e)},i.prototype.realloc=function(t){for(var e=this.buf.length;e<this.pos+t;)e*=2;if(e!=this.buf.length){var i=new r(e);this.buf.copy(i),this.buf=i}},i.prototype.finish=function(){return this.buf.slice(0,this.pos)},i.prototype.writePacked=function(t,e,r){if(r.length){for(var n=new i,s=0;s<r.length;s++)n["write"+t](r[s]);var o=n.finish();this.writeTag(e,i.Packed),this.writeBuffer(o)}},i.prototype.writeUInt32=function(t){this.realloc(4),this.buf.writeUInt32LE(t,this.pos),this.pos+=4},i.prototype.writeTaggedUInt32=function(t,e){this.writeTag(t,i.Int32),this.writeUInt32(e)},i.prototype.writeVarint=function(t){if(t=Number(t),isNaN(t)&&(t=0),127>=t)this.realloc(1),this.buf[this.pos++]=t;else if(16383>=t)this.realloc(2),this.buf[this.pos++]=128|t>>>0&127,this.buf[this.pos++]=0|t>>>7&127;else if(33554431>=t)this.realloc(3),this.buf[this.pos++]=128|t>>>0&127,this.buf[this.pos++]=128|t>>>7&127,this.buf[this.pos++]=0|t>>>14&127;else if(268435455>=t)this.realloc(4),this.buf[this.pos++]=128|t>>>0&127,this.buf[this.pos++]=128|t>>>7&127,this.buf[this.pos++]=128|t>>>14&127,this.buf[this.pos++]=0|t>>>21&127;else for(;t>0;){var e=127&t;t=Math.floor(t/128),t>0&&(e|=128),this.realloc(1),this.buf[this.pos++]=e}},i.prototype.writeTaggedVarint=function(t,e){this.writeTag(t,i.Varint),this.writeVarint(e)},i.prototype.writeSVarint=function(t){this.writeVarint(t>=0?2*t:-2*t-1)},i.prototype.writeTaggedSVarint=function(t,e){this.writeTag(t,i.Varint),this.writeSVarint(e)},i.prototype.writeBoolean=function(t){this.writeVarint(Boolean(t))},i.prototype.writeTaggedBoolean=function(t,e){this.writeTaggedVarint(t,Boolean(e))},i.prototype.writeString=function(t){t=String(t);var e=r.byteLength(t);this.writeVarint(e),this.realloc(e),this.buf.write(t,this.pos),this.pos+=e},i.prototype.writeTaggedString=function(t,e){this.writeTag(t,i.String),this.writeString(e)},i.prototype.writeFloat=function(t){this.realloc(4),this.buf.writeFloatLE(t,this.pos),this.pos+=4},i.prototype.writeTaggedFloat=function(t,e){this.writeTag(t,i.Int32),this.writeFloat(e)},i.prototype.writeDouble=function(t){this.realloc(8),this.buf.writeDoubleLE(t,this.pos),this.pos+=8},i.prototype.writeTaggedDouble=function(t,e){this.writeTag(t,i.Int64),this.writeDouble(e)},i.prototype.writeBuffer=function(t){var e=t.length;this.writeVarint(e),this.realloc(e),t.copy(this.buf,this.pos),this.pos+=e},i.prototype.writeTaggedBuffer=function(t,e){this.writeTag(t,i.String),this.writeBuffer(e)},i.prototype.writeMessage=function(t,e){var r=e.finish();this.writeTag(t,i.Message),this.writeBuffer(r)}}).call(this,t("buffer").Buffer)},{buffer:13,ieee754:2}],2:[function(t,e,r){r.read=function(t,e,r,i,n){var s,o,a=8*n-i-1,h=(1<<a)-1,u=h>>1,l=-7,f=r?n-1:0,c=r?-1:1,p=t[e+f];for(f+=c,s=p&(1<<-l)-1,p>>=-l,l+=a;l>0;s=256*s+t[e+f],f+=c,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=i;l>0;o=256*o+t[e+f],f+=c,l-=8);if(0===s)s=1-u;else{if(s===h)return o?0/0:1/0*(p?-1:1);o+=Math.pow(2,i),s-=u}return(p?-1:1)*o*Math.pow(2,s-i)},r.write=function(t,e,r,i,n,s){var o,a,h,u=8*s-n-1,l=(1<<u)-1,f=l>>1,c=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,p=i?0:s-1,d=i?1:-1,y=0>e||0===e&&0>1/e?1:0;for(e=Math.abs(e),isNaN(e)||1/0===e?(a=isNaN(e)?1:0,o=l):(o=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-o))<1&&(o--,h*=2),e+=o+f>=1?c/h:c*Math.pow(2,1-f),e*h>=2&&(o++,h/=2),o+f>=l?(a=0,o=l):o+f>=1?(a=(e*h-1)*Math.pow(2,n),o+=f):(a=e*Math.pow(2,f-1)*Math.pow(2,n),o=0));n>=8;t[r+p]=255&a,p+=d,a/=256,n-=8);for(o=o<<n|a,u+=n;u>0;t[r+p]=255&o,p+=d,o/=256,u-=8);t[r+p-d]|=128*y}},{}],3:[function(t,e){"use strict";function r(t,e){this.x=t,this.y=e}e.exports=r,r.prototype={clone:function(){return new r(this.x,this.y)},add:function(t){return this.clone()._add(t)},sub:function(t){return this.clone()._sub(t)},mult:function(t){return this.clone()._mult(t)},div:function(t){return this.clone()._div(t)},rotate:function(t){return this.clone()._rotate(t)},matMult:function(t){return this.clone()._matMult(t)},unit:function(){return this.clone()._unit()},perp:function(){return this.clone()._perp()},round:function(){return this.clone()._round()},mag:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals:function(t){return this.x===t.x&&this.y===t.y},dist:function(t){return Math.sqrt(this.distSqr(t))},distSqr:function(t){var e=t.x-this.x,r=t.y-this.y;return e*e+r*r},angle:function(){return Math.atan2(this.y,this.x)},angleTo:function(t){return Math.atan2(this.y-t.y,this.x-t.x)},angleWith:function(t){return this.angleWithSep(t.x,t.y)},angleWithSep:function(t,e){return Math.atan2(this.x*e-this.y*t,this.x*t+this.y*e)},_matMult:function(t){var e=t[0]*this.x+t[1]*this.y,r=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=r,this},_add:function(t){return this.x+=t.x,this.y+=t.y,this},_sub:function(t){return this.x-=t.x,this.y-=t.y,this},_mult:function(t){return this.x*=t,this.y*=t,this},_div:function(t){return this.x/=t,this.y/=t,this},_unit:function(){return this._div(this.mag()),this},_perp:function(){var t=this.y;return this.y=this.x,this.x=-t,this},_rotate:function(t){var e=Math.cos(t),r=Math.sin(t),i=e*this.x-r*this.y,n=r*this.x+e*this.y;return this.x=i,this.y=n,this},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}},r.convert=function(t){return t instanceof r?t:Array.isArray(t)?new r(t[0],t[1]):t}},{}],4:[function(t,e){e.exports.VectorTile=t("./lib/vectortile.js"),e.exports.VectorTileFeature=t("./lib/vectortilefeature.js"),e.exports.VectorTileLayer=t("./lib/vectortilelayer.js")},{"./lib/vectortile.js":5,"./lib/vectortilefeature.js":6,"./lib/vectortilelayer.js":7}],5:[function(t,e){"use strict";function r(t,e){for(this.layers={},this._buffer=t,e=e||t.length;t.pos<e;){var r=t.readVarint(),i=r>>3;if(3==i){var n=this.readLayer();n.length&&(this.layers[n.name]=n)}else t.skip(r)}}var i=t("./vectortilelayer");e.exports=r,r.prototype.readLayer=function(){var t=this._buffer,e=t.readVarint(),r=t.pos+e,n=new i(t,r);return t.pos=r,n}},{"./vectortilelayer":7}],6:[function(t,e){"use strict";function r(t,e,r,i,n){for(this.properties={},this.extent=r,this.type=0,this._buffer=t,this._geometry=-1,e=e||t.length;t.pos<e;){var s=t.readVarint(),o=s>>3;if(1==o)this._id=t.readVarint();else if(2==o)for(var a=t.readVarint(),h=t.pos+a;t.pos<h;){var u=i[t.readVarint()],l=n[t.readVarint()];this.properties[u]=l}else 3==o?this.type=t.readVarint():4==o?(this._geometry=t.pos,t.skip(s)):t.skip(s)}}var i=t("point-geometry");e.exports=r,r.types=["Unknown","Point","LineString","Polygon"],r.prototype.loadGeometry=function(){var t=this._buffer;t.pos=this._geometry;for(var e,r=t.readVarint(),n=t.pos+r,s=1,o=0,a=0,h=0,u=[];t.pos<n;){if(!o){var l=t.readVarint();s=7&l,o=l>>3}if(o--,1===s||2===s)a+=t.readSVarint(),h+=t.readSVarint(),1===s&&(e&&u.push(e),e=[]),e.push(new i(a,h));else{if(7!==s)throw new Error("unknown command "+s);e.push(e[0].clone())}}return e&&u.push(e),u},r.prototype.bbox=function(){var t=this._buffer;t.pos=this._geometry;for(var e=t.readVarint(),r=t.pos+e,i=1,n=0,s=0,o=0,a=1/0,h=-1/0,u=1/0,l=-1/0;t.pos<r;){if(!n){var f=t.readVarint();i=7&f,n=f>>3}if(n--,1===i||2===i)s+=t.readSVarint(),o+=t.readSVarint(),a>s&&(a=s),s>h&&(h=s),u>o&&(u=o),o>l&&(l=o);else if(7!==i)throw new Error("unknown command "+i)}return[a,u,h,l]}},{"point-geometry":3}],7:[function(t,e){"use strict";function r(t,e){this.version=1,this.name=null,this.extent=4096,this.length=0,this._buffer=t,this._keys=[],this._values=[],this._features=[];var r,i;for(e=e||t.length;t.pos<e;)r=t.readVarint(),i=r>>3,15===i?this.version=t.readVarint():1===i?this.name=t.readString():5===i?this.extent=t.readVarint():2===i?(this.length++,this._features.push(t.pos),t.skip(r)):3===i?this._keys.push(t.readString()):4===i?this._values.push(this.readFeatureValue()):t.skip(r)}var i=t("./vectortilefeature.js");e.exports=r,r.prototype.readFeatureValue=function(){for(var t,e,r=this._buffer,i=null,n=r.readVarint(),s=r.pos+n;r.pos<s;)if(t=r.readVarint(),e=t>>3,1==e)i=r.readString();else{if(2==e)throw new Error("read float");if(3==e)i=r.readDouble();else if(4==e)i=r.readVarint();else{if(5==e)throw new Error("read uint");6==e?i=r.readSVarint():7==e?i=Boolean(r.readVarint()):r.skip(t)}}return i},r.prototype.feature=function(t){if(0>t||t>=this._features.length)throw new Error("feature index out of bounds");this._buffer.pos=this._features[t];var e=this._buffer.readVarint()+this._buffer.pos;return new i(this._buffer,e,this.extent,this._keys,this._values)}},{"./vectortilefeature.js":6}],8:[function(t,e){function r(t,e,r,i,s){if(!e)return null;for(var o in e)this[o]=e[o];this.mvtLayer=t,this.mvtSource=t.mvtSource,this.map=t.mvtSource.map,this.id=i,this.layerLink=this.mvtSource.layerLink,this.toggleEnabled=!0,this.selected=!1,this.divisor=e.extent/r.tileSize,this.extent=e.extent,this.tileSize=r.tileSize,this.tiles={},this.style=s,this.addTileFeature(e,r);var a=this;this.map.on("zoomend",function(){a.staticLabel=null}),s&&s.dynamicLabel&&"function"==typeof s.dynamicLabel&&(this.dynamicLabel=this.mvtSource.dynamicLabel.createFeature(this)),n(a)}function n(t){var e=t.style;if(e&&e.ajaxSource&&"function"==typeof e.ajaxSource){var r=e.ajaxSource(t);r&&a.getJSON(r,function(e,r){if(e)throw["ajaxSource AJAX Error",e];return s(t,r),!0})}return!1}function s(t,e){t.ajaxData=e,"function"==typeof t.ajaxDataReceived&&t.ajaxDataReceived(t,e),t._setStyle(t.mvtLayer.style),o(t)}function o(t){var e=t.tiles,r=t.mvtLayer;for(var i in e){var n=parseInt(i.split(":")[0]),s=t.map.getZoom();n===s&&r.redrawTile(i)}}var a=t("./MVTUtil"),h=t("./StaticLabel/StaticLabel.js");e.exports=r,r.prototype._setStyle=function(t){this.style=t(this,this.ajaxData),this.removeLabel()},r.prototype.setStyle=function(t){this.ajaxData=null,this.style=t(this,null);var e=n(this);e||this.removeLabel()},r.prototype.draw=function(t){var e=this.tiles[t],r=e.vtf,i=e.ctx,n=t.split(":").slice(1,3).join(":");if(i.canvas=this.mvtLayer._tiles[n],this.selected)var s=this.style.selected||this.style;else var s=this.style;switch(r.type){case 1:if(this._drawPoint(i,r.coordinates,s),!this.staticLabel&&"function"==typeof this.style.staticLabel){if(this.style.ajaxSource&&!this.ajaxData)break;this._drawStaticLabel(i,r.coordinates,s)}break;case 2:this._drawLineString(i,r.coordinates,s);break;case 3:this._drawPolygon(i,r.coordinates,s);break;default:throw new Error("Unmanaged type: "+r.type)}},r.prototype.getPathsForTile=function(t){return this.tiles[t].paths},r.prototype.addTileFeature=function(t,e){var r=this.map.getZoom();e.zoom==r&&(this.clearTileFeatures(r),this.tiles[e.id]={ctx:e,vtf:t,paths:[]})},r.prototype.clearTileFeatures=function(t){for(var e in this.tiles)e.split(":")[0]!=t&&delete this.tiles[e]},r.prototype.toggle=function(){this.selected?this.deselect():this.select()},r.prototype.select=function(){this.selected=!0,this.mvtSource.featureSelected(this),o(this);var t=this.linkedFeature();t&&t.staticLabel&&!t.staticLabel.selected&&t.staticLabel.select()},r.prototype.deselect=function(){this.selected=!1,this.mvtSource.featureDeselected(this),o(this);var t=this.linkedFeature();t&&t.staticLabel&&t.staticLabel.selected&&t.staticLabel.deselect()},r.prototype.on=function(t,e){this._eventHandlers[t]=e},r.prototype._drawPoint=function(t,e,r){if(r&&t&&t.canvas){var i=this.tiles[t.id],n=1;n="function"==typeof r.radius?r.radius(t.zoom):r.radius;var s,o=this._tilePoint(e[0][0]),a=t.canvas;try{s=a.getContext("2d")}catch(h){return void console.log("_drawPoint error: "+h)}s.beginPath(),s.fillStyle=r.color,s.arc(o.x,o.y,n,0,2*Math.PI),s.closePath(),s.fill(),r.lineWidth&&r.strokeStyle&&(s.lineWidth=r.lineWidth,s.strokeStyle=r.strokeStyle,s.stroke()),s.restore(),i.paths.push([o])}},r.prototype._drawLineString=function(t,e,r){if(r&&t&&t.canvas){var n=t.canvas.getContext("2d");n.strokeStyle=r.color,n.lineWidth=r.size,n.beginPath();var s=[],o=this.tiles[t.id];for(var a in e){var h=e[a];for(i=0;i<h.length;i++){var u=(0===i?"move":"line")+"To",l=this._tilePoint(h[i]);s.push(l),n[u](l.x,l.y)}}n.stroke(),n.restore(),o.paths.push(s)}},r.prototype._drawPolygon=function(t,e,r){if(r&&t&&t.canvas){var i=t.canvas.getContext("2d"),n=r.outline;i.fillStyle="function"==typeof r.color?r.color(i):r.color,n&&(i.strokeStyle=n.color,i.lineWidth=n.size),i.beginPath();var s=[],o=this.tiles[t.id],a=this.dynamicLabel;a&&a.addTilePolys(t,e);for(var h=0,u=e.length;u>h;h++)for(var l=e[h],f=0;f<l.length;f++){var c=(l[f],(0===f?"move":"line")+"To"),p=this._tilePoint(l[f]);s.push(p),i[c](p.x,p.y)}i.closePath(),i.fill(),n&&i.stroke(),o.paths.push(s)}},r.prototype._drawStaticLabel=function(t,e,r){if(r&&t&&this.mvtLayer._map){var i=this._tilePoint(e[0][0]),n=this._project(i,t.tile.x,t.tile.y,this.extent,this.tileSize),s=L.point(n.x,n.y),o=this.map.unproject(s);this.staticLabel=new h(this,t,o,r),this.mvtLayer.featureWithLabelAdded(this)}},r.prototype.removeLabel=function(){this.staticLabel&&(this.staticLabel.remove(),this.staticLabel=null)},r.prototype._project=function(t,e,r,i,n){var s=e*n,o=r*n;return{x:Math.floor(t.x+s),y:Math.floor(t.y+o)}},r.prototype._tilePoint=function(t){return new L.Point(t.x/this.divisor,t.y/this.divisor)},r.prototype.linkedFeature=function(){var t=this.mvtLayer.linkedLayer();if(t){var e=t.features[this.id];return e}return null}},{"./MVTUtil":11,"./StaticLabel/StaticLabel.js":12}],9:[function(require,module,exports){function removeLabels(t){for(var e=t.featuresWithLabels,r=0,i=e.length;i>r;r++){var n=e[r];n.removeLabel()}t.featuresWithLabels=[]}function waitFor(testFx,onReady,timeOutMillis){var maxtimeOutMillis=timeOutMillis?timeOutMillis:3e3,start=(new Date).getTime(),condition="string"==typeof testFx?eval(testFx):testFx(),interval=setInterval(function(){(new Date).getTime()-start<maxtimeOutMillis&&!condition?condition="string"==typeof testFx?eval(testFx):testFx():condition?(console.log("'waitFor()' finished in "+((new Date).getTime()-start)+"ms."),clearInterval(interval),"string"==typeof onReady?eval(onReady):onReady("success")):(console.log("'waitFor()' timeout"),clearInterval(interval),"string"==typeof onReady?eval(onReady):onReady("timeout"))},50)}var MVTFeature=require("./MVTFeature"),Util=require("./MVTUtil");module.exports=L.TileLayer.Canvas.extend({options:{debug:!1,isHiddenLayer:!1,getIDForLayerFeature:function(){},tileSize:256,lineClickTolerance:2},_featureIsClicked:{},_isPointInPoly:function(t,e){if(e&&e.length){for(var r=!1,i=-1,n=e.length,s=n-1;++i<n;s=i)(e[i].y<=t.y&&t.y<e[s].y||e[s].y<=t.y&&t.y<e[i].y)&&t.x<(e[s].x-e[i].x)*(t.y-e[i].y)/(e[s].y-e[i].y)+e[i].x&&(r=!r);return r}},_getDistanceFromLine:function(t,e){var r=Number.POSITIVE_INFINITY;if(e&&e.length>1){t=L.point(t.x,t.y);for(var i=0,n=e.length-1;n>i;i++){var s=this._projectPointOnLineSegment(t,e[i],e[i+1]);s.distance<=r&&(r=s.distance)}}return r},_projectPointOnLineSegment:function(t,e,r){var i=e.distanceTo(r);if(1>i)return{distance:t.distanceTo(e),coordinate:e};var n=((t.x-e.x)*(r.x-e.x)+(t.y-e.y)*(r.y-e.y))/Math.pow(i,2);if(1e-7>n)return{distance:t.distanceTo(e),coordinate:e};if(n>.9999999)return{distance:t.distanceTo(r),coordinate:r};var s=L.point(e.x+n*(r.x-e.x),e.y+n*(r.y-e.y));return{distance:t.distanceTo(s),point:s}},initialize:function(t,e){var r=this;r.mvtSource=t,L.Util.setOptions(this,e),this.style=e.style,this.name=e.name,this._canvasIDToFeatures={},this.features={},this.featuresWithLabels=[],this._highestCount=0},onAdd:function(t){var e=this;e.map=t,L.TileLayer.Canvas.prototype.onAdd.call(this,t),t.on("layerremove",function(t){t.layer._leaflet_id===e._leaflet_id&&removeLabels(e)})},drawTile:function(t,e,r){var i={canvas:t,tile:e,zoom:r,tileSize:this.options.tileSize};i.id=Util.getContextID(i),this._canvasIDToFeatures[i.id]||this._initializeFeaturesHash(i),this.features||(this.features={})},_initializeFeaturesHash:function(t){this._canvasIDToFeatures[t.id]={},this._canvasIDToFeatures[t.id].features=[],this._canvasIDToFeatures[t.id].canvas=t.canvas},_draw:function(){},getCanvas:function(t){var e=t.tile,r=this._tiles[e.x+":"+e.y];if(r)return t.canvas=r,void this.redrawTile(t.id);var i=this;waitFor(function(){return r=i._tiles[e.x+":"+e.y],r?!0:void 0},function(){r=i._tiles[e.x+":"+e.y],t.canvas=r,i.redrawTile(t.id)},2e3)},parseVectorTileLayer:function(t,e){var r=this,i=e.tile,n={canvas:null,id:e.id,tile:e.tile,zoom:e.zoom,tileSize:e.tileSize};n.canvas=r._tiles[i.x+":"+i.y],this._canvasIDToFeatures[n.id]?this.clearTileFeatureHash(n.id):this._initializeFeaturesHash(n);for(var s=t.parsedFeatures,o=0,a=s.length;a>o;o++){var h=s[o];h.layer=t;var u=r.options.filter;if("function"!=typeof u||u(h,n)!==!1){var l;l="function"==typeof r.options.getIDForLayerFeature?r.options.getIDForLayerFeature:Util.getIDForLayerFeature;var f=r.options.getIDForLayerFeature(h)||o,c=r.features[f],p=r.options.layerOrdering;if("function"==typeof p&&p(h,n),c)c.addTileFeature(h,n);else{var d=r.style(h);r.features[f]=c=new MVTFeature(r,h,n,f,d),d&&d.dynamicLabel&&"function"==typeof d.dynamicLabel&&r.featuresWithLabels.push(c)}n&&n.id&&r._canvasIDToFeatures[n.id].features.push(c)}}var p=r.options.layerOrdering;p&&(r._canvasIDToFeatures[n.id].features=r._canvasIDToFeatures[n.id].features.sort(function(t,e){return-(e.properties.zIndex-t.properties.zIndex)})),r.redrawTile(n.id)},setStyle:function(t){this._highestCount=0,this._lowestCount=null,this.style=t;for(var e in this.features){var r=this.features[e];r.setStyle(t)}var i=this.map.getZoom();for(var e in this._tiles){var n=i+":"+e;this.redrawTile(n)}},setHighestCount:function(t){t>this._highestCount&&(this._highestCount=t)},getHighestCount:function(){return this._highestCount},setLowestCount:function(t){(!this._lowestCount||t<this._lowestCount)&&(this._lowestCount=t)},getLowestCount:function(){return this._lowestCount},setCountRange:function(t){this.setHighestCount(t),this.setLowestCount(t)},handleClickEvent:function(t,e){var r=t.tileID.split(":").slice(1,3).join(":"),i=this._tiles[r];i||e(t);for(var n,s,o,a=t.layerPoint.x-i._leaflet_pos.x,h=t.layerPoint.y-i._leaflet_pos.y,u={x:a,y:h},l=this._canvasIDToFeatures[t.tileID].features,f=Number.POSITIVE_INFINITY,c=null,p=0;p<l.length;p++){var d=l[p];switch(d.type){case 2:for(s=d.getPathsForTile(t.tileID),n=0;n<s.length;n++)if(d.style){var o=this._getDistanceFromLine(u,s[n]),y=d.selected&&d.style.selected?d.style.selected.size:d.style.size;o<y/2+this.options.lineClickTolerance&&f>o&&(c=d,f=o)}break;case 3:for(s=d.getPathsForTile(t.tileID),n=0;n<s.length;n++)this._isPointInPoly(u,s[n])&&(c=d,f=0)}if(0==f)break}c&&c.toggleEnabled&&c.toggle(),t.feature=c,e(t)},clearTile:function(t){var e=t.split(":"),r=e[1]+":"+e[2];if("undefined"==typeof this._tiles[r])return void console.error("typeof this._tiles[canvasId] === 'undefined'");var i=this._tiles[r],n=i.getContext("2d");n.clearRect(0,0,i.width,i.height)},clearTileFeatureHash:function(t){this._canvasIDToFeatures[t]={features:[]}},clearLayerFeatureHash:function(){this.features={}},redrawTile:function(t){this.clearTile(t);var e=this._canvasIDToFeatures[t];if(e){for(var r=e.features,i=[],n=0;n<r.length;n++){var s=r[n];s.selected?i.push(s):s.draw(t)}for(var o=0,a=i.length;a>o;o++){var h=i[o];h.draw(t)}}},_resetCanvasIDToFeatures:function(t,e){this._canvasIDToFeatures[t]={},this._canvasIDToFeatures[t].features=[],this._canvasIDToFeatures[t].canvas=e},linkedLayer:function(){if(this.mvtSource.layerLink){var t=this.mvtSource.layerLink(this.name);return this.mvtSource.layers[t]}return null},featureWithLabelAdded:function(t){this.featuresWithLabels.push(t)}})},{"./MVTFeature":8,"./MVTUtil":11}],10:[function(t,e){function r(t,e,r){var i=parseInt(Math.floor((e+180)/360*(1<<r))),n=parseInt(Math.floor((1-Math.log(Math.tan(t.toRad())+1/Math.cos(t.toRad()))/Math.PI)/2*(1<<r)));return""+r+":"+i+":"+n}function i(t,e){t.loadedTiles[e.id]=e}function n(t){for(var e in t.layers){var r=t.layers[e];s(r)}return t}function s(t){t.parsedFeatures=[];for(var e=t._features,r=0,i=e.length;i>r;r++){var n=t.feature(r);n.coordinates=n.loadGeometry(),t.parsedFeatures.push(n)}return t}var o=t("vector-tile").VectorTile,a=t("pbf"),h=(t("point-geometry"),t("./MVTUtil")),u=t("./MVTLayer");e.exports=L.TileLayer.MVTSource=L.TileLayer.Canvas.extend({options:{debug:!1,url:"",getIDForLayerFeature:function(){},tileSize:256,visibleLayers:[]},layers:{},processedTiles:{},_eventHandlers:{},_triggerOnTilesLoadedEvent:!0,_url:"",style:function(t){var e={},r=t.type;switch(r){case 1:e.color="rgba(49,79,79,1)",e.radius=5,e.selected={color:"rgba(255,255,0,0.5)",radius:6};break;case 2:e.color="rgba(161,217,155,0.8)",e.size=3,e.selected={color:"rgba(255,25,0,0.5)",size:4};break;case 3:e.color="rgba(49,79,79,1)",e.outline={color:"rgba(161,217,155,0.8)",size:1},e.selected={color:"rgba(255,140,0,0.3)",outline:{color:"rgba(255,140,0,1)",size:2}}}return e},initialize:function(t){L.Util.setOptions(this,t),this.layers={},this.activeTiles={},this.loadedTiles={},this._url=this.options.url,this.zIndex=t.zIndex,"function"==typeof t.style&&(this.style=t.style),"function"==typeof t.ajaxSource&&(this.ajaxSource=t.ajaxSource),this.layerLink=t.layerLink,this._eventHandlers={},this._tilesToProcess=0},redraw:function(t){t===!1&&(this._triggerOnTilesLoadedEvent=!1),L.TileLayer.Canvas.prototype.redraw.call(this)},onAdd:function(t){var e=this;e.map=t,L.TileLayer.Canvas.prototype.onAdd.call(this,t);var r=function(t){e._onClick(t)};t.on("click",r),t.on("layerremove",function(i){i.layer._leaflet_id===e._leaflet_id&&i.layer.removeChildLayers&&(i.layer.removeChildLayers(t),t.off("click",r))}),e.addChildLayers(t),"function"==typeof DynamicLabel&&(this.dynamicLabel=new DynamicLabel(t,this,{}))},drawTile:function(t,e,r){var i={id:[r,e.x,e.y].join(":"),canvas:t,tile:e,zoom:r,tileSize:this.options.tileSize};this._tilesToProcess<this._tilesToLoad&&(this._tilesToProcess=this._tilesToLoad);var n=i.id=h.getContextID(i);this.activeTiles[n]=i,this.processedTiles[i.zoom]||(this.processedTiles[i.zoom]={}),this.options.debug&&this._drawDebugInfo(i),this._draw(i)},setOpacity:function(t){this._setVisibleLayersStyle("opacity",t)},setZIndex:function(t){this._setVisibleLayersStyle("zIndex",t)},_setVisibleLayersStyle:function(t,e){for(var r in this.layers)this.layers[r]._tileContainer.style[t]=e},_drawDebugInfo:function(t){var e=this.options.tileSize,r=t.canvas.getContext("2d");r.strokeStyle="#000000",r.fillStyle="#FFFF00",r.strokeRect(0,0,e,e),r.font="12px Arial",r.fillRect(0,0,5,5),r.fillRect(0,e-5,5,5),r.fillRect(e-5,0,5,5),r.fillRect(e-5,e-5,5,5),r.fillRect(e/2-5,e/2-5,10,10),r.strokeText(t.zoom+" "+t.tile.x+" "+t.tile.y,e/2-30,e/2-10)},_draw:function(t){var e=this;if(this._url){var r=this.getTileUrl({x:t.tile.x,y:t.tile.y,z:t.zoom}),s=new XMLHttpRequest;s.onload=function(){if("200"==s.status){if(!s.response)return;var r=new Uint8Array(s.response),h=new a(r),u=new o(h);if(e.map&&e.map.getZoom()!=t.zoom)return void console.log("Fetched tile for zoom level "+t.zoom+". Map is at zoom level "+e._map.getZoom());e.checkVectorTileLayers(n(u),t),i(e,t)}e.reduceTilesToProcessCount()},s.onerror=function(){console.log("xhr error: "+s.status)},s.open("GET",r,!0),s.responseType="arraybuffer",s.send()}},reduceTilesToProcessCount:function(){this._tilesToProcess--,this._tilesToProcess||(this._eventHandlers.PBFLoad&&this._eventHandlers.PBFLoad(),this._pbfLoaded())},checkVectorTileLayers:function(t,e,r){var i=this;if(i.options.visibleLayers&&i.options.visibleLayers.length>0)for(var n=0;n<i.options.visibleLayers.length;n++){var s=i.options.visibleLayers[n];t.layers[s]&&i.prepareMVTLayers(t.layers[s],s,e,r)}else for(var o in t.layers)i.prepareMVTLayers(t.layers[o],o,e,r)},prepareMVTLayers:function(t,e,r,i){var n=this;n.layers[e]||(n.layers[e]=n.createMVTLayer(e,t.parsedFeatures[0].type||null)),i?n.layers[e].getCanvas(r,t):n.layers[e].parseVectorTileLayer(t,r)},createMVTLayer:function(t){var e,r=this;e="function"==typeof r.options.getIDForLayerFeature?r.options.getIDForLayerFeature:h.getIDForLayerFeature;var i={getIDForLayerFeature:e,filter:r.options.filter,layerOrdering:r.options.layerOrdering,style:r.style,name:t,asynch:!0};r.options.zIndex&&(i.zIndex=r.zIndex);var n=new u(r,i).addTo(r.map);return n},getLayers:function(){return this.layers},hideLayer:function(t){this.layers[t]&&(this._map.removeLayer(this.layers[t]),this.options.visibleLayers.indexOf("id")>-1&&this.visibleLayers.splice(this.options.visibleLayers.indexOf("id"),1))},showLayer:function(t){this.layers[t]&&(this._map.addLayer(this.layers[t]),-1==this.options.visibleLayers.indexOf("id")&&this.visibleLayers.push(t)),this.bringToFront()},removeChildLayers:function(t){for(var e in this.layers){var r=this.layers[e];t.removeLayer(r)}},addChildLayers:function(t){var e=this;if(e.options.visibleLayers.length>0)for(var r=0;r<e.options.visibleLayers.length;r++){var i=e.options.visibleLayers[r],n=this.layers[i];n&&t.addLayer(n)}else for(var s in this.layers){var n=this.layers[s];n._map||t.addLayer(n)}},bind:function(t,e){this._eventHandlers[t]=e},_onClick:function(t){var e=this,i=e.options.onClick,n=e.options.clickableLayers,s=e.layers;if(t.tileID=r(t.latlng.lat,t.latlng.lng,this.map.getZoom()),n||(n=Object.keys(e.layers)),n&&n.length>0)for(var o=0,a=n.length;a>o;o++){var h=n[o],u=s[h];u&&u.handleClickEvent(t,function(t){"function"==typeof i&&i(t)})}else"function"==typeof i&&i(t)},setFilter:function(t,e){for(var r in this.layers){var i=this.layers[r];e?r.toLowerCase()==e.toLowerCase()&&(i.options.filter=t,i.clearLayerFeatureHash()):(i.options.filter=t,i.clearLayerFeatureHash())}},setStyle:function(t,e){for(var r in this.layers){var i=this.layers[r];e?r.toLowerCase()==e.toLowerCase()&&i.setStyle(t):i.setStyle(t)}},featureSelected:function(t){this.options.mutexToggle&&(this._selectedFeature&&this._selectedFeature.deselect(),this._selectedFeature=t),this.options.onSelect&&this.options.onSelect(t)},featureDeselected:function(t){this.options.mutexToggle&&this._selectedFeature&&(this._selectedFeature=null),this.options.onDeselect&&this.options.onDeselect(t)},_pbfLoaded:function(){this.bringToFront();var t=this,e=t.options.onTilesLoaded;e&&"function"==typeof e&&this._triggerOnTilesLoadedEvent===!0&&e(this),t._triggerOnTilesLoadedEvent=!0}}),"undefined"==typeof Number.prototype.toRad&&(Number.prototype.toRad=function(){return this*Math.PI/180})},{"./MVTLayer":9,"./MVTUtil":11,pbf:1,"point-geometry":3,"vector-tile":4}],11:[function(t,e){var r=e.exports={};r.getContextID=function(t){return[t.zoom,t.tile.x,t.tile.y].join(":")},r.getIDForLayerFeature=function(t){return t.properties.id},r.getJSON=function(t,e){var r="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");r.onreadystatechange=function(){var t=r.status;if(4===r.readyState&&t>=200&&300>t){var i=JSON.parse(r.responseText);e(null,i)}else e({error:!0,status:t})},r.open("GET",t,!0),r.send()}},{}],12:[function(t,e){function r(t,e,r,n){var s=this;if(this.mvtFeature=t,this.map=t.map,this.zoom=e.zoom,this.latLng=r,this.selected=!1,t.linkedFeature){var o=t.linkedFeature();o&&o.selected&&(s.selected=!0)}i(s,t,e,r,n)}function i(t,e,r,i,n){var s=e.ajaxData,o=t.style=n.staticLabel(e,s),a=t.icon=L.divIcon({className:o.cssClass||"label-icon-text",html:o.html,iconSize:o.iconSize||[50,50]});t.marker=L.marker(i,{icon:a}).addTo(t.map),t.selected&&t.marker._icon.classList.add(t.style.cssSelectedClass||"label-icon-text-selected"),t.marker.on("click",function(){t.toggle()}),t.map.on("zoomend",function(e){var r=e.target.getZoom();t.zoom!==r&&t.map.removeLayer(t.marker)})}t("../MVTUtil");e.exports=r,r.prototype.toggle=function(){this.selected?this.deselect():this.select()},r.prototype.select=function(){this.selected=!0,this.marker._icon.classList.add(this.style.cssSelectedClass||"label-icon-text-selected");var t=this.mvtFeature.linkedFeature();t.selected||t.select()},r.prototype.deselect=function(){this.selected=!1,this.marker._icon.classList.remove(this.style.cssSelectedClass||"label-icon-text-selected");var t=this.mvtFeature.linkedFeature();t.selected&&t.deselect()},r.prototype.remove=function(){this.map&&this.marker&&this.map.removeLayer(this.marker)}},{"../MVTUtil":11}],13:[function(t,e,r){function i(t,e,r){if(!(this instanceof i))return new i(t,e,r);var n,s=typeof t;if("number"===s)n=t>0?t>>>0:0;else if("string"===s)"base64"===e&&(t=T(t)),n=i.byteLength(t,e);else{if("object"!==s||null===t)throw new TypeError("must start with number, buffer, array or string");"Buffer"===t.type&&B(t.data)&&(t=t.data),n=+t.length>0?Math.floor(+t.length):0}if(this.length>C)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+C.toString(16)+" bytes");var o;i.TYPED_ARRAY_SUPPORT?o=i._augment(new Uint8Array(n)):(o=this,o.length=n,o._isBuffer=!0);var a;if(i.TYPED_ARRAY_SUPPORT&&"number"==typeof t.byteLength)o._set(t);else if(I(t))if(i.isBuffer(t))for(a=0;n>a;a++)o[a]=t.readUInt8(a);else for(a=0;n>a;a++)o[a]=(t[a]%256+256)%256;else if("string"===s)o.write(t,0,e);else if("number"===s&&!i.TYPED_ARRAY_SUPPORT&&!r)for(a=0;n>a;a++)o[a]=0;return o}function n(t,e,r,i){r=Number(r)||0;var n=t.length-r;i?(i=Number(i),i>n&&(i=n)):i=n;var s=e.length;if(s%2!==0)throw new Error("Invalid hex string");i>s/2&&(i=s/2);for(var o=0;i>o;o++){var a=parseInt(e.substr(2*o,2),16);if(isNaN(a))throw new Error("Invalid hex string");t[r+o]=a}return o}function s(t,e,r,i){var n=k(S(e),t,r,i);return n}function o(t,e,r,i){var n=k(F(e),t,r,i);return n}function a(t,e,r,i){return o(t,e,r,i) }function h(t,e,r,i){var n=k(A(e),t,r,i);return n}function u(t,e,r,i){var n=k(P(e),t,r,i);return n}function l(t,e,r){return U.fromByteArray(0===e&&r===t.length?t:t.slice(e,r))}function f(t,e,r){var i="",n="";r=Math.min(t.length,r);for(var s=e;r>s;s++)t[s]<=127?(i+=D(n)+String.fromCharCode(t[s]),n=""):n+="%"+t[s].toString(16);return i+D(n)}function c(t,e,r){var i="";r=Math.min(t.length,r);for(var n=e;r>n;n++)i+=String.fromCharCode(t[n]);return i}function p(t,e,r){return c(t,e,r)}function d(t,e,r){var i=t.length;(!e||0>e)&&(e=0),(!r||0>r||r>i)&&(r=i);for(var n="",s=e;r>s;s++)n+=E(t[s]);return n}function y(t,e,r){for(var i=t.slice(e,r),n="",s=0;s<i.length;s+=2)n+=String.fromCharCode(i[s]+256*i[s+1]);return n}function v(t,e,r){if(t%1!==0||0>t)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function g(t,e,r,n,s,o){if(!i.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");if(e>s||o>e)throw new TypeError("value is out of bounds");if(r+n>t.length)throw new TypeError("index out of range")}function w(t,e,r,i){0>e&&(e=65535+e+1);for(var n=0,s=Math.min(t.length-r,2);s>n;n++)t[r+n]=(e&255<<8*(i?n:1-n))>>>8*(i?n:1-n)}function b(t,e,r,i){0>e&&(e=4294967295+e+1);for(var n=0,s=Math.min(t.length-r,4);s>n;n++)t[r+n]=e>>>8*(i?n:3-n)&255}function m(t,e,r,i,n,s){if(e>n||s>e)throw new TypeError("value is out of bounds");if(r+i>t.length)throw new TypeError("index out of range")}function L(t,e,r,i,n){return n||m(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),V.write(t,e,r,i,23,4),r+4}function _(t,e,r,i,n){return n||m(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),V.write(t,e,r,i,52,8),r+8}function T(t){for(t=x(t).replace(R,"");t.length%4!==0;)t+="=";return t}function x(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function I(t){return B(t)||i.isBuffer(t)||t&&"object"==typeof t&&"number"==typeof t.length}function E(t){return 16>t?"0"+t.toString(16):t.toString(16)}function S(t){for(var e=[],r=0;r<t.length;r++){var i=t.charCodeAt(r);if(127>=i)e.push(i);else{var n=r;i>=55296&&57343>=i&&r++;for(var s=encodeURIComponent(t.slice(n,r+1)).substr(1).split("%"),o=0;o<s.length;o++)e.push(parseInt(s[o],16))}}return e}function F(t){for(var e=[],r=0;r<t.length;r++)e.push(255&t.charCodeAt(r));return e}function P(t){for(var e,r,i,n=[],s=0;s<t.length;s++)e=t.charCodeAt(s),r=e>>8,i=e%256,n.push(i),n.push(r);return n}function A(t){return U.toByteArray(t)}function k(t,e,r,i){for(var n=0;i>n&&!(n+r>=e.length||n>=t.length);n++)e[n+r]=t[n];return n}function D(t){try{return decodeURIComponent(t)}catch(e){return String.fromCharCode(65533)}}var U=t("base64-js"),V=t("ieee754"),B=t("is-array");r.Buffer=i,r.SlowBuffer=i,r.INSPECT_MAX_BYTES=50,i.poolSize=8192;var C=1073741823;i.TYPED_ARRAY_SUPPORT=function(){try{var t=new ArrayBuffer(0),e=new Uint8Array(t);return e.foo=function(){return 42},42===e.foo()&&"function"==typeof e.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(r){return!1}}(),i.isBuffer=function(t){return!(null==t||!t._isBuffer)},i.compare=function(t,e){if(!i.isBuffer(t)||!i.isBuffer(e))throw new TypeError("Arguments must be Buffers");for(var r=t.length,n=e.length,s=0,o=Math.min(r,n);o>s&&t[s]===e[s];s++);return s!==o&&(r=t[s],n=e[s]),n>r?-1:r>n?1:0},i.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},i.concat=function(t,e){if(!B(t))throw new TypeError("Usage: Buffer.concat(list[, length])");if(0===t.length)return new i(0);if(1===t.length)return t[0];var r;if(void 0===e)for(e=0,r=0;r<t.length;r++)e+=t[r].length;var n=new i(e),s=0;for(r=0;r<t.length;r++){var o=t[r];o.copy(n,s),s+=o.length}return n},i.byteLength=function(t,e){var r;switch(t+="",e||"utf8"){case"ascii":case"binary":case"raw":r=t.length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":r=2*t.length;break;case"hex":r=t.length>>>1;break;case"utf8":case"utf-8":r=S(t).length;break;case"base64":r=A(t).length;break;default:r=t.length}return r},i.prototype.length=void 0,i.prototype.parent=void 0,i.prototype.toString=function(t,e,r){var i=!1;if(e>>>=0,r=void 0===r||1/0===r?this.length:r>>>0,t||(t="utf8"),0>e&&(e=0),r>this.length&&(r=this.length),e>=r)return"";for(;;)switch(t){case"hex":return d(this,e,r);case"utf8":case"utf-8":return f(this,e,r);case"ascii":return c(this,e,r);case"binary":return p(this,e,r);case"base64":return l(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return y(this,e,r);default:if(i)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),i=!0}},i.prototype.equals=function(t){if(!i.isBuffer(t))throw new TypeError("Argument must be a Buffer");return 0===i.compare(this,t)},i.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),"<Buffer "+t+">"},i.prototype.compare=function(t){if(!i.isBuffer(t))throw new TypeError("Argument must be a Buffer");return i.compare(this,t)},i.prototype.get=function(t){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(t)},i.prototype.set=function(t,e){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(t,e)},i.prototype.write=function(t,e,r,i){if(isFinite(e))isFinite(r)||(i=r,r=void 0);else{var l=i;i=e,e=r,r=l}e=Number(e)||0;var f=this.length-e;r?(r=Number(r),r>f&&(r=f)):r=f,i=String(i||"utf8").toLowerCase();var c;switch(i){case"hex":c=n(this,t,e,r);break;case"utf8":case"utf-8":c=s(this,t,e,r);break;case"ascii":c=o(this,t,e,r);break;case"binary":c=a(this,t,e,r);break;case"base64":c=h(this,t,e,r);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":c=u(this,t,e,r);break;default:throw new TypeError("Unknown encoding: "+i)}return c},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},i.prototype.slice=function(t,e){var r=this.length;if(t=~~t,e=void 0===e?r:~~e,0>t?(t+=r,0>t&&(t=0)):t>r&&(t=r),0>e?(e+=r,0>e&&(e=0)):e>r&&(e=r),t>e&&(e=t),i.TYPED_ARRAY_SUPPORT)return i._augment(this.subarray(t,e));for(var n=e-t,s=new i(n,void 0,!0),o=0;n>o;o++)s[o]=this[o+t];return s},i.prototype.readUInt8=function(t,e){return e||v(t,1,this.length),this[t]},i.prototype.readUInt16LE=function(t,e){return e||v(t,2,this.length),this[t]|this[t+1]<<8},i.prototype.readUInt16BE=function(t,e){return e||v(t,2,this.length),this[t]<<8|this[t+1]},i.prototype.readUInt32LE=function(t,e){return e||v(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},i.prototype.readUInt32BE=function(t,e){return e||v(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},i.prototype.readInt8=function(t,e){return e||v(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},i.prototype.readInt16LE=function(t,e){e||v(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},i.prototype.readInt16BE=function(t,e){e||v(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},i.prototype.readInt32LE=function(t,e){return e||v(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},i.prototype.readInt32BE=function(t,e){return e||v(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},i.prototype.readFloatLE=function(t,e){return e||v(t,4,this.length),V.read(this,t,!0,23,4)},i.prototype.readFloatBE=function(t,e){return e||v(t,4,this.length),V.read(this,t,!1,23,4)},i.prototype.readDoubleLE=function(t,e){return e||v(t,8,this.length),V.read(this,t,!0,52,8)},i.prototype.readDoubleBE=function(t,e){return e||v(t,8,this.length),V.read(this,t,!1,52,8)},i.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,1,255,0),i.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=t,e+1},i.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,2,65535,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t,this[e+1]=t>>>8):w(this,t,e,!0),e+2},i.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,2,65535,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=t):w(this,t,e,!1),e+2},i.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,4,4294967295,0),i.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=t):b(this,t,e,!0),e+4},i.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,4,4294967295,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t):b(this,t,e,!1),e+4},i.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,1,127,-128),i.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),0>t&&(t=255+t+1),this[e]=t,e+1},i.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,2,32767,-32768),i.TYPED_ARRAY_SUPPORT?(this[e]=t,this[e+1]=t>>>8):w(this,t,e,!0),e+2},i.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,2,32767,-32768),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=t):w(this,t,e,!1),e+2},i.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,4,2147483647,-2147483648),i.TYPED_ARRAY_SUPPORT?(this[e]=t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):b(this,t,e,!0),e+4},i.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,4,2147483647,-2147483648),0>t&&(t=4294967295+t+1),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t):b(this,t,e,!1),e+4},i.prototype.writeFloatLE=function(t,e,r){return L(this,t,e,!0,r)},i.prototype.writeFloatBE=function(t,e,r){return L(this,t,e,!1,r)},i.prototype.writeDoubleLE=function(t,e,r){return _(this,t,e,!0,r)},i.prototype.writeDoubleBE=function(t,e,r){return _(this,t,e,!1,r)},i.prototype.copy=function(t,e,r,n){var s=this;if(r||(r=0),n||0===n||(n=this.length),e||(e=0),n!==r&&0!==t.length&&0!==s.length){if(r>n)throw new TypeError("sourceEnd < sourceStart");if(0>e||e>=t.length)throw new TypeError("targetStart out of bounds");if(0>r||r>=s.length)throw new TypeError("sourceStart out of bounds");if(0>n||n>s.length)throw new TypeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var o=n-r;if(1e3>o||!i.TYPED_ARRAY_SUPPORT)for(var a=0;o>a;a++)t[a+e]=this[a+r];else t._set(this.subarray(r,r+o),e)}},i.prototype.fill=function(t,e,r){if(t||(t=0),e||(e=0),r||(r=this.length),e>r)throw new TypeError("end < start");if(r!==e&&0!==this.length){if(0>e||e>=this.length)throw new TypeError("start out of bounds");if(0>r||r>this.length)throw new TypeError("end out of bounds");var i;if("number"==typeof t)for(i=e;r>i;i++)this[i]=t;else{var n=S(t.toString()),s=n.length;for(i=e;r>i;i++)this[i]=n[i%s]}return this}},i.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(i.TYPED_ARRAY_SUPPORT)return new i(this).buffer;for(var t=new Uint8Array(this.length),e=0,r=t.length;r>e;e+=1)t[e]=this[e];return t.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var M=i.prototype;i._augment=function(t){return t.constructor=i,t._isBuffer=!0,t._get=t.get,t._set=t.set,t.get=M.get,t.set=M.set,t.write=M.write,t.toString=M.toString,t.toLocaleString=M.toString,t.toJSON=M.toJSON,t.equals=M.equals,t.compare=M.compare,t.copy=M.copy,t.slice=M.slice,t.readUInt8=M.readUInt8,t.readUInt16LE=M.readUInt16LE,t.readUInt16BE=M.readUInt16BE,t.readUInt32LE=M.readUInt32LE,t.readUInt32BE=M.readUInt32BE,t.readInt8=M.readInt8,t.readInt16LE=M.readInt16LE,t.readInt16BE=M.readInt16BE,t.readInt32LE=M.readInt32LE,t.readInt32BE=M.readInt32BE,t.readFloatLE=M.readFloatLE,t.readFloatBE=M.readFloatBE,t.readDoubleLE=M.readDoubleLE,t.readDoubleBE=M.readDoubleBE,t.writeUInt8=M.writeUInt8,t.writeUInt16LE=M.writeUInt16LE,t.writeUInt16BE=M.writeUInt16BE,t.writeUInt32LE=M.writeUInt32LE,t.writeUInt32BE=M.writeUInt32BE,t.writeInt8=M.writeInt8,t.writeInt16LE=M.writeInt16LE,t.writeInt16BE=M.writeInt16BE,t.writeInt32LE=M.writeInt32LE,t.writeInt32BE=M.writeInt32BE,t.writeFloatLE=M.writeFloatLE,t.writeFloatBE=M.writeFloatBE,t.writeDoubleLE=M.writeDoubleLE,t.writeDoubleBE=M.writeDoubleBE,t.fill=M.fill,t.inspect=M.inspect,t.toArrayBuffer=M.toArrayBuffer,t};var R=/[^+\/0-9A-z]/g},{"base64-js":14,ieee754:15,"is-array":16}],14:[function(t,e,r){var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(t){"use strict";function e(t){var e=t.charCodeAt(0);return e===o?62:e===a?63:h>e?-1:h+10>e?e-h+26+26:l+26>e?e-l:u+26>e?e-u+26:void 0}function r(t){function r(t){u[f++]=t}var i,n,o,a,h,u;if(t.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var l=t.length;h="="===t.charAt(l-2)?2:"="===t.charAt(l-1)?1:0,u=new s(3*t.length/4-h),o=h>0?t.length-4:t.length;var f=0;for(i=0,n=0;o>i;i+=4,n+=3)a=e(t.charAt(i))<<18|e(t.charAt(i+1))<<12|e(t.charAt(i+2))<<6|e(t.charAt(i+3)),r((16711680&a)>>16),r((65280&a)>>8),r(255&a);return 2===h?(a=e(t.charAt(i))<<2|e(t.charAt(i+1))>>4,r(255&a)):1===h&&(a=e(t.charAt(i))<<10|e(t.charAt(i+1))<<4|e(t.charAt(i+2))>>2,r(a>>8&255),r(255&a)),u}function n(t){function e(t){return i.charAt(t)}function r(t){return e(t>>18&63)+e(t>>12&63)+e(t>>6&63)+e(63&t)}var n,s,o,a=t.length%3,h="";for(n=0,o=t.length-a;o>n;n+=3)s=(t[n]<<16)+(t[n+1]<<8)+t[n+2],h+=r(s);switch(a){case 1:s=t[t.length-1],h+=e(s>>2),h+=e(s<<4&63),h+="==";break;case 2:s=(t[t.length-2]<<8)+t[t.length-1],h+=e(s>>10),h+=e(s>>4&63),h+=e(s<<2&63),h+="="}return h}var s="undefined"!=typeof Uint8Array?Uint8Array:Array,o="+".charCodeAt(0),a="/".charCodeAt(0),h="0".charCodeAt(0),u="a".charCodeAt(0),l="A".charCodeAt(0);t.toByteArray=r,t.fromByteArray=n}("undefined"==typeof r?this.base64js={}:r)},{}],15:[function(t,e){e.exports=t(2)},{"/Users/nick/code/Leaflet.MapboxVectorTile/node_modules/pbf/node_modules/ieee754/index.js":2}],16:[function(t,e){var r=Array.isArray,i=Object.prototype.toString;e.exports=r||function(t){return!!t&&"[object Array]"==i.call(t)}},{}]},{},[10]);