{"size": 12955, "ext": "js", "max_stars_repo_path": "arcgis_js_api/library/4.11/esri/widgets/Directions/DirectionsViewModel.js", "max_stars_repo_name": "mozenberger/data-management-tools", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "arcgis_js_api/library/4.11/esri/widgets/Directions/DirectionsViewModel.js", "max_issues_repo_name": "mozenberger/data-management-tools", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "arcgis_js_api/library/4.11/esri/widgets/Directions/DirectionsViewModel.js", "max_forks_repo_name": "mozenberger/data-management-tools", "max_forks_repo_forks_event_min_datetime": "2019-05-23T17:30:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-23T17:30:34.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 479.8148148148, "max_line_length": 931, "alphanum_fraction": 0.7455036665}
// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See https://js.arcgis.com/4.11/esri/copyright.txt for details.
//>>built
define("require exports ../../core/tsSupport/assignHelper ../../core/tsSupport/declareExtendsHelper ../../core/tsSupport/decorateHelper ../../Color ../../Graphic ../../symbols ../../core/Accessor ../../core/Collection ../../core/Error ../../core/Evented ../../core/Handles ../../core/Logger ../../core/promiseUtils ../../core/watchUtils ../../core/accessorSupport/decorators ../../geometry/support/graphicsUtils ../../geometry/support/scaleUtils ../../layers/GraphicsLayer ../../tasks/RouteTask ../../tasks/support/FeatureSet ../../tasks/support/RouteParameters ./support/directionsUtils ../support/GoTo".split(" "),
function(L,M,y,z,e,A,B,h,C,t,m,D,E,F,k,p,d,G,H,q,u,I,v,l,J){var K=F.getLogger("esri.widgets.Directions.DirectionsViewModel"),w={first:new h.SimpleMarkerSymbol({color:[105,220,255,1],size:19,outline:{color:[51,51,51,1],width:3}}),middle:new h.SimpleMarkerSymbol({color:[51,51,51,1],size:12,outline:{color:[105,220,255,1],width:3}}),last:new h.PictureMarkerSymbol({width:23,height:23,url:"data:image/svg+xml;base64,"+btoa('\x3csvg width\x3d"30" height\x3d"30" viewBox\x3d"0 0 30 30" xmlns\x3d"http://www.w3.org/2000/svg"\x3e\x3cg fill-rule\x3d"nonzero" fill\x3d"none"\x3e\x3cpath d\x3d"M15.15.3C6.9.3.3 6.9.3 15.15S6.9 29.7 15.15 29.7 29.7 23.1 29.7 15.15C29.7 6.9 23.25.3 15.15.3z" fill\x3d"#333"/\x3e\x3cpath d\x3d"M15 4.8C9.3 4.8 4.8 9.45 4.8 15c0 5.55 4.65 10.2 10.2 10.2 5.55 0 10.2-4.5 10.2-10.2 0-5.55-4.5-10.2-10.2-10.2z" fill\x3d"#69DCFF"/\x3e\x3cpath fill\x3d"#333" d\x3d"M10.5 10.5h9v9h-9z"/\x3e\x3c/g\x3e\x3c/svg\x3e')}),
unlocated:new h.PictureMarkerSymbol({height:18,width:18,url:"data:image/svg+xml;base64,"+btoa('\x3csvg width\x3d"20" height\x3d"20" viewBox\x3d"0 0 20 20" xmlns\x3d"http://www.w3.org/2000/svg"\x3e\x3cg fill\x3d"none" fill-rule\x3d"evenodd"\x3e\x3cpath d\x3d"M10.1.2C4.6.2.2 4.6.2 10.1s4.4 9.7 9.9 9.7 9.7-4.4 9.7-9.7c0-5.5-4.3-9.9-9.7-9.9z" fill\x3d"#333" fill-rule\x3d"nonzero"/\x3e\x3cpath d\x3d"M10 2.7c-4.08 0-7.3 3.328-7.3 7.3s3.328 7.3 7.3 7.3 7.3-3.22 7.3-7.3c0-3.972-3.22-7.3-7.3-7.3z" fill\x3d"#69DCFF" fill-rule\x3d"nonzero"/\x3e\x3cpath d\x3d"M11.414 10l5.304-5.303-1.415-1.415L10 8.586 4.697 3.282 3.282 4.697 8.586 10l-5.304 5.303 1.415 1.415L10 11.414l5.303 5.304 1.415-1.415L11.414 10z" fill\x3d"#333"/\x3e\x3c/g\x3e\x3c/svg\x3e')}),
waypoint:new h.SimpleMarkerSymbol({color:[255,255,255,1],size:10,outline:{color:[20,89,127,1],width:2.5}})};return function(x){function a(b){b=x.call(this,b)||this;b._handles=new E;b._routeLayer=new q({listMode:"hide"});b._highlightLayer=new q({listMode:"hide"});b._stopId=9999;b._stopLayer=new q({listMode:"hide"});b._serviceDescriptionLoadStatus=0;b.departureTime="now";b.lastRoute=null;b.routeSymbol=new h.SimpleLineSymbol({color:[105,220,255,1],width:7,cap:"round",join:"round"});b.routeParameters=
new v({doNotLocateOnRestrictedElements:!0,ignoreInvalidLocations:!0,directionsOutputType:"complete",findBestSequence:!1,preserveFirstStop:!0,preserveLastStop:!0,restrictUTurns:"at-dead-ends-and-intersections",directionsLengthUnits:"kilometers",returnBarriers:!1,returnDirections:!0,returnPolygonBarriers:!1,returnPolylineBarriers:!1,returnRoutes:!1,returnStops:!0,returnZ:!0,startTime:null,startTimeIsUTC:!0,stops:null,useHierarchy:!0,useTimeWindows:!1});b.routeServiceUrl="https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";
b.serviceDescription=null;b.error=null;b.stops=new t;b.view=null;return b}z(a,x);a.prototype.initialize=function(){var b=this;this._handles.add([p.on(this,"stops","change",function(a){b.clearResults();b._addStopsToLayer()}),p.init(this,"view.map",function(a,c){var g=[b._routeLayer,b._stopLayer,b._highlightLayer];c&&c.removeMany(g);a&&a.addMany(g)}),p.watch(this,"lastRoute",function(){return b._addRouteToLayer()})])};a.prototype.destroy=function(){this.stops.destroy()};Object.defineProperty(a.prototype,
"impedanceAttribute",{get:function(){var b=this.get("routeParameters.travelMode.impedanceAttributeName")||this.get("routeParameters.impedanceAttribute")||this.get("serviceDescription.impedance");return this.getCostAttribute(b)},enumerable:!0,configurable:!0});Object.defineProperty(a.prototype,"maxStops",{set:function(b){this._set("maxStops",2>=b?2:50<b?50:b)},enumerable:!0,configurable:!0});Object.defineProperty(a.prototype,"_routeTask",{get:function(){return new u(this.routeServiceUrl)},enumerable:!0,
configurable:!0});Object.defineProperty(a.prototype,"selectedTravelMode",{get:function(){var b=this.serviceDescription;if(!b)return null;for(var a=b.defaultTravelMode,b=b.supportedTravelModes,b=void 0===b?[]:b,c=null,d=0;d<b.length;d++)b[d].id===a&&(c=b[d]);return c||b[0]||null},set:function(b){void 0===b?this._clearOverride("selectedTravelMode"):this._override("selectedTravelMode",b)},enumerable:!0,configurable:!0});Object.defineProperty(a.prototype,"state",{get:function(){var b=this._serviceDescriptionLoadStatus;
return 4===b?"unauthenticated":0===b?"disabled":1===b?"initializing":this._activeRoute?"routing":3===b||this.error?"error":"ready"},enumerable:!0,configurable:!0});Object.defineProperty(a.prototype,"stopSymbols",{set:function(b){b=y({},w,b);this._set("stopSymbols",b)},enumerable:!0,configurable:!0});Object.defineProperty(a.prototype,"timeAttribute",{get:function(){var b=this.get("routeParameters.travelMode.timeAttributeName")||this.get("routeParameters.directionsTimeAttribute")||this.get("serviceDescription.directionsTimeAttribute");
return this.getCostAttribute(b)},enumerable:!0,configurable:!0});Object.defineProperty(a.prototype,"travelModes",{get:function(){return this.get("serviceDescription.supportedTravelModes")||[]},enumerable:!0,configurable:!0});a.prototype.load=function(){var b=this;return this.serviceDescription?k.resolve():k.resolve().then(function(){b._serviceDescriptionLoadStatus=1;b.notifyChange("state");return b._loadServiceDescription()}).then(function(){b._serviceDescriptionLoadStatus=2;b.notifyChange("state")}).catch(function(a){var c=
"identity-manager:user-aborted"===a.name;b._serviceDescriptionLoadStatus=c?4:3;b.notifyChange("state");if(!c)throw a=new m("directions-view-model:service-metadata-unavailable","Cannot load route service metadata",{error:a}),b._set("error",a),a;})};a.prototype.highlightSegment=function(b){var a=this._highlightLayer;if(this.view){this.clearHighlights();var c=b.symbol.clone();c.color=new A([0,0,0,.8]);c.width=Math.ceil(c.width/2);b=new B({geometry:b.geometry,symbol:c});a.graphics.add(b)}};a.prototype.clearHighlights=
function(){this._highlightLayer.graphics.removeAll()};a.prototype.centerAt=function(b){this.view&&this.callGoTo({target:b})};a.prototype.clearResults=function(){this._set("lastRoute",null)};a.prototype.getDirections=function(){var b=this,a=this.state;if("unauthenticated"===a||"initializing"===a||"disabled"===a||3===this._serviceDescriptionLoadStatus)return k.reject(new m("directions-view-model:not-loaded","Cannot get directions until view model loads."));this._set("error",null);this._activeRoute&&
(this._activeRoute.cancel(),this._activeRoute=null);a=this.departureTime;this.routeParameters.set({startTime:"now"===a?new Date:a,startTimeIsUTC:"now"===a});this.selectedTravelMode&&this.routeParameters.set({travelMode:this.selectedTravelMode});if(1>=this.stops.length)return a=new m("directions-view-model:not-enough-stops","Not enough stops for routing"),this._set("error",a),k.reject(a);this._activeRoute=this._enqueue(function(){var a=b.stops.clone().toArray(),d={},g=function(b){var c=b&&b.routeResults&&
b.routeResults[0]&&b.routeResults[0].stops||[];(b&&b.routeResults&&b.routeResults[0]&&b.routeResults[0].directions&&b.routeResults[0].directions.features||[]).map(function(b){for(var c=0;c<a.length;c++)if(-1<b.attributes.text.indexOf(a[c].attributes.Name)){var f=a[c].attributes.Name;b.attributes.text=b.attributes.text.replace(f,d[f]);b._associatedStop=a[c];break}});a.map(function(b){return b.attributes.Name=d[b.attributes.Name]});c.map(function(b){b.attributes.Name=d[b.attributes.Name]})},e=function(a){if(a&&
a.routeResults&&a.routeResults[0]){a=a.routeResults[0];var c=a.stops||[],d=b.stops.clone().toArray(),g=a.directions&&a.directions.routeName||a.routeName||"";c.map(function(b,a){var c=b.attributes,f=d[a].attributes;g=g.replace(c.Name,f.Name);Object.keys(c).forEach(function(b){0===b.indexOf("Cumul_")&&(f[b]=c[b])});f.ArriveCurbApproach=c.ArriveCurbApproach;f.ArriveTime=c.ArriveTime;f.ArriveTimeUTC=c.ArriveTimeUTC;f.DepartCurbApproach=c.DepartCurbApproach;f.DepartTime=c.DepartTime;f.DepartTimeUTC=c.DepartTimeUTC;
f.Sequence=c.Sequence;f.Status=c.Status});a.directions&&(a.directions.routeName=g);null!==a.route&&(a.route.attributes.Name=g);a.routeName=g}};(function(){a.map(function(a){a=a.attributes;var c=(a.Name||"[not yet geocoded]").substr(0,100)+"_#"+ ++b._stopId;d[c]=a.Name;a.Name=c})})();b.routeParameters.set({stops:new I({features:a})});return b._routeTask.solve(b.routeParameters).then(function(a){for(var c=a&&a.routeResults&&a.routeResults[0]&&a.routeResults[0].stops||[],f=b.stops.toArray(),n=c.length===
f.length,r=0;n&&r<c.length;)n=n&&d[c[r].attributes.Name]===f[r++].attributes.Name;if(n)return e(a),g(a),b._set("lastRoute",a),a;K.warn("Response stops don't match current stops of the ViewModel, invalidating the results.");b._set("lastRoute",null);return null}).catch(function(b){g(null);throw b;})}).then(function(a){b._activeRoute=null;b.notifyChange("state");b.zoomToRoute();return a}).catch(function(a){b._activeRoute=null;b.notifyChange("state");if("cancel"!==a.dojoType)throw a=new m("directions-view-model:unable-to-route",
"Unable to route to these addresses",{error:a}),b._set("error",a),a;});this.notifyChange("state");return this._activeRoute};a.prototype.getCostAttribute=function(b){for(var a=this.serviceDescription&&this.serviceDescription.networkDataset.networkAttributes||[],c="",d=0;d<a.length;d++)if(a[d].name===b&&"esriNAUTCost"===a[d].usageType){c=a[d];break}return c};a.prototype.reset=function(){this.stops.removeAll();this._set("lastRoute",null)};a.prototype.zoomToRoute=function(){var b=this.directionLines,
a=this.view;b&&a&&(b=G.graphicsExtent(b).expand(2),a=H.getScale(a,b),this.callGoTo({target:{target:b,scale:a}}))};a.prototype._loadServiceDescription=function(){var b=this;return this._routeTask.getServiceDescription().then(function(a){b._set("serviceDescription",a)})};a.prototype._enqueue=function(b,a){var c=this;this._requestQueueTail||(this._requestQueueTail=k.resolve());return this._requestQueueTail=a=k.create(function(a,d){c._requestQueueTail.catch(function(){}).then(function(){try{var e=b.call(c);
e&&"object"===typeof e&&e.hasOwnProperty("isFulfilled")?e.then(a,d):a(e)}catch(f){d(f)}})})};a.prototype._addStopsToLayer=function(){var a=this;this._stopLayer.graphics.removeAll();var d=this.stops.clone().map(function(b,d){var c=a.stopSymbols,e=c.first,f=c.middle,g=c.last,h=c.unlocated,c=c.waypoint;l.isWaypoint(b)?b.symbol=c:b.symbol=void 0===b.attributes.Status?0===d?e:d===a.stops.length-1?g:f:l.isWaypoint(b)?c:l.isStopLocated(b)?l.isFirstStop(b)?e:l.isLastStop(b)?g:f:h;return b});this._stopLayer.graphics.addMany(d)};
a.prototype._addRouteToLayer=function(){var b=this;this._routeLayer.graphics.removeAll();var a=this.directionLines;a&&(a.forEach(function(a){a.symbol=b.routeSymbol}),this._routeLayer.graphics.addMany(a))};e([d.property()],a.prototype,"departureTime",void 0);e([d.property({aliasOf:"lastRoute.routeResults.0.directions.features"})],a.prototype,"directionLines",void 0);e([d.property({readOnly:!0,dependsOn:["routeParameters","serviceDescription"]})],a.prototype,"impedanceAttribute",null);e([d.property({readOnly:!0})],
a.prototype,"lastRoute",void 0);e([d.property({value:50})],a.prototype,"maxStops",null);e([d.property()],a.prototype,"routeSymbol",void 0);e([d.property({type:v})],a.prototype,"routeParameters",void 0);e([d.property()],a.prototype,"routeServiceUrl",void 0);e([d.property({dependsOn:["routeServiceUrl"],type:u})],a.prototype,"_routeTask",null);e([d.property({dependsOn:["serviceDescription"]})],a.prototype,"selectedTravelMode",null);e([d.property({readOnly:!0})],a.prototype,"serviceDescription",void 0);
e([d.property({dependsOn:["error"],readOnly:!0})],a.prototype,"state",null);e([d.property()],a.prototype,"error",void 0);e([d.property({type:t})],a.prototype,"stops",void 0);e([d.property({value:w})],a.prototype,"stopSymbols",null);e([d.property({readOnly:!0,dependsOn:["routeParameters","serviceDescription"]})],a.prototype,"timeAttribute",null);e([d.property({dependsOn:["serviceDescription"]})],a.prototype,"travelModes",null);e([d.property()],a.prototype,"view",void 0);e([d.property()],a.prototype,
"getDirections",null);e([d.property()],a.prototype,"zoomToRoute",null);return a=e([d.subclass("esri.widgets.Directions.DirectionsViewModel")],a)}(d.declared(C,D,J))});