<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="handleCreationComplete(event);"
backgroundGradientAlphas="[1.0, 1.0]"
backgroundGradientColors="[#FFFFFF, #FFFFFF]"
viewSourceURL="srcview/index.html">
<mx:UIComponent id="mapContainer" width="100%" height="100%" />
<mx:Panel width="311" height="143" layout="absolute" left="10" top="10" id="mapStatus" title="Map Status" borderColor="#A69F9F">
<mx:TextInput text="Center LatLon: {_centerLatLon}" top="10" left="10" right="10"/>
<mx:TextInput editable="false" text="Center Address: {_centerAddressStr}" left="10" top="36" right="10"/>
<mx:Button click="_yahooMap.mapType=MapTypes.MAP" label="Map" width="85" horizontalCenter="-93" bottom="10"/>
<mx:Button click="_yahooMap.mapType=MapTypes.SATELLITE" label="Satellite" width="85" horizontalCenter="0" bottom="10"/>
<mx:Button click="_yahooMap.mapType=MapTypes.HYBRID" label="Hybrid" bottom="10" width="85" horizontalCenter="93"/>
</mx:Panel>
<mx:Script>
<![CDATA[
import mx.events.ResizeEvent;
import com.yahoo.maps.api.MapTypes;
import com.yahoo.maps.api.YahooMap;
import com.yahoo.maps.api.YahooMapEvent;
import com.yahoo.maps.api.core.location.Address;
import com.yahoo.maps.api.core.location.LatLon;
import com.yahoo.maps.api.widgets.WidgetAlign;
import com.yahoo.maps.webservices.geocoder.GeocoderResultSet;
import com.yahoo.maps.webservices.geocoder.GeocoderResult;
import com.yahoo.maps.webservices.geocoder.events.GeocoderEvent;
import com.yahoo.maps.webservices.geocoder.Geocoder;
private var _yahooMap:YahooMap;
private var _centerAddress:Address;
private var _geocoder:Geocoder;
[Bindable] private var _centerLatLon:LatLon;
[Bindable] private var _centerAddressStr:String;
private function handleCreationComplete(event:Event):void
{
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.zoomWidget.align = WidgetAlign.TOP_RIGHT;
mapContainer.addChild(_yahooMap);
}
private function handleMapInitialize(event:YahooMapEvent):void
{
mapContainer.addEventListener(ResizeEvent.RESIZE, handleContainerResize);
_geocoder = new Geocoder();
_geocoder.addEventListener(GeocoderEvent.GEOCODER_SUCCESS, handleGeocodeSuccess);
_centerAddress = new Address(this.loaderInfo.parameters.address || "San Francisco, CA");
_centerAddress.addEventListener(GeocoderEvent.GEOCODER_SUCCESS, handleCenterGeocodeSuccess);
_centerAddress.geocode();
}
private function handleGeocodeSuccess(event:GeocoderEvent):void
{
var resultSet:GeocoderResultSet = event.data as GeocoderResultSet;
var firstResult:GeocoderResult = resultSet.firstResult;
_centerAddressStr = firstResult.getLineAddress();
}
private function handleCenterGeocodeSuccess(event:GeocoderEvent):void
{
var result:GeocoderResult = _centerAddress.geocoderResultSet.firstResult;
_yahooMap.zoomLevel = result.zoomLevel;
_centerLatLon = _yahooMap.centerLatLon = result.latlon;
_centerAddressStr = result.getLineAddress();
reverseGeocodeCenter();
_yahooMap.addEventListener(YahooMapEvent.MAP_MOVE, handleMapMove);
_yahooMap.addEventListener(YahooMapEvent.MAP_DRAG_STOP, handleMapMoveStop);
_yahooMap.addEventListener(YahooMapEvent.MAP_DOUBLE_CLICK, handleDoubleClick);
}
private function handleMapMove(event:YahooMapEvent):void
{
_centerLatLon = _yahooMap.centerLatLon;
}
private function handleMapMoveStop(event:YahooMapEvent):void
{
_centerLatLon = _yahooMap.centerLatLon;
reverseGeocodeCenter();
}
private function handleDoubleClick(event:YahooMapEvent):void
{
_yahooMap.zoomLevel--;
_centerLatLon = _yahooMap.centerLatLon;
reverseGeocodeCenter();
}
private function reverseGeocodeCenter():void
{
_geocoder.reverseGeocode(_yahooMap.centerLatLon);
}
private function handleContainerResize(event:ResizeEvent):void
{
_yahooMap.setSize( mapContainer.width, mapContainer.height);
}
]]>
</mx:Script>
</mx:Application>