// 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/_base/html dojo/on dojo/Deferred dijit/_WidgetBase dojo/Evented esri/geometry/Extent jimu/portalUrlUtils esri/dijit/Search jimu/dijit/LoadingShelter jimu/utils".split(" "),function(k,e,g,h,l,m,n,p,q,r,t,f){return k([m,n],{baseClass:"jimu-extent-chooser",declaredClass:"jimu.dijit.ExtentChooser",portalUrl:null,itemId:null,initExtent:null,bingMapsKey:"",geometryServiceURL:null,shelter:null,postCreate:function(){this.inherited(arguments);!this.geometryServiceURL&&
esriConfig.defaults.geometryService&&(this.geometryServiceURL=esriConfig.defaults.geometryService.url);this.geometryServiceURL||(this.geometryServiceURL=f.getServices().geometryService);this.shelter=new t({hidden:!0});this.shelter.placeAt(this.domNode);this.shelter.startup();this.shelter.show();var d=g.create("div",{style:{width:"100%",height:"100%"}},this.domNode);this.search=g.create("div",{style:{position:"absolute",right:0,top:0}},d);if(this.portalUrl&&this.itemId){this.portalUrl=q.getStandardPortalUrl(this.portalUrl);
var a={geometryServiceURL:this.geometryServiceURL,bingMapsKey:this.bingMapsKey};this.initExtent&&("esri.geometry.Extent"!==this.initExtent.declaredClass&&(this.initExtent=new p(this.initExtent)),a.mapOptions={extent:this.initExtent});this.lods&&("object"===typeof a.mapOptions?a.mapOptions.lods=this.lods:a.mapOptions={lods:this.lods});f.createWebMap(this.portalUrl,this.itemId,d,a).then(e.hitch(this,function(c){this.map=c.map;this.map.webMapResponse=c;this.own(h(this.map,"extent-change",e.hitch(this,
function(b){this.onExtentChange(b.extent)})));c=new r({map:this.map,enableLabel:!1},this.search);c.startup();this.own(h(c,"search-results",e.hitch(this,function(b){if(b&&b.results&&b.results[0]&&b.results[0][0]&&b.results[0][0].extent)this.onExtentChange(b.results[0][0].extent)})));if(this.initExtent)this.onExtentChange(this.initExtent);else this.onExtentChange(this.map.extent);this.shelter.hide();this.emit("map-load",this.map)}),e.hitch(this,function(c){console.error(c)}))}},getExtent:function(){return this.map&&
this.map.extent},setExtent:function(d){if(this.map)return this.map.setExtent(d);var a=new l;setTimeout(e.hitch(this,function(){a.reject("map is null.")}),0);return a},restoreToDefaultWebMapExtent:function(){f.restoreToDefaultWebMapExtent(this.map,this.map.webMapResponse,this.geometryServiceURL)},onExtentChange:function(d){this.emit("extent-change",d)}})});