How to create clustered layer using an array of latitudes and longitudes

155
1
12-28-2021 11:00 AM
BushraSyed1
New Contributor II

Hello!

I am currently adding points onto a map by looping through an array of latitudes and longitudes. I was wondering how I would cluster this on the map, so that it doesn't display as an individual point?

This is the code:

          var graphicsLayer = new GraphicsLayer();
          webmap.layers.add(graphicsLayer);

          var simpleMarkerSymbol = {
            type: "simple-marker", //
            color: [226, 119, 40], // orange
            size: 30,
            style: "circle",
            outline: {
              color: [255, 255, 255], // white
              width: 2
            }
          };

          for (i=0; i< zLongitude.length; i++ ){
            // Create a point
            var point = {
              type: "point",
              longitude: zLongitude[i],
              latitude: zLatitude[i],
            };

            var pointGraphic = new Graphic({
              geometry: webMercatorUtils.geographicToWebMercator(point),
              symbol: simpleMarkerSymbol
            });
            graphicsLayer.add(pointGraphic);
          }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Reply
ReneRubalcava
Frequent Contributor II

Clustering isn't supported in GraphicsLayer. You can add your features to a client-side FeatureLayer with featureReduction.

 

Here's a sample

https://codepen.io/odoe/pen/vYepwwR?editors=1000