4

How can I set the size of an infoWindow dynamically, based on the length of its Title, when the Title isn't known until the user clicks on a map feature?

Take the map here as an example - how could you resize the popup infoWindow to accommodate varying Title lengths?

This map uses the ${Name} notation to represent the Title field, with the field value substituted into the infoWindow when the feature is clicked.

The infoWindow has a fixed size (set using map.infoWindow.resize(250,95)). Since the length of the title isn't known until the feature is clicked, how is it possible to resize the infoWindow based on the length of the Title?

Using ArcGIS Server 10 with the JavaScript API 2.3

3
  • u ever resolve this one Stephen?
    – jakc
    Jan 9, 2013 at 5:12
  • 1
    @Simon nope, I never got around to resolving this as it dropped off my priority list. Perhaps you could listen for when the infoWindow opens, evaluate the length of the title, and resize according? Jan 9, 2013 at 5:24
  • 1
    @Simon see the example below for an approach (similar to my brilliant suggestion ;) Aug 26, 2014 at 4:14

1 Answer 1

1

Here is a jsFiddle example. Try clicking on Ohio for a smaller info window and then South Carolina for a larger info window.

The relevant code is below:

var g = evt.graphic;
map.infoWindow.setContent(g.getContent());
if(g.getTitle().length > 10){
  map.infoWindow.resize(500,500);
} else {
  map.infoWindow.resize(100,100);
}
2
  • Good one but the small window is not re-sizable working on your fiddle
    – Sunil
    Jul 25, 2013 at 13:33
  • @Sunil, not sure what you mean. The small window appears when you click a state that has a name less than 10 chars, like Ohio, and only draws a box with a width of 100px. Whereas as state with a name longer than 10 chars, like South Carolina, draws a box with a width of 500px. Let me know if you are seeing something else, or if I misunderstood your original question.
    – CLJ
    Jul 26, 2013 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.