在openlayer中,将wms叠加到google上去

关键代码引自:


http://blog.sumbera.com/2010/11/02/tiled-wms-overlay-on-google-map-v3/
function init(){ 
    //首先要设置地图的投影:sphericalMercator,这一步是必须的
    var options = {
        projection:new OpenLayers.Projection("EPSG:900913")
    };
    map=new OpenLayers.Map("mapDiv",options);
    var ghyb = new OpenLayers.Layer.Google(
        "Google Hybrid",
        { 
            type: G_HYBRID_MAP,
            sphericalMercator: true
        }
    ); 
   //关键一步 
     var gwms = new OpenLayers.Layer.TMS(
        "wms",
         host+"geoserver/wms?service=WMS",
           {  
                layers: "cite:leida", 
                type: "png",
                visibility: true,
                //url处理器,根据wms的guich getURL: get_wms_url1,
                format: "image/png",
                isBaseLayer: false 
            }
    );
    map.addLayers([ghyb,gwms]);
    var lonlat = new OpenLayers.LonLat(114.055,22.541);
    lonlat.transform(proj, map.getProjectionObject());
    map.setCenter(lonlat, 5);
}

function get_wms_url1(bounds) {
 
   var proj = new OpenLayers.Projection("EPSG:4326");
   bounds.transform(map.getProjectionObject(), proj);


     var url = this.url;
     url += "&REQUEST=GetMap";
     url += "&SERVICE=WMS";
     url += "&VERSION=1.1.1";
     url += "&LAYERS=" + this.layers;
     url += "&FORMAT=" + this.format;
     url += "&TRANSPARENT=TRUE";
     url += "&SRS=" + "EPSG:4326";
     url += "&BBOX=" + bounds.toBBOX();
     url += "&WIDTH=" + this.tileSize.w;
     url += "&HEIGHT=" + this.tileSize.h;
     return url;
}


你可能感兴趣的:(Google,openlayer,wms)