Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm using openscales in a web mapping project, 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 googlemaps layer to openscales like it has been made on OpenLayers.

Thanks in advance

share|improve this question
    
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 Answer 1

up vote 1 down vote accepted

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";
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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