-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclustering.js
41 lines (33 loc) · 1.13 KB
/
clustering.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var fs = require('fs'),
L = require('./leaflet');
function cluster(zoom, callback) {
callback = callback || function () {};
fs.readFile('sample-data.geojson', function (err, content) {
var data = JSON.parse(content);
var map = L.map('map', {
center: [38.543869175876154, -92.5433349609375],
zoom: zoom,
maxZoom: 12
}),
dataLayer = L.geoJson(data),
clusterLayer = new L.MarkerClusterGroup();
map.addLayer(clusterLayer);
clusterLayer.addLayer(dataLayer);
var features = clusterLayer._featureGroup.getLayers().map(function (cluster) {
var f = cluster.toGeoJSON();
f.properties.featureCount = cluster.__parent.getChildCount();
return f;
});
callback({
type: "FeatureCollection",
features: features
});
});
}
if (require.main === module) {
cluster(9, function (geojson) {
process.stdout.write(JSON.stringify(geojson));
});
} else {
module.exports = cluster;
}