Skip to content

Commit

Permalink
Solved issues for PR: docstring, ValueError and restructuring of mous…
Browse files Browse the repository at this point in the history
…e event code
  • Loading branch information
GiuseppeGalilei committed Nov 23, 2023
1 parent 0c0427f commit 606afc3
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ class GeoJson(Layer):
Function mapping a GeoJson Feature to a style dict.
highlight_function: function, default None
Function mapping a GeoJson Feature to a style dict for mouse events.
popup_keep_highlighted: bool, default False
Whether to keep the highlighting active while the popup is open
name : string, default None
The name of the Layer, as it will appear in LayerControls
overlay : bool, default True
Expand Down Expand Up @@ -569,26 +571,13 @@ class GeoJson(Layer):
function {{this.get_name()}}_onEachFeature(feature, layer) {
layer.on({
{%- if this.highlight and not this.popup_keep_highlighted %}
{%- if this.highlight %}
mouseout: function(e) {
if(typeof e.target.setStyle === "function"){
{{ this.get_name() }}.resetStyle(e.target);
}
},
mouseover: function(e) {
if(typeof e.target.setStyle === "function"){
const highlightStyle = {{ this.get_name() }}_highlighter(e.target.feature)
e.target.setStyle(highlightStyle);
}
},
{%- endif %}
{%- if this.highlight and this.popup_keep_highlighted %}
mouseout: function(e) {
if(typeof e.target.setStyle === "function"){
if(!{{ this.get_name() }}.isPopupOpen()){
{%- if this.popup_keep_highlighted %}
if (!{{ this.get_name() }}.isPopupOpen())
{%- endif %}
{{ this.get_name() }}.resetStyle(e.target);
}
}
},
mouseover: function(e) {
Expand All @@ -597,6 +586,7 @@ class GeoJson(Layer):
e.target.setStyle(highlightStyle);
}
},
{%- if this.popup_keep_highlighted %}
popupopen: function(e) {
if(typeof e.target.setStyle === "function"){
const highlightStyle = {{ this.get_name() }}_highlighter(e.target.feature)
Expand All @@ -609,7 +599,7 @@ class GeoJson(Layer):
}
},
{%- endif %}
{%- endif %}
{%- if this.zoom_on_click %}
click: function(e) {
if (typeof e.target.getBounds === 'function') {
Expand Down Expand Up @@ -690,9 +680,9 @@ def __init__(
)

if popup_keep_highlighted and popup is None:
raise NameError(
"A popup is needed to use the popup_keep_highlighted feature"
)
raise ValueError(
"A popup is needed to use the popup_keep_highlighted feature"
)
self.popup_keep_highlighted = popup_keep_highlighted

self.marker = marker
Expand Down

0 comments on commit 606afc3

Please sign in to comment.