I am having trouble integrating OpenSeaMap into GWT application. I have followed their example and example of GWT-OpenLayers TMS. Here is my code:
private void initMap(MapView map) {
TMSOptions seamarkOptions = new TMSOptions();
seamarkOptions.setType("png");
seamarkOptions.setGetURL(getMyUrl());
seamarkOptions.setNumZoomLevels(18);
seamarkOptions.setIsBaseLayer(false);
seamarkOptions.setDisplayOutsideMaxExtent(true);
map.addLayer(OSM.Mapnik("OpenStreetMap"));
map.addLayer(new TMS("Seamark", "http://t1.openseamap.org/seamark/", seamarkOptions));
}
private static native JSObject getMyUrl() /*-{
function get_my_url(bounds) {
var res = this.map.getResolution();
var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
var z = this.map.getZoom();
var limit = Math.pow(2, z);
if (y < 0 || y >= limit) {
return null;
} else {
x = ((x % limit) + limit) % limit;
url = this.url;
path= z + "/" + x + "/" + y + "." + this.type;
if (url instanceof Array) {
url = this.selectUrl(path, url);
}
return url+path;
}
}
return get_my_url;
}-*/;
It don't work at all. Even more - for some reason the 'Seamark' overlay is disabled in Layers selector. Also I have tried using following JSNI function as getURL for TMS layer:
public static native JSObject getTileURL() /*-{
return $wnd.getTileURL;
}-*/;
That function comes from http://map.openseamap.org/javascript/map_utils.js But no luck too.
Any help appreciated.
The reason of this issue was null
maxExtent property of Map object. It was initialised as follows:
mapWidget = new MapWidget("100%", "100%", new MapOptions());
I have updated to the following:
MapOptions defaultMapOptions = new MapOptions();
defaultMapOptions.setMaxExtent(new Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34));
mapWidget = new MapWidget("100%", "100%", defaultMapOptions);
Now it works.