Skip to content

Commit 55216fa

Browse files
committed
implemented open_popup and close_popup methods
1 parent 3970dc7 commit 55216fa

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ipyleaflet/leaflet.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ class Popup(UILayer):
497497
auto_close = Bool(True).tag(sync=True, o=True)
498498
close_on_escape_key = Bool(True).tag(sync=True, o=True)
499499

500+
def open_popup(self, location=def_loc):
501+
self.send({'msg': 'open', 'location': location})
502+
503+
def close_popup(self):
504+
self.send({'msg': 'close'})
500505

501506
class RasterLayer(Layer):
502507
"""Abstract RasterLayer class.

js/src/layers/Popup.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class LeafletPopupView extends layer.LeafletUILayerView {
3434
this.obj = L.popup(this.get_options()).setLatLng(
3535
this.model.get('location')
3636
);
37+
this.model.on('msg:custom', this.handle_message.bind(this));
3738
}
3839

3940
initialize(parameters) {
@@ -94,7 +95,7 @@ export class LeafletPopupView extends layer.LeafletUILayerView {
9495
this.set_child(this.model.get('child'));
9596
});
9697
this.model.on_some_change(
97-
['min_width', 'max_width', 'max_height'],
98+
['min_width', 'max_width', 'max_height', 'location'],
9899
this.update_popup,
99100
this
100101
);
@@ -115,4 +116,11 @@ export class LeafletPopupView extends layer.LeafletUILayerView {
115116
this.map_view.obj.closePopup(this.obj);
116117
}
117118
}
119+
handle_message(content) {
120+
if (content.msg == 'open') {
121+
this.map_view.obj.openPopup(this.obj, content.location);
122+
} else if (content.msg == 'close') {
123+
this.map_view.obj.closePopup(this.obj);
124+
}
125+
}
118126
}

0 commit comments

Comments
 (0)