// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.11/esri/copyright.txt for details.
//>>built
define("esri/layers/StreamMode","dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/has ../kernel ../SpatialReference ../tasks/query ../tasks/QueryTask ../geometry/jsonUtils ./RenderMode".split(" "),function(k,l,m,n,p,q,r,s,t,u){k=k([u],{declaredClass:"esri.layers._StreamMode",constructor:function(a,b){this.featureLayer=a;this._featureMap={};this._setRefreshRate();this._drawBuffer={adds:[],updates:[]};this._timeoutId=null;this._flushDrawBuffer=l.hitch(this,this._flushDrawBuffer);this._drawFeatures=
l.hitch(this,this._drawFeatures);this._queryErrorHandler=l.hitch(this,this._queryErrorHandler)},startup:function(){},propertyChangeHandler:function(a){this._init&&(0===a?this._applyTimeFilter():3===a?this._redrawAllTracks():console.debug("StreamLayer: Stream Layer only supports changing map time or maximumTrackPoints. Layer id \x3d "+this.featureLayer.id))},drawFeature:function(a){var b=this.featureLayer,c=b.objectIdField;this._timeoutId||(this._timeoutId=setTimeout(this._flushDrawBuffer,this._refreshRate));
b._joinField&&this._getFeature(a.attributes[c])?this._drawBuffer.updates.push({oid:a.attributes[c],updates:a}):this._drawBuffer.adds.push(a)},resume:function(){this.propertyChangeHandler(0)},refresh:function(){var a=this.featureLayer;a._collection?(a._fireUpdateStart(),a._refresh(!0),a._fireUpdateEnd()):this._fetchArchive()},_drawFeatures:function(a){this._purgeRequests();var b=this.featureLayer;b._create(a.features||[]);b._fireUpdateEnd(null,null)},_applyTimeFilter:function(a){this.inherited(arguments);
this._redrawAllTracks()},_removeFeatures:function(a){var b=this.featureLayer,c=b.objectIdField;a&&m.forEach(a,function(a){a=a.attributes[c];b._unSelectFeatureIIf(a,this);this._decRefCount(a);this._removeFeatureIIf(a)},this)},_addFeatures:function(a){var b=this.featureLayer,c,g,d,h=[],e=[],f=[];c=b._trackManager;g=b.objectIdField;if(c)for(d in a=c.addFeatures(a),a)a.hasOwnProperty(d)&&(h.push(d),a[d].adds&&(e=e.concat(a[d].adds)),a[d].deletes&&(f=f.concat(a[d].deletes)));else e=a;m.forEach(e,function(a){var b=
a.attributes[g];this._addFeatureIIf(b,a);this._incRefCount(b)},this);f.length&&this._removeFeatures(f);c&&c.refreshTracks(h)},_updateFeatures:function(a){var b=this.featureLayer,c,g,d=[];c=b._trackManager;g=b._trackIdField;m.forEach(a,function(a){var e=a.updates;a=this._getFeature(a.oid);var f;if(a){e.geometry&&(a.geometry=e.geometry);e=e.attributes||{};for(f in e)e.hasOwnProperty(f)&&(a.attributes[f]=e[f]);a.visible=this._checkFeatureTimeIntersects(a);c&&a.attributes[g]?d.push(a.attributes[g]):b._repaint(a,
null,!0)}},this);d.length&&c.refreshTracks(d)},_redrawAllTracks:function(){var a=this.featureLayer._trackManager,b;if(a&&(b=a.trimTracks())&&0<b.length)this._removeFeatures(b),a.refreshTracks()},_flushDrawBuffer:function(){clearTimeout(this._timeoutId);var a=this._drawBuffer,b=a.adds.splice(0,a.adds.length),a=a.updates.splice(0,a.updates.length),c=this.featureLayer;if(!c)return!1;c.onUpdateStart();this._addFeatures(b);this._updateFeatures(a);c._purge();c.onUpdateEnd();this._timeoutId=null},_clearDrawBuffer:function(){var a=
this._timeoutId,b=this._drawBuffer,c=b.adds,b=b.updates;a&&clearTimeout(a);c.splice(0,c.length);b.splice(0,b.length);this._timeoutId=null},_setRefreshRate:function(a){a=a||0===a?a:200;0>a&&(a=200);this._refreshRate=a},_checkFeatureTimeIntersects:function(a){var b=this.featureLayer,c=b.getMap().timeExtent;return!c||!b.timeInfo||!b.timeInfo.startTimeField&&!b.timeInfo.endTimeField?!0:0<b._filterByTime([a],c.startTime,c.endTime).match.length},_getRequestId:function(a){return("_"+a.name+a.layerId+a._ulid).replace(/[^a-zA-Z0-9\_]+/g,
"_")},_fetchArchive:function(a){var b=this.featureLayer,c,g,d,h,e,f;b._fireUpdateStart();if(a)a=new s(a),c=new r,g=this.map,d=b.getFilter()||{},h=d.where||"1\x3d1",e=d.geometry?t.fromJson(d.geometry):null,d=d.outFields?d.outFields.split(","):["*"],c.geometry=e,c.where=h,c.outFields=d,c.returnGeometry=!0,c.outSpatialReference=new q(g.spatialReference.toJson()),b._usePatch&&(f=this._getRequestId(b),this._cancelPendingRequest(null,f)),a.execute(c,this._drawFeatures,this._queryErrorHandler,f);else return this._fireUpdateEnd({error:"No url provided"}),
!1},_queryErrorHandler:function(a){this._purgeRequests();var b=this.featureLayer;b._errorHandler(a);b._fireUpdateEnd(a)}});n("extend-esri")&&l.setObject("layers._StreamMode",k,p);return k});