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

まったく機能しません。さらに - 何らかの理由で、レイヤーセレクターで「シーマーク」オーバーレイが無効になっています。また、TMS レイヤーの getURL として次の JSNI 関数を使用してみました。

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

その関数はhttp://map.openseamap.org/javascript/map_utils.jsから来ていますが、運もありません。

助けていただければ幸いです。 </p>

4

1 に答える 1

0

この問題の原因はnull、Map オブジェクトの 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 に答える