TransWikia.com

Leaflet Geodata Marker clustering and intersection

Geographic Information Systems Asked on February 18, 2021

I’m having a problem with grouping(clustering) markers

I have a list geosjon features that I display as markers in the leaflet. And it looks like this:

MapMarkers

These points are saved in my Database and are located on my Geoserver.

And when fetch them from DB I get it like this, then I loop over them and add them as markers.

const points = [
  { lat: 48.371768, lng: 16.723857 },
  { lat: 48.354206, lng: 16.703258 },
  { lat: 48.401474, lng: 16.727156 },
  { lat: 48.283497, lng: 16.545787 },
  { lat: 48.361275, lng: 16.699054 },
  { lat: 48.283497, lng: 16.545787 },
];

The problem that I’m having is that I have to summerize points on a within a specific radius and grouped(cluster) them automatically.

I have to expand points for some specific radius say 100 meters

Like in Turf js buffer option:

https://turfjs.org/

Like here:

enter image description here

And in Points where those circles intersect with each other, add an additional marker with those i already have

I have tried with Leaflet Clustering marker

https://github.com/Leaflet/Leaflet.markercluster

But haven’t had any luck, markers are not displayed at all.

Here is my code so far:

var markers = L.markerClusterGroup({
  maxClusterRadius: function (zoom) {
    return 10;
  },
});

points.forEach((point) => {
  const location = { latlng: { lat: point, point: event.lng } };
  var marker = L.marker(location.latlng);
  markers.addLayer(marker);
  this.layers.markersLayer.instance.addLayer(markers);
});

And that works fine but I would like to cluster points, by distance in meters instead of pixels like in maxClusterRadius

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP