none
PointBasedClustering module: how to get the names of all the pushpins contained in a clustered pushpin ? RRS feed

  • Question

  • Hi Ricky,

    I'm using the last version of your nice module modified for the V8 and I wonder how to retreive those  infos please...

    In fact I'm using one significant name representing one integer value related to each individual pushpin and I would like to display the total of those values as text label for each clustered puspin on the map !

    Thanks in advance for your appreciated programming help and kind regards,

    Germain

    Saturday, October 22, 2016 7:01 AM

Answers

All replies

  • The cluster pushpin callback function receives a clusterInfo object. This object has an index property. Pass this index into the GetDataByClusterIndex function. This will return an array of all the pushpins that are in that cluster. From there you can access the custom property on the pushpin that you stored your data in.

    [Blog] [twitter] [LinkedIn]

    Monday, October 24, 2016 4:54 PM
  • Thank you for your guideline but please could you provide me with a coding example ?

    Actually I'm displaying the pushpin amount with the following code:

    function PBCMLoaded() {
        myLayer = new PBCE(map, {
            sPC: cP,
            cPC: cCP
        });
    }
    
    function cP(data, ci) {
        txt = data.Name;
        if (txt) {
            if (txt > 254) {
                txt = '+++';
            } else {
                txt = txt + '';
            }
    
            var pin = new Microsoft.Maps.Pushpin(ci.center, {
                icon: '../ypin.png',
                textOffset: new Microsoft.Maps.Point(0, 0),
                text: txt,
                anchor: new Microsoft.Maps.Point(12, 7)
            });
    
            if (map.getZoom() > 9) {
                lay.remove(pol[ci.center]);
                pol[ci.center] = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(ci.center.latitude - 0.05, ci.center.longitude - 0.05), new Microsoft.Maps.Location(ci.center.latitude - 0.05, ci.center.longitude + 0.05), new Microsoft.Maps.Location(ci.center.latitude + 0.05, ci.center.longitude + 0.05), new Microsoft.Maps.Location(ci.center.latitude + 0.05, ci.center.longitude - 0.05)], {
                    fillColor: 'rgba(0,255,255,0.1)',
                    strokeColor: 'black',
                    strokeThickness: 1,
                    strokeDashArray: '1 3'
                });
    
                lay.add(pol[ci.center]);
            } else {
                lay.clear();
            }
    
            return pin;
        }
    }
    
    function cCP(ci) {
        txt = ci.dataIndices.length + '*';
    
        var pin = new Microsoft.Maps.Pushpin(ci.center, {
            icon: '../ypin.png',
            textOffset: new Microsoft.Maps.Point(0, 0),
            text: txt,
            anchor: new Microsoft.Maps.Point(12, 7)
        });
    
        if (map.getZoom() > 9) {
            lay.remove(pol[ci.center]);
    
            pol[ci.center] = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(ci.center.latitude - 0.05, ci.center.longitude - 0.05), new Microsoft.Maps.Location(ci.center.latitude - 0.05, ci.center.longitude + 0.05), new Microsoft.Maps.Location(ci.center.latitude + 0.05, ci.center.longitude + 0.05), new Microsoft.Maps.Location(ci.center.latitude + 0.05, ci.center.longitude - 0.05)], {
                fillColor: 'rgba(255,255,0,0.1)',
                strokeColor: 'black',
                strokeThickness: 1,
                strokeDashArray: '1 3'
            });
    
            lay.add(pol[ci.center]);
        } else {
            lay.clear();
        }
    
        return pin;
    }

    As I would like to get for each pushpin in each cluster its Name, I don't understand fully how to retreive this property Name, sorry !


    • Edited by Ricky_Brundritt Monday, October 24, 2016 8:55 PM Made code more readable
    Monday, October 24, 2016 8:16 PM
  • You can add the following code to your cCP function:

    //This will retrieve all the data for all pushpins in the cluster. 
    //data[0].Name will give you the name of the first data object in the cluster.
    var data = myLayer.GetDataByClusterIndex(ci.index);
    
    var sum = 0;
    
    for(var i=0,len = data.length;i<len;i++){
    	sum += data[i].YourIntPropertyName;
    }
    


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Monday, October 24, 2016 9:08 PM
    • Marked as answer by VEHICALL Tuesday, October 25, 2016 6:13 PM
    Monday, October 24, 2016 9:08 PM
  • Thank you Ricky, it is so simple with a coding example but I was unable to find any of them with GetDataByClusterIndex...

    Here is my final resulting program:

    function cCP(ci){
     dat=myLayer.GetDataByClusterIndex(ci.index);
     sum=0;
     len=dat.length;
     for(i=0;i<len;i++){
      sum+=parseInt(dat[i].Name);
     }
     if(sum>999){
      sum='+++';
     }else{
      sum=sum+'';
     }
     var pin=new Microsoft.Maps.Pushpin(ci.center,{icon:'../ypin.png',textOffset: new Microsoft.Maps.Point(0,0),text:sum,anchor: new Microsoft.Maps.Point(12,7)});
    }

    Tuesday, October 25, 2016 6:13 PM
  • Tuesday, October 25, 2016 8:39 PM
  • Yes I know, but I prefer your point based solution instead of the grid or the mean average ones :-)
    • Edited by VEHICALL Tuesday, October 25, 2016 8:44 PM
    Tuesday, October 25, 2016 8:43 PM