Select to view content in your preferred language

Automatcially zoom to selected records (SFV 1.x)?

914
6
07-28-2010 06:00 AM
BoCastillo
Deactivated User
When a user performs a search, I want the record(s) to be automatically zoomed to. Due to the way the click on the selected record and zoom in feature works in the SFV by using a set scale, this may not work so well for automatically zooming in on multiple records. Is it possible to have it zoom in automatically for all records and use a new set scale or just one returned record? I've tried searching the old and new forums but I haven't been able to find any samples.
Tags (2)
0 Kudos
6 Replies
KeithPalmer
Emerging Contributor
You're in luck Bo.  I needed to do this today too so I pulled together the logic from various samples (yes, I hate reinventing the "wheel"):

private function zoomSelected():void
{
if (graphicsLayer.numGraphics > 0)
{
  var pt:MapPoint = new MapPoint();
  var extSelected:Extent;
  for each (var selgra:Graphic in graphicsLayer.graphicProvider)         
     {
        pt = getGeomCenter(selgra);
  //Calculate the Selected Feature Extent
          if (extSelected == null) {
                 extSelected= new Extent(pt.x,pt.y,pt.x,pt.y);
            } else {
               if (pt.x > extSelected.xmax) {extSelected.xmax=pt.x;}
               if (pt.y > extSelected.ymax) {extSelected.ymax=pt.y;}
               if (pt.x < extSelected.xmin) {extSelected.xmin=pt.x;}
               if (pt.y < extSelected.ymin) {extSelected.ymin=pt.y;}
       }           
     }      
    }
    map.extent= extSelected.expand(2);   
}

-Keith
0 Kudos
BoCastillo
Deactivated User
Keith,

Thank You! It works perfectly!
0 Kudos
MayJeff
Deactivated User
Can you show me where to add the code to make it to work?  I tried it on the SearchWidget.mxml for SFV1.3. 

Thank you.

May
0 Kudos
BoCastillo
Deactivated User
May,

You can add Keith's code almost anywhere in the SearchWidget.mxml, as it is a stand alone function. This alone won't be enough and you will need to set up a section of you code to actually call up the "zoomSelected" function.

I added this small section of code near the end of the "createRecordData" function:

if (featureSet.features.length > 0)
{
     zoomSelected();
}


Right before this line of code:

return recAC;


This executes the "zoomSelected" function when the search results are generated and will not execute the code unless there is at least one selected feature.
0 Kudos
MayJeff
Deactivated User
Thank you very much.  It works.
0 Kudos
MikeHouts
Emerging Contributor
Im have been trying to make a model in 9.3 that will select a polygon by attributes and then zoom to the selected.  Once created I plan to add the tool to a .net web app to facilitate user quarry and zoom capability. 

I have the selection part ok, but cant get the zoom to selected.  I found the python script to do in in 10, but our server is still using 9.3.

Any help with python code or python code to call a VB script (and the VB script) or if there any other way would be greatly appreciated.

Thanks, Mike



import sys, string, os, arcgisscripting

## create the geoprocessor object ##
gp = arcgisscripting.create()

## Load required toolboxes ##
# gp.addtoolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx
             
# set workspace
# arcpy.env.workspace = "C:/temp/"

# mxd = MapDocument('CURRENT')
# df = ListDataFrames(mxd,"Layers")[0]

# Script arguments
section = gp.GetParameterAsText(0)
township = gp.GetParameterAsText(1)
range_ = gp.GetParameterAsText(2)
range_dir = gp.GetParameterAsText(3)

# Local variables:
PLSS = "PLSS"

#### Use the SelectLayerByAttribute tool to select a Section
gp.SelectLayerByAttribute_management(PLSS, "NEW_SELECTION", "\"SECTION\" = "+section)
gp.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"TOWNSHIP\" = "+township)
# arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"TOWNSHIP_D\" = S")
gp.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"RANGE\" = "+range_)
gp.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"RANGE_dir\" = "+range_dir)

#Zoom to selected features in the map

--------- HELP NEEDED HERE !! -------------

# Clear the selection and refresh the active view
gp.SelectLayerByAttribute_management(PLSS, "CLEAR_SELECTION")
gp.RefreshActiveView(
0 Kudos