Inserting EA WMS layers into OpenLayers

The Environment Agency have provided lots of very useful data under the OGC WMS. To get this into OpenLayers, you need two pieces of information.

Firstly, there is a URL provided at the bottom of the page:

http://www.geostore.com/OGC/OGCInterface?SERVICE=WMS&INTERFACE=ENVIRONMENT&LC=0

In addition to this, we need the layer name that you would like to view. To find these we need to add the following to the URL:

&VERSION=1.1.1&REQUEST=GetCapabilities

This will then open the following XML:

pastedImage

The red box highlights the branch you are searching for.

Once you have the name, you can use the code below to add the layer.


var ea_wms = new ol.layer.Tile({
              source: new ol.source.TileWMS({
                  url: 'http://www.geostore.com/OGC/OGCInterface',
                  params: {"SERVICE": "WMS",
                           "UID": 'UDATAGOV2011',
                           "PASSWORD": "datagov2011",
                           "INTERFACE": "ENVIRONMENT",
                           "LC": "0",
                           "LAYERS": "eainspire2011-wms-eaieaew00170015"
                           }
               })
});

The UID, PASSWORD, INTERFACE and LC all come from the initial URL with the LAYERS parameter indicating the name of the layer you wish to import. You can then see the layer on your map.

pastedImage

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s