<?xml version="1.0" encoding="utf-8"?>
<!--
////////////////////////////////////////////////////////////////////////////////
//
// Copyright © 2008 - 2009 ESRI
//
// All rights reserved under the copyright laws of the United States.
// You may freely redistribute and use this software, with or
// without modification, provided you include the original copyright
// and use restrictions. See use restrictions in the file:
// <install location>/FlexViewer/License.txt
//
////////////////////////////////////////////////////////////////////////////////
-->
<BaseWidget xmlns ="com.esri.solutions.flexviewer.*"
xmlns:mx ="http://www.adobe.com/2006/mxml"
xmlns:toccomp ="com.esri.solutions.flexviewer.components.toc.*"
xmlns:widgets ="com.esri.solutions.flexviewer.widgets.*"
x ="600"
y ="300"
widgetConfigLoaded ="init()">
<mx:Script>
<![CDATA[
import com.esri.ags.Map;
import com.esri.ags.layers.GraphicsLayer;
import com.esri.ags.layers.Layer;
import com.esri.solutions.flexviewer.AppEvent;
import com.esri.solutions.flexviewer.ConfigData;
import com.esri.solutions.flexviewer.SiteContainer;
import com.esri.solutions.flexviewer.components.toc.tocClasses.TocItem;
import com.esri.solutions.flexviewer.utils.WidgetEffects;
import mx.collections.*;
import mx.controls.Alert;
import mx.controls.RadioButton;
import mx.events.ItemClickEvent;
import mx.events.ListEvent;
import mx.events.StateChangeEvent;
//labels
[Bindable]
private var visibilityLabel:String;
[Bindable]
private var transparencyLabel:String;
private var lArr:Array;
private const ICON_URL:String = "com/esri/solutions/flexviewer/assets/images/icons/";
private function init():void
{
if (configXML)
{
//labels
visibilityLabel = configXML.labels.visibilitylabel || "Layer Visibility";
transparencyLabel = configXML.labels.transparencylabel || "Layer Transparency";
}
lArr = getLayers();
aLayerSlider.layerToNone = "Select an image, then this slider will adjust transparency";
wTemplate.addTitlebarButton(ICON_URL + "i_folder.png", "Radio Buttons", showStateToggleLayers);
var rBFormat:TextFormat = new TextFormat;
rBFormat.font = "Arial";
rBFormat.size = "11";
rBFormat.color = "#FFFFFF";
rBFormat.bold = true;
for(var i:uint = 0; i < lArr.length; i++)
{
var radioBtn:RadioButton = new RadioButton;
radioBtn.groupName = "radioBtnGroup";
radioBtn.label = lArr.name;
radioBtn.setStyle("textFormat","rBFormat");
radioBtn.value = i;
radioBtn.alpha = 1
radioBtn.height = 14
vBoxRadio.addChild(radioBtn);
}
//add a button for "none", ie no layer to be displayed
var radioBtn:RadioButton = new RadioButton;
radioBtn.groupName = "radioBtnGroup";
radioBtn.value = lArr.length;
radioBtn.label = "None";
vBoxRadio.addChild(radioBtn);
radioBtn.setStyle("textFormat","rBFormat");
//set the current selection to the "none" button
radioBtnGroup.selectedValue = lArr.length;
}
private function getLayers():Array
{
var basemapCount:Number = configData.configBasemaps.length;
var layerArray:Array = [];
for (var i:Number = map.layerIds.length -1; i >= basemapCount; i--)
{
var layer:Layer = map.getLayer(map.layerIds);
//change this to exclude any layers from the live map widgets.
if (!(layer is GraphicsLayer) && (layer.name!= "Supervisor Districts") && (layer.name!= "Schools & Fire Stations"))
layerArray.push(layer);
}
return layerArray;
}
private function showStateToggleLayers(event:MouseEvent):void
{
WidgetEffects.flipWidget(this, viewStack, "selectedIndex", 0, 400);
}
private function radioClickHandler(event:ItemClickEvent):void
{
//if no layer is selected, then set the slider text appropriately.
if (event.index == lArr.length){
aLayerSlider.layerToNone = "Select an image, then this slider will adjust transparency";
}
// update the visible layers to only show the layer selected
for(var i:uint = 0; i < lArr.length; i++)
{
if (lArr.name == event.label){
map.getLayer(lArr.name).visible = true;
var lay:Layer = map.getLayer(lArr.name);
aLayerSlider.layer = lay;
}else{
map.getLayer(lArr.name).visible = false;
}
}
}
]]>
</mx:Script>
<WidgetTemplate id="wTemplate">
<mx:ViewStack id="viewStack" width="100%" height="200%" creationPolicy="all">
<mx:VBox id="vBoxRadio" width="100%" height="200%" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Label text="Choose an Image" styleName="WidgetText" width="100%"/>
<mx:RadioButtonGroup id="radioBtnGroup" itemClick="radioClickHandler(event)"/>
<widgets:LayerAlpha id="aLayerSlider"/>
</mx:VBox>
</mx:ViewStack>
</WidgetTemplate>
</BaseWidget>
<?xml version="1.0" encoding="utf-8"?>
<!--
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2010 ESRI
//
// All rights reserved under the copyright laws of the United States.
// You may freely redistribute and use this software, with or
// without modification, provided you include the original copyright
// and use restrictions. See use restrictions in the file:
// <install location>/License.txt
//
////////////////////////////////////////////////////////////////////////////////
-->
<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:viewer="com.esri.viewer.*"
xmlns:toc="com.esri.viewer.components.toc.*"
x="600" y="400"
widgetConfigLoaded="init()">
<fx:Script>
<![CDATA[
import com.esri.ags.layers.Layer;
import mx.collections.ArrayCollection;
import mx.events.StateChangeEvent;
import spark.components.RadioButton;
[Bindable]
private var title:String;
private var layers:ArrayCollection;
private function init():void
{
toc.map = map;
toc.isMapServiceOnly = false; //gotta get this from the config file
toc.excludeLayers = getExcludeLayers();
toc.excludeGraphicsLayers = true;
if (configXML)
{
title = configXML.labels.title || "Map Layer List";
}
var rBFormat:TextFormat = new TextFormat;
rBFormat.font = "Arial";
rBFormat.size = "11";
rBFormat.color = "#000000";
rBFormat.bold = true;
for (var i:uint = 0; i < layers.length; i++)
{
radioBtn.groupName = "radioBtnGroup";
radioBtn.label = layers.name;
radioBtn.setStyle("textFormat","rBFormat");
radioBtn.value = i;
radioBtn.alpha = 1
radioBtn.height = 14
}
var radioBtn:RadioButton = new RadioButton;
radioBtn.groupName = "radioBtnGroup";
radioBtn.value = layers.length;
radioBtn.label = "None";
radioBtn.setStyle("textFormat","rBFormat");
//set the current selection to the "none" button
radioBtnGroup.selected = layers.length;
}
private function getExcludeLayers():ArrayCollection
{
var result:ArrayCollection = new ArrayCollection();
if (configData && configData.basemaps)
{
// exclude basemaps
for (var i:int = 0; i < configData.basemaps.length; i++)
{
result.addItem(configData.basemaps.label);
}
}
if (configXML)
{
// exclude these layers
var layers:XMLList = configXML.excludelayer as XMLList;
for (var j:Number = 0; j < layers.length(); j++)
{
result.addItem(layers.toString());
}
}
return result;
}
private function showStateToggleLayers(event:MouseEvent):void
{
viewStack.selectedIndex = 0;
}
private function radioClickHandler(event:ItemClickEvent):void
{
// update the visible layers to only show the layer selected
for(var i:uint = 0; i < layers.length; i++)
{
if (layers.name == event.label){
map.getLayer(layers.name).visible = true;
var lay:Layer = map.getLayer(layers.name);
}else{
map.getLayer(layers.name).visible = false;
}
}
}
]]>
</fx:Script>
<viewer:WidgetTemplate id="wTemplate" width="300" height="300">
<viewer:layout>
<s:VerticalLayout gap="8" paddingTop="15"/>
</viewer:layout>
<s:Label text="{title}"/>
<toc:TOC id="toc" width="100%" height="100%"/>
<s:RadioButton id="radioBtnGroup" />
<mx:ViewStack id="viewStack" width="100%" height="100%" creationPolicy="all" paddingTop="4" />
</viewer:WidgetTemplate>
</viewer:BaseWidget>
private function getLayers():void
{
if (configData && configData.opLayers){
for (var i:int=0; i< configData.opLayers.length; i++)
{
layerArray.addItem(configData.opLayers.label);
}
}private function excludeLayers(): void
{
if (configXML){
// exclude these layers
var layers:XMLList = configXML..excludelayer as XMLList;
for (var j:Number = 0; j < layers.length(); j++){
for(var i:int=0; i< layerArray.length; i++){
if(layerArray == layers){
layerArray.removeItemAt(i);
}
}
}
}
} for(var i:uint = 0; i < layerArray.length; i++)
{
radioBtn = new RadioButton;
radioBtn.groupName = "radioBtnGroup";
radioBtn.label = layerArray;
radioBtn.styleName = "WidgetText";
radioBtn.value = i;
radioBtn.height = 18
radioBtn.setStyle("textRollOverColor","#D0D0D0 ")
vBoxRadio.addChild(radioBtn);
} private function radioClickHandler(event:ItemClickEvent):void
{
// update the visible layers to only show the layer selected
for(var i:uint = 0; i < layerArray.length; i++)
{
if (layerArray == event.label){
map.getLayer(layerArray).visible = true;
}else{
map.getLayer(layerArray).visible = false;
}
}
}