Combining a drivetime and identify widget.

1595
0
08-01-2011 02:43 PM
SeanCook
New Contributor
[PHP]<?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:esri="http://www.esri.com/2008/ags"
                   xmlns:viewer="com.esri.viewer.*"
                   widgetConfigLoaded="init()">
    <fx:Script>
        <![CDATA[
   import com.esri.ags.FeatureSet;
   import com.esri.ags.Graphic;
   import com.esri.ags.events.MapMouseEvent;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.tasks.supportClasses.ExecuteResult;
   import com.esri.ags.tasks.supportClasses.ParameterValue;
   import com.esri.ags.events.DrawEvent;
   import com.esri.ags.events.GeoprocessorEvent;
   import com.esri.ags.tasks.supportClasses.LinearUnit;
   import com.esri.ags.tools.DrawTool;
   import com.esri.ags.layers.GraphicsLayer;
  
   import mx.controls.Alert;
   import mx.rpc.AsyncResponder;

   private var driveTimes:String = "1 2 3";
   private var myGraphicsLayer:GraphicsLayer = new GraphicsLayer();
   [Bindable]
   private var url:String;
  
            //this function called when the widget's configuration is loaded
   private function init():void
   {
    if (configXML) // checking for valid content in the configuration file
    {
     url = configXML.url;
     map.addLayer(myGraphicsLayer);
    
    }
   }
   private function computeServiceArea(mapPoint:MapPoint):void
   {
   
    myGraphicsLayer.clear();
    var graphic:Graphic = new Graphic(mapPoint, sms_circleAlphaSizeOutline);
    myGraphicsLayer.add(graphic);
    var featureSet:FeatureSet = new FeatureSet([ graphic ]);
    var params:Object =
     {
      "Input_Location": featureSet,
      "Drive_Times": driveTimes
     };
    gp.execute(params, new AsyncResponder(onResult, onFault));
    function onResult(gpResult:ExecuteResult,token:Object = null):void
    {
     var pv:ParameterValue = gpResult.results[0];
     var fs:FeatureSet = pv.value as FeatureSet;
     myGraphicsLayer.graphicProvider = fs.features;
     myGraphicsLayer.renderer=uniqueValueRenderer;
    }
    function onFault(info:Object, token:Object = null):void
    {
     Alert.show(info.toString());
    }
   }
   private function clear():void
   {
    myGraphicsLayer.clear();
   }
  
   private function mapClickHandler(event:MapMouseEvent):void
   {
    computeServiceArea(event.mapPoint);
   }
  
   protected function driveTime_openHandler(event:Event):void
   {
    map.addEventListener(MapMouseEvent.MAP_CLICK,mapClickHandler)   
   }
  
  
  
   protected function driveTime_closedHandler(event:Event):void
   {
    map.removeLayer(myGraphicsLayer);
    map.removeEventListener(MapMouseEvent.MAP_CLICK,mapClickHandler)
   }
  
  
  
  
        ]]>
    </fx:Script>



<fx:Declarations>
 
  <esri:SimpleMarkerSymbol id="sms_circleAlphaSizeOutline"
         alpha="0.5"
         size="15"
         style="circle"/>
 
  <esri:SimpleFillSymbol id="rFill"
          alpha="0.5"
          color="0xFF0000"/>
  <esri:SimpleFillSymbol id="gFill"
          alpha="0.5"
          color="0x00FF00"/>
  <esri:SimpleFillSymbol id="bFill"
          alpha="0.5"
          color="0x0000FF"/>
 
  <esri:UniqueValueRenderer id="uniqueValueRenderer" attribute="ToBreak">
   <esri:UniqueValueInfo symbol="{rFill}" value="1"/>
   <esri:UniqueValueInfo symbol="{gFill}" value="2"/>
   <esri:UniqueValueInfo symbol="{bFill}" value="3"/>
  </esri:UniqueValueRenderer>

 
 
  <esri:Geoprocessor id="gp"
         outSpatialReference="{map.spatialReference}"
         url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network/ESRI_DriveTime_US/GPServer/Create..."
         useAMF="false"/>

</fx:Declarations>


<viewer:WidgetTemplate id= "driveTime"
         width="305"
         height="100"
         open="driveTime_openHandler(event)"
         closed="driveTime_closedHandler(event)"
     
       >
 
  <s:VGroup width="100%" height="100%">
   <s:Label text="This Widget Calculates DriveTimes "/>
  
   <s:HGroup width="100%"
       paddingLeft="5"
       paddingBottom="2"
       paddingTop="2" verticalAlign="middle" styleName="">
   
   
   
   </s:HGroup>
  </s:VGroup>
</viewer:WidgetTemplate>
</viewer:BaseWidget>
[/PHP]
Tags (2)
0 Kudos
0 Replies