| 1 |
/* |
|---|
| 2 |
* vim:et sts=4 sw=4 cindent: |
|---|
| 3 |
* $Id$ |
|---|
| 4 |
*/ |
|---|
| 5 |
|
|---|
| 6 |
import flash.geom.Point; |
|---|
| 7 |
import com.modestmaps.Map; |
|---|
| 8 |
import com.modestmaps.geo.Location; |
|---|
| 9 |
import com.modestmaps.core.MapExtent; |
|---|
| 10 |
|
|---|
| 11 |
class com.modestmaps.core.MarkerClip |
|---|
| 12 |
extends MovieClip |
|---|
| 13 |
{ |
|---|
| 14 |
private var __map:Map; |
|---|
| 15 |
private var __starting:Point; |
|---|
| 16 |
private var __names:Object; |
|---|
| 17 |
private var __locations:Object; |
|---|
| 18 |
private var __eventsObserved:Boolean; |
|---|
| 19 |
|
|---|
| 20 |
public static var symbolName:String = '__Packages.com.modestmaps.core.MarkerClip'; |
|---|
| 21 |
public static var symbolOwner:Function = MarkerClip; |
|---|
| 22 |
public static var symbolLink:Boolean = Object.registerClass(symbolName, symbolOwner); |
|---|
| 23 |
|
|---|
| 24 |
public function MarkerClip() |
|---|
| 25 |
{ |
|---|
| 26 |
__names = {}; |
|---|
| 27 |
__locations = {}; |
|---|
| 28 |
__eventsObserved = false; |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
public function attachMarker(id:String, location:Location, symbol:String):MovieClip |
|---|
| 32 |
{ |
|---|
| 33 |
if(!__eventsObserved) { |
|---|
| 34 |
__eventsObserved = true; |
|---|
| 35 |
|
|---|
| 36 |
__map.addEventObserver(this, Map.EVENT_MARKER_ENTERS, "onMapMarkerEnters"); |
|---|
| 37 |
__map.addEventObserver(this, Map.EVENT_MARKER_LEAVES, "onMapMarkerLeaves"); |
|---|
| 38 |
__map.addEventObserver(this, Map.EVENT_START_ZOOMING, "onMapStartZooming"); |
|---|
| 39 |
__map.addEventObserver(this, Map.EVENT_STOP_ZOOMING, "onMapStopZooming"); |
|---|
| 40 |
__map.addEventObserver(this, Map.EVENT_ZOOMED_BY, "onMapZoomedBy"); |
|---|
| 41 |
__map.addEventObserver(this, Map.EVENT_START_PANNING, "onMapStartPanning"); |
|---|
| 42 |
__map.addEventObserver(this, Map.EVENT_STOP_PANNING, "onMapStopPanning"); |
|---|
| 43 |
__map.addEventObserver(this, Map.EVENT_PANNED_BY, "onMapPannedBy"); |
|---|
| 44 |
__map.addEventObserver(this, Map.EVENT_RESIZED_TO, "onMapResizedTo"); |
|---|
| 45 |
__map.addEventObserver(this, Map.EVENT_EXTENT_CHANGED, "onMapExtentChanged"); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
var clip:MovieClip = attachMovie(symbol, 'marker'+getNextHighestDepth().toString(), getNextHighestDepth()); |
|---|
| 49 |
|
|---|
| 50 |
__names[id] = clip._name; |
|---|
| 51 |
__locations[id] = location; |
|---|
| 52 |
|
|---|
| 53 |
var point:Point = __map.locationPoint(location, this); |
|---|
| 54 |
clip._x = point.x; |
|---|
| 55 |
clip._y = point.y; |
|---|
| 56 |
|
|---|
| 57 |
return clip; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
public function getMarker(id:String):MovieClip |
|---|
| 61 |
{ |
|---|
| 62 |
if(__names[id] && this[__names[id]]) |
|---|
| 63 |
return this[__names[id]]; |
|---|
| 64 |
|
|---|
| 65 |
return undefined; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
public function removeMarker(id:String):Void |
|---|
| 69 |
{ |
|---|
| 70 |
if(__names[id]) { |
|---|
| 71 |
this[__names[id]].removeMovieClip(); |
|---|
| 72 |
delete __names[id]; |
|---|
| 73 |
delete __locations[id]; |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
public function setMap(map:Map):Void |
|---|
| 78 |
{ |
|---|
| 79 |
__map = map; |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
private function updateClips():Void |
|---|
| 83 |
{ |
|---|
| 84 |
for(var id:String in __names) |
|---|
| 85 |
if(this[__names[id]] && this[__names[id]]._visible) |
|---|
| 86 |
updateClip(id); |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
private function updateClip(id:String):Void |
|---|
| 90 |
{ |
|---|
| 91 |
var location:Location = __locations[id]; |
|---|
| 92 |
var name:String = __names[id]; |
|---|
| 93 |
var clip:MovieClip = this[name]; |
|---|
| 94 |
|
|---|
| 95 |
if(name && clip && location) { |
|---|
| 96 |
var point:Point = __map.locationPoint(location, this); |
|---|
| 97 |
|
|---|
| 98 |
clip._x = point.x; |
|---|
| 99 |
clip._y = point.y; |
|---|
| 100 |
} |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
public function onMapMarkerEnters(id:String, location:Location):Void |
|---|
| 104 |
{ |
|---|
| 105 |
var name:String = __names[id]; |
|---|
| 106 |
|
|---|
| 107 |
if(this[name]) { |
|---|
| 108 |
this[name]._visible = true; |
|---|
| 109 |
updateClip(id); |
|---|
| 110 |
} |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
public function onMapMarkerLeaves(id:String, location:Location):Void |
|---|
| 114 |
{ |
|---|
| 115 |
var name:String = __names[id]; |
|---|
| 116 |
|
|---|
| 117 |
if(this[name]) { |
|---|
| 118 |
this[name]._visible = false; |
|---|
| 119 |
updateClip(id); |
|---|
| 120 |
} |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
public function onMapStartZooming(level:Number):Void |
|---|
| 124 |
{ |
|---|
| 125 |
updateClips(); |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
public function onMapZoomedBy(delta:Number):Void |
|---|
| 129 |
{ |
|---|
| 130 |
updateClips(); |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
public function onMapStopZooming(level:Number):Void |
|---|
| 134 |
{ |
|---|
| 135 |
updateClips(); |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
public function onMapStartPanning():Void |
|---|
| 139 |
{ |
|---|
| 140 |
__starting = new Point(_x, _y); |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
public function onMapPannedBy(delta:Point):Void |
|---|
| 144 |
{ |
|---|
| 145 |
_x = __starting.x + delta.x; |
|---|
| 146 |
_y = __starting.y + delta.y; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
public function onMapStopPanning():Void |
|---|
| 150 |
{ |
|---|
| 151 |
this._x = __starting.x; |
|---|
| 152 |
this._y = __starting.y; |
|---|
| 153 |
|
|---|
| 154 |
updateClips(); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
public function onMapResizedTo(width:Number, height:Number):Void |
|---|
| 158 |
{ |
|---|
| 159 |
_x = width/2; |
|---|
| 160 |
_y = height/2; |
|---|
| 161 |
|
|---|
| 162 |
updateClips(); |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
public function onMapExtentChanged(extent:MapExtent):Void |
|---|
| 166 |
{ |
|---|
| 167 |
updateClips(); |
|---|
| 168 |
} |
|---|
| 169 |
} |
|---|