| 1 |
import SampleMarker; |
|---|
| 2 |
import com.bigspaceship.utils.Delegate; |
|---|
| 3 |
import com.modestmaps.core.MapExtent; |
|---|
| 4 |
import com.modestmaps.geo.Location; |
|---|
| 5 |
import com.modestmaps.Map; |
|---|
| 6 |
import com.modestmaps.mapproviders.microsoft.MicrosoftRoadMapProvider; |
|---|
| 7 |
import com.stamen.twisted.Reactor; |
|---|
| 8 |
import flash.geom.Point; |
|---|
| 9 |
|
|---|
| 10 |
class SampleClient1 |
|---|
| 11 |
{ |
|---|
| 12 |
private static var __map:Map; |
|---|
| 13 |
private static var __navButtons:MovieClip; |
|---|
| 14 |
private static var __mapButtons:MovieClip; |
|---|
| 15 |
private static var __status:TextField; |
|---|
| 16 |
|
|---|
| 17 |
public static function main(clip:MovieClip):Void |
|---|
| 18 |
{ |
|---|
| 19 |
Reactor.run(clip, 50); |
|---|
| 20 |
|
|---|
| 21 |
__map = Map(clip.attachMovie(Map.symbolName, 'map', clip.getNextHighestDepth())); |
|---|
| 22 |
__map.init(Stage.width-256, Stage.height-256, true, new MicrosoftRoadMapProvider()); |
|---|
| 23 |
__map.addEventObserver(SampleClient1, Map.EVENT_ZOOMED_BY, "onZoomed"); |
|---|
| 24 |
__map.addEventObserver(SampleClient1, Map.EVENT_STOP_ZOOMING, "onStopZoom"); |
|---|
| 25 |
__map.addEventObserver(SampleClient1, Map.EVENT_PANNED_BY, "onPanned"); |
|---|
| 26 |
__map.addEventObserver(SampleClient1, Map.EVENT_STOP_PANNING, "onStopPan"); |
|---|
| 27 |
__map.addEventObserver(SampleClient1, Map.EVENT_RESIZED_TO, "onResized"); |
|---|
| 28 |
|
|---|
| 29 |
__status = clip.createTextField('status', clip.getNextHighestDepth(), 0, 0, 600, 100); |
|---|
| 30 |
__status.selectable = false; |
|---|
| 31 |
__status.textColor = 0x000000; |
|---|
| 32 |
__status.text = '...'; |
|---|
| 33 |
__status._height = __status.textHeight + 2; |
|---|
| 34 |
|
|---|
| 35 |
__map.setExtent(new MapExtent(37.829853, 37.700121, -122.212601, -122.514725)); |
|---|
| 36 |
|
|---|
| 37 |
//Reactor.callLater(2000, Delegate.create(__map, __map.setNewCenter), new Location(37.811411, -122.360916), 14); |
|---|
| 38 |
|
|---|
| 39 |
__map.addEventObserver(SampleClient1, Map.EVENT_MARKER_ENTERS, "onMarkerEnters"); |
|---|
| 40 |
__map.addEventObserver(SampleClient1, Map.EVENT_MARKER_LEAVES, "onMarkerLeaves"); |
|---|
| 41 |
|
|---|
| 42 |
// Add a bunch of markers by attaching clips to the __map.markers movieclip: |
|---|
| 43 |
__map.putMarker('Rochdale', new Location(37.865571, -122.259679), SampleMarker.symbolName); |
|---|
| 44 |
__map.putMarker('Parker Ave.', new Location(37.780492, -122.453731), SampleMarker.symbolName); |
|---|
| 45 |
__map.putMarker('Pepper Dr.', new Location(37.623443, -122.426577), SampleMarker.symbolName); |
|---|
| 46 |
__map.putMarker('3rd St.', new Location(37.779297, -122.392877), SampleMarker.symbolName); |
|---|
| 47 |
__map.putMarker('Divisadero St.', new Location(37.771919, -122.437413), SampleMarker.symbolName); |
|---|
| 48 |
__map.putMarker('Market St.', new Location(37.812734, -122.280064), SampleMarker.symbolName); |
|---|
| 49 |
__map.putMarker('17th St.', new Location(37.804274, -122.262940), SampleMarker.symbolName); |
|---|
| 50 |
|
|---|
| 51 |
Stage.scaleMode = 'noScale'; |
|---|
| 52 |
Stage.align = 'TL'; |
|---|
| 53 |
Stage.addListener(SampleClient1); |
|---|
| 54 |
|
|---|
| 55 |
Reactor.callNextFrame(onResize); |
|---|
| 56 |
|
|---|
| 57 |
var buttons:Array = new Array(); |
|---|
| 58 |
|
|---|
| 59 |
__navButtons = clip.createEmptyMovieClip("navButtons", clip.getNextHighestDepth()); |
|---|
| 60 |
|
|---|
| 61 |
buttons.push(makeButton(__navButtons, 'plus', 'zoom in', Delegate.create(__map, __map.zoomIn))); |
|---|
| 62 |
buttons.push(makeButton(__navButtons, 'minus', 'zoom out', Delegate.create(__map, __map.zoomOut))); |
|---|
| 63 |
buttons.push(makeButton(__navButtons, 'left', 'pan left', Delegate.create(__map, __map.panLeft))); |
|---|
| 64 |
buttons.push(makeButton(__navButtons, 'up', 'pan up', Delegate.create(__map, __map.panUp))); |
|---|
| 65 |
buttons.push(makeButton(__navButtons, 'down', 'pan down', Delegate.create(__map, __map.panDown))); |
|---|
| 66 |
buttons.push(makeButton(__navButtons, 'left', 'pan right', Delegate.create(__map, __map.panRight))); |
|---|
| 67 |
|
|---|
| 68 |
//__navButtons._x = __navButtons._y = 50; |
|---|
| 69 |
|
|---|
| 70 |
var nextX:Number = 0; |
|---|
| 71 |
|
|---|
| 72 |
for(var i:Number = 0; i < buttons.length; i++) { |
|---|
| 73 |
buttons[i]._x = nextX; |
|---|
| 74 |
nextX += buttons[i]['label']._width + 5; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
// mapProvider buttons |
|---|
| 78 |
|
|---|
| 79 |
__mapButtons = clip.createEmptyMovieClip("mapButtons", clip.getNextHighestDepth()); |
|---|
| 80 |
|
|---|
| 81 |
buttons = new Array(); |
|---|
| 82 |
|
|---|
| 83 |
buttons.push(makeButton(__mapButtons, 'MICROSOFT_ROAD', 'ms road', Delegate.create(SampleClient1, SampleClient1.switchMapProvider))); |
|---|
| 84 |
buttons.push(makeButton(__mapButtons, 'MICROSOFT_AERIAL', 'ms aerial', Delegate.create(SampleClient1, SampleClient1.switchMapProvider))); |
|---|
| 85 |
buttons.push(makeButton(__mapButtons, 'MICROSOFT_HYBRID', 'ms hybrid', Delegate.create(SampleClient1, SampleClient1.switchMapProvider))); |
|---|
| 86 |
|
|---|
| 87 |
buttons.push(makeButton(__mapButtons, 'GOOGLE_ROAD', 'google road', Delegate.create(SampleClient1, SampleClient1.switchMapProvider))); |
|---|
| 88 |
buttons.push(makeButton(__mapButtons, 'GOOGLE_AERIAL', 'google aerial', Delegate.create(SampleClient1, SampleClient1.switchMapProvider))); |
|---|
| 89 |
buttons.push(makeButton(__mapButtons, 'GOOGLE_HYBRID', 'google hybrid', Delegate.create(SampleClient1, SampleClient1.switchMapProvider))); |
|---|
| 90 |
|
|---|
| 91 |
buttons.push(makeButton(__mapButtons, 'YAHOO_ROAD', 'yahoo road', Delegate.create(SampleClient1, SampleClient1.switchMapProvider))); |
|---|
| 92 |
buttons.push(makeButton(__mapButtons, 'YAHOO_AERIAL', 'yahoo aerial', Delegate.create(SampleClient1, SampleClient1.switchMapProvider))); |
|---|
| 93 |
buttons.push(makeButton(__mapButtons, 'YAHOO_HYBRID', 'yahoo hybrid', Delegate.create(SampleClient1, SampleClient1.switchMapProvider))); |
|---|
| 94 |
|
|---|
| 95 |
buttons.push(makeButton(__mapButtons, 'BLUE_MARBLE', 'blue marble', Delegate.create(SampleClient1, SampleClient1.switchMapProvider))); |
|---|
| 96 |
buttons.push(makeButton(__mapButtons, 'OPEN_STREET_MAP', 'open street map', Delegate.create(SampleClient1, SampleClient1.switchMapProvider))); |
|---|
| 97 |
|
|---|
| 98 |
var nextY : Number = 0; |
|---|
| 99 |
|
|---|
| 100 |
for(var i:Number = 0; i < buttons.length; i++) { |
|---|
| 101 |
buttons[i]._y = nextY; |
|---|
| 102 |
nextY += buttons[i]['label']._height + 5; |
|---|
| 103 |
buttons[i]._alpha = 60; |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
_root.createEmptyMovieClip('marks', _root.getNextHighestDepth()); |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
private static function switchMapProvider(button:MovieClip):Void |
|---|
| 111 |
{ |
|---|
| 112 |
switch(button._name) { |
|---|
| 113 |
case 'VANILLA': |
|---|
| 114 |
__map.setMapProvider(new com.modestmaps.mapproviders.VanillaMapProvider()); |
|---|
| 115 |
break; |
|---|
| 116 |
|
|---|
| 117 |
case 'BLUE_MARBLE': |
|---|
| 118 |
__map.setMapProvider(new com.modestmaps.mapproviders.BlueMarbleMapProvider()); |
|---|
| 119 |
break; |
|---|
| 120 |
|
|---|
| 121 |
case 'OPEN_STREET_MAP': |
|---|
| 122 |
__map.setMapProvider(new com.modestmaps.mapproviders.OpenStreetMapProvider()); |
|---|
| 123 |
break; |
|---|
| 124 |
|
|---|
| 125 |
case 'MICROSOFT_ROAD': |
|---|
| 126 |
__map.setMapProvider(new com.modestmaps.mapproviders.microsoft.MicrosoftRoadMapProvider()); |
|---|
| 127 |
break; |
|---|
| 128 |
|
|---|
| 129 |
case 'MICROSOFT_AERIAL': |
|---|
| 130 |
__map.setMapProvider(new com.modestmaps.mapproviders.microsoft.MicrosoftAerialMapProvider()); |
|---|
| 131 |
break; |
|---|
| 132 |
|
|---|
| 133 |
case 'MICROSOFT_HYBRID': |
|---|
| 134 |
__map.setMapProvider(new com.modestmaps.mapproviders.microsoft.MicrosoftHybridMapProvider()); |
|---|
| 135 |
break; |
|---|
| 136 |
|
|---|
| 137 |
case 'GOOGLE_ROAD': |
|---|
| 138 |
__map.setMapProvider(new com.modestmaps.mapproviders.google.GoogleRoadMapProvider()); |
|---|
| 139 |
break; |
|---|
| 140 |
|
|---|
| 141 |
case 'GOOGLE_AERIAL': |
|---|
| 142 |
__map.setMapProvider(new com.modestmaps.mapproviders.google.GoogleAerialMapProvider()); |
|---|
| 143 |
break; |
|---|
| 144 |
|
|---|
| 145 |
case 'GOOGLE_HYBRID': |
|---|
| 146 |
__map.setMapProvider(new com.modestmaps.mapproviders.google.GoogleHybridMapProvider()); |
|---|
| 147 |
break; |
|---|
| 148 |
|
|---|
| 149 |
case 'YAHOO_ROAD': |
|---|
| 150 |
__map.setMapProvider(new com.modestmaps.mapproviders.yahoo.YahooRoadMapProvider()); |
|---|
| 151 |
break; |
|---|
| 152 |
|
|---|
| 153 |
case 'YAHOO_AERIAL': |
|---|
| 154 |
__map.setMapProvider(new com.modestmaps.mapproviders.yahoo.YahooAerialMapProvider()); |
|---|
| 155 |
break; |
|---|
| 156 |
|
|---|
| 157 |
case 'YAHOO_HYBRID': |
|---|
| 158 |
__map.setMapProvider(new com.modestmaps.mapproviders.yahoo.YahooHybridMapProvider()); |
|---|
| 159 |
break; |
|---|
| 160 |
} |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
public static function makeButton(clip:MovieClip, name:String, label:String, action:Function):MovieClip |
|---|
| 164 |
{ |
|---|
| 165 |
var button:MovieClip = clip.createEmptyMovieClip(name, clip.getNextHighestDepth()); |
|---|
| 166 |
|
|---|
| 167 |
button.createTextField('label', button.getNextHighestDepth(), 0, 0, 100, 100); |
|---|
| 168 |
button['label'].selectable = false; |
|---|
| 169 |
button['label'].textColor = 0xFFFFFF; |
|---|
| 170 |
button['label'].text = label; |
|---|
| 171 |
button['label']._width = button['label'].textWidth + 4; |
|---|
| 172 |
button['label']._height = button['label'].textHeight + 2; |
|---|
| 173 |
|
|---|
| 174 |
button.moveTo(0, 0); |
|---|
| 175 |
button.beginFill(0x000000, 100); |
|---|
| 176 |
button.lineTo(0, button['label']._height); |
|---|
| 177 |
button.lineTo(button['label']._width, button['label']._height); |
|---|
| 178 |
button.lineTo(button['label']._width, 0); |
|---|
| 179 |
button.lineTo(0, 0); |
|---|
| 180 |
button.endFill(0, 0); |
|---|
| 181 |
|
|---|
| 182 |
button.onRelease = function() |
|---|
| 183 |
{ |
|---|
| 184 |
action.apply(SampleClient1, [button]); |
|---|
| 185 |
}; |
|---|
| 186 |
|
|---|
| 187 |
return button; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
public static function output(str:String):Void |
|---|
| 191 |
{ |
|---|
| 192 |
trace(str); |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
// Event Handlers |
|---|
| 196 |
|
|---|
| 197 |
private static function onResize():Void |
|---|
| 198 |
{ |
|---|
| 199 |
__map._x = __map._y = 50; |
|---|
| 200 |
__map.setSize(Stage.width - 2*__map._x, Stage.height - 2*__map._y); |
|---|
| 201 |
|
|---|
| 202 |
__navButtons._x = __map._x; |
|---|
| 203 |
__navButtons._y = __map._y - __navButtons._height - 10; |
|---|
| 204 |
|
|---|
| 205 |
__mapButtons._x = __map._x + (Stage.width - 2*__map._x) - __mapButtons._width - 10; |
|---|
| 206 |
__mapButtons._y = __map._y + 10; |
|---|
| 207 |
|
|---|
| 208 |
__status._width = __map.getSize()[0]; |
|---|
| 209 |
__status._x = __map._x + 2; |
|---|
| 210 |
__status._y = __map._y + __map.getSize()[1]; |
|---|
| 211 |
} |
|---|
| 212 |
|
|---|
| 213 |
private static function onPanned( delta : Point ):Void |
|---|
| 214 |
{ |
|---|
| 215 |
__status.text = 'Panned by '+ delta.toString() +', top left: '+__map.getExtent().northWest.toString()+', bottom right: '+__map.getExtent().southEast.toString(); |
|---|
| 216 |
} |
|---|
| 217 |
|
|---|
| 218 |
private static function onStopPan():Void |
|---|
| 219 |
{ |
|---|
| 220 |
__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]; |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
private static function onZoomed( delta : Number ):Void |
|---|
| 224 |
{ |
|---|
| 225 |
__status.text = 'Zoomed by '+delta.toString()+', top left: '+__map.getExtent().northWest.toString()+', bottom right: '+__map.getExtent().southEast.toString(); |
|---|
| 226 |
} |
|---|
| 227 |
|
|---|
| 228 |
private static function onStopZoom( zoomLevel : Number ):Void |
|---|
| 229 |
{ |
|---|
| 230 |
__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]; |
|---|
| 231 |
} |
|---|
| 232 |
|
|---|
| 233 |
private static function onResized( width : Number, height : Number ):Void |
|---|
| 234 |
{ |
|---|
| 235 |
__status.text = 'Resized to: '+ width +' x '+ height; |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
private static function onMarkerEnters( id : String, location : Location ):Void |
|---|
| 239 |
{ |
|---|
| 240 |
trace('+ '+id+' =)'); |
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
private static function onMarkerLeaves( id : String, location : Location ):Void |
|---|
| 244 |
{ |
|---|
| 245 |
trace('- '+id+' =('); |
|---|
| 246 |
} |
|---|
| 247 |
} |
|---|