Skip to content

Commit

Permalink
Add function to overwrite elements displayed in LegendTool (#320)
Browse files Browse the repository at this point in the history
* Add function to overwrite elements displayed in LegendTool

* Add more checks to overwriteLegends function

* Add overwriteLegends to mmgisAPI
  • Loading branch information
ac-61 authored Jan 31, 2023
1 parent ce6414a commit e959617
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 155 deletions.
52 changes: 52 additions & 0 deletions docs/pages/APIs/JavaScript/JavaScript_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,55 @@ The following is an example of how to call the `unproject` function:
window.mmgisAPI.unproject({ x: 8120633.560692952, y: -237291.62355915268 });
// returns {lat: -4.000000000000019, lng: 137}
```

### overwriteLegends(legends)

This function can be used to overwrite the contents displayed in the LegendTool. This can be useful when used with the `toolChange` event listener in the mmgisAPI.

#### Function parameters

- `legends` - An array of objects, where each object must contain the following keys: legend, layerUUID, display_name, opacity. The value for the legend key should be in the same format as what is stored in the layers data under the `_legend` key (i.e. `L_.layers.data[layerName]._legend`). layerUUID and display_name should be strings and opacity should be a number between 0 and 1.

The following is an example of how to call the `overwriteLegends` function:
```javascript
const legends = [
{
color: '#00e400',
strokecolor: '#000000',
shape: 'continuous',
value: '0 - 54',
},
{
color: '#ffff00',
strokecolor: '#000000',
shape: 'continuous',
value: '54 - 154',
},
{
color: '#ff7e00',
strokecolor: '#000000',
shape: 'continuous',
value: '154 - 254',
},
{
color: '#8f3f97',
strokecolor: '#000000',
shape: 'continuous',
value: '254 - 354',
},
{
color: '#8f3f97',
strokecolor: '#000000',
shape: 'continuous',
value: '354 - 424',
},
{
color: '#7e0023',
strokecolor: '#000000',
shape: 'continuous',
value: '> 424',
},
];

window.mmgisAPI.overwriteLegends(legends);
```
Loading

0 comments on commit e959617

Please sign in to comment.