define(["exports","./when-b60132fc","./Check-7b2a090c","./RuntimeError-4a5c8994"],(function(e,t,r,n){"use strict"; /** * @license * * Grauw URI utilities * * See: http://hg.grauw.nl/grauw-lib/file/tip/src/uri.js * * @author Laurens Holst (http://www.grauw.nl/) * * Copyright 2012 Laurens Holst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */function i(e){if(e instanceof i)this.scheme=e.scheme,this.authority=e.authority,this.path=e.path,this.query=e.query,this.fragment=e.fragment;else if(e){var t=o.exec(e);this.scheme=t[1],this.authority=t[2],this.path=t[3],this.query=t[4],this.fragment=t[5]}}i.prototype.scheme=null,i.prototype.authority=null,i.prototype.path="",i.prototype.query=null,i.prototype.fragment=null;var o=new RegExp("^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\\?([^#]*))?(?:#(.*))?$");i.prototype.getScheme=function(){return this.scheme},i.prototype.getAuthority=function(){return this.authority},i.prototype.getPath=function(){return this.path},i.prototype.getQuery=function(){return this.query},i.prototype.getFragment=function(){return this.fragment},i.prototype.isAbsolute=function(){return!!this.scheme&&!this.fragment},i.prototype.isSameDocumentAs=function(e){return e.scheme==this.scheme&&e.authority==this.authority&&e.path==this.path&&e.query==this.query},i.prototype.equals=function(e){return this.isSameDocumentAs(e)&&e.fragment==this.fragment},i.prototype.normalize=function(){this.removeDotSegments(),this.scheme&&(this.scheme=this.scheme.toLowerCase()),this.authority&&(this.authority=this.authority.replace(a,c).replace(s,f)),this.path&&(this.path=this.path.replace(s,f)),this.query&&(this.query=this.query.replace(s,f)),this.fragment&&(this.fragment=this.fragment.replace(s,f))};var s=/%[0-9a-z]{2}/gi,u=/[a-zA-Z0-9\-\._~]/,a=/(.*@)?([^@:]*)(:.*)?/;function f(e){var t=unescape(e);return u.test(t)?t:e.toUpperCase()}function c(e,t,r,n){return(t||"")+r.toLowerCase()+(n||"")}function p(e,r){if(null===e||"object"!=typeof e)return e;r=t.defaultValue(r,!1);var n=new e.constructor;for(var i in e)if(e.hasOwnProperty(i)){var o=e[i];r&&(o=p(o,r)),n[i]=o}return n}function l(e,r,n){n=t.defaultValue(n,!1);var i,o,s,u={},a=t.defined(e),f=t.defined(r);if(a)for(i in e)e.hasOwnProperty(i)&&(o=e[i],f&&n&&"object"==typeof o&&r.hasOwnProperty(i)?(s=r[i],u[i]="object"==typeof s?l(o,s,n):o):u[i]=o);if(f)for(i in r)r.hasOwnProperty(i)&&!u.hasOwnProperty(i)&&(s=r[i],u[i]=s);return u}function h(e,t){var r;return"undefined"!=typeof document&&(r=document),h._implementation(e,t,r)}i.prototype.resolve=function(e){var t=new i;return this.scheme?(t.scheme=this.scheme,t.authority=this.authority,t.path=this.path,t.query=this.query):(t.scheme=e.scheme,this.authority?(t.authority=this.authority,t.path=this.path,t.query=this.query):(t.authority=e.authority,""==this.path?(t.path=e.path,t.query=this.query||e.query):("/"==this.path.charAt(0)?(t.path=this.path,t.removeDotSegments()):(e.authority&&""==e.path?t.path="/"+this.path:t.path=e.path.substring(0,e.path.lastIndexOf("/")+1)+this.path,t.removeDotSegments()),t.query=this.query))),t.fragment=this.fragment,t},i.prototype.removeDotSegments=function(){var e,t=this.path.split("/"),r=[],n=""==t[0];for(n&&t.shift(),""==t[0]&&t.shift();t.length;)".."==(e=t.shift())?r.pop():"."!=e&&r.push(e);"."!=e&&".."!=e||r.push(""),n&&r.unshift(""),this.path=r.join("/")},i.prototype.toString=function(){var e="";return this.scheme&&(e+=this.scheme+":"),this.authority&&(e+="//"+this.authority),e+=this.path,this.query&&(e+="?"+this.query),this.fragment&&(e+="#"+this.fragment),e},h._implementation=function(e,r,n){if(!t.defined(r)){if(void 0===n)return e;r=t.defaultValue(n.baseURI,n.location.href)}var o=new i(r);return new i(e).resolve(o).toString()};var d,m=/^blob:/i;function y(e){return m.test(e)}var v=/^data:/i;function g(e){return v.test(e)}var q=Object.freeze({UNISSUED:0,ISSUED:1,ACTIVE:2,RECEIVED:3,CANCELLED:4,FAILED:5}),b=Object.freeze({TERRAIN:0,IMAGERY:1,TILES3D:2,OTHER:3,PACK:4,BLOCK:5,BLOCKPACK:6});function R(e){e=t.defaultValue(e,t.defaultValue.EMPTY_OBJECT);var r=t.defaultValue(e.throttleByServer,!1),n=t.defaultValue(e.throttle,!1);this.url=e.url,this.requestFunction=e.requestFunction,this.cancelFunction=e.cancelFunction,this.priorityFunction=e.priorityFunction,this.priority=t.defaultValue(e.priority,0),this.throttle=n,this.throttleByServer=r,this.type=t.defaultValue(e.type,b.OTHER),this.serverKey=void 0,this.state=q.UNISSUED,this.deferred=void 0,this.cancelled=!1}function w(e,t,r){this.statusCode=e,this.response=t,this.responseHeaders=r,"string"==typeof this.responseHeaders&&(this.responseHeaders=function(e){var t={};if(!e)return t;for(var r=e.split("\r\n"),n=0;n0){var s=i.substring(0,o),u=i.substring(o+2);t[s]=u}}return t}(this.responseHeaders))}function A(){this._listeners=[],this._scopes=[],this._toRemove=[],this._insideRaiseEvent=!1}function _(e,t){return t-e}function O(e){this._comparator=e.comparator,this._array=[],this._length=0,this._maximumLength=void 0}function E(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}R.prototype.cancel=function(){this.cancelled=!0},R.prototype.clone=function(e){return t.defined(e)?(e.url=this.url,e.requestFunction=this.requestFunction,e.cancelFunction=this.cancelFunction,e.priorityFunction=this.priorityFunction,e.priority=this.priority,e.throttle=this.throttle,e.throttleByServer=this.throttleByServer,e.type=this.type,e.serverKey=this.serverKey,e.state=this.RequestState.UNISSUED,e.deferred=void 0,e.cancelled=!1,e):new R(this)},w.prototype.toString=function(){var e="Request has failed.";return t.defined(this.statusCode)&&(e+=" Status Code: "+this.statusCode),e},Object.defineProperties(A.prototype,{numberOfListeners:{get:function(){return this._listeners.length-this._toRemove.length}}}),A.prototype.addEventListener=function(e,t){this._listeners.push(e),this._scopes.push(t);var r=this;return function(){r.removeEventListener(e,t)}},A.prototype.removeEventListener=function(e,t){for(var r=this._listeners,n=this._scopes,i=-1,o=0;o0){for(s.sort(_),e=0;ee&&e>0&&(this._length=e,this._array.length=e)}},comparator:{get:function(){return this._comparator}}}),O.prototype.reserve=function(e){e=t.defaultValue(e,this._length),this._array.length=e},O.prototype.heapify=function(e){e=t.defaultValue(e,0);for(var r=this._length,n=this._comparator,i=this._array,o=-1,s=!0;s;){var u=2*(e+1),a=u-1;o=a=0;--t)this.heapify(t)},O.prototype.insert=function(e){var r,n=this._array,i=this._comparator,o=this._maximumLength,s=this._length++;for(so&&(r=n[o],n.pop(),this._length=o),r},O.prototype.pop=function(e){if(e=t.defaultValue(e,0),0!==this._length){var r=this._array,n=r[e];return E(r,e,--this._length),r[this._length]=void 0,this.heapify(e),n}};var C="undefined"!=typeof performance&&"function"==typeof performance.now&&isFinite(performance.now())?function(){return performance.now()}:function(){return Date.now()};function I(e,t){return e.priority-t.priority}var T={numberOfAttemptedRequests:0,numberOfActiveRequests:0,numberOfCancelledRequests:0,numberOfCancelledActiveRequests:0,numberOfFailedRequests:0,numberOfActiveRequestsEver:0,lastNumberOfActiveRequests:0,totalRequestTime:0},S=20,k=new O({comparator:I});k.maximumLength=S,k.reserve(S);var U=[],x={},P="undefined"!=typeof document?new i(document.location.href):new i,B=new A;function L(){}function D(e){t.defined(e.priorityFunction)&&(e.priority=e.priorityFunction())}function K(e){var r=t.defaultValue(L.requestsByServer[e],L.maximumRequestsPerServer);return x[e]0||e.type!==b.OTHER)&&(T.totalRequestTime+=e.endTime-e.startTime),e.type===b.BLOCK||e.type===b.BLOCKPACK)){var n=j(e);t.defined(L.blockDefer[n])&&(L.blockDefer[n]=void 0,delete L.blockDefer[n])}}}(e)).otherwise(function(e){return function(t){e.state!==q.CANCELLED&&(++T.numberOfFailedRequests,--T.numberOfActiveRequests,--x[e.serverKey],B.raiseEvent(t),e.state=q.FAILED,e.deferred.reject(t))}}(e)),n}function z(e){var r=e.state===q.ACTIVE;e.state=q.CANCELLED,++T.numberOfCancelledRequests,e.deferred.reject(),r&&(--T.numberOfActiveRequests,--x[e.serverKey],++T.numberOfCancelledActiveRequests),t.defined(e.cancelFunction)&&e.cancelFunction()}L.TIMEOUT=5e3,L.CANCLE_COUNT=3,L.statisticRequestTime=-1,L.maximumRequests=50,L.maximumRequestsPerServer=6,L.perPacketCount=20,L.requestsByServer={"api.cesium.com:443":18,"assets.cesium.com:443":18},L.throttleRequests=!0,L.debugShowStatistics=!1,L.requestCompletedEvent=B,Object.defineProperties(L,{activeRequestLength:{get:function(){return U.length}},statistics:{get:function(){return T}},priorityHeapLength:{get:function(){return S},set:function(e){if(ee;){z(k.pop())}S=e,k.maximumLength=e,k.reserve(e)}}}),L.packRequestGroup={},L.packRequestPromise={},L.packRequestQuadKey={},L.quadKeyIndex={},L.packRequestHeap={},L.blockDefer={},L.blockRequest={},L.update=function(){var e,t,r=0,n=U.length;for(e=0;e0&&(U[e-r]=t):++r;U.length-=r;var i=k.internalArray,o=k.length;for(e=0;e0;){var r=t.pop();r.cancelled?z(r):F(r)}H()}();for(var s=Math.max(L.maximumRequests-U.length,0),u=0;u0;)(t=k.pop()).cancelled?z(t):!t.throttleByServer||K(t.serverKey)?(X(t),++u):z(t);!function(){if(!L.debugShowStatistics)return;0===T.numberOfActiveRequests&&T.lastNumberOfActiveRequests>0&&(T.numberOfAttemptedRequests>0&&(console.log("Number of attempted requests: "+T.numberOfAttemptedRequests),T.numberOfAttemptedRequests=0),T.numberOfCancelledRequests>0&&(console.log("Number of cancelled requests: "+T.numberOfCancelledRequests),T.numberOfCancelledRequests=0),T.numberOfCancelledActiveRequests>0&&(console.log("Number of cancelled active requests: "+T.numberOfCancelledActiveRequests),T.numberOfCancelledActiveRequests=0),T.numberOfFailedRequests>0&&(console.log("Number of failed requests: "+T.numberOfFailedRequests),T.numberOfFailedRequests=0));T.lastNumberOfActiveRequests=T.numberOfActiveRequests}()},L.getServerKey=function(e){var r=new i(e).resolve(P);r.normalize();var n=r.authority;/:/.test(n)||(n=n+":"+("https"===r.scheme?"443":"80"));var o=x[n];return t.defined(o)||(x[n]=0),n},L.request=function(e){if(g(e.url)||y(e.url))return B.raiseEvent(),e.state=q.RECEIVED,e.requestFunction();if(++T.numberOfAttemptedRequests,t.defined(e.serverKey)||(e.serverKey=L.getServerKey(e.url)),e.type===b.BLOCK)return function(e){var r=j(e),n=L.blockDefer[r];return t.defined(n)||(n=L.blockDefer[r]=t.when.defer(),L.blockRequest[r]=e),e.deferred=n,e.state=q.ISSUED,e.deferred.promise}(e);if(!e.throttleByServer||K(e.serverKey)){if(!L.throttleRequests||!e.throttle)return X(e);if(!(U.length>=L.maximumRequests)){var r;if(D(e),e.type===b.PACK||e.type===b.BLOCKPACK){var n=function(e){var r=V(e),n=L.packRequestHeap[r];return t.defined(n)||((n=L.packRequestHeap[r]=new O({comparator:I})).maximumLength=L.perPacketCount,n.reserve(S)),n}(e),i=!0;if(e.type===b.BLOCKPACK)for(var o=0;o0;){z(k.pop())}for(var e=U.length,t=0;t2){var u=n[i].indexOf("=");s=[n[i].substring(0,u),n[i].substring(u+1,n[i].length)]}var a=decodeURIComponent(s[0]),f=s[1];f=t.defined(f)?decodeURIComponent(f):"";var c=r[a];"string"==typeof c?r[a]=[c,f]:Array.isArray(c)?c.push(f):r[a]=f}return r}(s);r._queryParameters=n?oe(o,r._queryParameters,i):o,e.query=void 0}function re(e,r){var n=r._queryParameters,i=Object.keys(n);1!==i.length||t.defined(n[i[0]])?e.query=function(e,t){var r="";for(var n in e)if(e.hasOwnProperty(n)){var i=e[n],o=encodeURIComponent(n)+"=";if(Array.isArray(i))for(var s=0,u=i.length;s0}}}),se.prototype.getUrlComponent=function(e,r){if(this.isDataUri)return this._url;var n=new i(this._url);e&&re(n,this);var o=n.toString().replace(/%7B/g,"{").replace(/%7D/g,"}"),s=this._templateValues;return o=o.replace(/{(.*?)}/g,(function(e,r){var n=s[r];return t.defined(n)?encodeURIComponent(n):e})),r&&t.defined(this.proxy)&&(o=this.proxy.getURL(o)),o},se.prototype.setQueryParameters=function(e,t){this._queryParameters=t?oe(this._queryParameters,e,!1):oe(e,this._queryParameters,!1)},se.prototype.appendQueryParameters=function(e){this._queryParameters=oe(e,this._queryParameters,!0)},se.prototype.setTemplateValues=function(e,t){this._templateValues=t?l(this._templateValues,e):l(e,this._templateValues)},se.prototype.getDerivedResource=function(e){var r=this.clone();if(r._retryCount=0,t.defined(e.url)){var n=new i(e.url);te(n,r,!0,t.defaultValue(e.preserveQueryParameters,!1)),n.fragment=void 0,r._url=n.resolve(new i(h(this._url))).toString()}return t.defined(e.queryParameters)&&(r._queryParameters=l(e.queryParameters,r._queryParameters)),t.defined(e.templateValues)&&(r._templateValues=l(e.templateValues,r.templateValues)),t.defined(e.headers)&&(r.headers=l(e.headers,r.headers)),t.defined(e.proxy)&&(r.proxy=e.proxy),t.defined(e.request)&&(r.request=e.request),t.defined(e.retryCallback)&&(r.retryCallback=e.retryCallback),t.defined(e.retryAttempts)&&(r.retryAttempts=e.retryAttempts),r},se.prototype.retryOnError=function(e){var r=this.retryCallback;if("function"!=typeof r||this._retryCount>=this.retryAttempts)return t.when(!1);var n=this;return t.when(r(this,e)).then((function(e){return++n._retryCount,e}))},se.prototype.clone=function(e){return t.defined(e)||(e=new se({url:this._url})),e._url=this._url,e._queryParameters=p(this._queryParameters),e._templateValues=p(this._templateValues),e.headers=p(this.headers),e.proxy=this.proxy,e.retryCallback=this.retryCallback,e.retryAttempts=this.retryAttempts,e._retryCount=0,e.request=this.request.clone(),e},se.prototype.getBaseUri=function(e){return function(e,r){var n="",o=e.lastIndexOf("/");return-1!==o&&(n=e.substring(0,o+1)),r?(e=new i(e),t.defined(e.query)&&(n+="?"+e.query),t.defined(e.fragment)&&(n+="#"+e.fragment),n):n}(this.getUrlComponent(e),e)},se.prototype.appendForwardSlash=function(){var e;this._url=(0!==(e=this._url).length&&"/"===e[e.length-1]||(e+="/"),e)},se.prototype.fetchArrayBuffer=function(){return this.fetch({responseType:"arraybuffer"})},se.fetchArrayBuffer=function(e){return new se(e).fetchArrayBuffer()},se.prototype.fetchBlob=function(){return this.fetch({responseType:"blob"})},se.fetchBlob=function(e){return new se(e).fetchBlob()},se.prototype.fetchImage=function(e){e=t.defaultValue(e,t.defaultValue.EMPTY_OBJECT);var r=t.defaultValue(e.preferImageBitmap,!1),n=t.defaultValue(e.preferBlob,!1),i=t.defaultValue(e.flipY,!1);if(ie(this.request),!ee||this.isDataUri||this.isBlobUri||!this.hasHeaders&&!n)return ue({resource:this,flipY:i,preferImageBitmap:r});var o,s,u,a=this.fetchBlob();return t.defined(a)?se.supportsImageBitmapOptions().then((function(e){return o=e&&r,a})).then((function(e){if(t.defined(e)){if(u=e,o)return se.createImageBitmapFromBlob(e,{flipY:i,premultiplyAlpha:!1});var r=window.URL.createObjectURL(e);return ue({resource:s=new se({url:r}),flipY:i,preferImageBitmap:!1})}})).then((function(e){if(t.defined(e))return e.blob=u,o||window.URL.revokeObjectURL(s.url),e})).otherwise((function(e){return t.defined(s)&&window.URL.revokeObjectURL(s.url),e.blob=u,t.when.reject(e)})):void 0},se.fetchImage=function(e){return new se(e).fetchImage({flipY:e.flipY,preferBlob:e.preferBlob,preferImageBitmap:e.preferImageBitmap})},se.prototype.fetchText=function(){return this.fetch({responseType:"text"})},se.fetchText=function(e){return new se(e).fetchText()},se.prototype.fetchJson=function(){var e=this.fetch({responseType:"text",headers:{Accept:"application/json,*/*;q=0.01"}});if(t.defined(e))return e.then((function(e){if(t.defined(e))return JSON.parse(e)}))},se.fetchJson=function(e){return new se(e).fetchJson()},se.prototype.fetchXML=function(){return this.fetch({responseType:"document",overrideMimeType:"text/xml"})},se.fetchXML=function(e){return new se(e).fetchXML()},se.prototype.fetchJsonp=function(e){var r;e=t.defaultValue(e,"callback"),ie(this.request);do{r="loadJsonp"+Math.random().toString().substring(2,8)}while(t.defined(window[r]));return ae(this,e,r)},se.fetchJsonp=function(e){return new se(e).fetchJsonp(e.callbackParameterName)},se.prototype._makeRequest=function(e){var r=this;ie(r.request);var n=r.request;n.url=r.url,n.requestFunction=function(i){var o=e.responseType,s=l(e.headers,r.headers),u=e.overrideMimeType,a=e.method,f=e.data,c=t.when.defer(),p=t.defined(i)?i:r.url,h=se._Implementations.loadWithXhr(p,o,a,f,s,c,u);return t.defined(h)&&t.defined(h.abort)&&(n.cancelFunction=function(){h.abort()}),c.promise};var i=L.request(n);if(t.defined(i))return i.then((function(e){return e})).otherwise((function(i){return n.state!==q.FAILED?t.when.reject(i):r.retryOnError(i).then((function(o){return o?(n.state=q.UNISSUED,n.deferred=void 0,r.fetch(e)):t.when.reject(i)}))}))};var fe=/^data:(.*?)(;base64)?,(.*)$/;function ce(e,t){var r=decodeURIComponent(t);return e?atob(r):r}function pe(e,t){for(var r=ce(e,t),n=new ArrayBuffer(r.length),i=new Uint8Array(n),o=0;o=300)||l&&0===c.status){var e=c.response,o=c.responseType;if("HEAD"===i||"OPTIONS"===i){var s=c.getAllResponseHeaders().trim().split(/[\r\n]+/),a={};return s.forEach((function(e){var t=e.split(": "),r=t.shift();a[r]=t.join(": ")})),void u.resolve(a)}if(204===c.status)u.resolve();else if(!t.defined(e)||t.defined(r)&&o!==r)if("json"===r&&"string"==typeof e)try{u.resolve(JSON.parse(e))}catch(e){u.reject(e)}else(""===o||"document"===o)&&t.defined(c.responseXML)&&c.responseXML.hasChildNodes()?u.resolve(c.responseXML):""!==o&&"text"!==o||!t.defined(c.responseText)?u.reject(new n.RuntimeError("Invalid XMLHttpRequest response type.")):u.resolve(c.responseText);else u.resolve(e)}else u.reject(new w(c.status,c.response,c.getAllResponseHeaders()))},c.onerror=function(e){u.reject(new w)},c.send(o),c}!function(e,t,r,i,o,s,u){var a=require("url").parse(e),f="https:"===a.protocol?require("https"):require("http"),c=require("zlib"),p={protocol:a.protocol,hostname:a.hostname,port:a.port,path:a.path,query:a.query,method:r,headers:o};f.request(p).on("response",(function(e){if(e.statusCode<200||e.statusCode>=300)s.reject(new w(e.statusCode,e,e.headers));else{var r=[];e.on("data",(function(e){r.push(e)})),e.on("end",(function(){var i=Buffer.concat(r);"gzip"===e.headers["content-encoding"]?c.gunzip(i,(function(e,r){e?s.reject(new n.RuntimeError("Error decompressing response.")):s.resolve(le(r,t))})):s.resolve(le(i,t))}))}})).on("error",(function(e){s.reject(new w)})).end()}(e,r,i,0,s,u)}else u.resolve(function(e,r){r=t.defaultValue(r,"");var n=e[1],i=!!e[2],o=e[3];switch(r){case"":case"text":return ce(i,o);case"arraybuffer":return pe(i,o);case"blob":var s=pe(i,o);return new Blob([s],{type:n});case"document":return(new DOMParser).parseFromString(ce(i,o),n);case"json":return JSON.parse(ce(i,o))}}(f,r))},se._Implementations.loadAndExecuteScript=function(e,r,n){return function(e){var r=t.when.defer(),n=document.createElement("script");n.async=!0,n.src=e;var i=document.getElementsByTagName("head")[0];return n.onload=function(){n.onload=void 0,i.removeChild(n),r.resolve()},n.onerror=function(e){r.reject(e)},i.appendChild(n),r.promise}(e).otherwise(n.reject)},se._DefaultImplementations={},se._DefaultImplementations.createImage=se._Implementations.createImage,se._DefaultImplementations.loadWithXhr=se._Implementations.loadWithXhr,se._DefaultImplementations.loadAndExecuteScript=se._Implementations.loadAndExecuteScript,se.DEFAULT=Object.freeze(new se({url:"undefined"==typeof document?"":document.location.href.split("?")[0]}));var de,me,ye,ve=/((?:.*\/)|^)Cesium\.js$/;function ge(e){return"undefined"==typeof document?e:(t.defined(de)||(de=document.createElement("a")),de.href=e,de.href=de.href,de.href)}function qe(){return t.defined(me)||(e="undefined"!=typeof CESIUM_BASE_URL?CESIUM_BASE_URL:"object"==typeof define&&t.defined(define.amd)&&!define.amd.toUrlUndefined&&t.defined(require.toUrl)?h("..",we("Core/buildModuleUrl.js")):function(){for(var e=document.getElementsByTagName("script"),t=0,r=e.length;t