Skip to content

Feat: limit markers to count #1265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
79 changes: 79 additions & 0 deletions examples/simple.geo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"stroke": "#555555",
"stroke-width": 2,
"stroke-opacity": 1,
"fill": "#555555",
"fill-opacity": 0.5
},
"geometry": {
"coordinates": [
[
[
6.3198722284199675,
46.475212657477016
],
[
5.744162894532366,
46.10709600323992
],
[
6.497738039632395,
45.70237717844603
],
[
7.134249175373981,
46.14082290891099
],
[
6.448472560825223,
46.030608286903174
],
[
6.3198722284199675,
46.475212657477016
]
]
],
"type": "Polygon"
},
"id": 0
},
{
"type": "Feature",
"properties": {},
"geometry": {
"coordinates": [
6.146144956875389,
46.4506138274553
],
"type": "Point"
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"coordinates": [
[
5.790034254132081,
46.35543828997646
],
[
5.693917615455717,
46.240555677111445
],
[
5.610702086380968,
46.37069535445781
]
],
"type": "LineString"
}
}
]
}
12 changes: 7 additions & 5 deletions python/ipyleaflet/ipyleaflet/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,9 @@ class Tooltip(UILayer):
offset: tuple, default (0, 0)
Optional offset of the tooltip position (in pixels).
direction: str, default 'auto'
Direction where to open the tooltip.
Possible values are: right, left, top, bottom, center, auto.
auto will dynamically switch between right and left according
Direction where to open the tooltip.
Possible values are: right, left, top, bottom, center, auto.
auto will dynamically switch between right and left according
to the tooltip position on the map.
permanent: bool, default False
Whether to open the tooltip permanently or only on mouseover.
Expand Down Expand Up @@ -2367,7 +2367,7 @@ class GeomanDrawControl(DrawControlBase):
circlemarker = Dict({ 'pathOptions': {} }).tag(sync=True)

# Hover style (applies for all drawing modes)
hover_style = Dict().tag(sync=True)
hover_style = Dict().tag(sync=True)

# Disabled by default
text = Dict().tag(sync=True)
Expand All @@ -2378,6 +2378,8 @@ class GeomanDrawControl(DrawControlBase):
cut = Bool(True).tag(sync=True)
rotate = Bool(True).tag(sync=True)

limit_markers_to_count = Int(-1).tag(sync=True)

def __init__(self, **kwargs):
super(GeomanDrawControl, self).__init__(**kwargs)
self.on_msg(self._handle_leaflet_event)
Expand Down Expand Up @@ -2420,7 +2422,7 @@ def on_click(self, callback, remove=False):
Whether to remove this callback or not. Defaults to False.
"""
self._click_callbacks.register_callback(callback, remove=remove)


def clear_text(self):
"""Clear all text."""
Expand Down
10 changes: 9 additions & 1 deletion python/jupyter_leaflet/src/controls/GeomanDrawControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export class LeafletGeomanDrawControlView extends LeafletControlView {
this.data_to_layers();
this.map_view.obj.addLayer(this.feature_group);

this.setControlOptions();

this.setMode();

this.map_view.obj.on(
Expand Down Expand Up @@ -398,7 +400,13 @@ export class LeafletGeomanDrawControlView extends LeafletControlView {
mode = mode.split(':')[1];
this.map_view.obj.pm.enableDraw(mode, this.model.get(mode.toLowerCase()));
} else if (mode == 'edit') {
this.map_view.obj.pm.enableGlobalEditMode();
let n_markers = this.model.get('limit_markers_to_count');
if (!n_markers) {
n_markers = -1;
}
this.map_view.obj.pm.enableGlobalEditMode({
limitMarkersToCount: n_markers
});
} else if (mode == 'drag') {
this.map_view.obj.pm.enableGlobalDragMode();
} else if (mode == 'remove') {
Expand Down
Loading