forked from: Modest Maps Example
これはBSDライセンスです。
*
* Modest Mapsという(新)BSDライセンスの地図APIのデモ
* http://modestmaps.com/
* http://wonderfl.net/code/4bc00c11098ba2924331e5d9f5085ff500d6e55f#
* ソースに同梱されているSampleほぼそのまま。
* wonderfl用にパッケージを解いてちょっといじったくらい。
* 右上のメニューから地図画像を選択できる。
* 一部(AC Transit,Daily Planet)がうまく動かないけど、
* たぶん、地図が用意されていないから。
*
// forked from Ctrl's Modest Maps Example
/*
* これはBSDライセンスです。
*
* Modest Mapsという(新)BSDライセンスの地図APIのデモ
* http://modestmaps.com/
* http://wonderfl.net/code/4bc00c11098ba2924331e5d9f5085ff500d6e55f#
* ソースに同梱されているSampleほぼそのまま。
* wonderfl用にパッケージを解いてちょっといじったくらい。
* 右上のメニューから地図画像を選択できる。
* 一部(AC Transit,Daily Planet)がうまく動かないけど、
* たぶん、地図が用意されていないから。
* */
package
{
import com.modestmaps.Map;
import com.modestmaps.TweenMap;
import com.modestmaps.core.MapExtent;
import com.modestmaps.events.MapEvent;
import com.modestmaps.events.MarkerEvent;
import com.modestmaps.extras.MapControls;
import com.modestmaps.extras.MapCopyright;
import com.modestmaps.extras.ZoomBox;
import com.modestmaps.extras.ZoomSlider;
import com.modestmaps.geo.Location;
import com.modestmaps.mapproviders.*;
import com.modestmaps.mapproviders.microsoft.*;
import com.modestmaps.mapproviders.yahoo.*;
import flash.utils.setTimeout;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.geom.Point;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Timer;
/**
* Pure Actionscript 3 Flex Builder project,
* based on ModestMapsSample.fla by David Knape.
* @author David Knape
*/
[SWF(backgroundColor="#000000", frameRate="60")]
public class DocumentClass extends Sprite
{
// Our modest map
private var map:Map;
// a tooltip/flag that appears on marker rollover
private var tooltip:Tooltip;
// status text field at bottom of screen
private var status:TextField;
// our map provier button holder
private var mapButtons:Sprite;
// padding around map in pixels
private const PADDING:int = 0;
private var time:Timer = new Timer(500, 12);
/**
* This constructor is called automatically when the SWF starts
*/
public function DocumentClass()
{
Wonderfl.capture_delay(12);
// setup stage
stage.scaleMode = StageScaleMode.NO_SCALE;
//stage.align = StageAlign.TOP_LEFT;
// create child components
createChildren();
time.addEventListener(TimerEvent.TIMER, zoomMe);
time.addEventListener(TimerEvent.TIMER_COMPLETE, panMe);
time.start();
}
private function createChildren():void
{
// create map
map = new TweenMap(stage.stageWidth - 2 * PADDING, stage.stageHeight - 2 * PADDING,
true,
new YahooHybridMapProvider(),
//new MapExtent(85, -85, 180, -180));
new MapExtent(-13, 14.9690791, -74.4109478, -75.9048588));
map.addEventListener(MouseEvent.DOUBLE_CLICK, map.onDoubleClick);
map.x = map.y = PADDING;
// listen for map events
map.addEventListener(MapEvent.ZOOMED_BY, onZoomed);
map.addEventListener(MapEvent.STOP_ZOOMING, onStopZoom);
map.addEventListener(MapEvent.PANNED, onPanned);
map.addEventListener(MapEvent.STOP_PANNING, onStopPan);
map.addEventListener(MapEvent.RESIZED, onResized);
// listen for marker events
map.addEventListener(MarkerEvent.MARKER_CLICK, onMarkerClick);
map.addEventListener(MarkerEvent.MARKER_ROLL_OVER, onMarkerRollOver);
map.addEventListener(MarkerEvent.MARKER_ROLL_OUT, onMarkerRollOut);
// create text field to hold status text
status = new TextField();
status.defaultTextFormat = new TextFormat('Verdana', 10, 0xeeeeee);
status.selectable = false;
status.text = 'Welcome to Modest Maps...';
status.width = 600;
status.height = 20;
// create some provider buttons
mapButtons = new Sprite();mapButtons.addChild(new MapProviderButton('MS Road', map.getMapProvider(), true));
mapButtons.addChild(new MapProviderButton('MS Aerial', new MicrosoftAerialMapProvider()));
mapButtons.addChild(new MapProviderButton('MS Hybrid', new MicrosoftHybridMapProvider()));
mapButtons.addChild(new MapProviderButton('Yahoo Aerial', new YahooAerialMapProvider()));
mapButtons.addChild(new MapProviderButton('Yahoo Hybrid', new YahooHybridMapProvider()));
mapButtons.addChild(new MapProviderButton('Open Street Map', new OpenStreetMapProvider()));
// arrange buttons 22px apart
for( var n:int = 0; n < mapButtons.numChildren; n++) {
mapButtons.getChildAt(n).y = n * 22;
}
// listen for map provider button clicks
mapButtons.addEventListener(MouseEvent.CLICK, onProviderButtonClick);
// add children to the display list
addChild(map);
panMe1();
}
private function zoomMe(e:TimerEvent = null):void
{
map.zoomIn();
}
private function panMe(e:TimerEvent = null):void
{
map.panBy(-890, 400);
setTimeout(zoomMe, 1000);
setTimeout(zoomMe, 2000);
addChild(mapButtons);
map.addChild(new MapControls(map));
}
private function panMe1():void
{
map.panBy(-12,41);
}
/**
* Change map provider when provider buttons are clicked
*/
private function onProviderButtonClick(event:Event = null):void
{
var button:MapProviderButton = event.target as MapProviderButton;
map.setMapProvider(button.mapProvider);
button.selected = true;
for (var i:int = 0; i < mapButtons.numChildren; i++) {
var other:MapProviderButton = mapButtons.getChildAt(i) as MapProviderButton;
if (other != button) {
other.selected = false;
}
}
}
/**
* Marker Click
*/
private function onMarkerClick(event:MarkerEvent):void
{
var marker:SampleMarker = event.marker as SampleMarker;
status.text = "Marker Clicked: " + marker.title + " " + event.location;
}
/**
* Marker Roll Over
*/
private function onMarkerRollOver(event:MarkerEvent):void
{
//trace('Roll Over ' + event.marker + event.location);
var marker:SampleMarker = event.marker as SampleMarker;
// show tooltip
var pt:Point = map.locationPoint( event.location, this );
tooltip.x = pt.x;
tooltip.y = pt.y;
tooltip.label = marker.title;
tooltip.visible = true;
}
/**
* Marker Roll Out
*/
private function onMarkerRollOut(event:MarkerEvent):void
{
// hide the tooltip
tooltip.visible = false;
}
//---------------------
// Map Event Handlers
//---------------------
private function onPanned(event:MapEvent):void
{
status.text = 'Panned by ' + event.panDelta.toString() + ', top left: ' + map.getExtent().northWest.toString() + ', bottom right: ' + map.getExtent().southEast.toString();
}
private function onStopPan(event:MapEvent):void
{
status.text = 'Stopped panning, top left: ' + map.getExtent().northWest.toString() + ', center: ' + map.getCenterZoom()[0].toString() + ', bottom right: ' + map.getExtent().southEast.toString() + ', zoom: ' + map.getCenterZoom()[1];
}
private function onZoomed(event:MapEvent):void
{
status.text = 'Zoomed by ' + event.zoomDelta.toFixed(3) + ', top left: ' + map.getExtent().northWest.toString() + ', bottom right: ' + map.getExtent().southEast.toString();
}
private function onStopZoom(event:MapEvent):void
{
status.text = 'Stopped zooming, top left: ' + map.getExtent().northWest.toString() + ', center: ' + map.getCenterZoom()[0].toString() + ', bottom right: ' + map.getExtent().southEast.toString() + ', zoom: ' + map.getCenterZoom()[1];
}
private function onResized(event:MapEvent):void
{
status.text = 'Resized to: ' + event.newSize[0] + ' x ' + event.newSize[1];
}
}
}
//MapProviderButton.as
import com.modestmaps.mapproviders.IMapProvider;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
import flash.geom.ColorTransform;
import flash.text.TextField;
import flash.text.TextFormat;
/**
* Button for use in ModestMaps Sample
*
* @author David Knape
*/
class MapProviderButton extends Sprite {
private var label:TextField;
public var mapProvider:IMapProvider;
private var overTransform:ColorTransform = new ColorTransform(1,1,1);
private var outTransform:ColorTransform = new ColorTransform(1,.9,.6);
private var normalFormat:TextFormat = new TextFormat( 'Verdana', 10, 0x000000, false);
private var selectedFormat:TextFormat = new TextFormat( 'Verdana', 10, 0x000000, true);
private var _selected:Boolean = false;
public function MapProviderButton( label_text:String, map_provider:IMapProvider, selected:Boolean=false ) {
useHandCursor = true;
mouseChildren = false;
buttonMode = true;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
mapProvider = map_provider;
filters = [ new DropShadowFilter(1,45,0,1,3,3,.7,2) ];
transform.colorTransform = outTransform;
// create label
label = new TextField();
label.selectable = false;
label.defaultTextFormat = normalFormat;
label.text = label_text;
label.width = label.textWidth + 8;
label.height = 18;
label.x = label.y=1;
addChild( label );
this.selected = selected;
// create background
graphics.clear();
graphics.beginFill(0xdddddd);
graphics.drawRoundRect(0, 0, 110, 18, 9, 9);
graphics.beginFill(0xffffff);
graphics.drawRoundRect(0, 0, 108, 16, 9, 9);
graphics.beginFill(0xbbbbbb);
graphics.drawRoundRect(2, 2, 108, 16, 9, 9);
graphics.beginFill(0xdddddd);
graphics.drawRoundRect(1, 1, 108, 16, 9, 9);
}
public function onMouseOver(event:MouseEvent=null):void
{
transform.colorTransform = overTransform;
}
public function onMouseOut(event:MouseEvent=null):void
{
transform.colorTransform = outTransform;
}
public function set selected(s:Boolean):void
{
_selected = s;
label.setTextFormat(s ? selectedFormat : normalFormat);
}
public function get selected():Boolean
{
return _selected;
}
}
//SampleMarker.as
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.filters.BevelFilter;
/**
* Sample Marker
* @author David Knape
*/
class SampleMarker extends Sprite {
private var _title : String;
public function SampleMarker() {
buttonMode = true;
mouseChildren = false;
tabEnabled = false;
//cacheAsBitmap = true;
mouseEnabled = true;
// David's Flash example draws the marker
// in the Flash environment
// but need to draw something:
// first a zero-alpha circle so the filter's bitmap cache doesn't mess things up
graphics.beginFill(0xff0000,0);
graphics.drawCircle(0, 0, 11);
graphics.endFill();
// now a red circle
graphics.beginFill(0x4465d7);
graphics.drawCircle(0, 0, 10);
graphics.endFill();
filters = [ new BevelFilter(1,45,0xffffff,0.35,0x000000,0.35,2,2,1,1) ];
addEventListener( MouseEvent.MOUSE_OVER, mouseOver );
}
public function get title () : String {
return _title;
}
public function set title (s:String) : void {
_title = s;
}
protected function mouseOver(e:MouseEvent) : void {
parent.swapChildrenAt(parent.getChildIndex(this), parent.numChildren - 1);
}
override public function toString() : String {
return '[SampleMarker] ' + title;
}
}
//Tooltip.as
import flash.display.Shape;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
/**
* @author David Knape
*/
class Tooltip extends Sprite {
public var background:Shape;
public var label_txt:TextField;
public function Tooltip() {
background = new Shape();
background.graphics.beginFill(0xffffff);
background.graphics.drawRect(0,0,100,20);
background.graphics.endFill();
addChild(background);
label_txt = new TextField();
label_txt.selectable = false;
label_txt.defaultTextFormat = new TextFormat( 'Verdana', 10, 0x000000 );
addChild(label_txt);
visible = false;
mouseEnabled = false;
}
public function set label ( s: String ) : void {
label_txt.autoSize = TextFieldAutoSize.LEFT;
label_txt.width = 200;
label_txt.multiline = label_txt.wordWrap = true;
label_txt.text = s;
background.width = Math.max( 100, label_txt.textWidth + 10);
background.height = label_txt.textHeight + 18;
background.y = Math.round( -background.height - 16 );
background.x = 1;
label_txt.y = background.y + 2;
graphics.clear();
graphics.lineStyle(0,0x000000);
graphics.beginFill(0xffffff);
graphics.moveTo(0,0);
graphics.lineTo(background.x-1,background.y+background.height+1);
graphics.lineTo(background.x-1,background.y-1);
graphics.lineTo(background.x+background.width+1,background.y-1);
graphics.lineTo(background.x+background.width+1,background.y+background.height+1);
graphics.lineTo(background.x+10,background.y+background.height+1);
graphics.lineTo(0,0);
}
}