Select to view content in your preferred language

Auto zoom from larger extent into initial extent

1436
10
05-05-2011 06:55 PM
RobertMyers
Deactivated User
Is it possible on opening a flex app to an extent showing a wide area, pause ,then zoom into the initial extent? An example would be to show a State for a second then zoom into a city which would be the area of interest for the flex map.
Tags (2)
0 Kudos
10 Replies
RobertScheitlin__GISP
MVP Emeritus
Robert,

   Sure just set the map's inital extent to the state value and then have a zoom function like this called using setTimeout:

//2000 is milliseconds and equals 2 seconds.
setTimeout(zoomNext, 2000, [ new Extent(xmin, ymin, xmax, ymax) ]);
private function zoomNext(ext:Extent):void
{
   map.extent = ext;
}
0 Kudos
RobertMyers
Deactivated User
I can not figure out how I would call setTimeout automatically as the flex app opens.  I have tried creationComplete with a handler to call a funtcion with doQuery and the setTimeout as a fuction. No luck. I'm really not familiar how this is done beyond doing it with click event.



Robert,

   Sure just set the map's inital extent to the state value and then have a zoom function like this called using setTimeout:

//2000 is milliseconds and equals 2 seconds.
setTimeout(zoomNext, 2000, [ new Extent(xmin, ymin, xmax, ymax) ]);
private function zoomNext(ext:Extent):void
{
   map.extent = ext;
}
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Robert,

  Try calling it from a map load event listener.
0 Kudos
RobertMyers
Deactivated User
I'm not quite experienced enough to know how to do the map load event listener. I did find however some code on a layerLoadHandler().  I created the below function and added load="layerLoadHandler()" to each of the layers being loaded - Bing Maps, ArcGISDynamicMapServiceLayer and the GraphicsLayer. I found that the function executed buy the Alert.show message but the zooming affect did not work.

Any addition help with the map load event listener or the code below would be appreciated. Thank you.

   private function layerLoadHandler():void
   {
    var allLayersLoaded:Boolean = true;
   
    for each (var id:String in myMap.layerIds)
    {
     var layer:Layer = myMap.getLayer(id);
     if (!layer.loaded)
     {
      allLayersLoaded = false;
      break;
     }
    }
   
    if (allLayersLoaded)
    {
          Alert.show("All Layers Have Loaded!");
             setTimeout(zoomNext, 2000, [ new Extent(-9811265, 5111444, -9791850, 5130706)]);

    }
   }
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Robert,

   It is probably going to be best if you attach your code or a sample application and I can show you where to put the code to do this.
0 Kudos
RobertMyers
Deactivated User
I have attached a version of the code. It's a zipped text file. Thinking this through, I would also need to reset the initial extent in the case when the Initial Extents button is clicked it doesn't go to the opening extent. Basically, at the app opening it would pause, giving an opening reference to the local with respect to the City of Chicago then zooms into the suburb. I really appreciate your help.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Robert,

   Here is the code working.
0 Kudos
RobertMyers
Deactivated User
Perfect. Now I understand it. I am fairly new to flex and seeking help in this forum.  I am getting an understanding why you are MVP! Thank you, again!

You can see my full app here with the zooming function.

http://gis.vil.woodridge.il.us/availablesites/
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Robert,

   Only problem I see is that when you click an available property on the list to the right it zooms to Africa.
0 Kudos