Select to view content in your preferred language

Info Window blank on intial map.infoWindow.show()

1529
3
05-16-2012 02:47 PM
DaveHighness
Deactivated User
I am doing an identify task and take the first returned feature, symbolize it, add an Info Window Template and then add the graphic to the map. Finally I tell the Info Window to Show using the identify point. On first showing the Info Window always is blank. If I close the Info Window and then open again it is filled in correctly. On subsequent identifies it is filled in correctly. Any idea whats up?

This is designed to work with the currently selected (active) layer in a dynamic map service. We'd like the Info Window to display on click.

function showFeature(response) {
    map.graphics.clear();    

    var layer = response[0];
    var feature = layer.feature;

    var symbol;
    if (layer.geometryType == 'esriGeometryPolygon') {
        symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
            new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
            new dojo.Color([0,0,125,0.6]), 2),new dojo.Color([0,0,255,0.6]));
    }
    else if (layer.geometryType == 'esriGeometryPolyline') {
        symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
            new dojo.Color([0,0,125,0.6]), 5);
    }
    else if (layer.geometryType == 'esriGeometryPoint' || layer.geometryType == 'esriGeometryMultipoint') {
        symbol =  new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10,
           new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
           new dojo.Color([0,0,255]), 2),
           new dojo.Color([0,0,125,0.6]));
    }
    else {
        Ext.MessageBox.alert("INFORMATION", "Geometry not symbolized");
        return;
    }
    
    feature.setSymbol(symbol);

    var infoTemplate = new esri.InfoTemplate();
    infoTemplate.setTitle(layer.layerName);
    
    var contStr = "<table>";
    for (var prop in feature.attributes) {
        contStr += "<tr><td><b>" + prop + ":</b></td><td>${" + prop + "}</td></tr>";
    }
    contStr += "</table>";

    infoTemplate.setContent(contStr);

    feature.setInfoTemplate(infoTemplate);

    map.graphics.add(feature);
    map.infoWindow.show(identPnt);
    //setTimeout(function () { map.infoWindow.show(identPnt); }, 1000);
}
0 Kudos
3 Replies
DaveHighness
Deactivated User
Another, likely related, issue is that on subsequent identifies where it displays the info window populated the contents are for the previously identified feature and not the current one.
0 Kudos
StephenLead
Honored Contributor
Dave,

I haven't tested this, but you could try setting the map's infoWindow content and title directly:

map.infoWindow.setTitle(layer.layerName);
map.infoWindow.setContent(contStr);
map.infoWindow.show(identPnt);


Off-topic, but rather than doing this:
    if (layer.geometryType == 'esriGeometryPolygon') {
      ...
    }
    else if (layer.geometryType == 'esriGeometryPolyline') {
     ...
    }
    else if (layer.geometryType == 'esriGeometryPoint' || layer.geometryType == 'esriGeometryMultipoint') {
     ...
    }
    else {
    ...
    }


you could use a SWITCH statement, which is more efficient as it only needs to evaluate once.

Good luck,
Steve
0 Kudos
DaveHighness
Deactivated User
Yeah, that did it. It seems counter intuitive to have to do this but I populate the window twice, once for the map.infoWindow and again for the feature.infoWindow. Shouldn't there be a Map onGraphicAdded event that passes and reference to the added Graphic and a Graphic.openInfoWindow() method?

    var infoTemplate = new esri.InfoTemplate();
    infoTemplate.setTitle(layer.layerName);
    map.infoWindow.setTitle(layer.layerName);
    
    var contStr = "<table style='width:290px'>";
    var mapStr = "<table style='width:290px'>";
    for (var prop in feature.attributes) {
        contStr += "<tr><td style='text-align:right'><b>" + prop + ":</b></td><td> ${" + prop + "}</td></tr>";
        mapStr += "<tr><td style='text-align:right'><b>" + prop + ":</b></td><td> " + feature.attributes[prop] + "</td></tr>";
    }
    contStr += "</table>";
    mapStr += "</table>";

    infoTemplate.setContent(contStr);
    map.infoWindow.setContent(mapStr);

    feature.setInfoTemplate(infoTemplate);

    map.graphics.add(feature);
    map.infoWindow.show(identPnt, esri.dijit.InfoWindow.ANCHOR_UPPERRIGHT);


Thanks, Dave
0 Kudos