0

我无法将OpenSeaMap集成到 GWT 应用程序中。我遵循了他们的示例和GWT-OpenLayers TMS 示例。这是我的代码:

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;
}-*/;

它根本不起作用。甚至更多 - 出于某种原因,图层选择器中的“Seamark”叠加层被禁用。我还尝试使用以下 JSNI 函数作为 TMS 层的 getURL:

public static native JSObject getTileURL() /*-{
    return $wnd.getTileURL;
}-*/;

该功能来自http://map.openseamap.org/javascript/map_utils.js但也没有运气。

任何帮助表示赞赏。</p>

4

1 回答 1

0

此问题的原因是nullMap 对象的 maxExtent 属性。它被初始化如下:

mapWidget = new MapWidget("100%", "100%", new MapOptions());

我已更新为以下内容:

MapOptions defaultMapOptions = new MapOptions();
defaultMapOptions.setMaxExtent(new Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34));

mapWidget = new MapWidget("100%", "100%", defaultMapOptions);

现在它起作用了。

于 2014-08-24T15:31:50.083 回答