<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (c) 2008 Yahoo! Inc.  All rights reserved.  
    The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
-->
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute" 
    creationComplete="handleCreationComplete();" 
    viewSourceURL="srcview/index.html">
    
    <mx:UIComponent id="mapContainer" width="100%" height="100%"/>
    <mx:Script>
        <![CDATA[
            import com.yahoo.maps.api.markers.SimpleMarker;
            import com.yahoo.maps.api.core.location.LatLon;
            import com.yahoo.maps.api.core.location.BoundingBox;
            import com.yahoo.maps.api.YahooMapEvent;
            import com.yahoo.maps.api.YahooMap;
            
            private var _yahooMap:YahooMap;
            
            private function handleCreationComplete():void 
            {
                // this examples uses an application id passed into the app via FlashVars.
                // Get your own from the Yahoo! Developer Network @ http://developer.yahoo.com/wsregapp/
                var appid:String = Application.application.parameters.appid;
                
                // create YahooMap instance and listen for map initialize event
                _yahooMap = new YahooMap(); 
                _yahooMap.addEventListener(YahooMapEvent.MAP_INITIALIZE, handleMapInitialize); 
                _yahooMap.init(appid, mapContainer.width, mapContainer.height);
                
                _yahooMap.addPanControl();
                _yahooMap.addZoomWidget();
                
                mapContainer.addChild(_yahooMap);
            }
            
            private function handleMapInitialize(event:YahooMapEvent):void 
            {
                _yahooMap.zoomLevel = 13;
                _yahooMap.centerLatLon = new LatLon(37.5, -122.14);
                
                // add 1000 markers randomly across the bounds of the map.
                var bounds:BoundingBox = _yahooMap.getMapBounds();
                var southwest:LatLon = bounds.southwest;
                var northeast:LatLon = bounds.northeast;
                
                var lonSpan:Number = northeast.lon - southwest.lon;
                var latSpan:Number = northeast.lat - southwest.lat;
                
                for (var i:int = 0; i < 1000; i++) 
                {
                    var latlon:LatLon = new LatLon(southwest.lat + latSpan * Math.random(), southwest.lon + lonSpan * Math.random());
                    var marker:SimpleMarker = new SimpleMarker();
                    marker.latlon = latlon;
                    marker.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
                    marker.addEventListener(Event.REMOVED_FROM_STAGE, onRemoved);
                    _yahooMap.markerManager.addMarker(marker);
                }
            }
            
            private function onAddedToStage( event:Event):void
            {
                trace(event.type, event.target);
            }
            
            private function onRemoved( event:Event):void
            {
                trace(event.type, event.target);
            }
        ]]>
    </mx:Script>
</mx:Application>