1

I am using Google maps for my application. For getting some custom private map data, I have set up a WMS using Mapserver. How can I add this Custom UMN Mapserver WMS layer over Google API (without using Openlayers)?

  • just a simple question, why don't you use openlayers? – Gery Jan 27 '14 at 11:50
  • Do you mean I can just change into openlayers without changing any coding? (coding for geocoding with Google API) – mapsir Jan 27 '14 at 12:44
1

It's possible to do it without using OpenLayers:

https://stackoverflow.com/questions/8354163/google-map-api-3-wms

The revelant code:

 //Define custom WMS tiled layer
 var SLPLayer = new google.maps.ImageMapType({
                getTileUrl: function (coord, zoom) {
                    var proj = map.getProjection();
                    var zfactor = Math.pow(2, zoom);
                    // get Long Lat coordinates
                    var top = proj.fromPointToLatLng(new google.maps.Point(coord.x * 256 / zfactor, coord.y * 256 / zfactor));
                    var bot = proj.fromPointToLatLng(new google.maps.Point((coord.x + 1) * 256 / zfactor, (coord.y + 1) * 256 / zfactor));

                    //corrections for the slight shift of the SLP (mapserver)
                    var deltaX = 0.0013;
                    var deltaY = 0.00058;

                    //create the Bounding box string
                    var bbox =     (top.lng() + deltaX) + "," +
                                   (bot.lat() + deltaY) + "," +
                                   (bot.lng() + deltaX) + "," +
                                   (top.lat() + deltaY);

                    //base WMS URL
                    var url = "http://mapserver-slp.mendelu.cz/cgi-bin/mapserv?map=/var/local/slp/krtinyWMS.map&";
                    url += "&REQUEST=GetMap"; //WMS operation
                    url += "&SERVICE=WMS";    //WMS service
                    url += "&VERSION=1.1.1";  //WMS version  
                    url += "&LAYERS=" + "typologie,hm2003"; //WMS layers
                    url += "&FORMAT=image/png" ; //WMS format
                    url += "&BGCOLOR=0xFFFFFF";  
                    url += "&TRANSPARENT=TRUE";
                    url += "&SRS=EPSG:4326";     //set WGS84 
                    url += "&BBOX=" + bbox;      // set bounding box
                    url += "&WIDTH=256";         //tile size in google
                    url += "&HEIGHT=256";
                    return url;                 // return URL for the tile

                },
                tileSize: new google.maps.Size(256, 256),
                isPng: true
            });


    map.overlayMapTypes.push(SLPLayer);
  • Yes, I already did it the same way. Thank you @Julien – mapsir Jan 28 '14 at 11:26
0

Well, you need to code a bit, but it's not that difficult. If you follow these examples you can go through the process quite smoothly:

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.