// 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 dojo/topic dojo/promise/all esri/geometry/Point esri/geometry/Extent esri/geometry/scaleUtils esri/SpatialReference esri/tasks/ProjectParameters esri/config esri/geometry/webMercatorUtils esri/symbols/jsonUtils esri/graphic esri/layers/GraphicsLayer esri/InfoTemplate esri/tasks/query ./utils ./LayerInfos/LayerInfos ./shareUtils".split(" "),function(I,x,y,J,z,q,A,K,m,L,M,B,C,D,N,O,P,n,E,r){function Q(a,d){var b=a.center.split(";");1===b.length&&
(b=a.center.split(","));if(2===b.length||3===b.length){a=parseFloat(b[0]);var c=parseFloat(b[1]);if(isNaN(a)||isNaN(c))a=parseFloat(b[0]),c=parseFloat(b[1]);if(!isNaN(a)&&!isNaN(c)){var e=4326;3!==b.length||isNaN(b[2])||(e=parseInt(b[2],10));b=new q(a,c,new m(e));t(b.spatialReference,d.spatialReference)?d.centerAt(b):u(b,d.spatialReference,function(f){d.centerAt(f[0])},function(){console.error("Project center point error.")})}}}function R(a,d){var b=a.extent.split("wkt\x3d"),c=null;2===b.length?(c=
b[1],b=b[0],b=b.split(",")):(b=a.extent.split(";"),1===b.length&&(b=a.extent.split(",")));if(4===b.length||5===b.length){a=parseFloat(b[0]);var e=parseFloat(b[1]),f=parseFloat(b[2]),g=parseFloat(b[3]);if(isNaN(a)||isNaN(a)||isNaN(a)||isNaN(a))a=parseFloat(b[0]),e=parseFloat(b[1]),f=parseFloat(b[2]),g=parseFloat(b[3]);if(isNaN(a)||isNaN(e)||isNaN(f)||isNaN(g))console.error("Wrong extent parameters.");else{var h=4326;5!==b.length||isNaN(b[4])||(h=parseInt(b[4],10));b=null;b=c?new A(a,e,f,g,new m({wkt:c})):
new A(a,e,f,g,new m({wkid:h}));t(d.spatialReference,b.spatialReference)?d.setExtent(b):u(b,d.spatialReference,function(k){d.setExtent(k[0])},function(){console.error("Project extent error.")})}}else console.error("Wrong extent parameters.")}function S(a,d){var b=null;if(a.markertemplate){b={title:"",content:"",isIncludeShareUrl:!1};try{var c=JSON.parse(decodeURIComponent(a.markertemplate));I.mixin(b,c)}catch(l){console.error("urlParams: \x26markertemplate JSON.parse error."+l.stack)}}c=a.marker.split(";");
1===c.length&&(c=a.marker.split(","));if(2<=c.length&&6>=c.length&&c[0].length&&!isNaN(c[0])&&c[1].length&&!isNaN(c[1])){var e=parseFloat(c[0]),f=parseFloat(c[1]),g=4326;3<=c.length&&c[2].length&&!isNaN(c[2])&&(g=parseInt(c[2],10));var h="";4<=c.length&&(h=c[3]);a=null;5<=c.length&&0===c[4].indexOf("http")&&(a=c[4]);var k=null;6===c.length&&(k=c[5]);var v=C.fromJson({type:"esriPMS",url:a,contentType:"image/png"}),w=null;k&&(w=C.fromJson({color:[0,0,0,255],type:"esriTS",verticalAlignment:"baseline",
horizontalAlignment:"left",angle:0,xoffset:0,yoffset:0,rotated:!1,kerning:!0,font:{size:12,style:"normal",weight:"bold",family:"Arial"},text:k}));T(v).then(function(){var l=new q(e,f,new m({wkid:g}));t(l.spatialReference,d.spatialReference)?F(l,v,w,h,b,d):u(l,d.spatialReference,function(U){F(U[0],v,w,h,b,d)},function(){console.error("Project center point error.")})})}}function F(a,d,b,c,e,f){c=new O("",c);if(e){var g=r.getXyContent(e);e.isIncludeShareUrl&&(e=r.getShareUrl(f,e,!0),e=r.getShareUrlContent(e),
g+=e);c.setContent(g)}g=new N({id:"marker-feature-action-layer"});f.addLayer(g);c=new D(a,d,null,c);g.add(c);b&&(b.xoffset=d.width/2,b.yoffset=d.height/2+d.yoffset,d=new D(new q(a.toJson()),b),g.add(d),c._textSymbol=d);f.centerAt(a)}function T(a){var d=new y;a.url?n.getImagesSize(a.url).then(function(b){a.width=b[0];a.height=b[1];d.resolve(a)},function(){a.url=require.toUrl("jimu")+"/images/EsriBluePinCircle26.png";a.width=26;a.height=26;a.setOffset(0,a.height/2);d.resolve(a)}):(a.url=require.toUrl("jimu")+
"/images/EsriBluePinCircle26.png",a.width=26,a.height=26,a.setOffset(0,a.height/2),d.resolve(a));return d}function V(a,d){var b=a.query.split(";");1===b.length&&(b=a.query.split(","));if(2!==b.length&&3!==b.length)console.error("query URL parameter is not correct.");else{var c=b[0];G("name",c,d).then(function(e){null===e?G("id",c,d).then(function(f){null===f?console.error("Invalid layer name or id."):H(d,f,b)}):H(d,e,b)})}}function H(a,d,b){var c=new P,e="";c.outSpatialReference=a.spatialReference;
if(2===b.length)c.where=b[1];else if(3===b.length&&(d.layerObject.url&&n.isHostedService(d.layerObject.url)&&n.containsNonLatinCharacter(b[2])&&(e="N"),x.forEach(d.layerObject.fields,function(f){if(f.alias.toLowerCase()===b[1].toLowerCase()||f.name.toLowerCase()===b[1].toLowerCase())-1<["esriFieldTypeSmallInteger","esriFieldTypeInteger","esriFieldTypeSingle","esriFieldTypeDouble","esriFieldTypeOID"].indexOf(f.type)?c.where=f.name+"\x3d"+b[2]:-1<["esriFieldTypeString"].indexOf(f.type)&&(c.where=b[1]+
"\x3d"+e+"'"+b[2].replace(/'/g,"''")+"'")},this),!c.where)){console.error("Invalid field name or type in query URL parameter.");return}c.maxAllowableOffset=1E-5;d.layerObject.queryFeatures(c).then(function(f){f=f.features;if(0===f.length)console.log("No result from query URL parameter.");else{if("esriGeometryPoint"===d.layerObject.geometryType&&1===f.length)a.setExtent(K.getExtentForScale(a,1E3)),a.centerAt(f[0].geometry);else{var g=n.graphicsExtent(f);a.setExtent(g)}W(a,d,f)}},function(f){console.error(f)})}
function W(a,d,b){function c(g){x.forEach(b,function(h){h.setInfoTemplate(g)})}function e(){a.infoWindow.setFeatures(b);a.infoWindow.show(X(b[0]))}if(a.getLayer(d.layerInfo.id))e();else{var f=d.layerInfo.getInfoTemplate();f?(c(f),e()):d.layerInfo.loadInfoTemplate().then(function(g){c(g);e()})}}function X(a){a=a.geometry;if("point"!==a.type)if("multipoint"===a.type)a=a.getPoint(0);else if("polyline"===a.type)a=a.getExtent().getCenter();else if("polygon"===a.type)a=a.getExtent().getCenter();else if("extent"===
a.type)a=a.getCenter();else return console.error("Can not get layer geometry type, unknow error."),null;return a}function G(a,d,b){var c=new y,e=[];E.getInstance(b,b.itemInfo).then(function(f){f.traversal(function(g){if(c.isResolved())return!0;("id"===a&&g.id.toLowerCase()===d.toLowerCase()||"name"===a&&g.title.toLowerCase()===d.toLowerCase())&&e.push(z({layerType:g.getLayerType(),layerObject:g.getLayerObject()}).then(function(h){"FeatureLayer"===h.layerType&&c.resolve({layerInfo:g,layerObject:h.layerObject})},
function(h){console.error("Find layer error from query URL parameter",h);c.resolve(null)}))});z(e).then(function(){c.isResolved()||c.resolve(null)})});return c}function u(a,d,b,c){var e=[102113,102100,3857];if(4326===a.spatialReference.wkid&&p(e,d.wkid)){a.ymin=Math.max(a.ymin,-89.99);a.ymax=Math.min(a.ymax,89.99);a=B.geographicToWebMercator(a);if((c=a.spatialReference._getInfo())&&a.xmin>a.xmax){e=c.valid[1]-a.xmin;var f=a.xmax-c.valid[0];e>f?a.xmax=c.valid[1]+f:a.xmin=c.valid[0]-e}a.spatialReference.wkid=
d.wkid;b([a],null)}else p(e,a.spatialReference.wkid)&&4326===d.wkid?(a=B.webMercatorToGeographic(a),(c=a.spatialReference._getInfo())&&a.xmin>a.xmax&&(e=c.valid[1]-a.xmin,f=a.xmax-c.valid[0],e>f?a.xmax=c.valid[1]+f:a.xmin=c.valid[0]-e),b([a],null)):(e=new L,e.geometries=[a],e.outSR=d,M.defaults.geometryService.project(e,function(g){!(g&&0<g.length&&g[0]&&"extent"===g[0].type)||isNaN(g[0].xmin)||isNaN(g[0].ymin)||isNaN(g[0].xmax)||isNaN(g[0].ymax)?g&&0<g.length&&g[0]&&"point"===g[0].type&&!isNaN(g[0].x)&&
!isNaN(g[0].y)&&b(g,null):b(g,null)},c))}function t(a,d){var b=[102113,102100,3857];return a&&d&&a.wkt===d.wkt&&(a.wkid===d.wkid||a.latestWkid&&a.latestWkid===d.wkid||d.latestWkid&&a.wkid===d.latestWkid||a.latestWkid&&a.latestWkid===d.latestWkid)||a&&d&&a.wkid&&d.wkid&&p(b,a.wkid)&&p(b,d.wkid)?!0:!1}function p(a,d){for(var b=a.length;b--;)if(a[b]===d)return!0;return!1}function Y(a,d,b,c){var e=[];a&&a[d]&&a[d].split&&(e=a[d].split(";"));if(e&&0<=e.length){var f={};f[b]=e;E.getInstance(c,c.itemInfo).then(function(g){g.setSimplificationState(f)})}}
return{postProcessUrlParams:function(a,d){a:for(var b=["showLayers","hideLayers","showLayersEncoded","hideLayersEncoded"],c=0,e=b.length;c<e;c++){var f=b[c],g=f.toLowerCase(),h;for(h in a){var k=h.toLowerCase();if(g===k){Y(a,h,f,d);break a}}}if("extent"in a)return R(a,d);if("center"in a)return Q(a,d);if("marker"in a)return S(a,d);if("find"in a)J.publish("publishData","framework","framework",{searchString:a.find},!0);else if("query"in a)return V(a,d)}}});