From 61f44873145cb77a2d0c792459aa84cc3d1f404e Mon Sep 17 00:00:00 2001 From: gjmooney Date: Wed, 6 Dec 2023 16:49:43 +0100 Subject: [PATCH 1/4] Expose MarkerCluster API options to ipyleaflet --- ipyleaflet/leaflet.py | 19 +++++++++++++++++++ js/src/layers/MarkerCluster.js | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/ipyleaflet/leaflet.py b/ipyleaflet/leaflet.py index d164d6985..e4806ffc6 100644 --- a/ipyleaflet/leaflet.py +++ b/ipyleaflet/leaflet.py @@ -1366,9 +1366,28 @@ class MarkerCluster(Layer): _model_name = Unicode("LeafletMarkerClusterModel").tag(sync=True) markers = Tuple().tag(trait=Instance(Layer), sync=True, **widget_serialization) + # Options + show_coverage_on_hover = Bool(True).tag(sync=True, o=True) + zoom_to_bounds_on_click = Bool(True).tag(sync=True, o=True) + spiderfy_on_max_zoom = Bool(True).tag(sync=True, o=True) + remove_outside_visible_bounds = Bool(True).tag(sync=True, o=True) + animate = Bool(True).tag(sync=True, o=True) + animate_adding_markers = Bool(False).tag(sync=True, o=True) disable_clustering_at_zoom = Int(18).tag(sync=True, o=True) max_cluster_radius = Int(80).tag(sync=True, o=True) + polygon_options = Dict({}).tag(sync=True, o=True) + + single_marker_mode = Bool(False).tag(sync=True, o=True) + spider_leg_polyline_options = Dict({"weight": 1.5, "color": "#222", "opacity": 0.5}).tag(sync=True, o=True) + spiderfy_distance_multiplier = Int(1).tag(sync=True, o=True) + + chunked_loading = Bool(False).tag(sync=True, o=True) + chunk_interval = Int(200).tag(sync=True, o=True) + chunk_delay = Int(50).tag(sync=True, o=True) + + + class LayerGroup(Layer): diff --git a/js/src/layers/MarkerCluster.js b/js/src/layers/MarkerCluster.js index b9815cce1..4f37d1ade 100644 --- a/js/src/layers/MarkerCluster.js +++ b/js/src/layers/MarkerCluster.js @@ -12,8 +12,26 @@ export class LeafletMarkerClusterModel extends layer.LeafletLayerModel { _view_name: 'LeafletMarkerClusterView', _model_name: 'LeafletMarkerClusterModel', markers: [], + show_coverage_on_hover: true, + zoom_to_bounds_on_click: true, + spiderfy_on_max_zoom: true, + remove_outside_visible_bounds: true, + animate: true, + animate_adding_markers: false, disableClusteringAtZoom: 18, maxClusterRadius: 80, + single_marker_mode: false, + spiderfy_distance_multiplier: 1, + polygon_options: {}, + chunked_loading: false, + chunk_interval: 200, + chunk_delay: 50, + + spider_leg_polyline_options: { + weight: 1.5, + color: '#333', + opacity: 0.5, + }, }; } } From 5b91c257f65cbe771740c7eced89490390d7d140 Mon Sep 17 00:00:00 2001 From: gjmooney Date: Thu, 7 Dec 2023 12:06:51 +0100 Subject: [PATCH 2/4] Update environment dependencies for docs --- docs/build-environment.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/build-environment.yml b/docs/build-environment.yml index 207331353..225a30d11 100644 --- a/docs/build-environment.yml +++ b/docs/build-environment.yml @@ -4,8 +4,8 @@ channels: - conda-forge dependencies: - - yarn~=1.0 - - jupyterlab~=3.6.0 + - yarn~=3.0 + - jupyterlab~=4.0 - jupyter-packaging~=0.12 - jupyter-sphinx - scipy @@ -18,4 +18,4 @@ dependencies: - jupyterlite-sphinx - jupyterlite-xeus-python >=0.9.2,<0.10 - pip: - - .. + - .. From 0e56a16510885118a531197ceb6dbe6decb6e12b Mon Sep 17 00:00:00 2001 From: gjmooney Date: Thu, 7 Dec 2023 12:07:19 +0100 Subject: [PATCH 3/4] Update documentation for MarkerCluster --- ipyleaflet/leaflet.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/ipyleaflet/leaflet.py b/ipyleaflet/leaflet.py index e4806ffc6..6c6510b53 100644 --- a/ipyleaflet/leaflet.py +++ b/ipyleaflet/leaflet.py @@ -1360,6 +1360,29 @@ class MarkerCluster(Layer): ---------- markers: list, default [] List of markers to include in the cluster. + show_coverage_on_hover: bool, default True + Mouse over a cluster to show the bounds of its markers. + zoom_to_bounds_on_click: bool, default True + Click a cluster to zoom in to its bounds. + spiderfy_on_max_zoom: bool, default True + When you click a cluster at the bottom zoom level, spiderfy it so you can see all of its markers. (Note: the spiderfy occurs at the current zoom level if all items within the cluster are still clustered at the maximum zoom level or at zoom specified by ``disableClusteringAtZoom`` option) + remove_outside_visible_bounds: bool, default True + Clusters and markers too far from the viewport are removed from the map for performance. + animate: bool, default True + Smoothly split / merge cluster children when zooming and spiderfying. If L.DomUtil.TRANSITION is false, this option has no effect (no animation is possible). + animate_adding_markers: bool, default False + If set to true (and animate option is also true) then adding individual markers to the MarkerClusterGroup after it has been added to the map will add the marker and animate it into the cluster. Defaults to false as this gives better performance when bulk adding markers. + disable_clustering_at_zoom: int, default 18 + Markers will not be clustered at or below this zoom level. Note: you may be interested in disabling ``spiderfyOnMaxZoom`` option when using ``disableClusteringAtZoom``. + max_cluster_radius: int, default 80 + The maximum radius that a cluster will cover from the central marker (in pixels). Decreasing will make more, smaller clusters. + polygon_options: dict, default {} + Options to pass when creating the L.Polygon(points, options) to show the bounds of a cluster. Defaults to empty, which lets Leaflet use the default `Path options `_. + + spider_leg_polyline_options: dict, default {"weight": 1.5, "color": "#222", "opacity": 0.5} + Allows you to specify `PolylineOptions `_ to style spider legs. + spiderfy_distance_multiplier: int, default 1 + Scale the distance away from the center that spiderfied markers are placed. Use if you are using big marker icons. """ _view_name = Unicode("LeafletMarkerClusterView").tag(sync=True) @@ -1377,15 +1400,9 @@ class MarkerCluster(Layer): disable_clustering_at_zoom = Int(18).tag(sync=True, o=True) max_cluster_radius = Int(80).tag(sync=True, o=True) polygon_options = Dict({}).tag(sync=True, o=True) - - single_marker_mode = Bool(False).tag(sync=True, o=True) spider_leg_polyline_options = Dict({"weight": 1.5, "color": "#222", "opacity": 0.5}).tag(sync=True, o=True) spiderfy_distance_multiplier = Int(1).tag(sync=True, o=True) - chunked_loading = Bool(False).tag(sync=True, o=True) - chunk_interval = Int(200).tag(sync=True, o=True) - chunk_delay = Int(50).tag(sync=True, o=True) - From 7d5bb6051456bce2a5093b42695c28f8b7357052 Mon Sep 17 00:00:00 2001 From: gjmooney Date: Fri, 8 Dec 2023 11:48:04 +0100 Subject: [PATCH 4/4] Clean up formatting --- ipyleaflet/leaflet.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ipyleaflet/leaflet.py b/ipyleaflet/leaflet.py index 6c6510b53..644ae016a 100644 --- a/ipyleaflet/leaflet.py +++ b/ipyleaflet/leaflet.py @@ -1378,7 +1378,6 @@ class MarkerCluster(Layer): The maximum radius that a cluster will cover from the central marker (in pixels). Decreasing will make more, smaller clusters. polygon_options: dict, default {} Options to pass when creating the L.Polygon(points, options) to show the bounds of a cluster. Defaults to empty, which lets Leaflet use the default `Path options `_. - spider_leg_polyline_options: dict, default {"weight": 1.5, "color": "#222", "opacity": 0.5} Allows you to specify `PolylineOptions `_ to style spider legs. spiderfy_distance_multiplier: int, default 1 @@ -1404,9 +1403,6 @@ class MarkerCluster(Layer): spiderfy_distance_multiplier = Int(1).tag(sync=True, o=True) - - - class LayerGroup(Layer): """LayerGroup class.