You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've searched through the plugins to make sure this feature isn't already available, or think it shouldn't require a plugin.
I've searched through the current issues to make sure this feature hasn't been requested already.
I agree to follow the Code of Conduct that this project adheres to.
Motivation
Hello, thanks for the great lib.
The geojson layers has plenty of QoL methods like geojson.resetStyle() that would be great to have when working with other types of layers, in my case L.featureGroup.
When hovering off a featureGroup it is very inconvenient to reset its style, when each element of it has a different style. The advice found on the internet advising to store a default and highlight style, only works when you want to style all the elements similarly.
pseudo-code MCVE
consthighLightStyle={weight: 3,color: '#666',dashArray: '',fillOpacity: 0.7,};letcurrentlyHighlighted: L.Layer|undefined=undefined;constresetHighlight=(e: L.LeafletMouseEvent)=>{
???// here layer.resetStyle() would be perfect// layer.options does not work for FeatureGroup};consthighlightFeature=(e: L.LeafletMouseEvent)=>{letlayer=e.target;currentlyHighlighted=layer;layer.setStyle(highLightStyle);layer.bringToFront();};exportconstmcve=(map: L.Map)=>{// minimal geojson polygonconstpolygon={
...
}constgeojson=L.geoJson(polygon,{style: ... });// different than the circlesconstcircles=[...]// each circle has a different style// in my case the click behavior is different for circles and geojson, and is added independently ...// mouseover is sharedconstlayer=L.featureGroup([polygon, ...circles]);layer.on({mouseover: highlightFeature,mouseout: resetHighlight,});layer.addTo(map);}
Suggested solution
Add resetStyle method to L.featureGroup, behaving exactly like the method of the same name on L.geojson
Alternatives considered
Maybe to amend the geojson to add the circles as a MultiPoint in it? But in that case hovering over a point would not display the outline of the polygon.
The text was updated successfully, but these errors were encountered:
In the meantime, if someone else stumbles on this issue, here is a workaround (basically tracking the style of each object yourself).
consthighLightStyle={weight: 3,color: '#666',dashArray: '',fillOpacity: 0.7,};constresetHighlight=(originalStyle: OriginalStyle)=>(e: L.LeafletMouseEvent)=>{originalStyle.resetStyle()};consthighlightFeature=(e: L.LeafletMouseEvent)=>{letlayer=e.target;currentlyHighlighted=layer;layer.setStyle(highLightStyle);layer.bringToFront();};exportconstmcve=(map: L.Map)=>{// minimal geojson polygonconstpolygon={
...
}constoriginalStyle=newOriginalStyle();constgeojson=L.geoJson(polygon,{style: style});// different than the circlesoriginalStyle.addGeoJson(geojson,style(style));constcircles=[...]// each circle has a different stylecircles.foreach(c=>originalStyle.addPath(c));// in my case the click behavior is different for circles and geojson, and is added independently
...
// mouseover is sharedconstlayer=L.featureGroup([polygon, ...circles]);layer.on({mouseover: highlightFeature,mouseout: resetHighlight(originalStyle),});layer.addTo(map);}conststyle=(feature?: Feature): L.PathOptions=>{ ... }// Manually track the original style of each object in the layerclassOriginalStyle{privateelm: [L.Path|L.GeoJSON,L.PathOptions][];constructor(){this.elm=[];}addPath(layer: L.Path){// deepCopy is conservative herethis.elm.push([layer,deepCopy(layer.options)]);}addGeoJson(geojson: L.GeoJSON,styleOptions: L.PathOptions){// deepCopy is conservative herethis.elm.push([geojson,deepCopy(styleOptions)]);}resetStyle(){for(const[layer,style]ofthis.elm){layer.setStyle(style);}}}
Checklist
Motivation
Hello, thanks for the great lib.
The geojson layers has plenty of QoL methods like
geojson.resetStyle()
that would be great to have when working with other types of layers, in my caseL.featureGroup
.When hovering off a
featureGroup
it is very inconvenient to reset its style, when each element of it has a different style. The advice found on the internet advising to store adefault
andhighlight
style, only works when you want to style all the elements similarly.pseudo-code MCVE
Suggested solution
Add
resetStyle
method toL.featureGroup
, behaving exactly like the method of the same name onL.geojson
Alternatives considered
Maybe to amend the geojson to add the circles as a
MultiPoint
in it? But in that case hovering over a point would not display the outline of the polygon.The text was updated successfully, but these errors were encountered: