google map自定义图层(带闪动和发光效果)

import com.google.maps.LatLng;
import com.google.maps.MapEvent;
import com.google.maps.MapZoomEvent;
import com.google.maps.PaneId;
import com.google.maps.interfaces.IMap;
import com.google.maps.interfaces.IPane;
import com.google.maps.overlays.OverlayBase;

import flash.display.DisplayObject;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.utils.Timer;

import mx.controls.Image;
import mx.effects.Glow;
import mx.effects.Sequence;

import spark.effects.Move3D;
import spark.effects.animation.RepeatBehavior;


public class CommonDisplayOverlay extends OverlayBase
{
private var latLng:LatLng;
private var display:DisplayObject;
private var timer:Timer;
private var flicker:Move3D;
private var flickerSeque:Sequence;
private var glowIn:Glow;
private var glowOut:Glow;

public function CommonDisplayOverlay(options:Object)
{
this.latLng = options.latLng;
this.display = options.display;
if(options.destroySecond > 0){
this.timer = new Timer(options.destroySecond * 1000, 1);
this.timer.addEventListener(TimerEvent.TIMER, destory);

if(options.move3D){
this.flicker = new Move3D();
flicker.repeatBehavior = RepeatBehavior.REVERSE;
flicker.zBy = -10; //修改目标的 z 位置所依据的像素数
flicker.duration = 500; //效果的持续时间(以毫秒为单位)。
flicker.repeatCount = 0;
flicker.target = this;
flicker.play();
}
if(options.glow){
this.flickerSeque = new Sequence();
this.glowIn = new Glow();
this.glowOut = new Glow();
glowIn.alphaFrom = 1;
glowIn.alphaTo = 0.2;
glowIn.blurXFrom = 0;
glowIn.blurXTo = 50;
glowIn.blurYFrom = 0;
glowIn.blurYTo = 50;
glowIn.color = 0xff0000;
glowOut.alphaFrom = 0.2;
glowOut.alphaTo = 0;
glowOut.blurXFrom = 50;
glowOut.blurXTo = 0;
glowOut.blurYFrom = 50;
glowOut.blurYTo = 0;
glowOut.color = 0xff0000;
flickerSeque.repeatCount = 0;
flickerSeque.addChild(glowIn);
flickerSeque.addChild(glowOut);
flickerSeque.repeatCount = 0;
flickerSeque.target = this;
flickerSeque.play();
}
this.addEventListener(MapEvent.OVERLAY_ADDED, onOverlayAdded);
this.addEventListener(MapEvent.OVERLAY_REMOVED, onOverlayRemoved);
this.addEventListener(MapZoomEvent.ZOOM_CHANGED,onMapZoomChanged);
}

/**********************************下面5个方法,每个自定义的overlaybase都要有*********************************/

public override function getDefaultPane(map:IMap):IPane {
return map.getPaneManager().getPaneById(PaneId.PANE_FLOAT);
}

private function onOverlayAdded(event:MapEvent):void {
this.addChild(display);
if(this.timer != null){
this.timer.start();
}
}

private function onOverlayRemoved(event:MapEvent):void {
if(flicker != null){
flicker.end();
}
this.removeChild(display);
}

private function onMapZoomChanged(event:MapZoomEvent):void {
var level:Number = 19 - event.zoomLevel;
this.display.scaleX = 1 - level / 10;
this.display.scaleY = 1 - level / 10; 
}

public override function positionOverlay(zoomChanged:Boolean):void {
var point:Point = this.pane.fromLatLngToPaneCoords(this.latLng);
this.display.x = point.x-this.display.width/2;
this.display.y = point.y-this.display.height/2;
}
/***********************************************************************************/


private function destory(event:TimerEvent) : void {
//this.removeChild(display);
this.pane.removeOverlay(this);
}
}

你可能感兴趣的:(google map自定义图层(带闪动和发光效果))