Select to view content in your preferred language

Flex sample for Reverse geocoding

2881
10
06-22-2010 03:37 PM
VijayashreeN
Emerging Contributor
Hey,

I have 2 questions. I just want to know if the samples that are provided in the ArcGIS resource center are not compatible with flash builder 4. I am  getting lot of runtime errors with those samples. I am a newbie, however with little knowledge I tried to replace wherever mx components are with the latest flash builder components. I am getting run time errors for some. Can any body help me. I am talking about the sample for reverse geocoding. For me it displays the map but it will not display the graphic and the address. It shows a blank window without any address.

I am attaching the file. Can anybody help me please.

Thanks
Tags (2)
0 Kudos
10 Replies
RobertScheitlin__GISP
MVP Emeritus
V,

    There were three issues in the code.

1. The most important the url to the geocode service was incorrect (GeocodedServer is suppose to be GeocodeServer)
2. import com.esri.ags.tasks.AddressCandidate; is now import com.esri.ags.tasks.supportClasses.AddressCandidate;
3. This line
+ candidate.address.toString() + "\n"

is supose to be
+ candidate.address.Address + "\n"
0 Kudos
SreeS
by
Emerging Contributor
Here is my ReverseGeocode Widget which was developed using Flex 3.2 sdk.
0 Kudos
VijayashreeN
Emerging Contributor
V,

    There were three issues in the code.

1. The most important the url to the geocode service was incorrect (GeocodedServer is suppose to be GeocodeServer)
2. import com.esri.ags.tasks.AddressCandidate; is now import com.esri.ags.tasks.supportClasses.AddressCandidate;
3. This line
+ candidate.address.toString() + "\n"

is supose to be
+ candidate.address.Address + "\n"



I did fix the 3 issues. Now my problem is I can display the graphic but no pop up window for the address.  Are there any other errors which I am unable to note?
Also I want to know is there any new version of sampleviewer available?
0 Kudos
VijayashreeN
Emerging Contributor
Here is my ReverseGeocode Widget which was developed using Flex 3.2 sdk.


There is a problem with the zip file after downloading. Can you please upload it again?

Thanks
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
V,

    Does your problem window in Flash Builder not list any issues?

The new ArcGIS Flex Viewer is still not available. It will be announced on the forum when it is available.
0 Kudos
SreeS
by
Emerging Contributor
There is a problem with the zip file after downloading. Can you please upload it again?

Thanks


I dont know why I no longer get forum updates to my email.

The previous upload was zipped with WinRar.

Try this one. This ones a regular zip file.
0 Kudos
VijayashreeN
Emerging Contributor
V,

    Does your problem window in Flash Builder not list any issues?

The new ArcGIS Flex Viewer is still not available. It will be announced on the forum when it is available.


Robert,

Thanks for you response. There was no window that was poping up to show errors. However I tried to replace

candidate.address.Address.Address  with candidate.address.Address.toString() + "\n"

Now it shows the address for me. Hope there is nothing wrong with this.


I have a question for you since I see you are the one who is answering most of the questions on this forum I thought you would suggest me something.

I am a student and need to develop a project for a county in NC I have a trial version for 60 days of flex and I am afraid I will not  be able to develop the entire app in this period. Earlier I had an education version in flex 3 now I replaced with this trial version. Since then I wanted to do some customization of sample viewer but when I migrated to flex 4 it is dumping lot of errors. That is the reason I asked you for new version of sample viewer and developers guide.

My question is - Is it a good idea to customize the sample viewer or develop own components.

Thanks once again.
0 Kudos
VijayashreeN
Emerging Contributor
I dont know why I no longer get forum updates to my email.

The previous upload was zipped with WinRar.

Try this one. This ones a regular zip file.


No luck. I have Win 7. Unable to unzip the file.
0 Kudos
SreeS
by
Emerging Contributor
Here's the code. Its working on my website.

I still need to test it though. Its been a really long time since i used it.

Try it and let me know how it goes for you.

You can take a look at the working sample under the tools menu: http://www.vahgis.com/flexviewer1.3/index.html


---------- ReverseGeocode.mxml-----

<?xml version="1.0" encoding="utf-8"?>
<BaseWidget xmlns:esri   ="http://www.esri.com/2008/ags"
   xmlns    ="com.esri.solutions.flexviewer.*"
   xmlns:mx   ="http://www.adobe.com/2006/mxml"
   xmlns:maplib  ="com.esri.maplib.*"
   xmlns:widgets  ="com.esri.solutions.flexviewer.widgets.*"
   x     ="600"
   y     ="300" 
   widgetConfigLoaded ="init()">
