text: /*! ramp-theme-usability 21-11-2014 12:38:14 : v. 4.0.0 
   * 
   * RAMP GIS viewer - Dragonfly; Sample of an implementation of RAMP with Usability Theme 
   **/
  define(["dojo/_base/declare","dojo/_base/array","dojo/dom","dojo/dom-construct","dojo/number","dojo/query","dojo/topic","dojo/on","esri/map","esri/layers/FeatureLayer","esri/layers/GraphicsLayer","esri/layers/ArcGISTiledMapServiceLayer","esri/layers/ArcGISDynamicMapServiceLayer","esri/SpatialReference","esri/dijit/Scalebar","esri/geometry/Extent","esri/layers/WMSLayer","ramp/globalStorage","ramp/ramp","ramp/featureClickHandler","ramp/mapClickHandler","ramp/navigation","ramp/eventManager","utils/util","utils/array","utils/dictionary"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z){"use strict";function A(){$("#map-load-indicator").removeClass("hidden")}function B(){$("#map-load-indicator").addClass("hidden")}function C(a){if(a.levelChange){var b=e.format(a.lod.scale),c="1 : "+b;d.empty("scaleLabel"),$("#scaleLabel").text(c)}}function D(a){var b,c,h=a.map,i=d.create("div",{id:"scaleDiv","class":"esriScalebarLabel"});$(i).html("<span>"+i18n.t("map.scale")+"</span><br><span id='scaleLabel'><span/>"),b=e.format(h.getScale()),c="1 : "+b,d.place(i,f(".esriScalebarRuler")[0],"before"),d.empty("scaleLabel"),$("#scaleLabel").text(c),g.subscribe(w.BasemapSelector.BASEMAP_CHANGED,function(a){$(".esriScalebar > div").removeClass().addClass(a.cssStyle)})}function E(a){function b(b){a.on(b,function(a){g.publish(c+"/"+b,a)})}var c="map";b("update-end"),b("extent-change"),b("zoom-start"),b("zoom-end"),b("pan-start"),b("pan-end")}function F(a){g.subscribe(w.Map.CENTER_AT,function(b){a.centerAt(b.point)}),g.subscribe(w.Map.CENTER_AND_ZOOM,function(b){var c=new esri.geometry.Point(b.graphic.geometry.x,b.graphic.geometry.y,a.spatialReference),d=a.centerAndZoom(c,b.level);b.callback&&d.then(b.callback)}),g.subscribe(w.Map.SET_EXTENT,function(b){b.extent.spatialReference=a.spatialReference;var c=a.setExtent(b.extent);b.callback&&c.then(b.callback)}),g.subscribe(w.Navigation.PAN,function(b){a[b.direction]()}),g.subscribe(w.Navigation.ZOOM_STEP,function(b){a.setLevel(a.getLevel()+b.level)}),g.subscribe(w.Navigation.ZOOM,function(b){a.setLevel(b.level)}),g.subscribe(w.Navigation.FULL_EXTENT,function(){a.setExtent(Q)}),g.subscribe(w.GUI.LAYOUT_CHANGE,function(){a.resize(!0)}),g.subscribe(w.GUI.SUBPANEL_CHANGE,function(a){!a.visible&&a.isComplete&&"rampPopup"===a.origin&&g.publish(w.FeatureHighlighter.HIGHLIGHT_HIDE,{})}),g.subscribe(w.FilterManager.LAYER_VISIBILITY_TOGGLED,function(c){var d=c.state,e=c.id,f=a.getLayer(e);f.setVisibility(d);try{b.forEach(r.LayerMap[e],function(b){var c=a.getLayer(b);c.setVisibility(d)})}catch(g){}}),g.subscribe(w.FilterManager.LAYER_TRANSPARENCY_CHANGED,function(c){var d=a.getLayer(c.layerId);d.setOpacity(c.value);try{b.forEach(r.LayerMap[c.layerId],function(b){var d=a.getLayer(b);d.setOpacity(c.value)})}catch(e){}}),g.subscribe(w.FilterManager.BOX_VISIBILITY_TOGGLED,function(a){J(a.id,a.state)}),g.subscribe(w.FilterManager.SELECTION_CHANGED,function(c){var d,e=c.index;a.layerIds.contains(c.id)?(d=b.map(a.graphicsLayerIds,function(b){return"Feature Layer"===a.getLayer(b).type?1:0}).sum(),e+=1-d):(O||(O=y.indexOf(a.graphicsLayerIds,function(b){var c=a.getLayer(b);return c.type&&"Feature Layer"===c.type})),e+=O),a.reorderLayer(a.getLayer(c.id),e),g.publish(w.Map.REORDER_END)}),g.subscribe(w.Map.ADD_LAYER,function(){var a=c.byId("addLayer-select-type").value,b=c.byId("addLayer-URL-input").value,d=c.byId("addLayer-Opacity").value;I(a,b,d)}),g.subscribe(w.Map.ADD_LAYER_READY,function(b){a.addLayer(b)})}function G(a){var c,d=b.filter(M,function(a){return a.ramp.type!==r.layerType.Static});b.forEach(d,function(a){a.on("click",function(a){a.stopImmediatePropagation(),t.onFeatureSelect(a)}),a.on("mouse-over",function(a){t.onFeatureMouseOver(a)}),a.on("mouse-out",function(a){t.onFeatureMouseOut(a)})}),a.on("load",D),a.on("extent-change",function(b){C(b),h.once(a,"update-end",function(){g.publish(w.Datagrid.APPLY_EXTENT_FILTER)})}),a.on("click",function(a){t.onFeatureDeselect(a),g.publish(w.Map.CLICK,a)}),a.on("update-end",function(){}),a.on("update-start",A),a.on("update-end",B),c=a.on("update-end",function(){var d=b.every(a.graphicsLayerIds.concat(a.layerIds),function(b){var c=a.getLayer(b);return c.loaded});d&&(c.remove(),g.publish(w.Map.ALL_LAYERS_LOADED))})}function H(a,b){return new p(a.xmin,a.ymin,a.xmax,a.ymax,b)}function I(a,b,c){c/=100;var d;switch(a){case"feature":d=new j(b,{opacity:c,mode:j.MODE_SNAPSHOT});break;case"tile":d=new l(b,{opacity:c});break;case"dynamic":d=new m(b,{opacity:c})}g.publish(w.Map.ADD_LAYER_READY,d),g.publish(w.GUI.ADD_LAYER_PANEL_CHANGE,{visible:!1})}function J(a,b){var c=N[a];c.setVisibility(b)}function K(a){return a.default||1}function L(a){var b,c=a.layerType||"feature";switch(c){case"feature":b=new j(a.url,{opacity:K(a.settings.opacity),mode:j.MODE_SNAPSHOT,id:a.id}),b.ramp={type:r.layerType.Static};break;case"tile":b=new l(a.url,{opacity:K(a.settings.opacity),id:a.id});break;case"dynamic":b=new m(a.url,{opacity:K(a.settings.opacity),id:a.id})}return b}var M,N,O,P,Q,R,S,T=[];return{getMaxExtent:function(){return R},getMap:function(){return x.isUndefined(P),P},getVisibleFeatureLayers:function(){return b.filter(P.getLayersVisibleAtScale(),function(a){return a.type&&"Feature Layer"===a.type&&a.visible})},getFeatureLayer:function(a){return y.find(M,function(b){return b.url===a})},checkBoundary:function(a,b){var c,d,e=a,f=e.width(),g=e.height(),h=e.centerX(),i=e.centerY();d=e.clone();var j=b.height();g>j&&(g=j),i>b.ymax?(d.ymax=b.ymax,d.ymin=b.ymax-g,c=!0):i<b.ymin&&(d.ymin=b.ymin,d.ymax=b.ymin+g,c=!0);var k=b.width();return f>k&&(f=k),h>b.xmax?(d.xmax=b.xmax,d.xmin=b.xmax-f,c=!0):h<b.xmin&&(d.xmin=b.xmin,d.xmax=b.xmin+f,c=!0),c?d:void 0},init:function(){var a=RAMP.config,c=new esri.SpatialReference(a.spatialReference),d=y.find(a.basemaps,function(a){return a.showOnInit}).url,e=new l(d,{id:"basemapLayer"});R=H(a.extents.maximumExtent,c),S=H(a.extents.defaultExtent,c),Q=H(a.extents.fullExtent,c),T=b.map(a.layers.wms,function(a){var b=new q(a.url,{id:a.id,format:a.format,opacity:K(a.settings.opacity),visibleLayers:[a.layerName]});return b.ramp={type:r.layerType.WMS},void 0!==a.featureInfo&&u.registerWMSClick({wmsLayer:b,layerConfig:a}),b.setVisibility(a.settings.visible),b}),M=b.map(a.layers.feature,function(a){var b;return a.isStatic?b=L(a):(b=new j(a.url,{id:a.id,mode:j.MODE_SNAPSHOT,outFields:[a.layerAttributes],visible:a.settings.visible,opacity:K(a.settings.opacity)}),b.ramp={type:r.layerType.Feature},a.settings.boundingBoxVisible===!0&&h.once(b,"update-end",function(){J(a.id,!0)})),a.settings.visible===!1&&h.once(b,"update-end",function(){b.setVisibility(!1)}),b});var f=b.map(a.layers.feature,function(a){var b=new k({id:String.format("boundingBoxLayer_{0}",a.id),visible:a.settings.boundingBoxVisible});b.ramp={type:r.layerType.BoundingBox};var d;if("undefined"!=typeof a.layerExtent){d=H(a.layerExtent,c);var e=new esri.Graphic({geometry:d,symbol:{color:[255,0,0,64],outline:{color:[240,128,128,255],width:1,type:"esriSLS",style:"esriSLSSolid"},type:"esriSFS",style:"esriSFSSolid"}});b.add(e)}return b});N=z.zip(b.map(a.layers.feature,function(a){return a.id}),f),P=new i(a.divNames.map,{extent:S,logo:!1,minZoom:a.levelOfDetails.minLevel,maxZoom:a.levelOfDetails.maxLevel,slider:!1}),r.map=P,u.init(P);var g=[],m=[],n=[];b.forEach(a.layers.feature,function(a){m=[],b.forEach(a.staticLayers,function(a,b){var c=P.generateStaticLayer(a);g.push(c),m[b]=a.id}),n[a.id]=m}),r.LayerMap=n,e.ramp={type:r.layerType.Basemap},P.addLayers([e].concat(T,g,f,M));var p=new o({map:P,attachTo:"bottom-left",scalebarUnit:"metric"});p.show(),E(P),F(P),G(P,M)}}});