<?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" backgroundColor="#FFFFFF"
    creationComplete="handleCreationComplete(event)" 
    viewSourceURL="srcview/index.html">
    
    <mx:UIComponent id="mapContainer" width="100%" height="100%"/>
    <mx:Script>
        <![CDATA[
            import mx.events.ResizeEvent;
            
            import com.yahoo.maps.api.YahooMap;
            import com.yahoo.maps.api.YahooMapEvent;
            import com.yahoo.maps.api.core.location.LatLon;
            import com.yahoo.maps.api.core.location.Address;
            import com.yahoo.maps.webservices.geocoder.GeocoderResult;
            import com.yahoo.maps.webservices.geocoder.events.GeocoderEvent;
            
            // custom weather overlay class.
            import com.yahoo.weather.WeatherOverlay;
            
            private var _yahooMap:YahooMap;
            private var _address:Address;
            private var _weatherOverlay:WeatherOverlay;
            
            private function handleCreationComplete(event:Event):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;
                
                _yahooMap = new YahooMap();
                _yahooMap.addEventListener(YahooMapEvent.MAP_INITIALIZE, handleMapInitialize);
                _yahooMap.init(appid, mapContainer.width, mapContainer.height);
                
                _yahooMap.addPanControl();
                _yahooMap.addZoomWidget();
                _yahooMap.addTypeWidget();
                
                mapContainer.addChild(_yahooMap);
            }
            
            private function handleMapInitialize(event:YahooMapEvent):void
            {
                _yahooMap.zoomLevel = 14;
                _yahooMap.centerLatLon = new LatLon(42.11,-116.992);
                
                mapContainer.addEventListener(ResizeEvent.RESIZE, handleContainerResize);
                
                _weatherOverlay = new WeatherOverlay(_yahooMap);
                
                var addresses:Array = ["denver,co","santa monica,ca","green bay, wi", "nyc",
                                        "miami","seattle","atlanta","austin","honolulu,hi","juneau, alaska"];
                
                for each( var addressStr:String in addresses )
                {
                    var address:Address = new Address(addressStr);
                    address.addEventListener(GeocoderEvent.GEOCODER_SUCCESS, handleGeocodeSuccess);
                    address.geocode();
                }
            }
            
            private function handleGeocodeSuccess(event:GeocoderEvent):void 
            {
                var address:Address = (event.target as Address);
                var result:GeocoderResult = address.geocoderResultSet.firstResult;
                _weatherOverlay.getWeather( result.uzip, "f" );
            }
            
            private function handleContainerResize(event:ResizeEvent):void 
            {
                _yahooMap.setSize( mapContainer.width, mapContainer.height );
            }
        ]]>
    </mx:Script>
</mx:Application>