Skip to content

Commit

Permalink
feat: Add option "useCluster" for switching marker cluster on or off.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeeters authored and thet committed Apr 3, 2023
1 parent 24ac976 commit 57d1242
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
3 changes: 2 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ <h2>pat-leaflet demo - full</h2>
"geosearch": true,
"geosearch_provider": "nominatim",
"addmarker": true,
"maxClusterRadius": 80
"maxClusterRadius": 80,
"useCluster": true
}'
data-geojson='{
"type": "FeatureCollection",
Expand Down
14 changes: 9 additions & 5 deletions src/leaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -320,7 +325,6 @@ class Pattern extends BasePattern {
bounds = this.marker_cluster.getBounds();
map.fitBounds(bounds, this.fitBoundsOptions);
}

}

bind_popup(feature, marker) {
Expand Down

0 comments on commit 57d1242

Please sign in to comment.