[OpenLayers] Using WMS

Hi,

Is there any configuration to perform in order to be able to display WMS layers? I can’t display any ArcGIS Online, Metacarta or locally created (Geoserver) WMS.
The code I use is:


                WebMapServiceLayer metacarta = new WebMapServiceLayer();
		metacarta.setUri("http://labs.metacarta.com/wms/vmap0");
		metacarta.setLayers("basic");
		metacarta.setDisplayName("Metacarta");
		metacarta.setFormat("image/png");
		metacarta.setBaseLayer(true);

               map.addLayer(metacarta);

Regards.

It’s not possible to display ArcGIS layers because the class ArcGISCache (from OpenLayers) is not implemented in the Vaadin OpenLayers add-on, I think.

Hi,

I don’t use or have access to ArcGIS, but according to this example the feature should be quite easy to implement:
http://dev.openlayers.org/releases/OpenLayers-2.12/examples/arcgiscache_direct.html

Pretty similar to plain WMS, but just needs some options to be passed. Especially if options are implemented using JSON it should wouldn’t require too much. You could add an issue to the project page about the feature. If you want to ensure something happens fast, I’d suggest to
hire one of our talented experts
to implement the feature or check out the project from SVN and start working with it yourself. I’m currently quite busy elsewhere but I’d be honoured to add your contribution to the project.

cheers,
matti

ArcGISCache is ment to directly acess the cached ArcGIS layers.

Using the WMS service it should be perfectly possible to access WMS server. I will try to do it in the next few days and will let know about any problems or success.

Ok thanks guys.
PS: I’m an intern so hiring experts goes beyond my expectations for the moment :stuck_out_tongue:

But still, I have a problem with adding a simple WMS from my Geoserver. I wrote the same script in HTML/Javascript and it works with no problems.

Definitely, there is some problem with the WMS layer or I have something wrong in my application. Even the WMS layers in the Demo.java don’t work for me. Could someone please confirm that the WMS layers in Demo.java work fine?

Some sample code (an WMS base layer plus two additional layers)


        OpenLayersMap map = new OpenLayersMap();
        map.setSizeFull();
        map.setImmediate(true);

        map.setJsMapOptions("{ " + "projection: new OpenLayers.Projection(\"EPSG:2180\")," + "units: \"m\"," + "maxExtent: new OpenLayers.Bounds(150000, 120000, 920000, 800000)," + "}");

        map.getControls().clear();
        map.getControls().add(Control.MousePosition);
        map.getControls().add(Control.Navigation);
        map.getControls().add(Control.ZoomPanel);
        map.getControls().add(Control.ScaleLine);
        map.getControls().add(Control.LayerSwitcher);

        WebMapServiceLayer gdos = new WebMapServiceLayer();
        gdos.setUri("http://wms.gdos.gov.pl/geoserver/wms");
        gdos.setLayers("gdos_int:ObszarySpecjalnejOchrony,gdos_int:SpecjalneObszaryOchrony,gdos_int:ParkiNarodowe,gdos_int:ParkiKrajobrazowe,gdos_int:ObszaryChronionegoKrajobrazu");
        gdos.setBaseLayer(false);
        gdos.setOpacity(0.5d);
        gdos.setDisplayName("GDOS");

        map.addLayer(gdos);

        WebMapServiceLayer natura = new WebMapServiceLayer();
        natura.setUri("http://mapserv.gridw.pl/cgi-bin/mapserv?map=/srv/mapserver/ai.map&");
        natura.setLayers("ai_oso,ai_soo");
        natura.setBaseLayer(false);
        gdos.setOpacity(0.5d);
        natura.setDisplayName("Natura");

        map.addLayer(natura);

        WebMapServiceLayer admin = new WebMapServiceLayer();
        admin.setUri("http://mapserv.gridw.pl/cgi-bin/mapserv?map=/srv/mapserver/ai.map&");
        admin.setLayers("ai_woj,ai_pow,ai_gmin");
        admin.setBaseLayer(true);
        admin.setDisplayName("Mapa");

        map.addLayer(admin);

It works for me.

Thank you Filip :slight_smile:

Did somebody test openLayers add-on with a Geoserver WMS? I really don’t understand what is going on in my application. I will explain the context and post the codes, hoping that someone figures out what the problem is …

Data:
SHP data, named “my_data” in EPSG:900913 projection was imported into a PostGIS 1.5 database.
my_data was published into a Geoserver 2.1.4.
my_data is used in an openLayers map as a WMS.

Map:
OpenLayers map with EPSG:900913 projection.
the map contains an OSM layer the WMS layer of my_data.
the WMS is added to the map before the OSM layer.

Problem:
the WMS layer is displayed in EPSG:4326 instead of EPSG:900913.
when I switch from the WMS layer to the OSM layer, the display is no more on the right position: the OSM layer is centered on the Atlantic Ocean.

Surprise:
the same code written in Vaadin was translated to OpenLayers Javascript / HTML and no problem is detected. Everything is displayed where it should.

Guess:
Maybe there is a special projections configuration that should be done in Vaadin, in order to have everything right?!

Code used in Vaadin:


private final OpenLayersMap map = new OpenLayersMap();
                map.setImmediate(true);
		map.addControl(Control.Navigation);
		map.addControl(Control.OverviewMap);
		map.addControl(Control.MousePosition);
		map.addControl(Control.LayerSwitcher);
		map.addControl(Control.ScaleLine);
		map.setApiProjection("EPSG:900913");

		final OpenStreetMapLayer osm = new OpenStreetMapLayer();

		WebMapServiceLayer wms = new WebMapServiceLayer();
		wms.setUri("http://10.3.9.151:8080/geoserver/wms");
		wms.setLayers("baboa");
		wms.setProjection("EPSG:900913");
		wms.setDisplayName("Geoserver");
		wms.setTransparent(true);
		wms.setFormat("image/png");
		wms.setBaseLayer(true);   
		
		map.addLayer(wms);
                map.addLayer(osm);
		
		map.setCenter(246498, 6238585);
		map.setZoom(13);
		map.setWidth("100%");
		map.setHeight("775px");

Code used in Javascript:


 map = new OpenLayers.Map ('map', {
	controls:[new OpenLayers.Control.LayerSwitcher(),
			  new OpenLayers.Control.OverviewMap(),
			  new OpenLayers.Control.MousePosition(),
			  new OpenLayers.Control.ScaleLine(),
			  new OpenLayers.Control.Navigation()],
	projection: new OpenLayers.Projection("EPSG:900913"),
    displayProjection: new OpenLayers.Projection("EPSG:900913")
});

var osm = new OpenLayers.Layer.OSM();
var wms = new OpenLayers.Layer.WMS(
  "Geoserver", "http://10.3.9.151:8080/geoserver/wms",
  {
   srs: 'EPSG:900913',
   layers: 'baboa',
   transparent:"true",
   format: 'image/png',
   isBaseLayer: 'true'
  });
  map.addLayer(wms);
  map.addLayer(osm);
  lonlat = new OpenLayers.LonLat(246498, 6238585);
  map.setCenter(lonlat, 13, true, true);

I hope somebody sees where the problem is!

Regards.

Is it because WMS services (in Vaadin) are preconfigured to be served in the WGS84 coordinates system, like Marker objects?

Use map.setAPIProjection(String) method. Then use that projection on the server side. On client side all coordinates are then converted to what the underlaying base layer uses.

cheers,
matti

As shown in the example above, everything is in EPSG:900913.
The map is set to be in EPSG:900913 by the setAPIProjection(String) method. And still, the Geoserver WMS layer is displayed in the EPSG:4326!