Cluster for graphic layer Arcgis Javascript 3.x

974
5
09-10-2019 08:07 AM
ADITYAKUMAR1
Occasional Contributor II

I have a graphic layer.

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

Any idea?

0 Kudos
5 Replies
BenElan
Esri Contributor
ADITYAKUMAR1
Occasional Contributor II

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

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

0 Kudos