openscales 加载 google地图

<!-- lang: as3 -->
package com.maphao.shipsys.map.ascript.feature

{

import mx.collections.ArrayCollection;

import org.openscales.core.layer.osm.OSM;
import org.openscales.geometry.basetypes.Bounds;

public class GoogleMap extends OSM {

    public function GoogleMap(name:String, layers:String) {
        //http://mt0.google.cn/vt/lyrs=s@108&hl=zh-CN&gl=CN&src=app&type=s@108&x=100&y=54&z=7&s=Galil
        var url:String = "http://mt0.google.cn/vt/lyrs=" + layers
            + "&hl=zh-CN&gl=CN&src=app&type=" + layers;
        super(name, url);
        this.altUrls = ["http://mt0.google.cn/vt/lyrs=" + layers
            + "&hl=zh-CN&gl=CN&src=app&type=" + layers, 
            "http://mt1.google.cn/vt/lyrs=" + layers
            + "&hl=zh-CN&gl=CN&src=app&type=" + layers,
            "http://mt2.google.cn/vt/lyrs=" + layers
            + "&hl=zh-CN&gl=CN&src=app&type=" + layers, 
            "http://mt3.google.cn/vt/lyrs=" + layers
            + "&hl=zh-CN&gl=CN&src=app&type=" + layers];
        this.generateResolutions(19, OSM.DEFAULT_MAX_RESOLUTION);
    }

    override public function getURL(bounds:Bounds):String{
        var res:Number = this.map.resolution;
        var x:Number = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileWidth));
        var y:Number = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileHeight));
        var z:Number = this.map.zoom;
        var limit:Number = Math.pow(2, z);
        if (y < 0 || y >= limit ||x < 0 || x >= limit) {
            return "";
        } else {
            x = ((x % limit) + limit) % limit;
            y = ((y % limit) + limit) % limit;
            var url:String = this.url;
            var path:String = "&x=" + x + "&y=" + y + "&z="+z;
            if (this.altUrls != null) {
                url = this.selectUrl(this.url + path, this.getUrls());
            }
            return url + path + "&s=" + getGalileo();
        }
    }

    //产生Galileo随机
    public function getGalileo():String {
        var array:ArrayCollection = new ArrayCollection(["", "G", "Ga", "Gal", "Gali", "Galil", "Galile", "Galileo"]);
        var index:int = Math.round(Math.random() * 7);// 0-7之间的随机数
        return array[index];
    }
}

}

你可能感兴趣的:(openscales 加载 google地图)