我可以在Google Map的Groundoverlay中使用Sprite吗?

时间:2011-05-13 09:25:27

标签: flash google-maps

(使用闪光灯) 我有一个想要在谷歌地图上显示的Sprite对象。所以我使用我的Sprite对象创建了一个GroundOverlay对象,但它没有显示出来。我想这是因为Sprite比DisplayObject更高级。 (GroundOverlay似乎只获得了DisplayObject ..?)我们的Sprite对于我的GroundOverlay有什么方法吗?还是另类的想法?

1 个答案:

答案 0 :(得分:0)

我从这个网站上获取此代码,我不记得确切的链接,但你可以尝试,它几乎是你想做的...

package

{     import flash.display。;     import flash.geom。;     导入com.google.maps。*;

public class sample extends Sprite
{
               private var polyLayer:Sprite = new Sprite();
               private var mapLayer:Sprite = new Sprite();
               private var map:Map = new Map();
               private var center:LatLng = new LatLng(36.469889,-93.949641);

               private var state:String = "39.108751,-94.586848 35.160337,-90.049495 35.474091,-97.520198";

               public function sample()
               {
                               addChild(mapLayer);
                               addChild(polyLayer);
                               map.key = "*** HERE YOUR API KEY ***";
                               map.sensor = 'false';
                               map.setSize(new Point(800, 600));
                               map.addEventListener(MapEvent.MAP_READY, function(event:MapEvent) {
                                               map.enableScrollWheelZoom();
                                               map.setMapType(MapType.NORMAL_MAP_TYPE);
                                               map.setCenter(center, 6);
                                               redrawPolygons();
                               });

                               map.addEventListener(MapZoomEvent.ZOOM_CHANGED, function(event:MapZoomEvent) {
                                               redrawPolygons();
                               });

                               map.addEventListener(MapMouseEvent.DRAG_STEP, function(event:MapMouseEvent) {
                                               redrawPolygons();
                               });

                               mapLayer.addChild(map);
               }


               private function redrawPolygons():void
               {
                               polyLayer.graphics.clear();
                               polyLayer.graphics.lineStyle(1,0x000000,0.8);
                               polyLayer.graphics.beginFill(0xFF0000,0.5);
                               var coo:Array = state.split(" ");
                               for (var g=0; g<coo.length; g++) {
                                               var latlon:LatLng = LatLng.fromUrlValue(coo[g]);
                                               if (g==0) 
                                                    polyLayer.graphics.moveTo(map.fromLatLngToViewport(latlon).x, map.fromLatLngToViewport(latlon).y);
                                               else
                                                    polyLayer.graphics.lineTo(map.fromLatLngToViewport(latlon).x, map.fromLatLngToViewport(latlon).y);
                               }

                               polyLayer.graphics.endFill();
               }
}

}