Select to view content in your preferred language

Overriding a feature's infoTemplate using map.infoWindow.setContent()

7914
19
09-23-2014 11:10 AM
by Anonymous User
Not applicable

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.

Edit fiddle - JSFiddle

0 Kudos
19 Replies
williamcarr
Frequent Contributor

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");

    

            });

0 Kudos
by Anonymous User
Not applicable

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) {....

0 Kudos
williamcarr
Frequent Contributor

Now it's not liking this part... Is it an issue where my layers are added?

var asdf = evt.layers[0].layer;

0 Kudos
by Anonymous User
Not applicable

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.

0 Kudos
williamcarr
Frequent Contributor

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.

0 Kudos
by Anonymous User
Not applicable

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);

0 Kudos
williamcarr
Frequent Contributor

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.

0 Kudos
by Anonymous User
Not applicable

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.

0 Kudos
williamcarr
Frequent Contributor

OH crap, you're right.. I'll keep tinkering to find something that works.

0 Kudos
YungKaiChin
Regular Contributor

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)

0 Kudos