OL2 versions have long supported WMS - it would be nice to have that functionality added to the Drupal OL3 module. I am beginning some of the coding needed for this, but attached patches are a work in progress for anyone who wants to contribute.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

robertwb’s picture

Patch drupal-2475355-1.patch takes small steps towards WMS support in Drupal OL3. This patch:

  • Adds the WMS source type to the "Source Type" (admin/structure/openlayers/sources/type) screen Add list (Image 1).
  • Provides WMS URL and Layers Fields to the "Source Type options" (admin/structure/openlayers/sources/add/options) screen (image 2).
  • Image 1

    Add Source Type WMS

    Image 2

    Source Type Options WMS

m.stenta’s picture

Status: Active » Needs work
FileSize
2.31 KB

Thanks @robertwb for the initial patch!

I made a few changes. Attached is a new patch (still a work in progress).

Changes:

  • Moved to new directory structure and updated code to match current dev
  • Changed "ImageWMS" to "TileWMS" in the JS (perhaps we want both?)
  • Changed plugin name to TileWMS to be consistent with Openlayers library itself, and leave option to also add ImageWMS
  • Changed "layers" setting to "wms_layers", because for some reason "layers" wasn't showing up at all on my test
  • Added "Version" parameter, to allow the default WMS version to be overridden
  • Removed hard-coded URL

I will be testing this more soon, and will update the patch as necessary.

m.stenta’s picture

Oops. Previous patch had a console.log() in it.

Here's a clean one...

robertwb’s picture

Awesome @m.stenta - thanks for picking this up!

m.stenta’s picture

@robertwd: My pleasure! I need it for my own project anyway. :-)

Question: your original patch used ImageWMS, but I replaced that with TileWMS because that's what I needed. Do you need ImageWMS? If so, it probably won't be hard to extend this patch to add support for it. Basically just copying the files to another new source plugin called "ImageWMS". I've never used ImageWMS sources before, but I'm sure it's relatively similar setup. Here are some links to the two types in Openlayers docs:

http://openlayers.org/en/v3.7.0/apidoc/ol.source.ImageWMS.html

http://openlayers.org/en/v3.7.0/apidoc/ol.source.TileWMS.html

Are you using ImageWMS?

robertwb’s picture

My early tests were Images but tiles is obviously the best route to go. Thanks for asking!

m.stenta’s picture

Status: Needs work » Needs review
FileSize
54.95 KB

OK! I feel pretty confident with this patch. I'm going to change this to "Needs Review".

I tested it with the following parameters:

URL: http://services.nationalmap.gov/arcgis/services/transportation/MapServer...
Layers: 1,2,3,4,5,6,7,8,9
Version: (blank so it uses OL default 1.3.0)

Attached is a screenshot of the WMS layer in action! :-)

Pol’s picture

It would be amazing if we could provide a complete map with a layer and stuff in the Openlayers Examples module.

Pol’s picture

+++ b/src/Plugin/Source/TileWMS/js/tilewms.js
@@ -0,0 +1,23 @@
+    if (!goog.isDef(data.opt)) {

What do you think about removing those tests from JS and put them in PHP, in the class ? The methods optionFormValidate() and optionFormSubmit() exists.

We must make sure that what we pass to JS is correct so we speed up things on client side.

robertwb’s picture

> We must make sure that what we pass to JS is correct so we speed up things on client side.

FWIW - I think this is a good idea. The least js the better for module performance as well as insuring that we submit properly formed info to OL.

m.stenta’s picture

Thanks for the input @Pol and @robertwb, attached is a new patch that addresses these things:

  • Move all of the code out of JS and into PHP, so the JS is simply passing the options to Openlayers. PHP is doing all the work.
  • Added example source, layer, and map to the Openlayers Examples module

  • Pol committed cbcca9e on drupal-7.x-3.x authored by m.stenta
    Issue #2475355 by m.stenta, robertwb: Add WMS Layer Support to OL3
    
Pol’s picture

Status: Needs review » Fixed

Super, that's in :)

Thanks !!!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.