11

OSMをGWTに統合したいのですが。このライブラリはgwt-openlayersと呼ばれていますが、OSMマップでどのように機能させることができるのかわかりません。

誰かが私に簡単な例を教えてもらえますか?

4

3 に答える 3

11

GWT- HelloWorldOpenStreetMapを使用したOpenLayers

次の例は、上記のようにを使用OpenLayers-2.8/OpenLayers.jsして正常に機能します。OpenStreetMap.js

public void onModuleLoad(){

MapOptions defaultMapOptions = new MapOptions();
MapWidget mapWidget = new MapWidget("800px", "600px", defaultMapOptions);

OSM osm_1 = OSM.Osmarender("Osmarender");   // Label for menu 'LayerSwitcher'
    osm_1.setIsBaseLayer(true);

OSM osm_2 = OSM.Mapnik("Mapnik");   // Label for menu 'LayerSwitcher'
    osm_2.setIsBaseLayer(true);

OSM osm_3 = OSM.CycleMap("CycleMap"); 
    osm_3.setIsBaseLayer(true);

OSM osm_4 = OSM.Maplint("Maplint"); 
    osm_4.setIsBaseLayer(true);

Map map = mapWidget.getMap();
    map.addLayer(osm_1);
    map.addLayer(osm_2);
    map.addLayer(osm_3);
    map.addLayer(osm_4);
    map.addControl(new LayerSwitcher());
    map.addControl(new MousePosition());

 // map.setCenter(new LonLat(6.95, 50.94), 12);            // Warning:  In the case of OSM-Layers the method 'setCenter()' uses Gauss-Krueger coordinates,
                                                           //           thus we have to transform normal latitude/longitude values into this projection first:
    LonLat lonLat = new LonLat(6.95, 50.94);               //           (6.95, 50.94)  -->  (773670.4, 6610687.2)
           lonLat.transform("EPSG:4326", "EPSG:900913");   //           
    map.setCenter(lonLat, 12);                             //           see  http://docs.openlayers.org/library/spherical_mercator.html

RootPanel.get().add(mapWidget); }
于 2010-07-21T10:31:14.560 に答える
11

モジュールファイルに以下を追加して、gwt-openlayersから継承していることを確認してください。

<inherits name='org.gwtopenmaps.openlayers.OpenLayers'/>

また、「Application.html」ページに次の行を追加して、OpenLayersjavascriptライブラリーとOpenStreetMapOpenLayersをアプリケーションに組み込んでください。

<script src="http://www.openlayers.org/api/OpenLayers.js"></script>

<script src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>

次に、オープンストリートマップを使用するレイヤーを作成するのは簡単なことです。

OSM openStreetMap = OSM.Osmarender("Base Map"); openStreetMap.setIsBaseLayer(true);

MapWidget mapWidget = new MapWidget("350px", "350px"); mapWidget.getMap().addLayer(openStreetMap);

于 2010-05-08T21:15:16.320 に答える
1

gwt-openlayersの現在のバージョンはここにあります:http ://sourceforge.net/projects/gwt-openlayers/

于 2010-10-30T00:36:09.130 に答える