Skip to content

Commit

Permalink
Show all props in tooltip if no prop is supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Jan 23, 2024
1 parent 3cceaa9 commit 268110a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/examples/geopandas/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
def create_map():
m = Map(map_options)
m.add_layer(wilderness_layer)
m.add_tooltip(LAYER_ID, "NAME")
# m.add_tooltip(LAYER_ID, "NAME")
m.add_tooltip(LAYER_ID, None)
return m


Expand Down
7 changes: 6 additions & 1 deletion maplibre/srcjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@
const popup = new maplibregl.Popup(popupOptions);
this._map.on("mousemove", layerId, (e) => {
const feature = e.features[0];
const text = feature.properties[property];
let text;
if (property === null) {
text = Object.keys(feature.properties).map((key) => `${key}: ${feature.properties[key]}`).join("</br>");
} else {
text = feature.properties[property];
}
popup.setLngLat(e.lngLat).setHTML(text).addTo(this._map);
});
this._map.on("mouseleave", layerId, () => {
Expand Down
10 changes: 9 additions & 1 deletion srcjs/pymaplibregl.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ export default class PyMapLibreGL {
const popup = new maplibregl.Popup(popupOptions);
this._map.on("mousemove", layerId, (e) => {
const feature = e.features[0];
const text = feature.properties[property];
let text;
if (property === null) {
text = Object.keys(feature.properties)
.map((key) => `${key}: ${feature.properties[key]}`)
.join("</br>");
} else {
text = feature.properties[property];
}

popup.setLngLat(e.lngLat).setHTML(text).addTo(this._map);
});

Expand Down

0 comments on commit 268110a

Please sign in to comment.