Select to view content in your preferred language

InfoWindow Size

689
1
03-29-2012 06:34 AM
BetsySchenck-Gardner
Deactivated User
I know you can set the infoWindow size using the map.infoWindow.resize(x,y) command.  My question is whether you can dynamically calculate what the size of that window should be based on the content.  I have some information windows that contain a lot of content and therefore need to be very large.  I have other information windows that contain very little content and therefore don't need to be very large.  So programmatically I would like to figure out the size of each information window for each individual point.  Can this be done?
0 Kudos
1 Reply
ChadWilcomb
Deactivated User
If there are certain attributes that can be very long, you could do something like this...

var template = new esri.InfoTemplate();
template.setContent(getTextContent);

function getTextContent(graphic) {

    var attribute1 = graphic.attributes.Attribute1;
    var attribute2 = graphic.attributes.Attribute2;

    if (attribute1.length > 20 || attribute2.length > 20) {
        map.infoWindow.resize(x,y); //Resize the infoWindow
    }
    
    var content = "<b>Attribute 1</b>: " + attribute1 + "<br>";
    content += "<b>Attribute 2</b>: " + attribute2;
    return content;
}

0 Kudos