Cluster for graphic layer Arcgis Javascript 3.x

1876
6
09-10-2019 08:07 AM
ADITYAKUMAR1
Occasional Contributor III

I have a graphic layer.

I want to cluster this data and display cluster on map(Arcgis JavaScript 3.x)

Any idea?

0 Kudos
6 Replies
BenElan
Esri Contributor
ADITYAKUMAR1
Occasional Contributor III

Hi Ben,

   

clusterLayer = new ClusterLayer({
              "data": photoInfo.data,
              "distance": 100,
              "id": "clusters",
              "labelColor": "#fff",
              "labelOffset": 10,
              "resolution": map.extent.getWidth() / map.width,
              "singleColor": "#888",
              "singleTemplate": popupTemplate
            });

In my case what will be the data?

Thanks

Kumar

0 Kudos
BenElan
Esri Contributor

This is how I would turn on clustering

var layer = new FeatureLayer(serviceUrl, {
      featureReduction: {
        type: "cluster"
      }
})

Here is a simple sample to demonstrate the code above

0 Kudos
VictorTey
Esri Contributor

Hi ADITYA KUMAR‌, the data will be

photoInfo.data = arrayUtils.map(resp, function(p) {
             
var latlng = new  Point(parseFloat(p.lng), parseFloat(p.lat), wgs);
             
var webMercator = webMercatorUtils.geographicToWebMercator(latlng);
             
var attributes = {
               
"Caption": p.caption,
               
"Name": p.full_name,
               
"Image": p.image,
               
"Link": p.link
             
};
             
return {
               
"x": webMercator.x,
               
"y": webMercator.y,
               
"attributes": attributes
             
};

so basically an array with the following structure.

           {
               
"x": 120,
               
"y": -32,
               
"attributes": {

                     "Caption": "caption",
                    
"Name": "a name",
                    
"Image": small.jpg,
                   
"Link": "http link"

                    }
             
};

0 Kudos
CRSC
by
New Contributor II

Hi Adithya, Can you pls tell me which module have you imported for ClusterLayer? Currently i'm using 4.20 JS API version.

RaviVadlamani
New Contributor

Is it possible to add clustering to graphics layer in version 4.27 ?
featureReduction props is not available in the docs also.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-GraphicsLayer.html#propert...

Is it possible to have clustering if it has only points geometry in graphics layer ? i know Polygon and Line string is not supported

0 Kudos