Skip to content

Commit b5b367b

Browse files
authored
Merge pull request #914 from PROgram52bc/master
implemented open_popup and close_popup methods
2 parents 3970dc7 + 284e020 commit b5b367b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

ipyleaflet/leaflet.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,24 @@ 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=None):
501+
"""Open the popup on the bound map.
502+
503+
Parameters
504+
----------
505+
location: list, default to the internal location
506+
The location to open the popup at.
507+
"""
508+
509+
if location is not None:
510+
self.location = location
511+
self.send({'msg': 'open', 'location': self.location if location is None else location})
512+
513+
def close_popup(self):
514+
"""Close the popup on the bound map."""
515+
516+
self.send({'msg': 'close'})
517+
500518

501519
class RasterLayer(Layer):
502520
"""Abstract RasterLayer class.

js/src/layers/Popup.js

Lines changed: 8 additions & 0 deletions
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) {
@@ -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)