Skip to content

Commit

Permalink
Change the placeholder syntax in legend URLs to {{VAR_NAME}} and upda…
Browse files Browse the repository at this point in the history
…te the unit tests and docs accordingly.
  • Loading branch information
fschmenger committed Oct 27, 2022
1 parent 5e2e02d commit 4d9132e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/map-layer-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The following properties can be applied to all map layer types
| attributions | Text or HTML string to be displayed as source attribution in the map. This setting will override the layer attributions declared in the language packs. | `"attributions": "<a href='https://www.pdok.nl' target='_blank'>PDOK</a> by Dutch Kadaster",` |
| previewImage | URL to a preview image for layers to be displayed in the background layer selection control. This option has no effect if the layer is not a background layer - see option `isBaseLayer` | `"previewImage": "static/icon/my-layer-preview.png"` |
| legend | Boolean value, whether a layer legend image should be displayed in the LayerList. Defaults to `false`. | `"legend": true`|
| legendUrl | URL to a legend image. This value is required to produce a legend, if the layer is not a WMS layer. The URL may contain format placeholders corresponding to the parameters `language`, `scale` or any of the additional options given among `legendOptions`. | `"legendUrl": "static/icon/my-layer-legend-${LANGUAGE}.png"`
| legendUrl | URL to a legend image. This value is required to produce a legend, if the layer is not a WMS layer. The URL may contain format placeholders corresponding to the parameters `language`, `scale` or any of the additional options given among `legendOptions`. A placeholder is delimited by `{{` and `}}` – i.e. `{{VAR_NAME}}`. | `"legendUrl": "static/icon/my-layer-legend-{{LANGUAGE}}.png"`
| legendOptions | An object, containing additional parameters to request the legend image. Supported options may be vendor specific, e.g. see [GeoServer Docs](https://docs.geoserver.org/latest/en/user/services/wms/get_legend_graphic/index.html) for the options supported for WMS layers in GeoServer. | `"legendOptions": {"transparent": true, "width": 14 }`


Expand Down
2 changes: 1 addition & 1 deletion src/util/LayerLegend.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const CustomLegend = {
}

for (const key in placeholders) {
let regex = new RegExp('\\${' + key + '}', 'gi');
let regex = new RegExp('{{' + key + '}}', 'gi');
url = url.replace(regex, placeholders[key]);
}
return url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,14 @@ describe('layerlist/LayerLegendImage.vue', () => {
});

it('has correct legendURL for legend format URL', () => {
/* eslint-disable no-template-curly-in-string */
const layer = new TileLayer({
source: new OSM(),
legendUrl: 'http://my-image.png?transparent=${TRANSPARENT}&width=${WIDTH}&SCALE=${SCALE}&language=${LANGUAGE}',
legendUrl: 'http://my-image.png?transparent={{TRANSPARENT}}&width={{WIDTH}}&SCALE={{SCALE}}&language={{LANGUAGE}}',
legendOptions: {
transparent: true,
width: 14
}
});
/* eslint-enable no-template-curly-in-string */

comp.setProps({ layer: layer });
expect(vm.legendURL).to.equal('http://my-image.png?transparent=true&width=14&SCALE=139770566.00717944&language=en');
});
Expand Down

0 comments on commit 4d9132e

Please sign in to comment.