Problems zooming to a feature on the map.

899
4
04-26-2012 12:30 PM
by Anonymous User
Not applicable
I am trying to duplicate the zoom process of the search widget of the Flex Viewer. When you enter a street name and click one of the results it zooms to the particular graphic on the map. Like the Search widget, I am trying to zoom to a particular point on the map ina custom widget that I have created.

Click handler below from the Search Widget:

private function clickSearchResult(event:Event):void
{
                        
           var searchResult:SearchResult = ItemRenderer(event.target).data as SearchResult;
            if (searchResult.geometry)
                {
                    if (searchResult.geometry.type == Geometry.MAPPOINT)
                    {
                        if (map.scale > zoomScale)
                        {
                            map.scale = zoomScale;
                        }

                        map.centerAt(searchResult.point);
                    }
                    else
                    {
                        map.extent = searchResult.geometry.extent;

                        if (!map.extent.contains(searchResult.geometry))
                        {
                            map.level--;
                        }
                    }
                }
                clearTimeout(hitimer);
                hitimer = setTimeout(showHighlight, 300, [ searchResult ]);
            }



The above code works. It zooms to the feature point given. I have a sex offender widget that basically does the same thing It selects a group of features and displays them via a custom item renderer within the widget. I am trying to zoom to the feature on the map by clicking one of the results, same as the Search widget. My code bombs on the highlighted line below.



       private function clickHandler(event:Event):void
                  {
                        var bufferResult:HCSexOffenderResult = ItemRenderer(event.target).data as HCSexOffenderResult;
                        
                        if (bufferResult.geometry)
                        {
                              
                              if (bufferResult.geometry.type == Geometry.MAPPOINT)
                              {
                                    if (map.scale > zoomScale)
                                    {
                                          map.scale = zoomScale;
                                    }
                                    map.centerAt(bufferResult.point);
                              }
                        }
                        else
                        {
                              Alert.show("I am in else");
                        }
                        clearTimeout(hitimer);
                        hitimer = setTimeout(showHighlight, 300, [bufferResult]);               
}



Does anybody have any ideas about whats going on? Let me know if you need more information.

Thanks
Tags (2)
0 Kudos
4 Replies
FaizanTayyab
Occasional Contributor
Have you tried debugging to see what is event.target
0 Kudos
by Anonymous User
Not applicable
The event.target is returning a value but when I try to get the geometry using the itemrenderer class it returns a null.

event.target = widgets.HCSexOffender.HCSexOffenderInfo
ItemRenderer(event.target).data as HCSexOffenderResult = NULL

I am trying to define as my result class so that I can get the geometry so that I can zoom to it on the map.  Below is the class that I am using to get all the information.

package widgets.HCSexOffender
{
 import com.esri.ags.Graphic;
 import com.esri.ags.geometry.Geometry;
 import com.esri.ags.geometry.MapPoint;
 import com.esri.ags.symbols.Symbol;
 
 import flash.events.EventDispatcher;
 
 
 [Bindable]
 
 public class HCSexOffenderResult extends EventDispatcher
 {
  public var title:String;
  public var symbol:Symbol;
  public var content:String;
  public var point:MapPoint;
  public var link:String;
  public var linkAlias:String;
  public var geometry:Geometry;
  public var graphic:Graphic;
  public var zoomScale:Number;
  public var forceScale:Boolean;
  public var zoom2msg:String;
  public var photoLink:String;
  public var moreDetailsLink:String;
 }
}



How could I get the geometry information from the click event of my itemrenderer when an item is clicked?  Similiar to the Search widget?
0 Kudos
IvanBespalov
Occasional Contributor III
Step by step.

Do you have the same logic as in SearchWidget/BookmarkWidget/... ?
[ATTACH=CONFIG]14006[/ATTACH]
where each SearchResult is:
var searchResult:SearchResult = new SearchResult();
searchResult.title = title;
searchResult.content = content;
searchResult.point = getGeomCenter(graphic);
searchResult.link = link ? link : null;
searchResult.linkAlias = linkAlias;
searchResult.geometry = graphic.geometry;
searchResult.graphic = graphic;

Right?
0 Kudos
by Anonymous User
Not applicable
Ivan,
Thanks for your response.  Yes that is correct.  My widget follows the same logic in that you listed.
0 Kudos