// 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/views/vectorTiles/TileParser","require exports dojo/promise/all ../../core/promiseUtils ../../core/executeAsync ../../core/pbf ./SourceLayerData ./Feature ./BackgroundBucket ./FillBucket ./LineBucket ./SymbolBucket ../2d/engine/webgl/TileClipper".split(" "),function(N,O,H,E,F,w,x,I,J,K,L,M,m){return function(){function g(b,a,e){this._pbfTile=new w(new Uint8Array(b),new DataView(b));this._tile=a;this._connection=e;this._layers=a.getLayers();e=a.tileKey.split("/").map(parseFloat);
var c=e[0];b=e[1];e=e[2];this._level=c;a.refKey&&(a=a.refKey.split("/").map(parseFloat)[0],a=c-a,0<a&&(c=(1<<a)-1,this._tileClipper=new m.TileClipper(a,b&c,e&c)));this._tileClipper||(this._tileClipper=new m.SimpleBuilder)}g.prototype.parse=function(){for(var b=this,a=this._parseTileData(this._pbfTile),e=this._layers,c=e.length,g=this._level,d,h=[],n={},m=new Set,c=c-1;0<=c;c--)if(d=e[c],!(d.minzoom&&g<d.minzoom||d.maxzoom&&g>=d.maxzoom||d.layout&&"none"===d.layout.visibility))if(0===d.type)d=this._createBucket(d),
d.layerIndex=c,h.push(d);else{var t=d.sourceLayer,p=a[t];p&&(m.add(t),d=this._createBucket(d))&&(d.layerIndex=c,d.layerExtent=p.extent,(p=n[t])||(p=n[t]=[]),p.push(d))}var w=10*this._level,x=10*(this._level+1),q=[],y=[],u=[],G=[],z=this._tileClipper,A=new Set,B={},C=[];m.forEach(function(b){return C.push(b)});var v=0,r=0,D=C.length;return F(function(){if(6===b._tile.status)return!0;switch(v){case 0:if(r<D){var d=C[r++],e=a[d],k=n[d];if(k&&0!==k.length)for(d=e.getData();d.next(2);){var c=new I(d.getMessage(),
e),f=c.values;if(f){var l=f._minzoom;if(l&&l>=x)continue;if((f=f._maxzoom)&&f<=w)continue}for(var l=0,g=k;l<g.length;l++)f=g[l],f.pushFeature(c)}}else{e=b._tile;for(d in n)for(k=n[d],c=0;c<k.length;c++)f=k[c],f.hasFeatures()&&(3===f.layer.type?(q.push(f),e.addBucket(f)):f.layer.refLayerId?u.push(f):(y.push(f),G[f.layer.id]=f));v=1;r=0;D=q.length}break;case 1:r<D?q[r++].getResources(z,A,B):v=2}return 2===v},50).then(function(){if(6===b._tile.status)return[];var a=[],d=b._tile.getWorkerTileHandler(),
c;0<A.size&&(c=d.fetchSprites(A,b._connection),a.push(c));for(var e in B)c=B[e],0<c.size&&(c=d.fetchGlyphs(b._tile.tileKey,e,c,b._connection),a.push(c));return H(a).then(function(a){if(6===b._tile.status)return[];var d=0,c=0,e=y.length;return F(function(){if(6===b._tile.status)return!0;switch(d){case 0:if(c<e){var a=y[c++];a.processFeatures(z,b._tile);h.push(a)}else d=1,c=0,e=u.length;break;case 1:for(var f=0;f<u.length;f++){var a=u[f],g=G[a.layer.refLayerId];g&&(g.assignBufferInfo(a),h.push(a))}d=
2;c=0;e=q.length;break;case 2:c<e?(a=q[c++],a.processFeatures(z,b._tile),h.push(a)):d=3}return 3===d},50).then(function(){h.sort(function(a,b){return a.layerIndex-b.layerIndex});return h})}).otherwise(function(a){return E.reject(Error(a))})}).otherwise(function(a){return E.reject(Error(a))})};g.prototype._parseTileData=function(b){for(var a={};b.next();)switch(b.tag()){case 3:var e=new x(b.getMessage());a[e.name]=e;break;default:b.skip()}return a};g.prototype._createBucket=function(b){switch(b.type){case 0:return this._createBackgroundBucket(b);
case 1:return this._createFillBucket(b);case 2:return this._createLineBucket(b);case 3:return this._createSymbolBucket(b)}};g.prototype._createBackgroundBucket=function(b){return new J(b,this._level)};g.prototype._createFillBucket=function(b){var a=this._tile;return new K(b,this._level,b.hasDataDrivenFill?a.fillDDVertexBuffer:a.fillVertexBuffer,a.fillIndexBuffer,b.hasDataDrivenOutline?a.outlineDDVertexBuffer:a.outlineVertexBuffer,a.outlineIndexBuffer)};g.prototype._createLineBucket=function(b){var a=
this._tile;return new L(b,this._level,b.hasDataDrivenLine?a.lineDDVertexBuffer:a.lineVertexBuffer,a.lineIndexBuffer)};g.prototype._createSymbolBucket=function(b){var a=this._tile;return new M(b,this._level,b.hasDataDrivenIcon?a.iconDDVertexBuffer:a.iconVertexBuffer,a.iconIndexBuffer,b.hasDataDrivenText?a.textDDVertexBuffer:a.textVertexBuffer,a.textIndexBuffer,a.placementEngine,a.getWorkerTileHandler())};return g}()});