<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="handleCreationComplete();" viewSourceURL="srcview/index.html">
<mx:Panel id="mapPanel" title="Yahoo! Maps - AIR Demo" top="5" left="5" bottom="5" right="5">
<mx:UIComponent id="mapContainer" width="100%" height="100%"/>
</mx:Panel>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
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.markers.SimpleMarker;
import com.yahoo.maps.webservices.geocoder.GeocoderResult;
import com.yahoo.maps.webservices.geocoder.GeocoderResultSet;
import com.yahoo.maps.webservices.geocoder.events.GeocoderEvent;
private var _yahooMap:YahooMap;
private var _locationList:Array;
private function handleCreationComplete():void
{
getLocationList();
}
private function getLocationList():void
{
var fileName:String = "locations.txt";
var file:File = File.desktopDirectory.resolvePath(fileName);
if(!file.exists)
{
mapPanel.visible = false;
Alert.show(file.nativePath + " does not exist", "File not found", 4, this, handleErrorAlertClose);
return;
}
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var fileContents:String = fileStream.readMultiByte(file.size, File.systemCharset);
fileStream.close();
var latlonStrs:Array = fileContents.split('\n');
_locationList = new Array();
for each(var llstr:String in latlonStrs)
{
var ll:LatLon = new LatLon(llstr.split(',')[0], llstr.split(',')[1]);
_locationList.push(ll);
}
addMap();
}
private function addMap():void
{
var appid:String = null;
if(!appid || appid == "")
{
mapPanel.visible = false;
Alert.show("No AppID provided","Map Error", 4, this, handleErrorAlertClose);
return;
}
_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
{
_yahooMap.zoomLevel = _yahooMap.config.defaultZoom;
_yahooMap.centerLatLon = _locationList[0] as LatLon;
for each(var latlon:LatLon in _locationList)
{
var marker:SimpleMarker = new SimpleMarker();
marker.latlon = latlon;
_yahooMap.markerManager.addMarker(marker);
}
_yahooMap.setMapBounds( _yahooMap.markerManager.getMarkerBounds() );
}
private function handleContainerResize(event:ResizeEvent):void
{
_yahooMap.setSize(mapContainer.width,mapContainer.height);
}
private function handleErrorAlertClose(event:Event):void
{
this.close();
}
]]>
</mx:Script>
</mx:WindowedApplication>