使用openstreetmap示例的gwt-openlayers

时间:2010-03-22 14:54:34

标签: gwt openstreetmap gwt-openlayers

我想在GWT中集成OSM。 我发现这个库名为gwt-openlayers,但我不明白如何使它与OSM地图一起使用。

有人可以给我一个简短的例子吗?

3 个答案:

答案 0 :(得分:11)

通过将以下内容添加到模块文件中,确保从gwt-openlayers继承:

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

还要确保通过在“Application.html”页面中添加以下行将OpenLayers javascript库和OpenStreetMap OpenLayers引入您的应用程序:

<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);

答案 1 :(得分:11)

使用OpenStreetMap的GWT-OpenLayers HelloWorld

以下示例对我使用OpenLayers-2.8/OpenLayers.jsOpenStreetMap.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); }

答案 2 :(得分:1)

您可以在此处找到当前版本的gwt-openlayers:http://sourceforge.net/projects/gwt-openlayers/