I have found that if I have an infoTemplate set for a feature layer, when I try to use map.infoWindow.setContent(attributeInspector) the infoTemplate content overrides it and continues to display.
If I first set
feature.setInfoTemplate()
with the blank parameters and then change the content, it works. Anyone know how to use map.infoWindow.destroyDijits or other methods to create a more elegant solution?
This JSFiddle demonstrates an infoTemplate overriding the setContent() method.
Sarah,
Sorry for bugging you again, but I ran into another issue. When I try to put this in with my current attribute inspector setup(working fine) it claims that the 'evt' is not defined. It will still allow the infowindows to be clicked on. Any ideas?
Thanks again.
map.on("click",function()
{
var option= registry.byId("selectfield");
var optionValue = option.value;
if (optionValue == "ON")
{console.log("adfasdfasdf");
asdf.setInfoTemplate();
initSelectToolbar(evt);
}
else { beacon1.setInfoTemplate(popupTemplate1);}
}
)
function initSelectToolbar(evt) {
var asdf = evt.layers[0].layer;
var selectQuery = new Query();
map.on("click", function(evt) {
var selectionQuery = new esri.tasks.Query();
var tol = map.extent.getWidth()/map.width * 15;
var x = evt.mapPoint.x;
var y = evt.mapPoint.y;
var queryExtent = new esri.geometry.Extent(x-tol,y-tol,x+tol,y+tol,evt.mapPoint.spatialReference);
selectionQuery.geometry = queryExtent;
asdf.selectFeatures(selectionQuery, FeatureLayer.SELECTION_NEW, function(features) {
//store the current feature
updateFeature = features[0]; console.log("adf");
map.infoWindow.setTitle(features[0].getLayer().name); console.log("adf");
map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint)); console.log("adf");
});
You need to pass in 'evt' as a parameter, so at the very top in order to capture the click event ('evt') and pass it on, try putting:
map.on('click', function(evt) {....
Now it's not liking this part... Is it an issue where my layers are added?
var asdf = evt.layers[0].layer;
Yes, in this part it's assuming the first layer in the map's layer array is the one you want to be working with. You can print your map object to the console to find the index for the layer you actually want.
Hrrmmm... Little stumped where to go from here. I'm not sure I understand why it's all of the sudden not defined upon adding popupTemplate. Is there an internal 'click' event that goes on in the popupTemplate? I'm not having luck with arrayUtils either.
Is 'evt' still not defined, or the layer part is not working? If it's the layer you can try to automatically add it at index '0':
map.addLayer(yourLayer, 0);
It's the 'evt'. I'm trying a different route, leaving the attribute inspector on and toggle off different infoWindows. I can get the toggle to work but destroying an info window is proving odd.
Appreciate your help, Sarah.
I see. Well my 2 cents is that an infoWindow is a dijit and dealing with dijits is awful. Make sure you are deleting not the just the variable, but also using the 'destroy' method on the dijit.
OH crap, you're right.. I'll keep tinkering to find something that works.
When you get the result from your query (aka features), set template for each feature and then set features (an array of features) to infoWindow. Pseudo codes:
for (var feature in features){
feature.setInfoTemplate(new InfoTemplate(title, content));
}
map.infoWindow.setFeatures(features)