-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vector layer can hide layer symbology when conditional styling used #222
Conversation
In some uses of conditional styling, styling is applied to feature values in a way that each feature is included and matches one style, similar to a pie chart. In such situations, including a style for the entire layer in a legend is unnecessary. This adds a "hideLayer" property to legend configuration in vector layers and to legend display HTML. When added to a vector/GeoJSON layer's legend configuration and set to true, the symbology for the layer (but not its conditional styling) is omitted in the legends.
Do you have an example of this behavior or a description on how to reproduce? |
I think it's easiest to show the difference :) Our use case is for the CleanBC app. The Ministry EVCS layer uses conditional styling to set the colour of a feature based on the stall type. Each feature is one of the two stall types we conditionally style for, but we still show a style for the layer itself, which seems redundant: With this change, and a change to CleanBC to add "hideLayer": true to the layer's legend config, we modify the legend display to make more sense: |
The following link has a legend with an 'Other' entry which is analogous to the 'default'. |
* Documentation is updated for vector/GeoJSON layer * Legend swatches are now always omitted when conditional styling is used * Property "includeOtherLegendWithDefaultStyling" is added to legend configuration in the vector layer. When set to true, an "Other" legend is added for the layer and the swatch is styled with the default styling. * Legend tool CSS is updated to add padding
src/smk/layer/layer-vector.js
Outdated
@@ -24,7 +24,8 @@ include.module( 'layer.layer-vector-js', [ 'layer.layer-js' ], function () { | |||
const legendData = []; | |||
legendData.push({ | |||
title: self.config.legend && self.config.legend.title || self.config.title, | |||
style: self.config.style | |||
style: self.config.style, | |||
hasConditionalStyling: self.config.conditionalStyles || false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While JavaScript allows the assignment of an object or a boolean to the same variable, it is not good practice. I'd suggest assigning true/false or assigning the object/undefined to hasConditionalStyling
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My choice would be true/false as you never actually access the object properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm checking for the existence of the "conditionalStyles" property in config, but yes, it is kind of dumb to actually assign it when it's present :) . I'll update this to do a better check of existence.
docs/configuration/layers/vector.md
Outdated
|
||
Set the shape of the legend swatch. "line" is the default. | ||
|
||
`"includeOtherLegendWithDefaultStyling": Boolean` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On further thought, I think I will reverse this to something like "hideOtherLegendWithDefaultStyling". I think we should include the default styling as a ... default :) . I think most uses of conditional styling will want to include the default, and I want to favour inclusion.
In some uses of conditional styling, styling is applied to feature values in a way that each feature is included and matches one style, similar to a pie chart. In such situations, including a style for the entire layer in a legend is unnecessary.
This adds a "hideLayer" property to legend configuration in vector layers and to legend display HTML. When added to a vector/GeoJSON layer's legend configuration and set to true, the symbology for the layer (but not its conditional styling) is omitted in the legends.