<mx:Script>
  <![CDATA[
   import com.esri.ags.geometry.Geometry;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.geometry.Extent;
   import com.esri.ags.Graphic;  
   import com.esri.ags.Map;        
   import com.esri.ags.tasks.AddressCandidate;       
   import com.esri.ags.tasks.Locator; 
   import com.esri.ags.tasks.FeatureSet;  
   import com.esri.ags.events.LocatorEvent;           
   import com.esri.ags.events.MapMouseEvent;
   import com.esri.ags.events.DrawEvent;
   import com.esri.ags.layers.GraphicsLayer;
   import com.esri.ags.layers.Layer;
   import com.esri.ags.symbol.PictureMarkerSymbol;
   import com.esri.ags.toolbars.Draw; 
   import mx.controls.Alert;           
   import mx.controls.TextArea;     
   import com.esri.solutions.flexviewer.SiteContainer;
   import com.esri.solutions.flexviewer.utils.WidgetEffects;
   import mx.collections.*;
   import mx.rpc.AsyncResponder;
   import mx.rpc.events.FaultEvent;
      import mx.events.FlexEvent;
     
  
   [Bindable]
   private var pointLabel:String;
  
   [Bindable]
   private var clearLabel:String;
  
   [Bindable]
   private var descriptionLabel:String;
  
   private var addressPoint:MapPoint;
  
   private var zoomScale:Number = 5000;
  
   private var graphicsLayer:GraphicsLayer;
  
   private var graphicSym:PictureMarkerSymbol;
   
   private function init():void
   {
    if (configXML)
    {
     //labels
     pointLabel = configXML.labels.pointlabel || "Point";
     clearLabel = configXML.labels.clearlabel || "Disable Tool";
     descriptionLabel = configXML.labels.descriptionlabel || "Find Address";
   
     graphicsLayer = new GraphicsLayer();
     graphicSym = new PictureMarkerSymbol(widgetIcon, 20, 20);
     graphicsLayer.symbol = graphicSym;
     map.addLayer(graphicsLayer);
     if (Number(configXML.zoomscale) > 0)
      zoomScale = Number(configXML.zoomscale);
     var url:String = configXML.locator;
    }
    activateTool();
    map.infoWindow.addEventListener(FlexEvent.HIDE, mapInfoWindowHiddenHandler);
   }   
  
   private function mapInfoWindowHiddenHandler(event:FlexEvent):void
   {
    map.infoWindow.hide();
    graphicsLayer.clear();
    setMapNavigation(null, null);
   }
  
  
         private function onLocationToAddressComplete(event:LocatorEvent):void           
         {               
          var candidate:AddressCandidate = event.addressCandidate;               
            if (candidate != null && candidate.address)               
             {                   
              var myGraphic:Graphic = new Graphic(candidate.location, graphicSym, candidate.address);                   
              var text1:TextArea = new TextArea();                   
               text1.editable = false;                   
              text1.percentHeight = 100;                   
              text1.percentWidth = 100;                        
              graphicsLayer.clear();                   
              graphicsLayer.add(myGraphic);                   
          text1.htmlText = "<font color='#FFFFFF'>" + candidate.address.KeyField.toString() + "</font> ";    //Street            
        map.infoWindow.label = "Address:";                   
        map.infoWindow.content = text1;                   
        map.infoWindow.height = 70;                   
        map.infoWindow.alpha = 0.91;
        map.infoWindow.show(myGraphic.geometry as MapPoint);                 
      }               
     else               
        {                   
         Alert.show("This location does not have a known address.");               
       }           
   }     
        
   private function onFault(event:FaultEvent):void           
   {               
       Alert.show(event.fault.faultDetail);           
   }  
  
   private function activateTool():void
   {
    var status:String = pointLabel;
    setMapAction(Draw.MAPPOINT, status, drawEnd);
   } 
   
   private function drawEnd(event:DrawEvent):void
   {
    this.showInfoWindow(null);
    graphicsLayer.clear();
    graphicsLayer.add(event.graphic);
    addressPoint = event.graphic.geometry as MapPoint;
    locateTask.locationToAddress(addressPoint, 100); 
   }    
  
   private function clear():void
   {
    this.showInfoWindow(null);
    map.infoWindow.hide();
    graphicsLayer.clear();
    setMapNavigation(null, null);
   }
  
   private function widgetClosedHandler(event:Event):void
   {
    clear();
   }
     
   private function widgetOpenedHandler(event:Event):void
   {
    activateTool();
    graphicsLayer.visible = true;
   } 
  ]]>
</mx:Script>
<!-- Start Declarations --> 
<esri:Locator id="locateTask"  
  url="http://www.vahgis.com/ArcGIS/rest/services/WEB/Address_Locator_MAT/GeocodeServer" concurrency="last"           
  locationToAddressComplete="onLocationToAddressComplete(event)" fault="onFault(event)"/>  
  <WidgetTemplate id="wTemplate" widgetClosed="widgetClosedHandler(event)" widgetOpened="widgetOpenedHandler(event)">
  <mx:ViewStack id="viewStack" width="100%" height="100%" creationPolicy="all" paddingTop="4">
   <mx:VBox width="100%" height="100%" verticalGap="4" horizontalAlign="center">
    <mx:Text id="txtLabel" text="{descriptionLabel}" styleName="WidgetText" width="100%" textAlign="center"/>
    <mx:HBox horizontalAlign="center" width="100%" horizontalGap="15">
     <mx:Image click="{activateTool()}" source="com/esri/solutions/flexviewer/assets/images/icons/i_draw_point.png" useHandCursor="true" buttonMode="true" toolTip="{pointLabel}" width="40" height="40"/>
     <mx:Image click="{clear()}" source="com/esri/solutions/flexviewer/assets/images/icons/i_clear.png" useHandCursor="true" buttonMode="true" toolTip="{clearLabel}" width="40" height="40"/>
    </mx:HBox>
   </mx:VBox>
  </mx:ViewStack>
</WidgetTemplate> 
  <!-- End Declarations -->   
</BaseWidget>
------------------------------------------------------


------------  ReverseGeocode.xml ------------

<?xml version="1.0" ?>
<configuration>
<locator>http://www.vahgis.com/ArcGIS/rest/services/WEB/Address_Locator_MAT/GeocodeServer</locator>
<url>http://www.vahgis.com/ArcGIS/rest/services/WEB/Address_Locator_MAT/GeocodeServer</url>
<zoomscale>2188</zoomscale>
<labels>
  <pointlabel>Locate Address</pointlabel>
  <clearlabel>Clear</clearlabel>
  <descriptionlabel>Click on map to find address of the location:</descriptionlabel>
</labels>
</configuration>
0 Kudos