1

I'm using OpenScales in a web mapping project, and I would like to add a Google Maps layer. I know that there's some licence problems, but I don't care for these licence issues, I'm looking to add Google Maps layer to OpenScales like it has been made on OpenLayers.

  • you can use wms service like - peterdamen.com/GoogleWMS/googlewms.php.txt but your ip can be blocked by google if it is they deem it not an acceptable method in using their mapping tiles – Mapperz Mar 12 '12 at 15:12
  • Thanks a lot Mapperz, i will give a try for this solution :) – geogeek Mar 13 '12 at 9:03
1

You must create your own TMS layer and server side proxy script with crossdomain.xml

package openscalesmap {

import org.openscales.core.layer.TMS;
import org.openscales.geometry.basetypes.Bounds;
import org.openscales.geometry.basetypes.Location;
import org.openscales.proj4as.ProjProjection;
import flash.system.Security;

public class GoogleMap extends TMS
{
    private var _serviceVersion:String = "1.0.0";       
    private var _tileOrigin:Location = null;        
    private var _format:String = "png";     
    private var _layerName:String;
    private var _type:String;
    private var _proxy_url:String="http://proxysite.com/swf/proxy.php?url=";

    public static const HYBRID:String="mt0.google.com/vt/lyrs=h@159000000&hl=ru";
    public static const SAT:String="khm0.google.ru/kh/v=90";
    public static const STANDART:String="mt0.google.com/vt/lyrs=m@159000000&hl=ru";

    public function GoogleMap(name:String, url:String, layerName:String="", type:String=SAT)
    {
        super(name, url, layerName);
        //flash.system.Security.allowDomain("mt0.google.com");
    /*  Security.loadPolicyFile("http://google.com/crossdomain.xml");
        Security.allowDomain( "*" );
        Security.allowInsecureDomain( "*" );*/
        this.projection = new ProjProjection("EPSG:900913");
        this._layerName = layerName;
        _type=type;
        this.maxExtent = new Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34);
    }
    //-------------------------------------------------------------------
    override public function getURL(bounds:Bounds):String {
        var res:Number = this.map.resolution;
        if(this._tileOrigin==null) {
            this._tileOrigin = new Location(this.maxExtent.left,this.maxExtent.bottom);
        }

        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);


        x = ((x % limit) + limit) % limit;
        y = ((y % limit) + limit) % limit;
        var url:String =_proxy_url+escape(_type + "&z=" + z + "&x=" + x + "&y=" + y); 

        if (this.altUrls != null) {
            url = this.selectUrl(this.url, this.getUrls());
        }

        return url ;
    }
}

}

And change these lines for your language:

public static const HYBRID:String="mt0.google.com/vt/lyrs=h@159000000&hl=ru";
public static const SAT:String="khm0.google.ru/kh/v=90";
public static const STANDART:String="mt0.google.com/vt/lyrs=m@159000000&hl=ru";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.