Created
June 29, 2011 10:00
-
-
Save wwwins/1053564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map = new Map(); | |
map.key = API_KEY; | |
map.sensor = "false"; // sensor to determine the user's location(mobile) | |
map.setSize(new Point(stage.stageWidth, stage.stageHeight)); | |
map.addEventListener(MapEvent.MAP_PREINITIALIZE, onPreInit); | |
map.addEventListener(MapEvent.MAP_READY, onMapReady); | |
addChild(map); | |
private function onMapReady(e:MapEvent):void | |
{ | |
//地圖控制列 | |
map.addControl(new NavigationControl()); | |
map.addEventListener(MapMouseEvent.CLICK, addMarker); | |
// create random marker | |
addRandomMarker(); | |
} | |
private function onPreInit(e:MapEvent):void | |
{ | |
//客制化地圖樣式 | |
//參考http://gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.html | |
var options:StyledMapTypeOptions = new StyledMapTypeOptions( { name:'mystyle', alt:'custom style' } ); | |
var styles:Array = [ | |
new MapTypeStyle(MapTypeStyleFeatureType.ALL, MapTypeStyleElementType.ALL, [MapTypeStyleRule.hue(0xffb300), MapTypeStyleRule.gamma(1.05), MapTypeStyleRule.lightness(1.0)]), | |
new MapTypeStyle(MapTypeStyleFeatureType.ROAD, MapTypeStyleElementType.ALL, [MapTypeStyleRule.hue(0xffaa00), MapTypeStyleRule.gamma(1.26), MapTypeStyleRule.lightness(29.0), MapTypeStyleRule.saturation(11)]), | |
new MapTypeStyle(MapTypeStyleFeatureType.ADMINISTRATIVE_LOCALITY, MapTypeStyleElementType.ALL, [MapTypeStyleRule.visibility("off")]), | |
new MapTypeStyle(MapTypeStyleFeatureType.ADMINISTRATIVE_NEIGHBORHOOD, MapTypeStyleElementType.ALL, [MapTypeStyleRule.visibility("off")]), | |
new MapTypeStyle(MapTypeStyleFeatureType.ROAD_LOCAL, MapTypeStyleElementType.ALL, [MapTypeStyleRule.visibility("off")]), | |
new MapTypeStyle(MapTypeStyleFeatureType.LANDSCAPE, MapTypeStyleElementType.ALL, [MapTypeStyleRule.visibility("off")]) | |
]; | |
var styleMapType:StyledMapType = new StyledMapType(styles, options); | |
var myMapOptions:MapOptions = new MapOptions(); | |
myMapOptions.mapTypes = [styleMapType]; | |
myMapOptions.mapType = styleMapType; | |
myMapOptions.zoom = 14; | |
myMapOptions.center = new LatLng(25.0931667, 121.525); // taipei | |
//myMapOptions.viewMode = View.VIEWMODE_PERSPECTIVE; | |
//myMapOptions.attitude = new Attitude(0,30,0); | |
map.setInitOptions(myMapOptions); | |
} | |
private function addMarker(e:MapMouseEvent):void | |
{ | |
// marker | |
if (!marker) { | |
// 設定 marker屬性:draggable, icon, iconOffset, tooltip | |
marker = new Marker(e.latLng, new MarkerOptions( { draggable:true, icon:new ImageClass(), iconAlignment:MarkerOptions.ALIGN_HORIZONTAL_CENTER, iconOffset:new Point(10, -50), tooltip:"使用滑鼠拖曳標記,選好地點後,即開始進行作品上傳。" } )); | |
marker.addEventListener(MapMouseEvent.CLICK, openInfoWindow); | |
marker.addEventListener(MapMouseEvent.DRAG_START, closeInfoWindow); | |
marker.addEventListener(MapMouseEvent.DRAG_END, openInfoWindow); | |
map.addOverlay(marker); | |
} | |
else { | |
//設定座標 | |
marker.setLatLng(e.latLng); | |
} | |
private function closeInfoWindow(e:MapMouseEvent):void | |
{ | |
map.closeInfoWindow(); | |
} | |
private function openInfoWindow(e:MapMouseEvent):void | |
{ | |
map.openInfoWindow(e.latLng, new InfoWindowOptions( { content:"標記我的城市" + e.latLng } )); | |
} | |
private function addRandomMarker():void | |
{ | |
var i:uint = 0; | |
for (i = 0; i < 50; i++) { | |
map.addOverlay(new Marker(getRandomPoint())); | |
} | |
} | |
// return the current viewport LatLng in the bounds | |
private function getRandomPoint():LatLng | |
{ | |
var bounds:LatLngBounds = map.getLatLngBounds(); | |
var southWest:LatLng = bounds.getSouthWest(); | |
var northEast:LatLng = bounds.getNorthEast(); | |
var lngSpan:Number = northEast.lng() - southWest.lng() | |
var latSpan:Number = northEast.lat() - southWest.lat(); | |
var newLat:Number = southWest.lat() + (latSpan * Math.random()); | |
var newLng:Number = southWest.lng() + (lngSpan * Math.random()); | |
return new LatLng(newLat, newLng); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment