1

Topic: Geoserver layers on report maps don't show names in legend

I have a report made using Form category = Reporting, and form = Distribution Map 1.

I have added a distribution layer from the cache_occurrences table, and I can give it a caption using, for example, {species} and on the legend the species name shows up correctly.

If I add other layers in the 'Other Map Settings' section by listing them in the 'WMS layers from GeoServer' box there is no option to add captions and they show up in the legend (and layer switcher) with the titles 0, 1, 2 etc (see attached screenshot.)

I've also tested other reports to see if it makes any difference but it doesn't

So, the question: is there a way to get the report maps to use the layer names from Geoserver so that they show in the legend and layer switcher?

2

Re: Geoserver layers on report maps don't show names in legend

Hi

Here is some background.
The additional WMS layers are added by the following code in media/jquery.indiciaMapPanel.js

      $.each(this.settings.indiciaWMSLayers, function(key, value)
      {
        div.settings.layers.push(new OpenLayers.Layer.WMS(key, div.settings.indiciaGeoSvc + 'wms', {layers: value, transparent: true}, {singleTile: true, isBaseLayer: false, sphericalMercator: true}));
      });

This is calling the constructor for an OLpenLayers WMS Layer http://dev.openlayers.org/docs/files/Op … MS-js.html

The first parameter of the constructor is a name for the layer which is given the value of the key to the array of indiciaWMSLayers.

The array of indiciaWMSLayers is an option of the map_panel() function in client_helpers\map_helper.php which is passed in from the option you have set.

The value you set is converted to an array in the iform_map_get_map_options() function of client_helpers\prebuilt_forms\include\map.php.

  if (!empty($args['indicia_wms_layers'])) {
    $options['indiciaWMSLayers'] = explode("\n", $args['indicia_wms_layers']);
  }

I see no way to influence this behaviour without using code: either applying your own javascript to modify the output or updating the server-side code to allow you to supply a name for the layer.

One question. How many layers do you want to show? The Distribution Map 3 allows for 3 named layers and the Quick Species Map allows user selection of up to 4 species layers (https://indicia-docs.readthedocs.org/en … -maps.html).

Assuming neither of these works for you, how about the following modification to map.php which would allow you to specify the additional WMS layers in a name=layer format.

  if (!empty($args['indicia_wms_layers'])) {
    $wmsLayers = explode("\n", $args['indicia_wms_layers']);
    // Layers may be in the form name = layer or the layer on its own.
    foreach ($wmsLayers as $layer) {
      $separatorPos = strpos($layer, '=');
      if ($separatorPos !== FALSE) {
        $name = trim(substr($layer, 0, $separatorPos - 1));
        $layer = trim(substr($layer, $separatorPos + 1)); 
        $options['indiciaWMSLayers'][$name] = $layer;
      }
      else {
        $options['indiciaWMSLayers'][] = $layer;
      }      
    }
  }

Jim Bacon.

3

Re: Geoserver layers on report maps don't show names in legend

Thanks for this. I'm trying to implement it but nothing I change in map.php is having any effect. I've cleared every cache I know about (Drupal, Iform, warehouse scheduled_tasks). What am I missing?

4

Re: Geoserver layers on report maps don't show names in legend

Hi

There ought to be two steps.
1. Update the code with the modification above. (I hope it was unambiguous locating the code to change.)
2. Update the 'WMS layers from GeoServer' setting by adding name= to the start of each line where name is replaced by the title you want to appear in the layer switcher.

If this doesn't work it may be on account of other differences in the code we are using. To overcome that we would have to update your code from the Git repository.

Jim Bacon

5

Re: Geoserver layers on report maps don't show names in legend

Thanks for your reply.

I'm sure the problem is that it is not using the updated map.php file. I just get a pink square as it doesn't understand the geoserver reference.  My file is here: indicia_warehouse/client_helpers/prebuilt_forms/includes/map.php. If I put rubbish code in that file, it still draws the map - is there another cache somewhere that I need to clear?

6

Re: Geoserver layers on report maps don't show names in legend

Hi

I know what it is.

The client_helpers library is used by both the warehouse and by the Drupal iForm module. You have it in two places.

You have modified the warehouse version where, in fact, it is the processing on your Drupal site that we need to change.

Jim Bacon.

7

Re: Geoserver layers on report maps don't show names in legend

Yes, that's it! Thanks. Should I change the code back in the warehouse version, or should they both be the same?

8

Re: Geoserver layers on report maps don't show names in legend

Ah well, that brings us on to the question of how your organisation manages code control.

As the files do not need to be the same I would revert the warehouse so that you are back to a known version of the code there at least.

With the code on the Drupal side, I would suggest that you probably don't want to fork Indicia and maintain your own version. What I can do for you is commit that modification to the development branch of our repository and it will make its way in to the next release.

If you wanted to avoid running an uncontrolled version of the code you could always update your iForm module from our repository once I have pushed the change. I couldn't be sure that you wouldn't have to update your warehouse to the latest version to maintain compatibility though.

Jim Bacon.

9 (edited by namwebs 18-02-2016 15:01:32)

Re: Geoserver layers on report maps don't show names in legend

Okay, thanks. 'My organisation' is just me...  and my code control is rather haphazard. If you commit the code (and add an explanatory note to the help text on the 'WMS layers from GeoServer' field), that'd be great.

Many thanks - again - for your assistance.

10

Re: Geoserver layers on report maps don't show names in legend

Committed in https://github.com/Indicia-Team/client_ … 57b7cdcee2

11

Re: Geoserver layers on report maps don't show names in legend

Jim Bacon wrote:

Hi

        $title= trim(substr($layer, 0, $separatorPos - 1));

Jim Bacon.

In this case the last letter of the title will be truncated.
For me I  changed it to

$title = trim(substr($layer, 0, $separatorPos));

jürgen

12

Re: Geoserver layers on report maps don't show names in legend

Thanks, Jürgen.
Corrected in https://github.com/Indicia-Team/client_ … 4ce72968e3

Jim Bacon.