Skip to content

Commit d30b18a

Browse files
committed
Fixes #264
Simple fix, add a try catch around retrieving the popup text. I was unable to figure out *why* this error occurs. It seems the Drawn layers somehow look like they have a popup content without having the corresponding getPopup() method.
1 parent d56d9a5 commit d30b18a

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

streamlit_folium/frontend/src/index.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,30 @@ function onLayerClick(e: any) {
164164
const global_data = window.__GLOBAL_DATA__
165165
global_data.last_object_clicked = e.latlng
166166

167-
if (e.sourceTarget._tooltip && e.sourceTarget._tooltip._content) {
168-
let tooltip_text = extractContent(e.sourceTarget.getTooltip().getContent())
169-
global_data.last_object_clicked_tooltip = tooltip_text
170-
} else if (e.target._tooltip && e.target._tooltip._content) {
171-
let tooltip_text = e.target.getTooltip().getContent()(
172-
e.sourceTarget
173-
).innerText
174-
global_data.last_object_clicked_tooltip = tooltip_text
167+
try {
168+
if (e.sourceTarget._tooltip && e.sourceTarget._tooltip._content) {
169+
let tooltip_text = extractContent(e.sourceTarget.getTooltip().getContent())
170+
global_data.last_object_clicked_tooltip = tooltip_text
171+
} else if (e.target._tooltip && e.target._tooltip._content) {
172+
let tooltip_text = e.target.getTooltip().getContent()(
173+
e.sourceTarget
174+
).innerText
175+
global_data.last_object_clicked_tooltip = tooltip_text
176+
}
177+
} catch(error) {
178+
console.log(error);
175179
}
176180

177-
if (e.sourceTarget._popup && e.sourceTarget._popup._content) {
178-
let popup_text = e.sourceTarget.getPopup().getContent().innerText
179-
global_data.last_object_clicked_popup = popup_text
180-
} else if (e.target._popup && e.target._popup._content) {
181-
let popup_text = e.target.getPopup().getContent()(e.sourceTarget).innerText
182-
global_data.last_object_clicked_popup = popup_text
181+
try {
182+
if (e.sourceTarget._popup && e.sourceTarget._popup._content) {
183+
let popup_text = e.sourceTarget.getPopup().getContent().innerText
184+
global_data.last_object_clicked_popup = popup_text
185+
} else if (e.target._popup && e.target._popup._content) {
186+
let popup_text = e.target.getPopup().getContent()(e.sourceTarget).innerText
187+
global_data.last_object_clicked_popup = popup_text
188+
}
189+
} catch(error) {
190+
console.log(error);
183191
}
184192

185193
let details: Array<any> = []

0 commit comments

Comments
 (0)