// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define("dojo/_base/declare dojo/_base/lang dojo/Stateful esri/geometry/screenUtils esri/symbols/SimpleLineSymbol esri/symbols/SimpleMarkerSymbol esri/graphic esri/geometry/ScreenPoint esri/geometry/geometryEngine dojo/_base/fx dojo/fx dojo/on".split(" "),function(w,t,x,u,v,p,y,z,A,q,B,C){return w([v,x],{constructor:function(a){this.inherited(arguments);this.setStyle(a.style);this.setColor(a.color);this.setWidth(a.width);this.directionSymbols={arrow1:"m0.5,50.5c0,0 99.5,-41 99.5,-41c0,0 0.5,81.5 0.5,81.5c0,0 -100,-40.5 -100,-40.5z",
arrow2:"M1,50l99.5,-50c0,0 -40,49.5 -40,49.5c0,0 39.5,50 39.5,50c0,0 -99,-49.5 -99,-49.5z",arrow3:"m0.5,50.5l90,-50l9,9.5l-79.5,40.5l80,39.5l-10,10.5l-89.5,-50z",arrow4:"m55.4605,51.5754l43.0685,-48.2908l-43.3797,48.2908l43.8197,44.8899l-43.5085,-44.8899zm-6.0505,42.3899l-0.44,-88.1807l-43.37967,45.7908l43.81967,42.3899z"};this.directionColor=a.directionColor||this.color;this.directionSize=a.directionSize||12;this.directionPixelBuffer=a.directionPixelBuffer||40;this.animationRepeat=a.animationRepeat;
this.animationDuration=a.animationDuration||350;this.directionSymbol=a.directionSymbol||"arrow1";this.showDirectionalSymbols=a.showDirectionalSymbols||!0;this.showStartSymbol=a.showStartSymbol||!1;this.startSymbol=a.startSymbol||new p({color:[128,128,128,64],size:8,type:"esriSMS",style:"esriSMSCircle",outline:{color:[0,0,0,255],width:2,type:"esriSLS",style:"esriSLSSolid"}});this.showEndSymbol=a.showEndSymbol||!1;this.endSymbol=a.startSymbol||new p({color:[128,128,128,64],size:8,type:"esriSMS",style:"esriSMSX",
outline:{color:[0,0,0,255],width:2,type:"esriSLS",style:"esriSLSSolid"}});this.graphics=[];this.map=null;this.drawGraphicDirection=this._drawDirection;this.type="DirectionalLineSymbol"},getStroke:function(){var a=0<arguments.callee.caller.arguments.length?arguments.callee.caller.arguments[4]:arguments.callee.caller.caller.arguments[4];if(!a||a.dlsSymbolGroup)return this.inherited(arguments);this.graphics.push(a);var c=a.getLayer(),b=this.map=c.getMap();a.dlsSymbolGroup=c._div.createGroup();this._drawDirection(a,
c,b);c.dlsGraphicRemove||(c.dlsGraphicRemove=c.on("graphic-remove",function(f){f.graphic.dlsSymbolGroup&&(dojo.query(".dls-symbol",f.graphic.dlsSymbolGroup.rawNode).forEach(dojo.destroy),dojo.destroy(f.graphic.dlsSymbolGroup.rawNode),f.graphic.dlsSymbolGroup=null)}));var d=null,e=null;b.graphics.dlsGraphicDraw||(b.graphics.dlsGraphicDraw=b.graphics.on("graphic-draw",function(f){f.graphic.dlsSymbolGroup&&(d=f.graphic,(e="DirectionalLineSymbol"===d.symbol.type?d.symbol:d.symbol.outline&&"DirectionalLineSymbol"===
d.symbol.outline.type?d.symbol.outline:null)&&e.drawGraphicDirection(d,this,this.getMap()))}));b.dlsExtChanged||(b.dlsExtChanged=b.on("extent-change",function(){for(var f=0,g=this.graphics.graphics.length;f<g;f++)if(d=this.graphics.graphics[f],d.symbol)if(d.attributes&&d.attributes.isDirectionalGraphic)this.graphics.remove(d),f--,g--;else{var h="DirectionalLineSymbol"===d.symbol.type?d.symbol:d.symbol.outline&&"DirectionalLineSymbol"===d.symbol.outline.type?d.symbol.outline:null;h&&h.drawGraphicDirection(d,
c,this)}for(f=0;f<this.graphicsLayerIds.length;f++)if(c=this.getLayer(this.graphicsLayerIds[f]),c.dlsGraphicRemove)for(g=0,h=c.graphics.length;g<h;g++)d=c.graphics[g],d.symbol&&(d.attributes&&d.attributes.isDirectionalGraphic?(c.remove(d),g--,h--):d.symbol.drawGraphicDirection(d,c,this))}));return this.inherited(arguments)},_drawDirection:function(a,c,b){if(a.dlsSymbolGroup){var d=a.dlsSymbolGroup,e=a.geometry;e.spatialReference.wkid!==b.spatialReference.wkid&&(esri.geometry.canProject(e,b)?e=esri.geometry.project(e,
b):console.error("Can't project geometry wkid - "+e.spatialReference.wkid+" to map wkid "+b.spatialReference.wkid));a.directions=[];dojo.query(".dls-symbol",a.dlsSymbolGroup.rawNode).forEach(dojo.destroy);var f=u.toScreenGeometry(b.extent,b.width,b.height,e);b=u.toScreenGeometry(b.extent,b.width,b.height,b.extent);if(f="polyline"===e.type?f.paths:f.rings){if(this.showStartSymbol&&(e=this._getFirstItem(f),e=this._createGraphic(e,this.startSymbol),e.geometry)){c.add(e);var g=e.getShape();g?(d.add(g),
e.attr("class","dls-symbol"),a.directions.push(e),a.visible||e.hide(),e.origJson=e.toJson(),e.toJson=this.directionGraphicToJson):c.remove(e)}if(this.showDirectionalSymbols)for(e=0,g=f.length;e<g;e++)for(var h=f[e],m=0,r=h.length-1;m<r;m++)if(m!==h.length){var n=h[m],k=h[m+1],D=this._getAngle(n,k);n=this._getDirectionPoints(n,k,b);k=0;for(var E=n.length;k<E;k++){var l=this._createGraphic(n[k],this._createSymbol(this.directionSymbol,D));c.add(l);var F=l.getShape();d.add(F);l.attr("class","dls-symbol");
a.directions.push(l);a.visible||l.hide();l.origJson=l.toJson();l.toJson=this.directionGraphicToJson}}this.showEndSymbol&&(e=this._getSecondToLastItem(f))&&(b=this._getLastItem(f))&&!this._isEqual(e,b)&&(f=this._getAngle(e,b),f=this._createSymbol(this.endSymbol,f),b=this._createGraphic(b,f),b.geometry&&(c.add(b),(f=b.getShape())?(d.add(f),b.attr("class","dls-symbol"),a.directions.push(b),a.visible||b.hide(),b.origJson=b.toJson(),b.toJson=this.directionGraphicToJson):c.remove(b)));a.dlsAnimationRepeat&&
(1<a.dlsAnimationRepeat||Infinity===a.dlsAnimationRepeat)&&this._animateGraphic(a,a.dlsAnimationRepeat)}else console.error("Can't apply DirectionalLineSymbol to geometry "+e.type)}},_getLastItem:function(a){return a[a.length-1][a[a.length-1].length-1]},_getSecondToLastItem:function(a){return a[a.length-1][a[a.length-1].length-2]},_getFirstItem:function(a){return a[0][0]},_getAngle:function(a,c){return 180/Math.PI*Math.atan2(c[1]-a[1],c[0]-a[0])-180},_isEqual:function(a,c){var b=Object.getOwnPropertyNames(a),
d=Object.getOwnPropertyNames(c);if(b.length!==d.length)return!1;for(d=0;d<b.length;d++){var e=b[d];if(a[e]!==c[e])return!1}return!0},_createSymbol:function(a,c){if("simplemarkersymbol"===a.type||"picturemarkersymbol"===a.type)var b=t.clone(a);else"string"===typeof a?(b=new p,b.setSize(this.directionSize).setPath(this.directionSymbols[a]?this.directionSymbols[a]:a).setOutline(null).setColor(this.directionColor)):console.error("Symbol must be set to one of the pre-defined strings {'arrow1', 'arrow2', 'arrow3', 'arrow4'}, or a SimpleMarkerSymbol or PictureMarkerSymbol.");
b.setAngle(c);return b},_createGraphic:function(a,c){var b=new y;b.setSymbol(c);b.attributes={isDirectionalGraphic:!0};a=new z(a[0],a[1]);a=this.map.toMap(a);b.geometry=A.within(a,this.map.extent)?a:null;return b},_getDirectionPoints:function(a,c,b){var d=[],e=a[0]<c[0]?a[0]:c[0],f=a[0]>c[0]?a[0]:c[0],g=a[1]<c[1]?a[1]:c[1],h=a[1]>c[1]?a[1]:c[1],m=b.xmin<b.xmax?b.xmin:b.xmax,r=b.xmin>b.xmax?b.xmin:b.xmax,n=b.ymin<b.ymax?b.ymin:b.ymax;b=b.ymin>b.ymax?b.ymin:b.ymax;c=[c[0]-a[0],c[1]-a[1]];var k=Math.sqrt(c[0]*
c[0]+c[1]*c[1]);if(k<this.directionPixelBuffer)return d;c[0]=c[0]/k*this.directionPixelBuffer;c[1]=c[1]/k*this.directionPixelBuffer;for(a=[a[0]+c[0],a[1]+c[1]];a[0]>=e&&a[0]<=f&&a[1]>=g&&a[1]<=h;)a[0]>=m&&a[0]<=r&&a[1]>=n&&a[1]<=b&&d.push([a[0],a[1]]),a=[a[0]+c[0],a[1]+c[1]];return d},get:function(a){return this[a]?this[a]:null},_setDirectionSymbolAttr:function(a){this._set("directionSymbol",a);this._drawDirection()},_setStartSymbolAttr:function(a){this._set("startSymbol",a);this._drawDirection()},
_setEndSymbolAttr:function(a){this._set("endSymbol",a);this._drawDirection()},_setShowStartSymbolAttr:function(a){this._set("showStartSymbol",a);this._drawDirection()},_setShowEndSymbolAttr:function(a){this._set("showEndSymbol",a);this._drawDirection()},animateDirection:function(a,c){a&&(a=parseInt(a,10),isNaN(a)&&(a=Infinity),this.animationRepeat=a);if(!this.animationRepeat||1>this.animationRepeat)this.stopAnimation();else for(c&&(this.animationDuration=c),this.animationChain=null,this.animationEnd&&
this.animationEnd.remove(),c=0,a=this.graphics.length;c<a;c++){var b=this.graphics[c];b.dlsSymbolGroup&&this._animateGraphic(b,this.animationRepeat)}},_animateGraphic:function(a,c){var b=[],d=this.animationDuration;a.dlsAnimationChain&&a.dlsAnimationChain.stop();dojo.query(".dls-symbol",a.dlsSymbolGroup.rawNode).forEach(function(e){q.fadeOut({node:e,duration:10}).play();e=q.fadeIn({node:e,duration:d});b.push(e)});a.dlsAnimationRepeat=c;a.dlsAnimationChain=B.chain(b);a.dlsAnimationEnd=C(a.dlsAnimationChain,
"End",t.hitch(this,function(){!isNaN(c)&&1<c?(c--,this._animateGraphic(a,c)):Infinity===c&&this._animateGraphic(a,c)}));try{a.dlsAnimationChain.play()}catch(e){}},stopAnimation:function(){for(var a=0,c=this.graphics.length;a<c;a++){var b=this.graphics[a];b.dlsSymbolGroup&&(dojo.query(".dls-symbol",b.dlsSymbolGroup.rawNode).forEach(function(d){q.fadeIn({node:d,duration:10}).play()}),b.dlsAnimationRepeat=0,b.dlsAnimationChain&&b.dlsAnimationChain.stop(),b.dlsAnimationEnd&&b.dlsAnimationEnd.remove())}},
toJson:function(){return v.prototype.toJson.call(this)},directionGraphicToJson:function(){if(this.jsonUpdated||!this.origJson.symbol||!this.origJson.symbol.angle)return this.origJson;this.origJson.symbol.angle*=-1;this.jsonUpdated=!0;return this.origJson}})});