Select to view content in your preferred language

Cluster Layer from data and the single Popup?

1118
4
10-09-2013 09:58 AM
AndrewDavis
Deactivated User
Hey there..
I am working with the esri ClusterLayer.js and have gotten to the point here I can feed it a large JSON and then have it render successfully on my webmap.  I have been reading many of the different threads (a really good one: http://forums.arcgis.com/threads/68422-ESRI-point-clustering-example-using-featurelayer-or-querytask...)  and they are all of a help but I am confused about how to render the individual infoWindow or popup for the singles.  The best I have been able to get is the "clusterID" and then the value to show in the "singletemplate"..



I am calling it thusly..
Using the code from the examples..


 var aDocs= [{
   "place": "a happy place",
   "label": "a happy label",
   "coords": "33.540744, -117.782432�?�
 },{
   "place": "another nearby happy place",
   "label": "a happy label",
   "coords": "33.540744, -117.782432" 
 }];

 function addClusters(aDocs){
   try{
      for (var key in aDocs){
         console.log(aDocs [key];
         var myObj = aDocs [key];
         var coordPair = [];
         for(var prop in myObj){
            if (myObj.hasOwnProperty(prop)){
              if(prop === �??coords�??){
                   coordPair = myObj[prop].split(�??,�??);
                   myObj[�??y�?�] = parseFloat(coordPair[0]);
                   myObj[�??x�?�] = parseFloat(coordPair[1]);
              }
            }
         }       
       }
     clusterLayer = new extras.ClusterLayer({


       �??data�?�: aDocs,
        �??distance�?�: 100,
        �??id�?�:�?�clusters�?�,
        �??labelColor�?�: �??#fff�?�,
        �??labelOffset�?�: 10,
         �??resolution�?�: map.extent.getWidth() / map.width,
        �??singleColor�?�: �??#888�?�,
        �??singleTemplate�?�: infoTemplate
     });
   }
   catch(e){
     console.log(e);
   }
 }
 


Does anyone know how to get setup the template?


I've been able to put over 2,000 points on the map and everything looks nice but the infoTemplate is eluding me..

Andy...
0 Kudos
4 Replies
StephenLead
Honored Contributor
In your code you use:


"singleTemplate": infoTemplate



but I can't see where you've defined infoTemplate in the code snippet. Can you include a link to your live site, or otherwise show more code?


What about putting a breakpoint on that line and verifying that infoTemplate exists?


If you look at the sample at http://developers.arcgis.com/en/javascript/samples/layers_point_clustering and step through the code, you can see that they first define the info window, then use it as you have done:


var popupTemplate = PopupTemplate({
....
});


clusterLayer = new ClusterLayer({
 �?�
 "singleTemplate": popupTemplate
});



so you're on the right track - you may be missing the infoTemplate definition.


Steve
0 Kudos
AndrewDavis
Deactivated User
In your code you use:


"singleTemplate": infoTemplate



but I can't see where you've defined infoTemplate in the code snippet. Can you include a link to your live site, or otherwise show more code?


What about putting a breakpoint on that line and verifying that infoTemplate exists?


If you look at the sample at http://developers.arcgis.com/en/javascript/samples/layers_point_clustering and step through the code, you can see that they first define the info window, then use it as you have done:


var popupTemplate = PopupTemplate({
....
});


clusterLayer = new ClusterLayer({
 �?�
 "singleTemplate": popupTemplate
});



so you're on the right track - you may be missing the infoTemplate definition.


Steve


Steve, Thanks for the reply.  I am able to add the example points and see the example single popup on my home machine

I am working on getting the data from my own collection of objects to work with the popup.  My scripts are not written with the AMD notation, and I am missing something in translation from the examples to my work. 

I will post the code after I get it organized on my home machine.


Andy..
0 Kudos
AndrewDavis
Deactivated User
Still trying to figure this out.
I need to be able to feed a set of values in from a database query (non  esri query) which comes back in a Collection of Objects

Attached  is the code for an example I am trying to unwind and then use.   I can  get the click event with a listener connected to the button  inside the  script.  My issue seems to be that I am unable to call the  "addClusters"  function with myData from outside of the script I have  attached here  without this listener. I have this working in javascript  without the AMD but am getting hung up on the   "myData =  arrayUtils.map" line in non-AMD code.

I have been looking at Subscibers and Publishers for trying to capture  the change in status from my database query that would be looking out of  the grouped functionality for a database response with no  luck.

If anyone has advice regarding how to push a database response in I  would love the input. attached is my example that I have changed  to take input from a collection of objects and is listening for the  button click.

Andy
0 Kudos
AndrewDavis
Deactivated User
**Edited**..  I re-read this and it kind of walked from single popup into an AMD issue.  The reason..  I could not get my legacy style code to create the popup info correctly but the newer examples all worked (I'm running jsapi 3.6 locally).  So.. off I went to figure out why it was different, and realized I had to use the AMD style of js.  Or at least that would work.. while my attempt didnt.


I was reading more about AMD and how the newer scripting will be using much more of it, https://developers.arcgis.com/en/javascript/jshelp/inside_dojo_amd.html

This Thread:  http://forums.arcgis.com/threads/91611-Legacy-code-vs-AMD-code?highlight=AMD

has a few links for you as well.

I also found some tutorials on it, and made a simple page which will allow you to see some of the behaviors of 'publish' and 'subscribe'.    I am including it as a .zip file for anyone who can use it.  Watch the console tab in FireBug if you are running FireFox and you can see the interplay between the different subscribers and publishers.


This was the thing I was looking for.  I can now use this to take responses from a database query, and 'publish' them where a 'subscriber' inside my map.js script will see the publication through its subscription and feed the data to the ClusterLayer.js.
0 Kudos