views:

564

answers:

1

I want to include a open-street-map widget into my apache wicket application. Im using the wicket-contrib-openlayers component from wicket-stuff and the following code:

 List<Layer> layers = new ArrayList<Layer>();
 Layer layerOSMTilesAtHome = new OSM("Osmarender", OSMLayer.TilesAtHome);
 Layer layerOSMMapnik = new OSM("Mapnik", OSMLayer.Mapnik);
 Layer layerOSMCycleMap = new OSM("CycleMap", OSMLayer.CycleMap);

 layers.add(layerOSMMapnik);
 layers.add(layerOSMTilesAtHome);  
 layers.add(layerOSMCycleMap);

 HashMap<String, String> mapOptions = new HashMap<String, String>();
 Bounds boundsExtend = new Bounds(new LonLat(-20037508.34, -20037508.34), new LonLat(20037508.34, 20037508.34));  
 mapOptions.put("maxExtent", boundsExtend.getJSconstructor());
 mapOptions.put("projection", "new OpenLayers.Projection('EPSG:900913')");
 mapOptions.put("displayProjection", "new OpenLayers.Projection('EPSG:4326')");
 mapOptions.put("units", "'meters'");
 mapOptions.put("maxResolution", "156543");
 mapOptions.put("numZoomLevels", "18");

 OpenLayersMap map = new OpenLayersMap("map", layers, mapOptions);  

 map.addControl(Control.LayerSwitcher);
 map.addControl(Control.MousePosition);
 map.addControl(Control.KeyboardDefaults); 

 add(map);

This is a 1:1 copy of the SimpleOpenStreetMapExample from the component. The problem now is: How do I set the center of the map. I tried a

map.setCenter(new LonLat(5, 50), 13);

after the "add(map);" from the code above. This doesnt work, the map doesnt change at all. Im not sure what unit Lon and Lat have to be in, I also tried to convert them Mercator-System using this methods:

 private static double lon2Merc(double lon) {
    return 20037508.34*lon/180.0;
  }

  private static double lat2Merc(double lat) {
    lat = Math.log(Math.tan((90.0 + lat)*Math.PI/360.0))/(Math.PI/180.0);
    return 20037508.34*lat/180.0;
  }

But this doesnt help, nothing changes.

So: Can anybody post a short example how to embedded a OSM-Map into Wicket and how to set the center and zoom-level?

Thanks!