<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="handleCreationComplete();"
viewSourceURL="srcview/index.html">
<mx:Panel title="Yahoo! Maps - Internet Location Demo" top="5" left="5" bottom="5" right="5" resizeEffect="Resize">
<mx:UIComponent id="mapContainer" width="100%" height="100%"/>
</mx:Panel>
<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.Address;
import com.yahoo.maps.webservices.geocoder.Geocoder;
import com.yahoo.maps.webservices.geocoder.GeocoderResult;
import com.yahoo.maps.webservices.geocoder.GeocoderResultSet;
import com.yahoo.maps.webservices.geocoder.events.GeocoderEvent;
import com.yahoo.maps.examples.SimpleCustomMarker;
private var _yahooMap:YahooMap;
private var _address:Address;
private var _geocoder:Geocoder;
private var _appId:String;
private static const WHERE_NS:Namespace = new Namespace("http://where.yahooapis.com/v1/schema.rng");
private function handleCreationComplete():void
{
_appId = Application.application.parameters.appid;
_yahooMap = new YahooMap();
_yahooMap.addEventListener(YahooMapEvent.MAP_INITIALIZE, handleMapInitialize);
_yahooMap.init(_appId,mapContainer.width,mapContainer.height);
mapContainer.addChild(_yahooMap);
mapContainer.addEventListener(ResizeEvent.RESIZE, handleContainerResize);
_yahooMap.addPanControl();
_yahooMap.addZoomWidget();
_yahooMap.addTypeWidget();
}
private function handleMapInitialize(event:YahooMapEvent):void
{
_geocoder = new Geocoder();
_geocoder.addEventListener(GeocoderEvent.GEOCODER_SUCCESS, handleWOEGeocodeSuccess);
_address = new Address("seattle,wa");
_address.addEventListener(GeocoderEvent.GEOCODER_SUCCESS, handleAddrGeocodeSuccess);
_address.geocode();
}
private function handleAddrGeocodeSuccess(event:GeocoderEvent):void
{
var result:GeocoderResult = _address.geocoderResultSet.firstResult;
_yahooMap.zoomLevel = result.zoomLevel;
_yahooMap.centerLatLon = result.latlon;
getPlaceNeighbors(result.woeid, 0, 25);
}
private function getPlaceNeighbors(woeid:uint, start:int=0, count:int=20):void
{
var url:String = "http://where.yahooapis.com/v1/place/"+woeid+"/neighbors;start="+start+";count="+count+"?format=xml&appid="+_appId;
var req:URLRequest = new URLRequest();
req.url = url;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, handleURLLoadComplete);
urlLoader.load(req);
}
private function handleURLLoadComplete(event:Event):void
{
var target:URLLoader = (event.target as URLLoader);
var xml:XML = XML(target.data);
var places:XMLList = xml.WHERE_NS::place;
for each(var place:XML in places)
{
var woeid:uint = parseInt(place.WHERE_NS::woeid);
_geocoder.geocodeWOEId(woeid);
}
}
private function handleWOEGeocodeSuccess(event:GeocoderEvent):void
{
var resultSet:GeocoderResultSet = (event.data as GeocoderResultSet);
var firstResult:GeocoderResult = resultSet.firstResult;
var marker:SimpleCustomMarker = new SimpleCustomMarker();
marker.latlon = firstResult.latlon;
_yahooMap.markerManager.addMarker(marker);
}
private function handleContainerResize(event:ResizeEvent):void
{
_yahooMap.setSize(mapContainer.width,mapContainer.height);
}
]]>
</mx:Script>
</mx:Application>