// 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
require({cache:{"url:widgets/AddData/search/templates/AddFromFilePane.html":'\x3cdiv class\x3d"secondary-pane add-file-pane"\x3e\r\n\r\n  \x3cdiv class\x3d"generalize-options"\x3e\r\n    \x3cdiv data-dojo-type\x3d"jimu/dijit/CheckBox"\r\n      data-dojo-attach-point\x3d"generalizeCheckBox"\r\n      data-dojo-props\x3d"checked:true"\x3e\r\n    \x3c/div\x3e\r\n  \x3c/div\x3e\r\n\r\n  \x3cdiv class\x3d"browse-or-drop"\x3e\r\n    \x3cdiv class\x3d"drop-container" data-dojo-attach-point\x3d"dropContainer"\x3e\r\n      \x3cdiv class\x3d"drop-area" data-dojo-attach-point\x3d"dropArea"\x3e\r\n        \x3cdiv class\x3d"supported-file-types" data-dojo-attach-point\x3d"supportedFileTypes"\x3e\x3c/div\x3e\r\n        \x3cdiv class\x3d"or"\x3e${i18n.addFromFile.dropOrBrowse}\x3c/div\x3e\r\n        \x3cform class\x3d"file-form" enctype\x3d"multipart/form-data" method\x3d"post"\r\n          data-dojo-attach-point\x3d"fileForm"\x3e\r\n          \x3clabel for\x3d"${id}_file" class\x3d"jimu-btn"\r\n            data-dojo-attach-point\x3d"uploadLabel"\x3e${i18n.addFromFile.browse}\x3c/label\x3e\r\n          \x3cinput id\x3d"${id}_file" name\x3d"file" type\x3d"file" style\x3d"display:none"\r\n            data-dojo-attach-point\x3d"fileNode" /\x3e\r\n        \x3c/form\x3e\r\n        \x3ca href\x3d"#" class\x3d"drop-area-hint" data-dojo-attach-point\x3d"hintButton"\x3e\r\n          \x3ci class\x3d"esri-icon-question"\x3e\x3c/i\x3e\r\n        \x3c/a\x3e\r\n        \x3cspan class\x3d"upload-arrow"\x3e\x3c/span\x3e\r\n      \x3c/div\x3e\r\n    \x3c/div\x3e\r\n  \x3c/div\x3e\r\n\r\n\x3c/div\x3e\r\n'}});
define("dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/_base/json dojo/on dojo/Deferred dojo/dom-class dijit/Viewport dojo/sniff dijit/_WidgetBase dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dojo/text!./templates/AddFromFilePane.html dojo/i18n!../nls/strings ./LayerLoader ./util dojo/_base/kernel esri/request esri/layers/FeatureLayer esri/layers/KMLLayer esri/geometry/scaleUtils jimu/dijit/Message jimu/dijit/CheckBox".split(" "),function(D,v,w,E,k,F,p,G,H,I,J,K,L,f,B,r,M,A,N,O,P,
t){return D([I,J,K],{i18n:f,templateString:L,wabWidget:null,maxRecordCount:1E3,maxRecordThreshold:1E5,SHAPETYPE_ICONS:[{type:"shapefile",url:"images/filetypes/zip.svg"},{type:"csv",url:"images/filetypes/csv.svg"},{type:"kml",url:"images/filetypes/kml.svg"},{type:"gpx",url:"images/filetypes/gpx.svg"},{type:"geojson",url:"images/filetypes/geojson.svg"}],postCreate:function(){this.inherited(arguments);this.generalizeCheckBox.setLabel(f.addFromFile.generalizeOn);this.own(G.on("resize",this.resize()))},
destroy:function(){this.inherited(arguments)},startup:function(){if(!this._started){this.wabWidget.isPortal&&(this.SHAPETYPE_ICONS=[{type:"shapefile",url:"images/filetypes/zip.svg"},{type:"csv",url:"images/filetypes/csv.svg"},{type:"kml",url:"images/filetypes/kml.svg"},{type:"geojson",url:"images/filetypes/geojson.svg"}]);this.inherited(arguments);var a=this,c=this.dropArea,g=this.wabWidget.config;if(g.addFromFile)try{var d=Number(g.addFromFile.maxRecordCount);"number"!==typeof d||isNaN(d)||(d=Math.floor(d),
1<=d&&d<=this.maxRecordThreshold&&(this.maxRecordCount=d))}catch(b){console.warn("Error setting AddFromFile.maxRecordCount:"),console.warn(b)}if(f.addFromFile.types)try{for(var e in f.addFromFile.types)this._createFileTypeImage(e)}catch(b){console.warn("Error reading support file types:"),console.warn(b)}this.own(k(this.fileNode,"change",function(){if(!a._getBusy()){a._setBusy(!0);var b=a._getFileInfo();b.ok&&a._execute(b);a.fileNode.value=null}}));this.own(k(this.uploadLabel,"click",function(b){a._getBusy()&&
(b.preventDefault(),b.stopPropagation())}));this.own(k(c,"dragenter",function(b){b.preventDefault();a._getBusy()||(p.add(c,"hit"),a._setStatus(""))}));this.own(k(c,"dragleave",function(b){b.preventDefault();p.remove(c,"hit")}));this.own(k(c,"dragover",function(b){b.preventDefault()}));this.own(k(c,"drop",function(b){b.preventDefault();b.stopPropagation();a._getBusy()||(a._setBusy(!0),b=a._getFileInfo(b),b.ok&&a._execute(b))}));d=this.wabWidget.domNode;this.own(k(d,"dragenter",function(b){b.preventDefault()}));
this.own(k(d,"dragleave",function(b){b.preventDefault()}));this.own(k(d,"dragover",function(b){b.preventDefault()}));this.own(k(d,"drop",function(b){b.preventDefault()}));this.own(k(this.hintButton,"click",v.hitch(this,function(b){b.preventDefault();b='\x3cdiv class\x3d"intro"\x3e\x3clabel\x3e'+f.addFromFile.intro+"\x3c/label\x3e\x3cul\x3e\x3cli\x3e"+f.addFromFile.types.Shapefile+"\x3c/li\x3e\x3cli\x3e"+f.addFromFile.types.CSV+"\x3c/li\x3e\x3cli\x3e"+f.addFromFile.types.KML+"\x3c/li\x3e\x3cli\x3e"+
f.addFromFile.types.GPX+"\x3c/li\x3e\x3cli\x3e"+f.addFromFile.types.GeoJSON+'\x3c/li\x3e\x3cli\x3e\x3cspan class\x3d"note"\x3e'+f.addFromFile.maxFeaturesAllowedPattern.replace("{count}",this.maxRecordCount)+"\x3c/span\x3e\x3c/li\x3e\x3c/ul\x3e\x3c/div\x3e";this.wabWidget.isPortal&&(b='\x3cdiv class\x3d"intro"\x3e\x3clabel\x3e'+f.addFromFile.intro+"\x3c/label\x3e\x3cul\x3e\x3cli\x3e"+f.addFromFile.types.Shapefile+"\x3c/li\x3e\x3cli\x3e"+f.addFromFile.types.CSV+"\x3c/li\x3e\x3cli\x3e"+f.addFromFile.types.KML+
"\x3c/li\x3e\x3cli\x3e"+f.addFromFile.types.GeoJSON+'\x3c/li\x3e\x3cli\x3e\x3cspan class\x3d"note"\x3e'+f.addFromFile.maxFeaturesAllowedPattern.replace("{count}",this.maxRecordCount)+"\x3c/span\x3e\x3c/li\x3e\x3c/ul\x3e\x3c/div\x3e");new t({message:b})})))}},_addFeatures:function(a,c){var g,d=[],e=a.map,b=0,l=new B;c.layers&&(b=c.layers.length);w.forEach(c.layers,function(h){h=new N(h,{id:l._generateLayerId(),outFields:["*"]});h.xtnAddData=!0;h.graphics&&(a.numFeatures+=h.graphics.length);0===b?h.name=
a.baseFileName:"string"!==typeof h.name||0===h.name.length?h.name=a.baseFileName:0!==h.name.indexOf(a.baseFileName)&&(h.name=f.addFromFile.layerNamePattern.replace("{filename}",a.baseFileName).replace("{name}",h.name));l._setFeatureLayerInfoTemplate(h,null,null);if(h.fullExtent){var n=h.fullExtent.getCenter();n.x&&n.y&&(g=g?g.union(h.fullExtent):h.fullExtent)}d.push(h)});0<d.length&&(e.addLayers(d),g&&e.setExtent(g.expand(1.25),!0))},_analyze:function(a,c){if("csv"!==a.fileType.toLowerCase())return c=
new F,c.resolve(null),c;var g=null;this.wabWidget.batchGeocoderServers&&0<this.wabWidget.batchGeocoderServers.length&&(g=this.wabWidget.batchGeocoderServers[0]);var d={enableGlobalGeocoding:!0,sourceLocale:M.locale};g&&(d.geocodeServiceUrl=g.url,g.isWorldGeocodeServer&&(d.sourceCountry="world",d.sourceCountryHint=""));g=a.sharingUrl+"/content/features/analyze";d={f:"json",filetype:a.fileType.toLowerCase(),analyzeParameters:window.JSON.stringify(d)};c=A({url:g,content:d,form:c,handleAs:"json"});c.then(function(e){e&&
e.publishParameters&&(a.publishParameters=e.publishParameters)});return c},_createFileTypeImage:function(a){var c=window.isRTL;w.some(this.SHAPETYPE_ICONS,v.hitch(this,function(g,d){if(a.toLowerCase()===g.type.toLowerCase()){var e=document.createElement("IMG");e.src=this.wabWidget.folderUrl+g.url;e.alt=a;0===d?e.className+=" "+(c?"last":"first")+"-type-icon":1===d?e.className+=" second-"+(c?"last":"first")+"-type-icon":d===this.SHAPETYPE_ICONS.length-2?e.className+=" second-"+(c?"first":"last")+"-type-icon":
d===this.SHAPETYPE_ICONS.length-1&&(e.className+=" "+(c?"first":"last")+"-type-icon");this.supportedFileTypes.appendChild(e)}}))},_execute:function(a){var c={map:this.wabWidget.map,sharingUrl:this.wabWidget.getSharingUrl(),baseFileName:a.baseFileName,fileName:a.fileName,fileType:a.fileType,generalize:!!this.generalizeCheckBox.getValue(),publishParameters:{},numFeatures:0};this._setBusy(!0);this._setStatus(f.addFromFile.addingPattern.replace("{filename}",a.fileName));if("kml"===a.fileType.toLowerCase())return this._executeKml(a);
var g=a.fileName,d=this,e=new FormData;e.append("file",a.file);d._analyze(c,e).then(function(b){b&&b.publishParameters&&b.publishParameters.locationType&&"unknown"===b.publishParameters.locationType&&new t({titleLabel:f._widgetLabel,message:f.addFromFile.featureLocationsCouldNotBeFound});return d._generateFeatures(c,e)}).then(function(b){d._addFeatures(c,b.featureCollection);d._setBusy(!1);d._setStatus(f.addFromFile.featureCountPattern.replace("{filename}",g).replace("{count}",c.numFeatures))}).otherwise(function(b){d._setBusy(!1);
d._setStatus(f.addFromFile.addFailedPattern.replace("{filename}",g));console.warn("Error generating features.");console.warn(b);b&&"string"===typeof b.message&&0<b.message.length&&new t({titleLabel:f._widgetLabel,message:f.addFromFile.generalIssue+"\x3cbr\x3e\x3cbr\x3e"+b.message})})},_executeKml:function(a){var c=this,g=new FileReader,d=this.wabWidget.map,e=function(b,l){c._setBusy(!1);c._setStatus(f.addFromFile.addFailedPattern.replace("{filename}",a.fileName));console.warn(b);console.error(l);
l&&"string"===typeof l.message&&0<l.message.length&&new t({titleLabel:f._widgetLabel,message:f.addFromFile.generalIssue+"\x3cbr\x3e\x3cbr\x3e"+l.message})};g.onerror=function(b){e("FileReader::onerror",b)};g.onload=function(b){if(g.error)e("FileReader::error",g.error);else{var l=b.target.result,h=new B;b=h._generateLayerId();var n=new O("",{id:b,name:a.fileName,linkInfo:{visibility:!1}});n.visible=!0;delete n.linkInfo;n._parseKml=function(){var u=this;this._fireUpdateStart();this._io=A({url:this.serviceUrl,
content:{kmlString:encodeURIComponent(l),model:"simple",folders:"",refresh:this.loaded?!0:void 0,outSR:E.toJson(this._outSR.toJson())},callbackParamName:"callback",load:function(m){u._io=null;u._initLayer(m);h._waitForLayer(n).then(function(q){var C=0;q.name=a.fileName;q.xtnAddData=!0;w.forEach(q.getLayers(),function(x){x&&x.graphics&&0<x.graphics.length&&(C+=x.graphics.length)});var y=d.spatialReference,z=q._outSR;y&&z&&(y.equals(z)||y.isWebMercator()&&4326===z.wkid||z.isWebMercator()&&4326===y.wkid)?
d.addLayer(q):new t({titleLabel:f._widgetLabel,message:f.addFromFile.kmlProjectionMismatch});c._setBusy(!1);c._setStatus(f.addFromFile.featureCountPattern.replace("{filename}",a.fileName).replace("{count}",C))}).otherwise(function(q){e("kml-_waitForLayer.error",q)})},error:function(m){u._io=null;m=v.mixin(Error(),m);m.message="Unable to load KML: "+(m.message||"");u._fireUpdateEnd(m);u._errorHandler(m);e("Unable to load KML",m)}},{usePost:!0})};n._parseKml()}};try{g.readAsText(a.file)}catch(b){e("FileReader::readAsText",
b)}},_generateFeatures:function(a,c){var g=a.sharingUrl+"/content/features/generate";a.publishParameters=a.publishParameters||{};var d=v.mixin(a.publishParameters,{name:a.baseFileName,targetSR:a.map.spatialReference,maxRecordCount:this.maxRecordCount,enforceInputFileSizeLimit:!0,enforceOutputJsonSizeLimit:!0});if(a.generalize){var e=P.getExtentForScale(a.map,4E4).getWidth()/a.map.width;d.generalize=!0;d.maxAllowableOffset=e;e/=10;for(var b=0;1>e;)e*=10,b++;d.reducePrecision=!0;d.numberOfDigitsAfterDecimal=
b}a={f:"json",filetype:a.fileType.toLowerCase(),publishParameters:window.JSON.stringify(d)};return A({url:g,content:a,form:c,handleAs:"json"})},_getBaseFileName:function(a){H("ie")&&(a=a.split("\\"),a=a[a.length-1]);a=a.split(".");return a=a[0].replace("c:\\fakepath\\","")},_getBusy:function(){return p.contains(this.uploadLabel,"disabled")},_getFileInfo:function(a){var c={ok:!1,file:null,fileName:null,fileType:null};if((a=a?a.dataTransfer.files:this.fileNode.files)&&1===a.length)if(c.file=a=a[0],
c.fileName=a.name,r.endsWith(a.name,".zip"))c.ok=!0,c.fileType="Shapefile";else if(r.endsWith(a.name,".csv"))c.ok=!0,c.fileType="CSV";else if(r.endsWith(a.name,".kml"))c.ok=!0,c.fileType="KML";else if(r.endsWith(a.name,".gpx"))c.ok=!0,c.fileType="GPX";else if(r.endsWith(a.name,".geojson")||r.endsWith(a.name,".geo.json"))c.ok=!0,c.fileType="GeoJSON";c.ok&&(c.ok=w.some(this.SHAPETYPE_ICONS,function(d){return d.type.toLowerCase()===c.fileType.toLowerCase()}));if(c.ok)c.baseFileName=this._getBaseFileName(c.fileName);
else{a=f.addFromFile.invalidType;"string"===typeof c.fileName&&0<c.fileName.length&&(a=f.addFromFile.invalidTypePattern.replace("{filename}",c.fileName));this._setBusy(!1);this._setStatus(a);var g=document.createElement("div");g.appendChild(document.createTextNode(a));new t({titleLabel:f._widgetLabel,message:g})}return c},resize:function(){},_setBusy:function(a){a?(p.add(this.uploadLabel,"disabled"),p.add(this.dropArea,["hit","disabled"])):(p.remove(this.uploadLabel,"disabled"),p.remove(this.dropArea,
["hit","disabled"]))},_setStatus:function(a){this.wabWidget&&this.wabWidget._setStatus(a)}})});