gwt-openlayers with openstreetmap example

Tughi picture Tughi · Mar 22, 2010 · Viewed 10.3k times · Source

I'd like to integrate OSM in GWT. I found this library called gwt-openlayers, but I don't understand how can I make it work with the OSM map.

Can anyone provide me a short example?

Answer

btekab picture btekab · May 8, 2010

Make sure you inherit from gwt-openlayers by adding the following to your module file:

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

Also make sure you bring in the OpenLayers javascript library and OpenStreetMap OpenLayers into your application by adding the following lines in "Application.html" page:

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

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

Then it should a simple thing to create a layer that uses open street maps:

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

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