// 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/lang dojo/_base/array dojo/Deferred esri/config esri/graphic esri/graphicsUtils esri/geometry/Extent esri/geometry/Point esri/SpatialReference esri/geometry/webMercatorUtils esri/tasks/ProjectParameters".split(" "),function(l,q,m,n,u,v,w,x,r,t,y){var e={zoomToFeatureSet:function(a,b,c){var d=b.features&&0<b.features.length&&b.features[0].getLayer&&b.features[0].getLayer();d=d?d.id:null;b=e.graphicsExtent(b.features,c);return e.zoomToExtent(a,b,d)},zoomToExtent:function(a,b,c){if(!a||
!e.isValidExtent(b)){var d=new m;d.reject();return d}c?(d=new m,require(["jimu/LayerStructure"],function(g){(g=g.getInstance().getNodeById(c))?g.zoomTo(b).then(function(){d.resolve()},function(){d.reject()}):e.projectToMapSpatialReference(a,b).then(function(f){b.isSinglePoint&&(f=e.convertSinglePointExtent(a,f));a.setExtent(f,!0);d.resolve()},function(){d.reject()})})):d=e.projectToMapSpatialReference(a,b).then(function(g){b.isSinglePoint&&(g=e.convertSinglePointExtent(a,g));return a.setExtent(g,
!0)});return d},isValidExtent:function(a){return a&&e.isTrueOrZero(a.xmin)&&e.isTrueOrZero(a.ymin)&&e.isTrueOrZero(a.xmax)&&e.isTrueOrZero(a.ymax)}};e.isVaildExtent=e.isValidExtent;e.isTrueOrZero=function(a){return 0===a?!0:!!a};e.convertSinglePointExtent=function(a,b){var c=a.getScale();if(c=e.getMedianScale(a,c,0))b=e.adjustHeightToAspectRatio(a,b),b=e.getExtentForScale(b,a.width,c);return b};e.graphicsExtent=function(a,b){var c=null;try{if(a&&1===a.length&&a[0].geometry&&"esri.geometry.Multipoint"===
a[0].geometry.declaredClass&&1===a[0].geometry.points.length){var d=a[0].geometry.points[0],g=new x(d[0],d[1],a[0].geometry.spatialReference);a=[new u(g)]}if(a&&1===a.length&&a[0].geometry&&"esri.geometry.Point"===a[0].geometry.declaredClass){var f=a[0].geometry;c=new w(f.x-1E-4,f.y-1E-4,f.x+1E-4,f.y+1E-4,f.spatialReference);c.isSinglePoint=!0}else a&&0<a.length&&(c=v.graphicsExtent(a))&&"number"===typeof b&&0<b&&(c=c.expand(b))}catch(h){console.error(h)}return c};e.projectToMapSpatialReference=function(a,
b){return e.projectToSpatialReference(b,a.spatialReference)};e.projectToSpatialReference=function(a,b){var c=new m,d=a;if(b&&a)if(b.equals(a.spatialReference))c.resolve(d);else if(b.isWebMercator()&&a.spatialReference.equals(new r(4326)))d=t.geographicToWebMercator(a),d.isSinglePoint=a.isSinglePoint,c.resolve(d);else if(b.equals(new r(4326))&&a.spatialReference.isWebMercator())d=t.webMercatorToGeographic(a),d.isSinglePoint=a.isSinglePoint,c.resolve(d);else{var g=n&&n.defaults&&n.defaults.geometryService;
if(g&&"esri.tasks.GeometryService"===g.declaredClass){var f=new y;f.geometries=[a];f.outSR=b;g.project(f).then(function(h){(d=h&&0<h.length&&h[0])?(d.isSinglePoint=a.isSinglePoint,c.resolve(d)):c.reject()},function(){})}else c.reject()}else c.reject();return c};e.getMapLods=function(a){var b=null;a._params&&a._params.lods&&(b=q.map(a._params.lods,l.hitch(this,function(c){return c.toJson()})));return b};e.getMedianScale=function(a,b,c){return e.getTargetScale(a,2,b,c)};e.getTargetScale=function(a,
b,c,d){a=e.getMapLods(a);var g=1;if(a){var f=[],h=[];q.forEach(a,function(k){0<c&&k.scale>c||(k.scale<d?h.push(k.scale):f.push(k.scale))});f.reverse();1<=f.length?(g=h.length?h.length/a.length:1,b=Math.floor((f.length-1)/(b/g)),b=f[b]):b=null}else b=0===c?null:(c-d)/b;return b};e.getScaleForNextTileLevel=function(a,b,c){if(a=e.getMapLods(a)){if(c){for(c=0;c<a.length;c++)if(a[c].scale<b)return a[c].scale-1;return a[a.length-1].scale-1}for(c=a.length-1;0<=c;c--)if(a[c].scale>b)return a[c].scale+1;return a[0].scale+
1}return c?b-1:b+1};e.adjustExtentToAspectRatio=function(a,b){a=a.width/a.height;var c=b.getWidth()/b.getHeight();c>a?(a=b.getWidth()/a/2,l.mixin(b,{ymin:b.getCenter().y-a,ymax:b.getCenter().y+a})):c<a&&(a=b.getHeight()*a/2,l.mixin(b,{xmin:b.getCenter().x-a,xmax:b.getCenter().x+a}));return b};e.adjustHeightToAspectRatio=function(a,b){a=b.getWidth()*(a.height/a.width)/5;l.mixin(b,{ymin:b.getCenter().y-a,ymax:b.getCenter().y+a});return b};e.getExtentForScale=function(a,b,c){var d=20015077/180,g=esri.config.defaults,
f=esri.WKIDUnitConversion,h=a.spatialReference;if(h){var k=h.wkid;var p=h.wkt}h=null;k?h=f.values[f[k]]:p&&-1!==p.search(/^PROJCS/i)&&(f=/UNIT\[([^\]]+)\]\]$/i.exec(p))&&f[1]&&(h=parseFloat(f[1].split(",")[1]));return a.expand(c*b/(39.37*(h||d)*g.screenDPI)/a.getWidth())};e.getScaleForExtent=function(a,b){var c=20015077/180,d=esri.config.defaults,g=esri.WKIDUnitConversion,f=a.spatialReference;if(f){var h=f.wkid;var k=f.wkt}f=null;h?f=g.values[g[h]]:k&&-1!==k.search(/^PROJCS/i)&&(g=/UNIT\[([^\]]+)\]\]$/i.exec(k))&&
g[1]&&(f=parseFloat(g[1].split(",")[1]));return a.getWidth()/b*(f||c)*39.37*d.screenDPI};return e});