Saturday 18 November 2017

Custom UMN Mapserver WMS layer over Google API


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



Answer




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

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...