AnsweredAssumed Answered

infoWindow content not clearing as expected from clusterLayer

Question asked by schlot on Mar 2, 2015
Latest reply on Mar 3, 2015 by sarahclark

I have a clusterLayer based on the point clustering example:https://developers.arcgis.com/javascript/jssamples/layers_point_clustering.html 

Toward the top, I define my infoTemplate and call the function to generate the clusters:

      infoTemplateContent = "<b>Status: ${FlagStatusDescription}</b><br>"
        +"Type: ${ItemFunctionDescription}<br>"
        +"Agency: ${AgencyAcronym}<br>"+
        "Address: ${EntityLocationAddress1}<br>"
        +"City: ${EntityLocationCity}<br>"
        + "IP address: ${II_IPAddress}";
                         
        infoTemplate = new InfoTemplate();
        infoTemplate.setTitle("Server ID: ${Item_Name}");
        infoTemplate.setContent(infoTemplateContent);
        
        createCluster();

 

Here's the function

  function createCluster(){
    var queryTask = new QueryTask(pathName+"/ArcGIS/rest/services/myService/MapServer/1");
    var query = new Query();
    query.returnGeometry = true;
    query.where = '1=1';
    query.outFields = ["*"];
    
    queryTask.on("complete", function(results){
        var inputInfo = {};
        inputInfo.data = arrayUtils.map(results.featureSet.features, function(feature){
          var point = feature.geometry;
          var att = feature.attributes; 
          var pointX = feature.geometry.x;
          var pointY = feature.geometry.y;
            return {
                "x": pointX,
                "y": pointY,
                "attributes": att
            };
        });

        var singleServerSymbol =  new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10, 
         new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0,0,0]), 1),new Color([0,205,0,0.25]));
        // cluster layer that uses OpenLayers style clustering 
  
        clusterLayer = new ClusterLayer({
            "data": inputInfo.data,
            "distance": 5,
            "id": "clusterLayer",
            "labelColor": "#fff",
            "labelOffset": 10,
            "resolution": res,
            "singleColor": "#00ca00",
            "singleSym": "singleServerSymbol",           
            "singleTemplate": infoTemplate
        });
        var renderer = new ClassBreaksRenderer(singleServerSymbol, "clusterCount");     
        var single = new PictureMarkerSymbol("https://static.arcgis.com/images/Symbols/Shapes/GreenCircleLargeB.png", 18, 18);
        var small = new PictureMarkerSymbol("https://static.arcgis.com/images/Symbols/Shapes/GreenPin1LargeB.png", 48, 48).setOffset(0, 15);
        var medium = new PictureMarkerSymbol("https://static.arcgis.com/images/Symbols/Shapes/GreenPin1LargeB.png", 64, 64).setOffset(0, 15);
        var large = new PictureMarkerSymbol("https://static.arcgis.com/images/Symbols/Shapes/GreenPin1LargeB.png", 96, 96).setOffset(0, 15);
        
        renderer.addBreak(0, 2, single);
        renderer.addBreak(2, 25, small);
        renderer.addBreak(25, 100, medium);
        renderer.addBreak(100, 5001, large);  
        clusterLayer.setRenderer(renderer);
        map.addLayer(clusterLayer, 1);
        queryTask.on("error", function(err){
            alert(err.details);
        });


       map.on("key-down", function(e){
            if (e.keyCode == 27) {
                cleanUp();
            }
        });
    });
    queryTask.execute(query);
}  
function cleanUp() { 
    map.infoWindow.hide();
    clusterLayer.clearSingles(); 
  }

I'm noticing that if I first click on a cluster to get information and follow that with the geocoder Widget, the infoContents that popup from my geocoder's showLocation function continues to retain the information from the clusterLayer.  It does start with evt.result.name,but also has the arrow indicating additional content.  When you click the arrow, you see the additional content content is the previously show information from the clusterLayer.

 

   function showLocation(evt){
       var symbol = new SimpleMarkerSymbol();
       symbol.setStyle(SimpleMarkerSymbol.STYLE_CIRCLE);
       symbol.setColor(new Color([255,128,0,0.75]));
       map.graphics.clear();
       var point = evt.result.feature.geometry;
       var graphic = new Graphic(point, symbol);
       map.graphics.add(graphic);
       map.infoWindow.setContent(evt.result.name);
       map.infoWindow.show(evt.result.feature.geometry);
   }  

 

It seems like the the cleanUp function for the clusterLayer would take care of this.  This project contains sensitive data, so I'm sorry I can't give you a link to the actual project.

Outcomes