flex Aplikacje wykorzystujce mapy w Adobe Flex


Listing 1. Zastosowanie biblioteki Yahoo Map
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="onCreationComplete()">


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.GeocoderResult;
import com.yahoo.maps.webservices.geocoder.events.GeocoderEvent;

private var _yahooMap:YahooMap;
private var _address:Address;
private function onCreationComplete():void
{
var appid:String = 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, onMapContainerResize);

_yahooMap.addPanControl();
_yahooMap.addZoomWidget();
_yahooMap.addTypeWidget();
_yahooMap.addScaleBar();
}

private function handleMapInitialize(event:YahooMapEvent):void {
// Tu dodajemy isntrukcje wykonywane po zainicjalizowaniu mapy,
// np. wyszukiwanie i dodawanie punktów na mapie

_address = new Address("warszawa");
_address.addEventListener(GeocoderEvent.GEOCODER_SUCCESS, onGeocodeSuccess);
_address.geocode();
}

private function onGeocodeSuccess(event:GeocoderEvent):void
{
var result:GeocoderResult = _address.geocoderResultSet.firstResult;

_yahooMap.zoomLevel = result.zoomLevel;
_yahooMap.centerLatLon = result.latlon;

}

private function onMapContainerResize(event:ResizeEvent):void {
_yahooMap.setSize(mapContainer.width,mapContainer.height);
}
]]>








Listing 2. Modyfikacja funkcji onGeocodeSuccess()
private function onGeocodeSuccess(event:GeocoderEvent):void
{
var result:GeocoderResult = _address.geocoderResultSet.firstResult;

_yahooMap.zoomLevel = result.zoomLevel;
_yahooMap.centerLatLon = result.latlon;

for (var i:int = 0; i < 10; i++)
{
var latlon:LatLon = new LatLon(result.latlon.lat + Math.random() * 0.1, result.latlon.lon + Math.random() * 0.1);
var marker:SimpleMarker = new SimpleMarker();
marker.latlon = latlon;

_yahooMap.markerManager.addMarker(marker);
}
}





Listing 3. Tworzenie CustomMarker.as

package
{
import com.yahoo.maps.api.markers.Marker;

import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.filters.BitmapFilterQuality;
import flash.filters.DropShadowFilter;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;

public class CustomMarker extends Marker
{
private var dropShadowFilter:DropShadowFilter = new DropShadowFilter(0, 0, 0, 1, 12, 12, 1.5, 3);

private var marker:MovieClip;
private var toolTip:MovieClip;

private var adress:String;
private var imageURL:String;

public function CustomMarker(customName:String, customAdress:String, customImageURL:String)
{
super();

this.addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
this.addEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
this.addEventListener(MouseEvent.ROLL_OUT, this.onMouseOut);

this.name = customName;

this.adress = customAdress;
this.imageURL = customImageURL;

this.marker = new FlashMarker();
this.marker.filters = [this.dropShadowFilter];
this.addChild(this.marker);

this.toolTip = this.drawToolTip();
this.addChild(this.toolTip);
}

private function onMouseOver(event:MouseEvent):void
{
this.promoteToTop();

if(this.toolTip) this.toolTip.visible = true;
}

private function onMouseOut(event:MouseEvent):void
{
if(this.toolTip) this.toolTip.visible = false;
}

private function drawToolTip():MovieClip
{
var toolTipMC:MovieClip = new MovieClip();
toolTipMC.graphics.beginFill(0x3c3c3c, 0.66);
toolTipMC.graphics.drawRoundRect(
80,
155, 160, 125, 10, 10);
toolTipMC.graphics.endFill();
toolTipMC.visible = false;

var name:TextField = new TextField();
name.width = 160;
name.height = 20;
name.x =
80;
name.y =
150;
name.text = this.name;




Listing 4. Zaczenie pliku swf
package
{
import flash.display.MovieClip;

[Embed("Marker.swf", symbol="MarkerRed")]
public class FlashMarker extends MovieClip
{
public function FlashMarker()
{
super();
}

}
}




Listing 5. Modyfikacja funkcji onGeocodeSuccess
private function onGeocodeSuccess
(event:GeocoderEvent):void
{
var result:GeocoderResult = _address.geocoderResultSet.firstResult;

_yahooMap.zoomLevel = result.zoomLevel;
_yahooMap.centerLatLon = result.latlon;

var customMarker:CustomMarker =
new CustomMarker
("Przyklad", "Warszawa, Centrum", "icon.jpg");
customMarker.latlon = result.latlon;

_yahooMap.markerManager.addMarker(customMarker);
}





Wyszukiwarka