The cluster source may be used with any type of feature, but it is typically used with a set of point features. This example illustrates using the cluster source with some randomly generated points that are included with the sample files for this project in assets
/ data
/ cluster.geojson
. We'll first show the original data, then modify the example to use the cluster source. The following are the steps:
Starting from the previous example, we will add a new vector source that loads the sample data:
var originalSource = new ol.source.GeoJSON({ url: '../assets/data/cluster.geojson' });
Next, we will create a cluster source to cluster these features:
var originalLayer = new ol.layer.vector({ source: originalSource, });
Then, add the new layer to the map's
layers
array:var map = new ol.Map({ target: 'map', layers: [vectorLayer, originalLayer], view: view });
Load this in your browser and take a look:
That's a lot of points—about 5000 actually. If...