Hi Ryan-
That won't work because you're asynchronously loading the markers -
the callback function for each marker isn't necessarily reached until
after the setCenter lines.
You can do something like this, inside the callback:
if (count == (Model.getInstance().spots.length -1)) {
map.setCenter(bounds.getCenter());
map.setZoom(map.getBoundsZoomLevel(bounds))
}
That code will be checked each time a marker loads, and will execute
once all the markers are loaded.
- pamela
On Tue, May 19, 2009 at 5:24 PM, Ryan <[email protected]> wrote:
>
> I have been banging my head against the wall for the past few hours on
> this one, hoping some of you with a little more experience may be able
> to help me:
>
> private function setMarkers():void{
>
> var count :int = 0;
> var loader :SWFLoader;
> var bounds :LatLngBounds = new
> LatLngBounds();
>
> map.clearOverlays();
>
> for(var i:int = 0; i <
> Model.getInstance().spots.length; i++) {
>
> loader = new SWFLoader();
>
> loader.load("http://localhost/Atmosphere_Frontsite/App_Common/SWF/
> MapIconComponent.swf");
>
> loader.addEventListener(Event.COMPLETE, function
> completeHandler
> (event:Event):void{
>
> var spot
> :SpotVO = Model.getInstance().spots[count];
> var timeline
> :MovieClip = event.currentTarget.content;
> var markerOptions
> :MarkerOptions = new MarkerOptions;
> var latLon
> :LatLng;
>
> timeline.arrowSpeed.direction.rotation
> = spot.dir;
> timeline.arrowSpeed.windSpeed.text =
> String(spot.avg);
>
> markerOptions.icon =
> timeline.arrowSpeed;
> markerOptions.hasShadow = false;
>
> latLon = new
> LatLng(Model.getInstance().spots[count].lat,
> Model.getInstance().spots[count].lon);
>
> bounds.extend(latLon);
>
> var marker:Marker = new Marker(latLon,
> markerOptions);
> map.addOverlay(marker);
>
> count++;
>
> });
> }
>
> map.setCenter(bounds.getCenter());
> map.setZoom(map.getBoundsZoomLevel(bounds))
>
> }
>
>
> Basicly, I need to zoom to the extents of the markers being added to
> the map. From what I have read you have to add latLon to the bounds
> object in a certain order? is this true? Why wont this map center on
> the bounds and set the zoom level properly? cant seem to figure out
> why....
>
> HELP!
>
> Thanks
> -Ryan
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API For Flash" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-maps-api-for-flash?hl=en
-~----------~----~----~----~------~----~------~--~---