Tiled WMS overlay in Windows Phone 7


  Update 13/03/2013, here is new  blog about Tiled WMS overlay for Windows Phone 8 :http://blog.sumbera.com/2013/03/10/tiled-wms-overlay-in-windows-phone-8/

This post [http://blog.sumbera.com/2010/02/25/overlay-wms-on- google-in-silverlight-bing/ ] talked about how to overlay over the Bing maps Silverlight control Google tiles  and tiled WMS. It was quite easy to port this web sample into the Windows Phone 7 emulator. I took a smaple code from Training kit called “Ex1-TheBingMapControl” and extend it with the 2 classes : GoogleTile and WmsTile, with slight changes to the namespace using Microsoft.Phone.Controls.Maps (original for Silverlight was  Microsoft.Maps.MapControl). Then extend MainPage.XAML with :

                    <my:MapTileLayer Opacity=”1″>
                    <my:MapTileLayer Opacity=”1″>

Extended sample code availabel for download here : http://www.sumbera.com/lab/wp7/TheBingMapControlWithWMSandGoogle.zip

Update: I found the way calculating BoundingBox from the quadkey somehow limiting (the DeepEarth weay) since it worked only till the level 18. So here is updated class fro getting correct bounding box of the tiled WMS request in the Bing Silverlight control:

            public static double TileToWorldPosX(double tile_x, int zoom) {
return  (float)((tile_x / Math.Pow(2.0, zoom) * 360.0) – 180.0);
public static double TileToWorldPosY( double tile_y, int zoom) {
double n = Math.PI – ((2.0 * Math.PI * tile_y) / Math.Pow(2.0, zoom));
return   (float)(180.0 / Math.PI * Math.Atan(Math.Sinh(n)));
public override Uri GetUri(int tilePositionX, int tilePositionY, int tileLevel) {
                int zoom = tileLevel; //SSU tileLevel would be same as zoom in Bing control
double deltaX = 0;// 0.00135; //SSU deltaX for SLP WMS
double deltaY = 0;// 0.00058; //SSU deltaY for SLP WMS
double minXLon = TileToWorldPosX(tilePositionX, zoom) + deltaX;
double minYLat = TileToWorldPosY(tilePositionY + 1, zoom) + deltaY;
double maxXLon = TileToWorldPosX(tilePositionX + 1, zoom) + deltaX;
double maxYLat = TileToWorldPosY(tilePositionY, zoom) + deltaY;
string wmsUrl = string.Format(this.UriFormat, minXLon, minYLat, maxXLon, maxYLat, 256);
return new Uri(wmsUrl);


Tiled WMS overlay on Google Map v3

this is the third sample of the tiled WMS overlay over the Spherical Mercator, this time over the new Google Map v3. Previsous post talked about overlyaing WMS in  Silverlight Bing maps (http://blog.sumbera.com/2010/02/25/overlay-wms-on-google-in-silverlight-bing/ ) and OpenLayers (http://blog.sumbera.com/2010/02/17/overlay-wms-on-google-in-openlayers/).

Sample application can be found here: http://www.sumbera.com/lab/GoogleV3/tiledWMSoverlayGoogleV3.htm You can try to run it on your mobile device as well – suprisingly it run very well on my iPhone (sometimes it just crash Safari :), however on the iPad there are some more serious issues that will be hopefuly resolved with new iOS update (JavaScript stops to run).

For the new Google Map v3 you have to do the following :

//Define custom WMS tiled layer

var SLPLayer = 
 new google.maps.ImageMapType (
    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    
     }, //getTileURL

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

//add WMS layer


Overlay WMS on Google in OpenLayers

[Note: therea are related post: overlyaing tiled WMS over the new Google Map v3 http://blog.sumbera.com/2010/11/02/tiled-wms-overlay-on-google-map-v3/ and overlying tiled WMS over the Silverlight Bing map http://blog.sumbera.com/2010/02/25/overlay-wms-on-google-in-silverlight-bing/ ]

Is it possible to display WMS (EPSG:4326) over the Google (EPSG:900913) in Openlayers ? Yes ! thanks to the great img ‘feature’ that enables you to shrink/expand your return image based on defined image size. That means that if your map view is rectangular or you request WMS as tiles (rectangular too) you get proper overlay of EPSG:4326 on EPSG:900913) . Example of various image sizes follows (these are actually WMS GetMap requests):

256 x 160

256 x 256

Here is the way how to implement it in OpenLayers – very simplified:

1. read this post http://docs.openlayers.org/library/spherical_mercator.html and create your Google map:

var options = {
projection: new OpenLayers.Projection(“EPSG:900913”),
displayProjection: new OpenLayers.Projection(“EPSG:4326”),
units: “m”,
numZoomLevels: 22,
maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
20037508, 20037508.34)
map = new OpenLayers.Map(‘map’, options);
            // create Google Mercator layers
            var ghyb = new OpenLayers.Layer.Google(
“Google Hybrid”,
{ type: G_HYBRID_MAP, ‘sphericalMercator’: true }

2. add your WMS layer

var gwms = new OpenLayers.Layer.TMS(“SLP”, “http://mapserver-slp.mendelu.cz/cgi-bin/mapserv?map=/var/local/slp/krtinyWMS.map&”,
layers: ‘obrys,typologie,hm2003’,
type: ‘png’,
visibility: true,
getURL: get_wms_url,
format: “image/png”,
opacity: 1,
isBaseLayer: false,
deltaX: 0.0013,
deltaY: 0.00058

3. include support for reprojection before you include OpenLayers:

<script src =”proj4js/lib/proj4js-combined.js”>script>

4. handle WMS as TMS tiles as this:

function get_wms_url(bounds) {

// recalculate bounds from Google to WGS
var proj = new OpenLayers.Projection(“EPSG:4326”);
bounds.transform(map.getProjectionObject(), proj);

// this is not necessary for most servers display overlay correctly,
//but in my case the WMS  has been slightly shifted, so I had to correct this with this delta shift

bounds.left += this.deltaX;
bounds.right += this.deltaX;
bounds.top += this.deltaY;
bounds.bottom += this.deltaY;

            //construct WMS request

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


That is, live example you can see here http://www.sumbera.com/lab/wms/getcapWGS.htm

or in MapShake here : http://www.mapshake.cz/mapfs.aspx?i=464

WhateverMap on Apple Store

WhateverMap Lite v1.0, developed by Jiri Kaminek  has been today accepted for distribution through Apple Store . You can download it here (iTunes and iPhone requiered):


WhateverMap is similar to Google Maps but you can use different branch-specific map sources. Those sources should be more interesting and valuable in non-navigation filed of map using. WhateverMap use Web Map Services (WMS). WMS standard specification was created by the Open Geospatial Consortium (OGC). WMS may provide any geospatial data. There are many WMS severs and most of them are available for free. You can find servers with ortophoto, cadastral, soil types, migration of white storks, … simply WHATEVER.
You can add any WMS server by typing an URL address or simply use built-in catalog. There are some servers with interesting data as NASA Earth satellite photos, Mars satellite photos and many others. There is a rich list of Czech WMS servers.
You can browse a map using zoom-in, zoom-out or move. For better orientation it is possible to use actual position provided by built-in GPS module. Each WMS should map only limited area so there is a boundary of each map. It is possible to display whole map with boundary too.
It is possible to consume many sources in this application. So there is an easy way to change a source while browsing the map. You can easily compare the same area in different map sources. For example you can find out any building and then you can choose soil type map to determine stability of building’s foundation.
For better control of map there is a movement history. Sometimes GPS get lost a signal and display non-precision region. In this case it is posible to use undo and get more precision area before you get lost a signal. There is another interesting way to use the history. You can move around an area in first map layer and then use the same movements in different layers. For example you can follow a road and then you can use map layer with water or soil pollution to find out effect of road to water or soil quality.

・ZOOM-IN – double tap
・ZOOM-OUT – triple tap
・MOVEMENT – swipe on map

– Consume any WMS server map data (ortofoto, cadastral, mars, … WHATEVER)
– Map browsing (move, zoom)
– Support history in map movements (UNDO, REDO)
– Display your current location
– Display map boundary
– Change background color
– Movement history(UNDO, REDO)
– favourite list of WMS

– searching by location name (city, roads, country, …) – geocoding
– caching
– saving for offline use
– better catalog
– landmarks

first release


Compatible with iPhone and iPod Touch
Requires iPhone OS 2.2.1 or later

What’s new



iPhoneLayers – IPhone application for displaying WMS layers

orfotofokatastrMy student Jiri Kaminek, who is in first year of postgraduate study at department of Applied Geoinformatics at Mendel University has created in very short time an impressive  prototype for accessing WMS layers within iPhone using native iPhone SDK. It looks very promissing, with natural iPhone gestures, ability to access iPhone resources (tile cache, GPS position, history, etc..) . You can see his presentation on http://mapserver.mendelu.cz/iphonelayers together with sample screencasts. Codename of the project is iPhoneLayers. The big picture is that MapShake will store all map compositions and you will have various frontedns how to consume or shake your maps, iPhone will be one possible outlet where based on your current GPS position you will get your pre-shaked maps from MapShake store.

Update November 2009: Application is called Whatevermap and can be downloaded from AppStore. please check following category on this blog:


MapRip bookmarklet that saves map context

I was trying recently to utilize bookmarklets for injection of custom code into arbitrary webpage to get control a provide some additional funcitonality.. for example transfering the content of openlayers maps into MapShake. Not heard about MapShake ? I will post soon more. My bookmarlet looks like this:

javascript:(function(){var%20s=document.createElement(%22script%22);s.charset=%22UTF-8%22;s.src=%22http://www.sumbera.com/lab/MapRip/MapRip.js%22;document.body.appendChild (s)})();

var rippedMap = map;
var format = new OpenLayers.Format.WMC({‘layerOptions’: {buffer: 0}});
var text = format.write(rippedMap);
var w;
function e(w){
d = w.document;
d.write(“<textarea id=’wmc’ rows=’100′ cols=’65’>” + text +”</textarea>”);

page with bookmarklet

Caching WMS requests

Recently I was interested in caching WMS requests on MapSnack, that would allow off-line usage of WMS sources. Unfortunately there is no functional WMS discovery or search engine. Google is very weak in this area and even inurl: doesn’t bring too many results. There is one paper I found on this topics called “OpenGIS WMS-based prototype system of Spatial Information Search Engine” but to access this paper you nee to login to IEEE. pages. So how to help google to index WMS layers and pictures it produce ? one of the thoughts I have is to create simple set of pages on which each request for certain layer for certain zoom level and in particular tile would be referenced. Tiling is important as “sampling frequency” for the WMS cache. Actually last year I was working on prototype which enabled me to save for offline use WMS tiled layers (refer to http://www.sumbera.com/news/mapajax/mapajax.htm) what was missing was an automatic crawler on the area and layers – the saving was done only by manual navigation in the area. Last note : I expect the shift of the google search engine towards this freely available geospatail content (…. just right after I will start to generate my index pages ;)