Flash_and_Flex_03_2009

How to use Yahoo! Maps in Flex

Listing 3a. CustomMarker Component used in the complex Yahoo! Maps application

package com.flexer { import com.yahoo.maps.api.core.location.LatLon; import com.yahoo.maps.api.markers.Marker; import com.yahoo.maps.webservices.local.LocalSearchItem; import flash.events.MouseEvent; import flash.events.TextEvent; import flash.filters.DropShadowFilter; import flash.net.URLRequest; import flash.net.navigateToURL; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; public class CustomMarker extends Marker { // background color of the marker private var _markerColor:uint; // drop shadow filter private var _dropShadow:DropShadowFilter; // title object private var _titleText:TextField; // address object private var _addressText:TextField; // website text object private var _urlText:TextField; // web site address private var _web:String; // formats private var _titleFormat:TextFormat; private var _addressFormat:TextFormat; private var _urlFormat:TextFormat; // marker shape private var _customBigMarkerShape:Sprite; // local search item private var _localSearchItem:LocalSearchItem; // constructor public function CustomMarker(color:uint, centerLatLon: LatLon, localSearchItem:LocalSearchItem, web:String = null ) { super (); // setting its position latlon = centerLatLon; // setting color _markerColor = color; // setting local search item _localSearchItem = localSearchItem; // setting web site address _web = web; // creating drop shadow filter _dropShadow = new DropShadowFilter(3, 45, 0x000000, .7, 2, 2, 1, 3); import flash.display.Sprite; import flash.events.Event;

// setting format for the title _titleFormat = new TextFormat(); _titleFormat.size = 11; _titleFormat.color = 0x7bbee3; _titleFormat.bold = true ; _titleFormat.font = "Arial"; // setting format for the address _addressFormat = new TextFormat(); _addressFormat.size = 10; _addressFormat.bold = false ; _addressFormat.color = 0xdddddd; _addressFormat.font = "Arial"; // setting format for the website _urlFormat = new TextFormat(); _urlFormat.size = 11; _urlFormat.color = 0x7bbee3; _urlFormat.font = "Arial";

// add title object _titleText = new TextField();

_titleText.width = 1; _titleText.height = 1;

_titleText.autoSize = TextFieldAutoSize.LEFT; _titleText.text = _localSearchItem.title; _titleText.setTextFormat(_titleFormat);

// add address object _addressText = new TextField();

_addressText.width = 0; _addressText.height = 0; _addressText.autoSize = TextFieldAutoSize.LEFT; // concat what we need _addressText.text = _localSearchItem.addr+"\n" + _localSearchItem.city + (_localSearchItem.state.length > 0 ? (", judetul " + _localSearchItem.state):""); _addressText.setTextFormat(_addressFormat); // calculate max widths & heights var widthW:Number = Math.round(_titleText.textWidth + 20); var heightH:Number = _titleText.textHeight + _ addressText.textHeight; var radius:Number = 8; var padding:Number = 8; if (_addressText.textWidth > _titleText.textWidth) { widthW = _addressText.textWidth; } // add website object if it is specified if (_web && _web.length > 0) { _urlText = new TextField(); _urlText.htmlText = "website"; _urlText.x = widthW / 2 – _urlText.textWidth + 5; _urlText.y = -_urlText.textHeight – padding – 3; _urlText.setTextFormat(_urlFormat);

03/2009 (5)

49

Made with FlippingBook HTML5