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.
Solved! Go to Solution.
I've had a similar issue. I found if I had a layer with an infoTemplate that I needed to set it as empty before putting new content in the map infoWindow:
layer.setInfoTemplate(); map.infoWindow.clearFeatures(); map.infoWindow.setContent(newContent);
Tracy,
I don't know why the info is still there but you can manually clear this info by doing map.infoWindow.setFeatures([]);
That didn't take care of it. I put it in the cleanUp function as well as in the showLocation function.
Tracy,
I can't say that makes on bit of sense....
Try setting the infoWindows content to null.
map.infoWindow.setContent(null);
That didn't take care of it either. It must be the clusterLayer, which is based on GraphicsLayer. It doesn't happen with other types like FeatureLayers. If it was based on FeatureLayer, then you could expect it to inherit some of the 'clear' methods. I already have a map.graphics.clear, which didn't help.
At least the first content is from the geocoder. Most users will likely ignore the arrow, but for the curious, they're going to see something completely irrelevant. At first I thought it was only happening if the infoWindow was still open when I used the Geocoder. It doesn't seem to matter, it still remembers the contents from the previously selected graphic.
Tracy,
Completely up to you, but if you can throw together a simple sample app using esri or non sensitive data them I could look into it more.
I'll see what I can come up with. I looked through the clusterLayer.js file and I don't think I modified it at all. I only modified my function to use a queryTask to create the necessary input data to build the clusters in the first place. There's nothing fancy about my geocoder either.
Gotcha, My plate is just a little to full to go out and recreate an app that mimics your for testing.
I've had a similar issue. I found if I had a layer with an infoTemplate that I needed to set it as empty before putting new content in the map infoWindow:
layer.setInfoTemplate(); map.infoWindow.clearFeatures(); map.infoWindow.setContent(newContent);
And then set the infoTemplate back again? Otherwise I'll end up without an infoTemplate defined for my clusterLayer.