mapbox-gl-arcgis-tiled-map-service
Version:
ArcGIS Tile Map Service custom source plugin for Mapbox GL
3 lines (2 loc) • 25.8 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).ArcGISTiledMapServiceSource=e()}(this,function(){"use strict";function t(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];for(var r=0,i=e;r<i.length;r+=1){var s=i[r];for(var o in s)t[o]=s[o]}return t}function e(t,e){for(var n={},r=0;r<e.length;r++){var i=e[r];i in t&&(n[i]=t[i])}return n}function n(){return function t(e){return e?(e^16*Math.random()>>e/4).toString(16):([1e7]+-[1e3]+-4e3+-8e3+-1e11).replace(/[018]/g,t)}()}function r(t){return!!t&&/^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(t)}var i={};function s(t){i[t]||("undefined"!=typeof console&&console.warn(t),i[t]=!0)}function o(t){var e={};if(t.replace(/(?:^|(?:\s*\,\s*))([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)(?:\=(?:([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)|(?:\"((?:[^"\\]|\\.)*)\")))?/g,function(t,n,r,i){var s=r||i;return e[n]=!s||s.toLowerCase(),""}),e["max-age"]){var n=parseInt(e["max-age"],10);isNaN(n)?delete e["max-age"]:e["max-age"]=n}return e}function a(t){try{var e=self[t];return e.setItem("_mapbox_test_",1),e.removeItem("_mapbox_test_"),!0}catch(t){return!1}}var u,c,h,l,p={API_URL:"https://api.mapbox.com",get EVENTS_URL(){return this.API_URL?0===this.API_URL.indexOf("https://api.mapbox.cn")?"https://events.mapbox.cn/events/v2":0===this.API_URL.indexOf("https://api.mapbox.com")?"https://events.mapbox.com/events/v2":null:null},FEEDBACK_URL:"https://apps.mapbox.com/feedback",REQUIRE_ACCESS_TOKEN:!0,ACCESS_TOKEN:null,MAX_PARALLEL_IMAGE_REQUESTS:16},f=self.performance&&self.performance.now?self.performance.now.bind(self.performance):Date.now.bind(Date),d=self.requestAnimationFrame||self.mozRequestAnimationFrame||self.webkitRequestAnimationFrame||self.msRequestAnimationFrame,m=self.cancelAnimationFrame||self.mozCancelAnimationFrame||self.webkitCancelAnimationFrame||self.msCancelAnimationFrame,v={now:f,frame:function(t){var e=d(t);return{cancel:function(){return m(e)}}},getImageData:function(t,e){void 0===e&&(e=0);var n=self.document.createElement("canvas"),r=n.getContext("2d");if(!r)throw new Error("failed to create canvas 2d context");return n.width=t.width,n.height=t.height,r.drawImage(t,0,0,t.width,t.height),r.getImageData(-e,-e,t.width+2*e,t.height+2*e)},resolveURL:function(t){return u||(u=self.document.createElement("a")),u.href=t,u.href},hardwareConcurrency:self.navigator.hardwareConcurrency||4,get devicePixelRatio(){return self.devicePixelRatio},get prefersReducedMotion(){return!!self.matchMedia&&(null==c&&(c=self.matchMedia("(prefers-reduced-motion: reduce)")),c.matches)}};self.document&&((l=self.document.createElement("img")).onload=function(){h&&function(t){var e=t.createTexture();t.bindTexture(t.TEXTURE_2D,e);try{if(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,l),t.isContextLost())return}catch(t){}t.deleteTexture(e)}(h),h=null},l.onerror=function(){h=null},l.src="data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAQAAAAfQ//73v/+BiOh/AAA=");function g(t){return 0===t.indexOf("mapbox:")}var y=/^((https?:)?\/\/)?([^\/]+\.)?mapbox\.c(n|om)(\/|\?|$)/i;function E(t){return y.test(t)}var _=/^(\w+):\/\/([^\/?]*)(\/[^?]+)?\??(.+)?/;function x(t){if(!t)return null;var e,n=t.split(".");if(!n||3!==n.length)return null;try{return JSON.parse((e=n[1],decodeURIComponent(self.atob(e).split("").map(function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)}).join(""))))}catch(t){return null}}var A=function(t){this.type=t,this.anonId=null,this.eventData={},this.queue=[],this.pendingRequest=null};A.prototype.getStorageKey=function(t){var e,n=x(p.ACCESS_TOKEN),r="";return n&&n.u?(e=n.u,r=self.btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(t,e){return String.fromCharCode(Number("0x"+e))}))):r="",t?"mapbox.eventData."+t+":"+r:"mapbox.eventData:"+r},A.prototype.fetchEventData=function(){var t=a("localStorage"),e=this.getStorageKey(),n=this.getStorageKey("uuid");if(t)try{var r=self.localStorage.getItem(e);r&&(this.eventData=JSON.parse(r));var i=self.localStorage.getItem(n);i&&(this.anonId=i)}catch(t){s("Unable to read from LocalStorage")}},A.prototype.saveEventData=function(){var t=a("localStorage"),e=this.getStorageKey(),n=this.getStorageKey("uuid");if(t)try{self.localStorage.setItem(n,this.anonId),Object.keys(this.eventData).length>=1&&self.localStorage.setItem(e,JSON.stringify(this.eventData))}catch(t){s("Unable to write to LocalStorage")}},A.prototype.processRequests=function(t){},A.prototype.postEvent=function(e,n,r,i){var s=this;if(p.EVENTS_URL){var o=function(t){var e=t.match(_);if(!e)throw new Error("Unable to parse URL object");return{protocol:e[1],authority:e[2],path:e[3]||"/",params:e[4]?e[4].split("&"):[]}}(p.EVENTS_URL);o.params.push("access_token="+(i||p.ACCESS_TOKEN||""));var a,u,c={event:this.type,created:new Date(e).toISOString(),sdkIdentifier:"mapbox-gl-js",sdkVersion:"1.4.0",skuId:"01",userId:this.anonId},h=n?t(c,n):c,l={url:(a=o,u=a.params.length?"?"+a.params.join("&"):"",a.protocol+"://"+a.authority+a.path+u),headers:{"Content-Type":"text/plain"},body:JSON.stringify([h])};this.pendingRequest=j(l,function(t){s.pendingRequest=null,r(t),s.saveEventData(),s.processRequests(i)})}},A.prototype.queueRequest=function(t,e){this.queue.push(t),this.processRequests(e)};var T,w=function(t){function e(){t.call(this,"map.load"),this.success={},this.skuToken=""}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.postMapLoadEvent=function(t,e,n,r){this.skuToken=n,(p.EVENTS_URL&&r||p.ACCESS_TOKEN&&t.some(function(t){return g(t)||E(t)}))&&this.queueRequest({id:e,timestamp:Date.now()},r)},e.prototype.processRequests=function(t){var e=this;if(!this.pendingRequest&&0!==this.queue.length){var i=this.queue.shift(),s=i.id,o=i.timestamp;s&&this.success[s]||(this.anonId||this.fetchEventData(),r(this.anonId)||(this.anonId=n()),this.postEvent(o,{skuToken:this.skuToken},function(t){t||s&&(e.success[s]=!0)},t))}},e}(A),S=new(function(t){function e(e){t.call(this,"appUserTurnstile"),this._customAccessToken=e}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.postTurnstileEvent=function(t,e){p.EVENTS_URL&&p.ACCESS_TOKEN&&Array.isArray(t)&&t.some(function(t){return g(t)||E(t)})&&this.queueRequest(Date.now(),e)},e.prototype.processRequests=function(t){var e=this;if(!this.pendingRequest&&0!==this.queue.length){this.anonId&&this.eventData.lastSuccess&&this.eventData.tokenU||this.fetchEventData();var i=x(p.ACCESS_TOKEN),s=i?i.u:p.ACCESS_TOKEN,o=s!==this.eventData.tokenU;r(this.anonId)||(this.anonId=n(),o=!0);var a=this.queue.shift();if(this.eventData.lastSuccess){var u=new Date(this.eventData.lastSuccess),c=new Date(a),h=(a-this.eventData.lastSuccess)/864e5;o=o||h>=1||h<-1||u.getDate()!==c.getDate()}else o=!0;if(!o)return this.processRequests();this.postEvent(a,{"enabled.telemetry":!1},function(t){t||(e.eventData.lastSuccess=a,e.eventData.tokenU=s)},t)}},e}(A)),M=(S.postTurnstileEvent.bind(S),new w),b=(M.postMapLoadEvent.bind(M),"mapbox-tiles"),R=500,I=50,D=42e4;function U(t,e,n){if(self.caches){var r={status:e.status,statusText:e.statusText,headers:new self.Headers};e.headers.forEach(function(t,e){return r.headers.set(e,t)});var i=o(e.headers.get("Cache-Control")||"");if(!i["no-store"])i["max-age"]&&r.headers.set("Expires",new Date(n+1e3*i["max-age"]).toUTCString()),new Date(r.headers.get("Expires")).getTime()-n<D||function(t,e){if(void 0===T)try{new Response(new ReadableStream),T=!0}catch(t){T=!1}T?e(t.body):t.blob().then(e)}(e,function(e){var n=new self.Response(e,r);self.caches.open(b).then(function(e){return e.put(L(t.url),n)}).catch(function(t){return s(t.message)})})}}function L(t){var e=t.indexOf("?");return e<0?t:t.slice(0,e)}function N(t,e){if(!self.caches)return e(null);var n=L(t.url);self.caches.open(b).then(function(t){t.match(n).catch(e).then(function(r){var i=function(t){if(!t)return!1;var e=new Date(t.headers.get("Expires")),n=o(t.headers.get("Cache-Control")||"");return e>Date.now()&&!n["no-cache"]}(r);t.delete(n),i&&t.put(n,r.clone()),e(null,r,i)})}).catch(e)}var z=1/0;"function"==typeof Object.freeze&&Object.freeze({Unknown:"Unknown",Style:"Style",Source:"Source",Tile:"Tile",Glyphs:"Glyphs",SpriteImage:"SpriteImage",SpriteJSON:"SpriteJSON",Image:"Image"});var C=function(t){function e(e,n,r){401===n&&E(r)&&(e+=": you may have provided an invalid Mapbox access token. See https://www.mapbox.com/api-documentation/#access-tokens-and-token-scopes"),t.call(this,e),this.status=n,this.url=r,this.name=this.constructor.name,this.message=e}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.toString=function(){return this.name+": "+this.message+" ("+this.status+"): "+this.url},e}(Error);function P(){return"undefined"!=typeof WorkerGlobalScope&&"undefined"!=typeof self&&self instanceof WorkerGlobalScope}var k=P()?function(){return self.worker&&self.worker.referrer}:function(){return("blob:"===self.location.protocol?self.parent:self).location.href};function O(t,e){var n,r=new self.AbortController,i=new self.Request(t.url,{method:t.method||"GET",body:t.body,credentials:t.credentials,headers:t.headers,referrer:k(),signal:r.signal}),o=!1,a=!1,u=(n=i.url).indexOf("sku=")>0&&E(n);"json"===t.type&&i.headers.set("Accept","application/json");var c=function(n,r,o){if(!a){if(n&&"SecurityError"!==n.message&&s(n),r&&o)return h(r);var c=Date.now();self.fetch(i).then(function(n){if(n.ok){var r=u?n.clone():null;return h(n,r,c)}return e(new C(n.statusText,n.status,t.url))}).catch(function(t){20!==t.code&&e(new Error(t.message))})}},h=function(n,r,s){("arrayBuffer"===t.type?n.arrayBuffer():"json"===t.type?n.json():n.text()).then(function(t){a||(r&&s&&U(i,r,s),o=!0,e(null,t,n.headers.get("Cache-Control"),n.headers.get("Expires")))}).catch(function(t){return e(new Error(t.message))})};return u?N(i,c):c(null,null),{cancel:function(){a=!0,o||r.abort()}}}var q,B,G=function(t,e){if(n=t.url,!(/^file:/.test(n)||/^file:/.test(k())&&!/^\w+:/.test(n))){if(self.fetch&&self.Request&&self.AbortController&&self.Request.prototype.hasOwnProperty("signal"))return O(t,e);if(P()&&self.worker&&self.worker.actor)return self.worker.actor.send("getResource",t,e)}var n;return function(t,e){var n=new self.XMLHttpRequest;for(var r in n.open(t.method||"GET",t.url,!0),"arrayBuffer"===t.type&&(n.responseType="arraybuffer"),t.headers)n.setRequestHeader(r,t.headers[r]);return"json"===t.type&&(n.responseType="text",n.setRequestHeader("Accept","application/json")),n.withCredentials="include"===t.credentials,n.onerror=function(){e(new Error(n.statusText))},n.onload=function(){if((n.status>=200&&n.status<300||0===n.status)&&null!==n.response){var r=n.response;if("json"===t.type)try{r=JSON.parse(n.response)}catch(t){return e(t)}e(null,r,n.getResponseHeader("Cache-Control"),n.getResponseHeader("Expires"))}else e(new C(n.statusText,n.status,t.url))},n.send(t.body),{cancel:function(){return n.abort()}}}(t,e)},X=function(e,n){return G(t(e,{type:"json"}),n)},j=function(e,n){return G(t(e,{method:"POST"}),n)};q=[],B=0;var F=function(e,n){if(B>=p.MAX_PARALLEL_IMAGE_REQUESTS){var r={requestParameters:e,callback:n,cancelled:!1,cancel:function(){this.cancelled=!0}};return q.push(r),r}B++;var i=!1,s=function(){if(!i)for(i=!0,B--;q.length&&B<p.MAX_PARALLEL_IMAGE_REQUESTS;){var t=q.shift(),e=t.requestParameters,n=t.callback;t.cancelled||(t.cancel=F(e,n).cancel)}},o=function(e,n){return G(t(e,{type:"arrayBuffer"}),n)}(e,function(t,e,r,i){if(s(),t)n(t);else if(e){var o=new self.Image,a=self.URL||self.webkitURL;o.onload=function(){n(null,o),a.revokeObjectURL(o.src)},o.onerror=function(){return n(new Error("Could not load image. Please make sure to use a supported image type such as PNG or JPEG. Note that SVGs are not supported."))};var u=new self.Blob([new Uint8Array(e)],{type:"image/png"});o.cacheControl=r,o.expires=i,o.src=e.byteLength?a.createObjectURL(u):"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAUAAarVyFEAAAAASUVORK5CYII="}});return{cancel:function(){o.cancel(),s()}}};function Y(t,e,n){n[t]&&-1!==n[t].indexOf(e)||(n[t]=n[t]||[],n[t].push(e))}function K(t,e,n){if(n&&n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}var W=function(e,n){void 0===n&&(n={}),t(this,n),this.type=e},V=function(e){function n(n,r){void 0===r&&(r={}),e.call(this,"error",t({error:n},r))}return e&&(n.__proto__=e),n.prototype=Object.create(e&&e.prototype),n.prototype.constructor=n,n}(W),J=function(){};J.prototype.on=function(t,e){return this._listeners=this._listeners||{},Y(t,e,this._listeners),this},J.prototype.off=function(t,e){return K(t,e,this._listeners),K(t,e,this._oneTimeListeners),this},J.prototype.once=function(t,e){return this._oneTimeListeners=this._oneTimeListeners||{},Y(t,e,this._oneTimeListeners),this},J.prototype.fire=function(e,n){"string"==typeof e&&(e=new W(e,n||{}));var r=e.type;if(this.listens(r)){e.target=this;for(var i=0,s=this._listeners&&this._listeners[r]?this._listeners[r].slice():[];i<s.length;i+=1){s[i].call(this,e)}for(var o=0,a=this._oneTimeListeners&&this._oneTimeListeners[r]?this._oneTimeListeners[r].slice():[];o<a.length;o+=1){var u=a[o];K(r,u,this._oneTimeListeners),u.call(this,e)}var c=this._eventedParent;c&&(t(e,"function"==typeof this._eventedParentData?this._eventedParentData():this._eventedParentData),c.fire(e))}else e instanceof V&&console.error(e.error);return this},J.prototype.listens=function(t){return this._listeners&&this._listeners[t]&&this._listeners[t].length>0||this._oneTimeListeners&&this._oneTimeListeners[t]&&this._oneTimeListeners[t].length>0||this._eventedParent&&this._eventedParent.listens(t)},J.prototype.setEventedParent=function(t,e){return this._eventedParent=t,this._eventedParentData=e,this};var H,Q=(function(t,e){var n=function(){var t={},e=Math.PI/180,n=180/Math.PI,r=6378137,i=20037508.342789244;function s(t){return Number(t)===t&&t%1!=0}function o(e){if(e=e||{},this.size=e.size||256,!t[this.size]){var n=this.size,r=t[this.size]={};r.Bc=[],r.Cc=[],r.zc=[],r.Ac=[];for(var i=0;i<30;i++)r.Bc.push(n/360),r.Cc.push(n/(2*Math.PI)),r.zc.push(n/2),r.Ac.push(n),n*=2}this.Bc=t[this.size].Bc,this.Cc=t[this.size].Cc,this.zc=t[this.size].zc,this.Ac=t[this.size].Ac}return o.prototype.px=function(t,n){if(s(n)){var r=this.size*Math.pow(2,n),i=r/2,o=r/360,a=r/(2*Math.PI),u=r,c=Math.min(Math.max(Math.sin(e*t[1]),-.9999),.9999);return(h=i+t[0]*o)>u&&(h=u),(l=i+.5*Math.log((1+c)/(1-c))*-a)>u&&(l=u),[h,l]}i=this.zc[n],c=Math.min(Math.max(Math.sin(e*t[1]),-.9999),.9999);var h=Math.round(i+t[0]*this.Bc[n]),l=Math.round(i+.5*Math.log((1+c)/(1-c))*-this.Cc[n]);return h>this.Ac[n]&&(h=this.Ac[n]),l>this.Ac[n]&&(l=this.Ac[n]),[h,l]},o.prototype.ll=function(t,e){if(s(e)){var r=this.size*Math.pow(2,e),i=r/360,o=r/(2*Math.PI),a=r/2,u=(t[1]-a)/-o;return[(t[0]-a)/i,n*(2*Math.atan(Math.exp(u))-.5*Math.PI)]}u=(t[1]-this.zc[e])/-this.Cc[e];return[(t[0]-this.zc[e])/this.Bc[e],n*(2*Math.atan(Math.exp(u))-.5*Math.PI)]},o.prototype.bbox=function(t,e,n,r,i){r&&(e=Math.pow(2,n)-1-e);var s=[t*this.size,(+e+1)*this.size],o=[(+t+1)*this.size,e*this.size],a=this.ll(s,n).concat(this.ll(o,n));return"900913"===i?this.convert(a,"900913"):a},o.prototype.xyz=function(t,e,n,r){"900913"===r&&(t=this.convert(t,"WGS84"));var i=[t[0],t[1]],s=[t[2],t[3]],o=this.px(i,e),a=this.px(s,e),u=[Math.floor(o[0]/this.size),Math.floor((a[0]-1)/this.size)],c=[Math.floor(a[1]/this.size),Math.floor((o[1]-1)/this.size)],h={minX:Math.min.apply(Math,u)<0?0:Math.min.apply(Math,u),minY:Math.min.apply(Math,c)<0?0:Math.min.apply(Math,c),maxX:Math.max.apply(Math,u),maxY:Math.max.apply(Math,c)};if(n){var l={minY:Math.pow(2,e)-1-h.maxY,maxY:Math.pow(2,e)-1-h.minY};h.minY=l.minY,h.maxY=l.maxY}return h},o.prototype.convert=function(t,e){return"900913"===e?this.forward(t.slice(0,2)).concat(this.forward(t.slice(2,4))):this.inverse(t.slice(0,2)).concat(this.inverse(t.slice(2,4)))},o.prototype.forward=function(t){var n=[r*t[0]*e,r*Math.log(Math.tan(.25*Math.PI+.5*t[1]*e))];return n[0]>i&&(n[0]=i),n[0]<-i&&(n[0]=-i),n[1]>i&&(n[1]=i),n[1]<-i&&(n[1]=-i),n},o.prototype.inverse=function(t){return[t[0]*n/r,(.5*Math.PI-2*Math.atan(Math.exp(-t[1]/r)))*n]},o}();t.exports=n}(H={exports:{}},H.exports),H.exports),Z={0:156543.033928,1:78271.5169639999,2:39135.7584820001,3:19567.8792409999,4:9783.93962049996,5:4891.96981024998,6:2445.98490512499,7:1222.99245256249,8:611.49622628138,9:305.748113140558,10:152.874056570411,11:76.4370282850732,12:38.2185141425366,13:19.1092570712683,14:9.55462853563415,15:4.77731426794937,16:2.38865713397468,17:1.19432856685505,18:.597164283559817,19:.298582141647617,20:.14929107082381,21:.07464553541191,22:.0373227677059525,23:.0186613838529763},$=function(t,e,n){return Math.abs(t/e-1)<n};var tt=function(t,e){if(isNaN(t)||isNaN(e))throw new Error("Invalid LngLat object: ("+t+", "+e+")");if(this.lng=+t,this.lat=+e,this.lat>90||this.lat<-90)throw new Error("Invalid LngLat latitude value: must be between -90 and 90")};tt.prototype.wrap=function(){return new tt((t=this.lng,(i=((t-(e=-180))%(r=(n=180)-e)+r)%r+e)===e?n:i),this.lat);var t,e,n,r,i},tt.prototype.toArray=function(){return[this.lng,this.lat]},tt.prototype.toString=function(){return"LngLat("+this.lng+", "+this.lat+")"},tt.prototype.toBounds=function(t){void 0===t&&(t=0);var e=360*t/40075017,n=e/Math.cos(Math.PI/180*this.lat);return new et(new tt(this.lng-n,this.lat-e),new tt(this.lng+n,this.lat+e))},tt.convert=function(t){if(t instanceof tt)return t;if(Array.isArray(t)&&(2===t.length||3===t.length))return new tt(Number(t[0]),Number(t[1]));if(!Array.isArray(t)&&"object"==typeof t&&null!==t)return new tt(Number("lng"in t?t.lng:t.lon),Number(t.lat));throw new Error("`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]")};var et=function(t,e){t&&(e?this.setSouthWest(t).setNorthEast(e):4===t.length?this.setSouthWest([t[0],t[1]]).setNorthEast([t[2],t[3]]):this.setSouthWest(t[0]).setNorthEast(t[1]))};et.prototype.setNorthEast=function(t){return this._ne=t instanceof tt?new tt(t.lng,t.lat):tt.convert(t),this},et.prototype.setSouthWest=function(t){return this._sw=t instanceof tt?new tt(t.lng,t.lat):tt.convert(t),this},et.prototype.extend=function(t){var e,n,r=this._sw,i=this._ne;if(t instanceof tt)e=t,n=t;else{if(!(t instanceof et))return Array.isArray(t)?t.every(Array.isArray)?this.extend(et.convert(t)):this.extend(tt.convert(t)):this;if(e=t._sw,n=t._ne,!e||!n)return this}return r||i?(r.lng=Math.min(e.lng,r.lng),r.lat=Math.min(e.lat,r.lat),i.lng=Math.max(n.lng,i.lng),i.lat=Math.max(n.lat,i.lat)):(this._sw=new tt(e.lng,e.lat),this._ne=new tt(n.lng,n.lat)),this},et.prototype.getCenter=function(){return new tt((this._sw.lng+this._ne.lng)/2,(this._sw.lat+this._ne.lat)/2)},et.prototype.getSouthWest=function(){return this._sw},et.prototype.getNorthEast=function(){return this._ne},et.prototype.getNorthWest=function(){return new tt(this.getWest(),this.getNorth())},et.prototype.getSouthEast=function(){return new tt(this.getEast(),this.getSouth())},et.prototype.getWest=function(){return this._sw.lng},et.prototype.getSouth=function(){return this._sw.lat},et.prototype.getEast=function(){return this._ne.lng},et.prototype.getNorth=function(){return this._ne.lat},et.prototype.toArray=function(){return[this._sw.toArray(),this._ne.toArray()]},et.prototype.toString=function(){return"LngLatBounds("+this._sw.toString()+", "+this._ne.toString()+")"},et.prototype.isEmpty=function(){return!(this._sw&&this._ne)},et.convert=function(t){return!t||t instanceof et?t:new et(t)};Math.PI;function nt(t){return(180+t)/360}function rt(t){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+t*Math.PI/360)))/360}var it=function(t,e,n){this.bounds=et.convert(this.validateBounds(t)),this.minzoom=e||0,this.maxzoom=n||24};it.prototype.validateBounds=function(t){return Array.isArray(t)&&4===t.length?[Math.max(-180,t[0]),Math.max(-90,t[1]),Math.min(180,t[2]),Math.min(90,t[3])]:[-180,-90,180,90]},it.prototype.contains=function(t){var e=Math.pow(2,t.z),n=Math.floor(nt(this.bounds.getWest())*e),r=Math.floor(rt(this.bounds.getNorth())*e),i=Math.ceil(nt(this.bounds.getEast())*e),s=Math.ceil(rt(this.bounds.getSouth())*e);return t.x>=n&&t.x<i&&t.y>=r&&t.y<s};var st=/\{ *([\w_]+) *\}/g,ot=function(t,e){return e?e[Math.abs(t.x+t.y)%e.length]:null},at=self.HTMLImageElement,ut=self.HTMLCanvasElement,ct=self.HTMLVideoElement,ht=self.ImageData,lt=function(t,e,n,r){this.context=t,this.format=n,this.texture=t.gl.createTexture(),this.update(e,r)};return lt.prototype.update=function(t,e,n){var r=t.width,i=t.height,s=!(this.size&&this.size[0]===r&&this.size[1]===i||n),o=this.context,a=o.gl;if(this.useMipmap=Boolean(e&&e.useMipmap),a.bindTexture(a.TEXTURE_2D,this.texture),o.pixelStoreUnpackFlipY.set(!1),o.pixelStoreUnpack.set(1),o.pixelStoreUnpackPremultiplyAlpha.set(this.format===a.RGBA&&(!e||!1!==e.premultiply)),s)this.size=[r,i],t instanceof at||t instanceof ut||t instanceof ct||t instanceof ht?a.texImage2D(a.TEXTURE_2D,0,this.format,this.format,a.UNSIGNED_BYTE,t):a.texImage2D(a.TEXTURE_2D,0,this.format,r,i,0,this.format,a.UNSIGNED_BYTE,t.data);else{var u=n||{x:0,y:0},c=u.x,h=u.y;t instanceof at||t instanceof ut||t instanceof ct||t instanceof ht?a.texSubImage2D(a.TEXTURE_2D,0,c,h,a.RGBA,a.UNSIGNED_BYTE,t):a.texSubImage2D(a.TEXTURE_2D,0,c,h,r,i,a.RGBA,a.UNSIGNED_BYTE,t.data)}this.useMipmap&&this.isSizePowerOfTwo()&&a.generateMipmap(a.TEXTURE_2D)},lt.prototype.bind=function(t,e,n){var r=this.context.gl;r.bindTexture(r.TEXTURE_2D,this.texture),n!==r.LINEAR_MIPMAP_NEAREST||this.isSizePowerOfTwo()||(n=r.LINEAR),t!==this.filter&&(r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,t),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,n||t),this.filter=t),e!==this.wrap&&(r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,e),this.wrap=e)},lt.prototype.isSizePowerOfTwo=function(){return this.size[0]===this.size[1]&&Math.log(this.size[0])/Math.LN2%1==0},lt.prototype.destroy=function(){this.context.gl.deleteTexture(this.texture),this.texture=null},function(n){function r(r,i,s,o){n.call(this),this.id=r,this.dispatcher=s,this.setEventedParent(o),this.type="arcgisraster",this.minzoom=0,this.maxzoom=22,this.roundZoom=!0,this.tileSize=512,this._loaded=!1,this._options=t({type:"arcgisraster"},i),t(this,e(i,["url","scheme","tileSize"]))}return n&&(r.__proto__=n),r.prototype=Object.create(n&&n.prototype),r.prototype.constructor=r,r.prototype.load=function(){var n,r,i,s=this;this._loaded=!1,this.fire(new W("dataloading",{dataType:"source"})),n=this._options,r=function(e,n){s._loaded=!0,e?s.fire(new V(e)):n&&(t(s,n),n.bounds&&(s.tileBounds=new it(n.bounds,s.minzoom,s.maxzoom)),s.fire(new W("data",{dataType:"source",sourceDataType:"metadata"})),s.fire(new W("data",{dataType:"source",sourceDataType:"content"})))},i=function(t,n){if(t)return r(t);var i=e(n,["tileInfo","initialExtent","fullExtent","spatialReference","tileServers","documentInfo"]);i._lodMap={};var s=n.spatialReference.latestWkid||n.spatialReference.wkid;if(102100===s||3857===s){var o=n.fullExtent;if(o&&o.spatialReference&&102100===o.spatialReference.wkid){var a=[o.xmin,o.ymin,o.xmax,o.ymax],u=new Q({size:256}).convert(a);i.bounds=u}var c=n.tileInfo.lods,h=Z;i.minzoom=c[0].level,i.maxzoom=c[c.length-1].level;for(var l=0;l<c.length;l++){var p=c[l];for(var f in h){var d=h[f];if($(p.resolution,d,.1)){i._lodMap[f]=p.level;break}}}}else r(new Error("non-mercator spatial reference"));r(null,i)},n.url?X({url:n.url},i):v.frame(i.bind(null,null,n))},r.prototype.loaded=function(){return this._loaded},r.prototype.onAdd=function(t){var e=this.url.split("?")[0];this.tileUrl=e+"/tile/{z}/{y}/{x}",new RegExp(/tiles.arcgis(online)?\.com/g).test(this.url)&&(this.tileUrl=this.tileUrl.replace("://tiles","://tiles{s}"),this.subdomains=["1","2","3","4"]),this.token&&(this.tileUrl+="?token="+this.token),this.map=t,this.load()},r.prototype.onRemove=function(){},r.prototype.serialize=function(){return t({},this._options)},r.prototype.hasTile=function(t){return!this.tileBounds||this.tileBounds.contains(t.canonical)},r.prototype.loadTile=function(e,n){var r,i,s=this,o={z:e.tileID.overscaledZ,x:e.tileID.canonical.x,y:e.tileID.canonical.y},a=(r=this.tileUrl,i=t({s:ot(o,this.subdomains),z:this._lodMap&&this._lodMap[o.z]?this._lodMap[o.z]:o.z,x:o.x,y:o.y},this.options),r.replace(st,function(t,e){var n=i[e];if(void 0===n)throw new Error("No value provided for variable "+t);return"function"==typeof n&&(n=n(i)),n}));e.request=F({url:a},function(t,r){if(delete e.request,e.aborted)e.state="unloaded",n(null);else if(t)e.state="errored",n(t);else if(r){s.map._refreshExpiredTiles&&e.setExpiryData(r),delete r.cacheControl,delete r.expires;var i=s.map.painter.context,o=i.gl;e.texture=s.map.painter.getTileTexture(r.width),e.texture?e.texture.update(r,{useMipmap:!0}):(e.texture=new lt(i,r,o.RGBA,{useMipmap:!0}),e.texture.bind(o.LINEAR,o.CLAMP_TO_EDGE,o.LINEAR_MIPMAP_NEAREST),i.extTextureFilterAnisotropic&&o.texParameterf(o.TEXTURE_2D,i.extTextureFilterAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT,i.extTextureFilterAnisotropicMax)),e.state="loaded",a=s.dispatcher,++z>I&&(a.getActor().send("enforceCacheSizeLimit",R),z=0),n(null)}var a})},r.prototype.abortTile=function(t,e){t.request&&(t.request.cancel(),delete t.request),e()},r.prototype.unloadTile=function(t,e){t.texture&&this.map.painter.saveTileTexture(t.texture),e()},r.prototype.hasTransition=function(){return!1},r}(J)});
//# sourceMappingURL=mapbox-gl-arcgis-tiled-map-service.js.map