// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/layers/vectorTiles/layers/support/vectorTileLayerLoader","require exports dojo/has dojo/_base/lang ../../core/promiseUtils ../../core/urlUtils ../../config ../../request".split(" "),function(A,p,v,w,l,d,m,n){function k(a){if(a){var b=d.getOrigin(a);d.canUseXhr(b)||-1!==q.indexOf(b)||q.push(b);return a}}function r(a,b,c){if(null!=b.sources){c&&-1!==c.path.indexOf("root.json")&&(c.path=c.path.substr(0,c.path.indexOf("root.json")),a.styleUrl=c.path);var e=t(b,c),f=b.sprite||null,g=b.glyphs||
null;if(e=c&&c.path||e&&e.url)b.sprite&&!d.isAbsolute(b.sprite)&&(f=d.normalize(d.join(e,b.sprite))),b.glyphs&&!d.isAbsolute(b.glyphs)&&(g=d.normalize(d.join(e,b.glyphs)));a.style=b;a.spriteUrl=f;a.glyphsUrl=g;return x(a,b,c)}if(b.hasOwnProperty("tileInfo"))return a.layerDefinition=b,a.serviceUrl=c.path,y(a,b,c)}function y(a,b,c){if(z&&!b.hasOwnProperty("defaultStyles"))throw Error("Service definition must have 'defaultStyles' element!");b=b.defaultStyles;d.isAbsolute(b)?a.styleUrl=d.normalize(b):
a.styleUrl=d.normalize(d.join(c.path,b));k(a.styleUrl);return n(d.join(a.styleUrl,"root.json"),{responseType:"json"}).then(function(b){var c=b.data.sprite||null,e=b.data.glyphs||null;c&&!d.isAbsolute(c)&&(c=d.normalize(d.join(a.styleUrl,c)));e&&!d.isAbsolute(e)&&(e=d.normalize(d.join(a.styleUrl,e)));a.spriteUrl=c;a.glyphsUrl=e;return a.style=b.data})}function x(a,b,c){(b=t(b,c))||l.reject("Source isn't available in the syle object!");if(b.url)return a.serviceUrl=b.url,d.isAbsolute(a.serviceUrl)||
(a.serviceUrl=d.join(c.path,a.serviceUrl)),k(a.serviceUrl),n(a.serviceUrl,{query:{f:"json"},responseType:"json"}).then(function(b){a.layerDefinition=u(b.data);return a});a.layerDefinition=u(b);return l.resolve(a)}function t(a,b){if(!a.sources)return null;var c=a.sources,e=null;if(c.esri)e=c.esri,b&&e.url&&!d.isAbsolute(e.url)&&(c=b.path.substring(0,b.path.lastIndexOf("/")),e.url=d.join(c,e.url));else{for(var f=0,g=Object.keys(c);f<g.length;f++){var h=g[f];if(-1!==h.toLocaleLowerCase().indexOf("street")&&
"vector"===e.type){e=c[h];break}}if(!e)for(f=0,g=Object.keys(c);f<g.length&&(h=g[f],e=c[h],"vector"!==e.type);f++);}return e}function u(a){if(a.hasOwnProperty("tileInfo"))return a;for(var b={xmin:-2.0037507067161843E7,ymin:-2.0037507067161843E7,xmax:2.0037507067161843E7,ymax:2.0037507067161843E7,spatialReference:{wkid:102100}},c=(b.xmax-b.xmin)/512,e=[],d=a.hasOwnProperty("minzoom")?parseFloat(a.minzoom):0,g=a.hasOwnProperty("maxzoom")?parseFloat(a.maxzoom):16;d<g;d++){var h=c/Math.pow(2,d);e.push({level:d,
scale:Math.floor(3779.527559055118*h),resolution:h})}a.tiles.forEach(k);return{capabilities:"TilesOnly",initialExtent:b,fullExtent:b,minScale:e[0].scale,maxScale:e[e.length-1].scale,tiles:a.tiles,tileInfo:{rows:512,cols:512,dpi:96,format:"pbf",origin:{x:-2.0037508342787E7,y:2.0037508342787E7},lods:e,spatialReference:{wkid:102100}}}}Object.defineProperty(p,"__esModule",{value:!0});var z=v("dojo-debug-messages"),q=m.defaults&&m.defaults.io.corsEnabledServers||m.request.corsEnabledServers;p.loadMetadata=
function(a){if(!a)return l.reject("invalid input URL!");var b={layerDefinition:null,parsedUrl:null,serviceUrl:null,style:null,styleUrl:null,url:null,spriteUrl:null,glyphsUrl:null};if("string"!==typeof a)return r(b,a,null).then(function(){return b});a=b.url=d.normalize(a);var c=b.parsedUrl=d.urlToObject(a);k(a);return n(c.path,{responseType:"json",query:w.mixin({f:"json"},c.query)}).then(function(a){return r(b,a.data,c)}).then(function(){return b})}});