Select to view content in your preferred language

Zoom to selected

2267
3
02-09-2011 04:22 AM
BillLotz
Frequent Contributor
In my first flex app, non-sample viewer, I had a parcel search that used parts of the 'zoom to found' sample.
It adds the found features as a graphic and zooms to the extent of the graphic. You can zoom out a little by putting a ratio in the code.

"// zoom to extent of all features
var graphicProvider:ArrayCollection = myGraphicsLayer.graphicProvider as ArrayCollection;
var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
map.extent = graphicsExtent.expand(1.1); // zoom out a little "

The viewer widgets all seem to use zoom scale specified in the xml file.
The parcels service that I am using the search widget on has rural parcels of over 100 acres and small city lots, so the zoom scale does not work as well.

Has anybody incorporated the "old" style zoom to selected in to a search widget?
I hope to do that, but any help would be appreciated.
Thanks,
Bill
Tags (2)
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus
Bill,

   Here is how to do that for the SearchWidget in Flex Viewer 2.2 :

            private function clickSearchResult(event:Event):void
            {
                var searchResult:SearchResult = ItemRenderer(event.target).data as SearchResult;
    if(searchResult.geometry is Polygon){
     var pPoly:Polygon = searchResult.geometry as Polygon;
     map.extent = pPoly.extent.expand(1.2);
    }else{
     if (map.scale > zoomScale)
     {
      map.scale = zoomScale;
     }
     map.centerAt(searchResult.point as MapPoint);
    }
            }

Is that what you are asking?
0 Kudos
BillLotz
Frequent Contributor
Hello Robert,
That works nicely.
Thank you for your help once again, you saved me a lot of time.
I am struggling through this flex thing, I think I was better off when I was building my application from scratch (using the code samples as templates), as far as the learning process. With all the good widgets that have been put out I felt I had to go the Flex Viewer route, but now I often find myself in over my head, as the code is increasingly complicated.
It�??s a struggle, and I really appreciate the help.
Thanks,
Bill
Bill,

Here is how to do that for the SearchWidget in Flex Viewer 2.2 :

            private function clickSearchResult(event:Event):void
            {
                var searchResult:SearchResult = ItemRenderer(event.target).data as SearchResult;
                if(searchResult.geometry is Polygon){
                    var pPoly:Polygon = searchResult.geometry as Polygon;
                    map.extent = pPoly.extent.expand(1.2);
                }else{
                    if (map.scale > zoomScale)
                    {
                        map.scale = zoomScale;
                    }
                    map.centerAt(searchResult.point as MapPoint);
                }
            }

Is that what you are asking?
0 Kudos
DaveKirkley
Occasional Contributor
That works great for the Query Widget as well.

private function clickQueryResult(event:Event):void
            {
                var queryResult:QueryResult = ItemRenderer(event.target).data as QueryResult;
                if (queryResult.geometry is Polygon){
     var pPoly:Polygon = queryResult.geometry as Polygon;
     map.extent = pPoly.extent.expand(2.0);
    }else
   
                {
                    if (queryResult.geometry.type == Geometry.MAPPOINT)
                    {
                        if (map.scale > zoomScale)
                        {
                            map.scale = zoomScale;
                        }

                        map.centerAt(queryResult.point);
                    }
0 Kudos