首先从google 官方搞到一个SDK,他有flex和flash两个版本的swc,分别考入flash的文件夹内。注意flashcs3和flashcs4的文件夹是不一样的。然后按ctrl+f7,组件列表里面就会出现googlemap的图标,把它拖动到舞台上,然后删除掉,这样它就在你的library里面啦。好,首先我们先try一下直接的应用。
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player .)
package{
import flash.display .* ;
import flash.net .URLRequest ;
import flash.net .URLLoader ;
import flash.events .* ;
import flash.geom .* ;
import com.google .maps .MapEvent ;
import com.google .maps .Map ;
import com.google .maps .overlays .Marker ;
import com.google .maps .MapType ;
import com.google .maps .LatLng ;
import com.google .maps .LatLngBounds ;
import com.google .maps .controls .MapTypeControl ;
import com.google .maps .controls .ZoomControl ;
import com.google .maps .controls .PositionControl ;
import com.google .maps .controls .MapTypeControlOptions ;
import com.google .maps .controls .ZoomControlOptions ;
import com.google .maps .controls .PositionControlOptions ;
import com.google .maps .controls .ControlPosition ;
import com.google .maps .overlays .Marker ;
import com.google .maps .overlays .MarkerOptions ;
import com.google .maps .MapType ;
import com.google .maps .LatLng ;
import com.google .maps .styles .FillStyle ;
import com.google .maps .styles .StrokeStyle ;
public class contact extends MovieClip {
public var map:Map;
public var mapContainer:Sprite;
public function contact( ) {
map=new Map( ) ;
map.key ="ABQIAAAAhg20Q7yYKzNcG1q8c73SMRTiw-BtopF4xhpGp7qpySedZVuuIBTCAq2k1cZ3VPDsSxYYcUeGYs-pIg" ;
map.setSize ( new Point( 400 ,400 ) ) ;
map.x =0
map.y =0
map.language ="zh-cn" ;
map.addEventListener ( MapEvent.MAP_READY , onMapReady) ;
mapContainer = new Sprite( ) ;
mapContainer.addChild ( map) ;
addChild( mapContainer) ;
}
public function onMapReady( event:Event) :void {
trace ( "map ready" ) ;
map.setCenter ( new LatLng( 31.231307277713867 ,121.46057367324829 ) , 17 , MapType.NORMAL_MAP_TYPE ) ;
//var topLeft:ControlPosition=new ControlPosition(ControlPosition.ANCHOR_TOP_LEFT,20,14);
//var myZoomControl:ZoomControl=new ZoomControl(new ZoomControlOptions({position:topLeft}));
//map.addControl(myZoomControl);
//var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
//map.addControl(new ZoomControl(),topRight);
//map.addControl(new PositionControl());
//map.removeMapType(MapType.HYBRID_MAP_TYPE);
//map.removeMapType(MapType.PHYSICAL_MAP_TYPE);
//map.addControl(new MapTypeControl());
var markerA:Marker = new Marker(
new LatLng( 31.231307277713867 ,121.46057367324829 ) ,
new MarkerOptions( {
strokeStyle: new StrokeStyle( { color : 0x000000} ) ,
fillStyle: new FillStyle( { color : 0x00CBFF, alpha: 0.8 } ) ,
radius: 12 ,
hasShadow: true
} ) ) ;
map.addOverlay ( markerA) ;
}
}
}
再来看一下如何应用到papervision中,googlemap不能直接作为材质进行渲染,所以有高人想到了用bitmap.draw的办法,转换为bitmap,再贴到各种形状上,当然,这样的googlemap是不能进行互动的,比如不能缩放,不能拖动。在flash cs4里面,用flash cs4自带的3d api能直接操作google map,这个以后会讨论到. 由于flash的bitmap.draw()有security的限制(adobe的说法是防止远程拷贝机密的档案照片等)。所以在这边无法显示,除非googlemap公布crossdomian的用法。
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player .)
package {
import flash.display .* ;
import flash.events .* ;
import flash.utils .* ;
import flash.filters .* ;
import org.papervision3d .cameras .* ;
import org.papervision3d .materials .* ;
import org.papervision3d .objects .primitives .Cube ;
import org.papervision3d .materials .utils .MaterialsList ;
import org.papervision3d .objects .* ;
import org.papervision3d .scenes .* ;
import org.papervision3d .view .BasicView ;
import com.google .maps .Map ;
import com.google .maps .MapEvent ;
import com.google .maps .MapType ;
import com.google .maps .LatLng ;
import flash.geom .Point ;
import flash.geom .Matrix ;
public class pv3dGoogleMap extends BasicView {
private var cubeObj:Cube;
private var planeSize:int =300 ;
private var valx:Number =0 ;
private var valy:Number =0 ;
private var map:Map;
private var mapContainer:Sprite;
static public const
TEXTURE_W:int = 360 ,
TEXTURE_H:int = 360 ,
SCREEN_W:int = 400 ,
SCREEN_H:int = 400 ;
public function pv3dGoogleMap( ) {
//初期化
super ( ) ;
init( ) ;
//フレームレート表示
//showFPS();
}
public function init( ) {
map=new Map( ) ;
map.key ="ABQIAAAAhg20Q7yYKzNcG1q8c73SMRTiw-BtopF4xhpGp7qpySedZVuuIBTCAq2k1cZ3VPDsSxYYcUeGYs-pIg" ;
//The Point object represents a location in a
//two-dimensional coordinate system, where x
//represents the horizontal axis and y represents the vertical axis.
//methods and properties of the following classes use Point object
//Bitmapdata
//displayobject
//displayobjectcontainer
//displacementmapfilter
//nativewindow
//matrix
//rectangle
map.setSize ( new Point( TEXTURE_W,TEXTURE_H) ) ;
map.addEventListener ( MapEvent.MAP_READY ,function ( event:Event) :void { ;
//map.setCenter(new LatLng(35.698684,139.774214), 17, MapType.NORMAL_MAP_TYPE);
map.setCenter ( new LatLng( 31.231307277713867 ,121.46057367324829 ) , 17 , MapType.NORMAL_MAP_TYPE ) ;
map.disableDragging ( ) ;
} ) ;
mapContainer=new Sprite( ) ;
mapContainer.addChild ( map) ;
addChild( mapContainer) ;
mapContainer.visible =false ;
stage .frameRate =60 ;
stage .quality ="MEDIUM" ;
stage .align =StageAlign.TOP_LEFT ;
//this.stage.addEventListener(Event.RESIZE,onStageResize);
var bmpData:BitmapData=new BitmapData( TEXTURE_W,TEXTURE_H) ;
//materiallist
var ml:MaterialsList=new MaterialsList( {
all:new BitmapMaterial( bmpData) ,
front:new BitmapMaterial( bmpData) ,
back:new BitmapMaterial( bmpData) ,
right :new BitmapMaterial( bmpData) ,
left :new BitmapMaterial( bmpData) ,
top:new BitmapMaterial( bmpData) ,
bottom:new BitmapMaterial( bmpData)
} ) ;
cubeObj=new Cube( ml,planeSize,planeSize,planeSize,1 ,1 ,1 ) ;
cubeObj.material .lineColor =0x00ffffff;
cubeObj.material .lineAlpha =1 ;
scene.addChild ( cubeObj) ;
cubeObj.rotationX =45 ;
cubeObj.rotationY =45 ;
var filter:Array =new Array ;
filter.push ( new DropShadowFilter( ) ) ;
cubeObj.filters =filter
camera .zoom =100
startRendering( ) ;
}
override protected function onRenderTick( event:Event = null ) :void {
valx+=mouseX/150 ;
valy+=mouseY/150 ;
cubeObj.rotationY =valx;
cubeObj.rotationX =valy;
cubeObj.material .bitmap .draw ( mapContainer) ;
super .onRenderTick ( ) ;
}
private function onStageResize( event:Event) :void {
viewport.x =this .stage .stageWidth /2 ;
viewport.y =this .stage .stageHeight /2 ;
}
}
}