From 57d124212504aee9e77399aaf361dcd0d0d514f7 Mon Sep 17 00:00:00 2001 From: Martin Peeters Date: Thu, 16 Feb 2023 09:35:37 +0100 Subject: [PATCH] feat: Add option "useCluster" for switching marker cluster on or off. --- src/documentation.md | 1 + src/index.html | 3 ++- src/leaflet.js | 14 +++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/documentation.md b/src/documentation.md index 1cc78e2..3c9ed47 100644 --- a/src/documentation.md +++ b/src/documentation.md @@ -35,6 +35,7 @@ You might also check [their documentation](https://leafletjs.com/reference.html) | latitude | 0.0 | | Float | Latitude of the map. | | longitude | 0.0 | | Float | Longitude of the map. | | boundsPadding | 20 | | Integer | Padding for map boundaries. | +| useCluster | true | | Boolean | Enable/Disable the marker cluster feature. | | maxClusterRadius | 80 | | Integer | Set the marker cluster radius. | | zoom | auto | 1 - 19 | Integer | Zoom level of he map. | | zoomControl | true | | Boolean | Show zoom control buttons. | diff --git a/src/index.html b/src/index.html index 8be9e54..7e8e20e 100644 --- a/src/index.html +++ b/src/index.html @@ -32,7 +32,8 @@

pat-leaflet demo - full

"geosearch": true, "geosearch_provider": "nominatim", "addmarker": true, -"maxClusterRadius": 80 +"maxClusterRadius": 80, +"useCluster": true }' data-geojson='{ "type": "FeatureCollection", diff --git a/src/leaflet.js b/src/leaflet.js index 00faeb9..24e4061 100644 --- a/src/leaflet.js +++ b/src/leaflet.js @@ -16,6 +16,7 @@ parser.addArgument("longitude", "0.0"); parser.addArgument("zoom", "auto"); parser.addArgument("maxClusterRadius", "80"); +parser.addArgument("useCluster", true); parser.addArgument("boundsPadding", "20"); @@ -82,9 +83,13 @@ class Pattern extends BasePattern { sleepOpacity: 1, })); - const marker_cluster = (this.marker_cluster = new LMarkerClusterGroup({ - maxClusterRadius: this.options.maxClusterRadius, - })); + if (options.useCluster == true) { + this.marker_cluster = new LMarkerClusterGroup({ + maxClusterRadius: this.options.maxClusterRadius, + }); + } else { + this.marker_cluster = new this.L.featureGroup(); + } // hand over some map events to the element map.on("moveend zoomend", (e) => { @@ -196,7 +201,7 @@ class Pattern extends BasePattern { { properties: { editable: true, popup: e.location.label } }, e.marker ); - marker_cluster.addLayer(e.marker); + this.marker_cluster.addLayer(e.marker); } // fit to window map.fitBounds([latlng], fitBoundsOptions); @@ -320,7 +325,6 @@ class Pattern extends BasePattern { bounds = this.marker_cluster.getBounds(); map.fitBounds(bounds, this.fitBoundsOptions); } - } bind_popup(feature, marker) {