| 1 | package
|
|---|
| 2 | {
|
|---|
| 3 | import flash.display.*;
|
|---|
| 4 | import flash.events.*;
|
|---|
| 5 | import flash.text.*;
|
|---|
| 6 | import flash.geom.*;
|
|---|
| 7 | import flash.external.*;
|
|---|
| 8 | import exl.trans3d.*;
|
|---|
| 9 | import exl.render.collada.*;
|
|---|
| 10 | import exl.render.util.*;
|
|---|
| 11 | import exl.advanced.*;
|
|---|
| 12 | import com.google.maps.Map;
|
|---|
| 13 | import com.google.maps.MapType;
|
|---|
| 14 | import com.google.maps.MapEvent;
|
|---|
| 15 | import com.google.maps.MapMoveEvent;
|
|---|
| 16 | import com.google.maps.MapZoomEvent;
|
|---|
| 17 | import com.google.maps.LatLng;
|
|---|
| 18 | import com.google.maps.controls.*;
|
|---|
| 19 |
|
|---|
| 20 | public class GMapKMZ extends STDOUT
|
|---|
| 21 | {
|
|---|
| 22 | public static const DPI:Number = Math.PI * 2.0;
|
|---|
| 23 | public static const DEGTORAD:Number = 0.0174533;
|
|---|
| 24 | private var XY_PER_M:Number;
|
|---|
| 25 |
|
|---|
| 26 | private var mGMap:MyGMap;
|
|---|
| 27 | private var mMapMask:Sprite;
|
|---|
| 28 | private var mViewTrans:M44;
|
|---|
| 29 | private var mBaseTransForModel:M44 = new M44();
|
|---|
| 30 | private var mViewTransForModel:M44 = new M44();
|
|---|
| 31 | private var mViewSpriteTrans:Matrix = new Matrix();
|
|---|
| 32 | private var mDragPoint:Point = new Point();
|
|---|
| 33 | private var mMapRoot:Sprite;
|
|---|
| 34 | private var mModelLayer:Sprite;
|
|---|
| 35 | private var mCurrentKMZTitle:String = null;
|
|---|
| 36 |
|
|---|
| 37 | private var mMarkerLayer:MarkerLayer;
|
|---|
| 38 | private var mPrimaryMarker:ZMarker;
|
|---|
| 39 |
|
|---|
| 40 | private var mRZ:Number = 0;
|
|---|
| 41 | private var mRX:Number = 0;
|
|---|
| 42 |
|
|---|
| 43 | private var ttw:Map3DObject;
|
|---|
| 44 | private var mTextureConfirm:ConfirmBox;
|
|---|
| 45 |
|
|---|
| 46 | private var mLoadingLabel:TextLabel;
|
|---|
| 47 | private var mQualitySwitcher:QualitySwitcher;
|
|---|
| 48 | function GMapKMZ()
|
|---|
| 49 | {
|
|---|
| 50 | mQualitySwitcher = new QualitySwitcher(this);
|
|---|
| 51 | drawBase(graphics, 640, 480);
|
|---|
| 52 |
|
|---|
| 53 | mMapRoot = new Sprite();
|
|---|
| 54 | addChild(mMapRoot);
|
|---|
| 55 |
|
|---|
| 56 | mModelLayer = new Sprite();
|
|---|
| 57 | mModelLayer.mouseEnabled = false;
|
|---|
| 58 | addChild(mModelLayer);
|
|---|
| 59 |
|
|---|
| 60 | mGMap = new MyGMap();
|
|---|
| 61 | mGMap.setSize(new Point(640, 480));
|
|---|
| 62 | mMapRoot.addChild(mGMap);
|
|---|
| 63 |
|
|---|
| 64 | mGMap.addEventListener(MapEvent.MAP_READY, onMapReady);
|
|---|
| 65 |
|
|---|
| 66 | mGMap.x = -320;
|
|---|
| 67 | mGMap.y = -240;
|
|---|
| 68 |
|
|---|
| 69 | tx.width = 640;
|
|---|
| 70 | tx.height = 480;
|
|---|
| 71 |
|
|---|
| 72 | mMapMask = new Sprite();
|
|---|
| 73 | var mg:Graphics = mMapMask.graphics;
|
|---|
| 74 | mg.beginFill(0);
|
|---|
| 75 | mg.drawRect(-320, -240, 640, 480);
|
|---|
| 76 | mMapMask.visible = false;
|
|---|
| 77 | mMapRoot.addChild(mMapMask);
|
|---|
| 78 |
|
|---|
| 79 | mLoadingLabel = new TextLabel("Loading...");
|
|---|
| 80 | mLoadingLabel.x = 320;
|
|---|
| 81 | mLoadingLabel.y = 240;
|
|---|
| 82 | addChild(mLoadingLabel);
|
|---|
| 83 |
|
|---|
| 84 | removeChild(tx);
|
|---|
| 85 | addChild(tx);
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | protected function drawBase(g:Graphics, w:int, h:int):void
|
|---|
| 89 | {
|
|---|
| 90 | const gtype:String = GradientType.LINEAR;
|
|---|
| 91 | const gclrs:Array = [0xf0f0f0, 0xd0d4d9];
|
|---|
| 92 | const galphas:Array = [1, 1];
|
|---|
| 93 | const gratios:Array = [0, 130];
|
|---|
| 94 | const gtrans:Matrix = new Matrix(0, -.2, .2, 0, 20, 20);
|
|---|
| 95 |
|
|---|
| 96 | g.beginGradientFill(gtype, gclrs, galphas, gratios, gtrans);
|
|---|
| 97 | g.drawRect(0, 0, w, h);
|
|---|
| 98 | g.endFill();
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | public static const rxKMZNAME:RegExp = /([-a-zA-Z0-9_]+)\.[Kk][Mm][Zz]/;
|
|---|
| 102 | private function onMapReady(event:MapEvent):void
|
|---|
| 103 | {
|
|---|
| 104 | var zc:ZoomControl = new ZoomControl();
|
|---|
| 105 | addChild(zc);
|
|---|
| 106 | zc.initControlWithMap(mGMap);
|
|---|
| 107 | zc.x = 8;
|
|---|
| 108 | zc.y = 8;
|
|---|
| 109 |
|
|---|
| 110 | var tc:MapTypeControl = new MapTypeControl();
|
|---|
| 111 | addChild(tc);
|
|---|
| 112 | tc.initControlWithMap(mGMap);
|
|---|
| 113 | tc.x = 363;
|
|---|
| 114 | tc.y = 8;
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 | mGMap.setCenter(new LatLng(36.099834,139.654923), 17, MapType.NORMAL_MAP_TYPE);
|
|---|
| 118 |
|
|---|
| 119 | addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveCapture, true);
|
|---|
| 120 | addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownCapture, true);
|
|---|
| 121 | mGMap.addEventListener(MapMoveEvent.MOVE_STEP, onGMapMove);
|
|---|
| 122 | mGMap.addEventListener(MapMoveEvent.MOVE_END, onGMapMove);
|
|---|
| 123 | mGMap.addEventListener(MapZoomEvent.ZOOM_STEP, onGMapZoom);
|
|---|
| 124 | mGMap.addEventListener(MapZoomEvent.ZOOM_END, onGMapZoom);
|
|---|
| 125 |
|
|---|
| 126 | mGMap.ready = true;
|
|---|
| 127 |
|
|---|
| 128 | ///////////////////////////////////
|
|---|
| 129 | var loadpath:String = ExternalInterface.call("kmzparam") || "LandmarkTower.kmz";
|
|---|
| 130 | ttw = new Map3DObject(loadpath);
|
|---|
| 131 |
|
|---|
| 132 | mModelLayer.addChild(ttw);
|
|---|
| 133 | ttw.mouseChildren = false;
|
|---|
| 134 | ttw.mouseEnabled = false;
|
|---|
| 135 | ttw.visible = false;
|
|---|
| 136 | ttw.addEventListener("map3dobj_complete", onMap3DObjComplete);
|
|---|
| 137 | ///////////////////////////////////
|
|---|
| 138 | addChild(mMarkerLayer = new MarkerLayer(this));
|
|---|
| 139 | mMarkerLayer.mask = mMapMask;
|
|---|
| 140 |
|
|---|
| 141 | try{
|
|---|
| 142 | var this_name:String;
|
|---|
| 143 | var p_name:String;
|
|---|
| 144 | var rxres:Object;
|
|---|
| 145 |
|
|---|
| 146 | this_name = rxKMZNAME.exec(loadpath)[1];
|
|---|
| 147 | mCurrentKMZTitle = this_name;
|
|---|
| 148 |
|
|---|
| 149 | var p_list:Array = ExternalInterface.call("geopoint_list") as Array;
|
|---|
| 150 | for each(var poi:Object in p_list)
|
|---|
| 151 | {
|
|---|
| 152 | rxres = rxKMZNAME.exec(poi.link);
|
|---|
| 153 | if (!rxres) continue;
|
|---|
| 154 | p_name = rxres[1];
|
|---|
| 155 | if (!p_name) continue;
|
|---|
| 156 | if (p_name == this_name)
|
|---|
| 157 | continue;
|
|---|
| 158 |
|
|---|
| 159 | var mk:ZMarker = createArrowMarker(0xccbbaa);
|
|---|
| 160 | mk.lat = poi.lat;
|
|---|
| 161 | mk.lng = poi.lng;
|
|---|
| 162 | mk.link = poi.link;
|
|---|
| 163 | mk.title = poi.title;
|
|---|
| 164 | mk.createTitleLabel();
|
|---|
| 165 | mMarkerLayer.addMarker(mk);
|
|---|
| 166 | }
|
|---|
| 167 | } catch(e:Error) {
|
|---|
| 168 | STDOUT.puts(e);
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 | updateTransform();
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | public static function createArrowMarker(clr:uint):ZMarker
|
|---|
| 176 | {
|
|---|
| 177 | var m:ZMarker = new ZMarker();
|
|---|
| 178 | var g:Graphics = m.graphics;
|
|---|
| 179 | g.lineStyle(1, 0xffffff);
|
|---|
| 180 | g.beginFill(clr);
|
|---|
| 181 | g.moveTo(0, 0);
|
|---|
| 182 | g.lineTo(8, -10);
|
|---|
| 183 | g.lineTo(3, -10);
|
|---|
| 184 | g.lineTo(3, -19);
|
|---|
| 185 | g.lineTo(-3, -19);
|
|---|
| 186 | g.lineTo(-3, -10);
|
|---|
| 187 | g.lineTo(-8, -10);
|
|---|
| 188 | g.lineTo(0, 0);
|
|---|
| 189 | g.endFill();
|
|---|
| 190 |
|
|---|
| 191 | return m;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | protected function onMap3DObjComplete(e:Event):void
|
|---|
| 195 | {
|
|---|
| 196 | XY_PER_M = 1.0 / (Math.cos(ttw.modelPlacement.lat * DEGTORAD) * 40074000);
|
|---|
| 197 | mPrimaryMarker = createArrowMarker(0xee4422);
|
|---|
| 198 | mPrimaryMarker.lat = ttw.modelPlacement.lat;
|
|---|
| 199 | mPrimaryMarker.lng = ttw.modelPlacement.lng;
|
|---|
| 200 | mPrimaryMarker.title = "HERE";
|
|---|
| 201 | mPrimaryMarker.createTitleLabel(true);
|
|---|
| 202 | mMarkerLayer.addMarker(mPrimaryMarker);
|
|---|
| 203 |
|
|---|
| 204 | update3DLayer(true, true);
|
|---|
| 205 | ttw.visible = true;
|
|---|
| 206 | mGMap.setCenter(new LatLng(ttw.modelPlacement.lat, ttw.modelPlacement.lng), 16, MapType.NORMAL_MAP_TYPE);
|
|---|
| 207 |
|
|---|
| 208 | removeChild(mLoadingLabel);
|
|---|
| 209 | mLoadingLabel.dispose();
|
|---|
| 210 |
|
|---|
| 211 | if (ttw.texturePool)
|
|---|
| 212 | showTextureConfirm();
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | protected function showTextureConfirm():void
|
|---|
| 216 | {
|
|---|
| 217 | mTextureConfirm = new ConfirmBox("Load texture?", onTextureLoadYes, onTextureLoadNo);
|
|---|
| 218 | mTextureConfirm.x = 10;
|
|---|
| 219 | mTextureConfirm.y = 448;
|
|---|
| 220 | addChild(mTextureConfirm);
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | protected function onTextureLoadYes(e:MouseEvent):void
|
|---|
| 224 | {
|
|---|
| 225 | removeChild(mTextureConfirm);
|
|---|
| 226 | ttw.texturePool.loadAll(onTextureLoaded);
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | protected function onTextureLoaded(name:String, bmp:Bitmap, count:int):void
|
|---|
| 230 | {
|
|---|
| 231 | if (isZoomLevelTownLevel)
|
|---|
| 232 | ttw.drawOnly();
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | protected function onTextureLoadNo(e:MouseEvent):void
|
|---|
| 236 | {
|
|---|
| 237 | removeChild(mTextureConfirm);
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | protected function onMouseDownCapture(e:MouseEvent):void
|
|---|
| 241 | {
|
|---|
| 242 | if (e.ctrlKey || e.shiftKey)
|
|---|
| 243 | e.stopPropagation();
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | protected function onMouseMoveCapture(e:MouseEvent):void
|
|---|
| 247 | {
|
|---|
| 248 | if (e.ctrlKey || e.shiftKey)
|
|---|
| 249 | {
|
|---|
| 250 | e.stopPropagation();
|
|---|
| 251 | }
|
|---|
| 252 | onMouseMove(e);
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | protected function onMouseMove(e:MouseEvent):void
|
|---|
| 256 | {
|
|---|
| 257 | if (e.buttonDown)
|
|---|
| 258 | {
|
|---|
| 259 | var dx:int = stage.mouseX - mDragPoint.x;
|
|---|
| 260 | var dy:int = stage.mouseY - mDragPoint.y;
|
|---|
| 261 |
|
|---|
| 262 | if (e.ctrlKey || e.shiftKey)
|
|---|
| 263 | {
|
|---|
| 264 | mQualitySwitcher.switchLow();
|
|---|
| 265 | roll(Number(dx) * -0.01, Number(dy) * -0.01);
|
|---|
| 266 | }
|
|---|
| 267 | e.updateAfterEvent();
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | mDragPoint.x = stage.mouseX;
|
|---|
| 271 | mDragPoint.y = stage.mouseY;
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | protected function roll(rz:Number, rx:Number):void
|
|---|
| 275 | {
|
|---|
| 276 | mRZ += rz;
|
|---|
| 277 | if (mRZ < 0) mRZ += DPI;
|
|---|
| 278 | if (mRZ >= DPI) mRZ -= DPI;
|
|---|
| 279 |
|
|---|
| 280 | mRX += rx;
|
|---|
| 281 | if (mRX > 0) mRX = 0;
|
|---|
| 282 | if (mRX < -1.3) mRX = -1.3;
|
|---|
| 283 | updateTransform();
|
|---|
| 284 | update3DLayer(true);
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | protected function updateTransform():void
|
|---|
| 288 | {
|
|---|
| 289 | var mrz:M44 = (new M44()).rotZ(mRZ);
|
|---|
| 290 | var mrx:M44 = (new M44()).rotX(mRX);
|
|---|
| 291 |
|
|---|
| 292 | var m:M44 = new M44();
|
|---|
| 293 | m.mul(mrz, mrx);
|
|---|
| 294 |
|
|---|
| 295 | mViewTransForModel = m;
|
|---|
| 296 |
|
|---|
| 297 | mViewSpriteTrans.a = m._11;
|
|---|
| 298 | mViewSpriteTrans.b = m._12;
|
|---|
| 299 |
|
|---|
| 300 | mViewSpriteTrans.c = m._21;
|
|---|
| 301 | mViewSpriteTrans.d = m._22;
|
|---|
| 302 |
|
|---|
| 303 | mViewSpriteTrans.tx = 320;
|
|---|
| 304 | mViewSpriteTrans.ty = 240 - (mRX*100);
|
|---|
| 305 |
|
|---|
| 306 | mMapRoot.transform.matrix = mViewSpriteTrans;
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | public function convertLatLngtoScreenPos(lat:Number, lng:Number, out:Point):void
|
|---|
| 310 | {
|
|---|
| 311 | calcScreenPos(mMapRoot.transform.matrix, mGMap, lat, lng, out);
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | public static function calcScreenPos(trans:Matrix, gmap:Map, lat:Number, lng:Number, out:Point):void
|
|---|
| 315 | {
|
|---|
| 316 | var ll:LatLng = gmap.getCenter();
|
|---|
| 317 | var sz:Number = GMapCalc.calcMapSize(gmap.getZoom());
|
|---|
| 318 | var ptC:Point = new Point();
|
|---|
| 319 |
|
|---|
| 320 | GMapCalc.LatLngToXY(ll.lat() * DEGTORAD, ll.lng() * DEGTORAD, ptC);
|
|---|
| 321 |
|
|---|
| 322 | GMapCalc.LatLngToXY(lat * DEGTORAD, lng * DEGTORAD, out);
|
|---|
| 323 |
|
|---|
| 324 | out.x *= sz;
|
|---|
| 325 | out.y *= sz;
|
|---|
| 326 | ptC.x *= sz;
|
|---|
| 327 | ptC.y *= sz;
|
|---|
| 328 |
|
|---|
| 329 | out.x -= ptC.x;
|
|---|
| 330 | out.y -= ptC.y;
|
|---|
| 331 |
|
|---|
| 332 | var tx:Number = out.x;
|
|---|
| 333 | var ty:Number = out.y;
|
|---|
| 334 | out.x = trans.a * tx + trans.c * ty + trans.tx;
|
|---|
| 335 | out.y = trans.b * tx + trans.d * ty + trans.ty;
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | protected function onGMapMove(e:MapMoveEvent):void
|
|---|
| 339 | {
|
|---|
| 340 | if (mGMap.ready)
|
|---|
| 341 | update3DLayer(false);
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | protected function onGMapZoom(e:MapZoomEvent):void
|
|---|
| 345 | {
|
|---|
| 346 | if (mGMap.ready)
|
|---|
| 347 | update3DLayer(false, true);
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | protected function update3DLayer(rotate:Boolean, zoom:Boolean = false):void
|
|---|
| 351 | {
|
|---|
| 352 | if (!ttw.complete) return;
|
|---|
| 353 |
|
|---|
| 354 | var spos:Point = new Point();
|
|---|
| 355 | var placement:KModelPlacement = ttw.modelPlacement;
|
|---|
| 356 | convertLatLngtoScreenPos(placement.lat, placement.lng, spos);
|
|---|
| 357 | ttw.x = spos.x;
|
|---|
| 358 | ttw.y = spos.y;
|
|---|
| 359 |
|
|---|
| 360 | if (zoom)
|
|---|
| 361 | {
|
|---|
| 362 | var mRevX:M44 = (new M44()).rotX(Math.PI);
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 | mBaseTransForModel = mRevX;
|
|---|
| 366 | ttw.baseTransform = mBaseTransForModel;
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | if (rotate || zoom)
|
|---|
| 370 | {
|
|---|
| 371 | var sc:Number = GMapCalc.calcMapSize(mGMap.getZoom()) * XY_PER_M * ttw.model.meterPerUnit;
|
|---|
| 372 | var m:M44 = (new M44()).scaleXYZ(sc * placement.scaleX, sc * placement.scaleY, sc * placement.scaleZ);
|
|---|
| 373 |
|
|---|
| 374 | if (isZoomLevelTownLevel)
|
|---|
| 375 | ttw.viewTransform = (new M44()).mul(m, mViewTransForModel);
|
|---|
| 376 | else
|
|---|
| 377 | ttw.graphics.clear();
|
|---|
| 378 | }
|
|---|
| 379 |
|
|---|
| 380 | mMarkerLayer.update();
|
|---|
| 381 | mPrimaryMarker.visible = mGMap.getZoom() < 13;
|
|---|
| 382 | }
|
|---|
| 383 |
|
|---|
| 384 | private function get isZoomLevelTownLevel():Boolean
|
|---|
| 385 | {
|
|---|
| 386 | if (!mGMap)
|
|---|
| 387 | return false;
|
|---|
| 388 | return mGMap.getZoom() > 10;
|
|---|
| 389 | }
|
|---|
| 390 | }
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | class MyGMap extends com.google.maps.Map
|
|---|
| 394 | {
|
|---|
| 395 | public var ready:Boolean = false;
|
|---|
| 396 |
|
|---|
| 397 | function MyGMap()
|
|---|
| 398 | {
|
|---|
| 399 | super();
|
|---|
| 400 | // key = "ABQIAAAABxFFkLd0-1pnEhhkOq6s5RT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTn_p1iJ2v-X_A3pkHh6aueaBIRSw";
|
|---|
| 401 | }
|
|---|
| 402 | }
|
|---|
| 403 |
|
|---|
| 404 | class QualitySwitcher
|
|---|
| 405 | {
|
|---|
| 406 | import flash.display.*;
|
|---|
| 407 | import flash.events.*;
|
|---|
| 408 | private var mWait:uint = 0;
|
|---|
| 409 | private var mSprite:Sprite;
|
|---|
| 410 | private var mOriginalQ:String;
|
|---|
| 411 | function QualitySwitcher(s:Sprite)
|
|---|
| 412 | {
|
|---|
| 413 | mSprite = s;
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 | public function switchLow():void
|
|---|
| 417 | {
|
|---|
| 418 | if (mWait != 0) return;
|
|---|
| 419 |
|
|---|
| 420 | mWait = 2;
|
|---|
| 421 | mSprite.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
|---|
| 422 | mOriginalQ = mSprite.stage.quality;
|
|---|
| 423 | mSprite.stage.quality = StageQuality.LOW;
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | private function onEnterFrame(e:Event):void
|
|---|
| 427 | {
|
|---|
| 428 | if (--mWait == 0)
|
|---|
| 429 | {
|
|---|
| 430 | mSprite.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
|---|
| 431 | mSprite.stage.quality = mOriginalQ;
|
|---|
| 432 | }
|
|---|
| 433 | }
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | class MarkerLayer extends flash.display.Sprite
|
|---|
| 437 | {
|
|---|
| 438 | import flash.net.*;
|
|---|
| 439 | import flash.events.MouseEvent;
|
|---|
| 440 | import flash.geom.*;
|
|---|
| 441 | import flash.display.*;
|
|---|
| 442 | private var mKMZMap:GMapKMZ;
|
|---|
| 443 | private var mMarkers:Array;
|
|---|
| 444 |
|
|---|
| 445 | function MarkerLayer(kmzmap:GMapKMZ)
|
|---|
| 446 | {
|
|---|
| 447 | mKMZMap = kmzmap;
|
|---|
| 448 | mMarkers = [];
|
|---|
| 449 | /*
|
|---|
| 450 | var spos:Point = new Point();
|
|---|
| 451 | var placement:KModelPlacement = ttw.modelPlacement;
|
|---|
| 452 | calcScreenPos(placement.lat, placement.lng, spos);*/
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | public function addMarker(mk:ZMarker):void
|
|---|
| 456 | {
|
|---|
| 457 | mMarkers.push(mk);
|
|---|
| 458 | addChild(mk);
|
|---|
| 459 |
|
|---|
| 460 | if (mk.link)
|
|---|
| 461 | {
|
|---|
| 462 | mk.buttonMode = true;
|
|---|
| 463 | mk.addEventListener(MouseEvent.CLICK, onMarkerClick);
|
|---|
| 464 | }
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | protected function onMarkerClick(e:MouseEvent):void
|
|---|
| 468 | {
|
|---|
| 469 | if (e.target.link)
|
|---|
| 470 | navigateToURL(new URLRequest(e.target.link), "_self");
|
|---|
| 471 | }
|
|---|
| 472 |
|
|---|
| 473 | protected static function cmpY(a:Sprite, b:Sprite):int
|
|---|
| 474 | {
|
|---|
| 475 | return (a.y*10.0) - (b.y*10.0);
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | public function update():void
|
|---|
| 479 | {
|
|---|
| 480 | var pt:Point = new Point();
|
|---|
| 481 |
|
|---|
| 482 | for(;numChildren > 0;)
|
|---|
| 483 | removeChildAt(0);
|
|---|
| 484 |
|
|---|
| 485 | for each(var mk:ZMarker in mMarkers)
|
|---|
| 486 | {
|
|---|
| 487 | mKMZMap.convertLatLngtoScreenPos(mk.lat, mk.lng, pt);
|
|---|
| 488 | mk.x = int(pt.x);
|
|---|
| 489 | mk.y = int(pt.y);
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | mMarkers.sort(cmpY);
|
|---|
| 493 | for each(mk in mMarkers)
|
|---|
| 494 | {
|
|---|
| 495 | addChild(mk);
|
|---|
| 496 | }
|
|---|
| 497 | }
|
|---|
| 498 | }
|
|---|
| 499 |
|
|---|
| 500 | class ZMarker extends flash.display.Sprite
|
|---|
| 501 | {
|
|---|
| 502 | public var lat:Number;
|
|---|
| 503 | public var lng:Number;
|
|---|
| 504 | public var link:String = null;
|
|---|
| 505 | public var title:String = null;
|
|---|
| 506 |
|
|---|
| 507 | public function createTitleLabel(em:Boolean = false):void
|
|---|
| 508 | {
|
|---|
| 509 | var t:TextLabel = new TextLabel(title, em);
|
|---|
| 510 | addChild(t);
|
|---|
| 511 | t.y = -39;
|
|---|
| 512 | }
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | class TextLabel extends flash.display.Sprite
|
|---|
| 516 | {
|
|---|
| 517 | import flash.display.*;
|
|---|
| 518 | import flash.text.*;
|
|---|
| 519 | private static var fmt:TextFormat = null;
|
|---|
| 520 | private var mLabelBitmapData:BitmapData = null;
|
|---|
| 521 |
|
|---|
| 522 | function TextLabel(tx:String, em:Boolean = false)
|
|---|
| 523 | {
|
|---|
| 524 | if (!fmt)
|
|---|
| 525 | {
|
|---|
| 526 | fmt = new TextFormat();
|
|---|
| 527 | fmt.font = "Arial";
|
|---|
| 528 | fmt.color = 0xffffff;
|
|---|
| 529 | fmt.size = 10;
|
|---|
| 530 | }
|
|---|
| 531 |
|
|---|
| 532 | mouseEnabled = false;
|
|---|
| 533 | var tf:TextField = new TextField();
|
|---|
| 534 | tf.defaultTextFormat = fmt;
|
|---|
| 535 | tf.text = tx;
|
|---|
| 536 | tf.width = tf.textWidth+5;
|
|---|
| 537 | tf.height = tf.textHeight+3;
|
|---|
| 538 | tf.mouseEnabled = false;
|
|---|
| 539 |
|
|---|
| 540 | var bmp:BitmapData = new BitmapData(tf.width, tf.height, true, 0);
|
|---|
| 541 | bmp.draw(tf);
|
|---|
| 542 | var b:Bitmap = new Bitmap(bmp);
|
|---|
| 543 | addChild(b);
|
|---|
| 544 | b.x = -(tf.width/2);
|
|---|
| 545 | drawBase(tf.width, tf.height, em);
|
|---|
| 546 |
|
|---|
| 547 | mLabelBitmapData = bmp;
|
|---|
| 548 | }
|
|---|
| 549 |
|
|---|
| 550 | protected function drawBase(w:int, h:int, em:Boolean):void
|
|---|
| 551 | {
|
|---|
| 552 | var g:Graphics = graphics;
|
|---|
| 553 | g.clear();
|
|---|
| 554 |
|
|---|
| 555 | g.lineStyle(2, 0x000000, 0.3);
|
|---|
| 556 | g.beginFill(0x000000, 0.6);
|
|---|
| 557 |
|
|---|
| 558 | w += 4;
|
|---|
| 559 | h += 4;
|
|---|
| 560 | g.drawRoundRect(int(-w/2), -2, w, h, 6, 6);
|
|---|
| 561 |
|
|---|
| 562 | if (em)
|
|---|
| 563 | {
|
|---|
| 564 | g.lineStyle(1, 0xff6600);
|
|---|
| 565 | g.beginFill(0, 0);
|
|---|
| 566 | g.drawRoundRect(int(-w/2)+1, -1, w-3, h-3, 4, 4);
|
|---|
| 567 | }
|
|---|
| 568 | }
|
|---|
| 569 |
|
|---|
| 570 | public function dispose():void
|
|---|
| 571 | {
|
|---|
| 572 | if (mLabelBitmapData)
|
|---|
| 573 | {
|
|---|
| 574 | mLabelBitmapData.dispose();
|
|---|
| 575 | mLabelBitmapData = null;
|
|---|
| 576 | }
|
|---|
| 577 | }
|
|---|
| 578 | } |
|---|