Posted by: Jeff Germain | May 5, 2011

Bug in ArcGIS API for Flex InfoWindow Workaround

Update:  I’ve added examples for ArcGIS Viewer API for Flex 2.4 and 2.3.1 at the bottom of this post

I’m a big fan of the new PopUpRenderer and ability to use popups on an ArcGISDynamicMapServiceLayer with little code. They’re especially nice when working within an ArcGIS Viewer for Flex app as they’re so configurable. However, I’ve discovered one wrinkle though. The layer does not clear the title (infoWindow.label) property, thus retaining any previous title. The default PopUpRenderer does not use the infoWindow.label property. It simply ignores it. Take the following examples.

First, I’ll click on a graphic, a tweet in this case. The tweet content is actually a component instance that is set via map.infoWindowContent. We also set the map.infoWindow.label with the tweet owner.

infowindow_tweet

Next, we click on a feature from an ArcGISDynamicMapServiceLayer which displays the popup using the configured PopUpRenderer. Notice the tweet title is persisted. This is regardless if we close the InfoWindow and click another feature. And this isn’t limited to ArcGISDynamicMapServiceLayers. FeatureLayers are affected too.

infowindow_popuprenderer

The application I’m developing makes heavy use of the map’s InfoWindow class. So, I wanted to resolve this bug with as few lines of code as possible and in one single location if possible.

Here’s what I did. Once the map is initialized, I add a listener to its infoWindow.content property. Since the InfoWindow only exposes the close event, I had to use a ChangeWatcher to keep an eye on the content property.

// Edits to fix bug in InfoWindow/PopUpRenderer that 
//does not clear out InfoWindow.label property
ChangeWatcher.watch(map.infoWindow, "content",
                     infoWindowContentChangeHandler);

When the content property changes I check to see if the content is of type PopUpRenderer. Because the PopUpRenderer does not use the InfoWindow.label property, I clear it.

private function infoWindowContentChangeHandler(event:Event):void
{
  if(map.infoWindow.content is PopUpRenderer)
  {
    map.infoWindow.label = "";
  }
}

Fixed. Though now we have the added hassle of remembering to tote this along to future projects until Esri addresses it.

Update:  ArcGIS Viewer API for Flex 2.3.1 and 2.4 

Insert code into the MapManager.mxml file

2.4 -

At 2.4, insert code into the existing method this_creationCompleteHandler and add additional handler as follows:

private function this_creationCompleteHandler():void
{
existing esri code…

… then

// Edits to fix bug in InfoWindow/PopUpRenderer that
// does not clear out InfoWindow.label property
// This is more of a defensive move!
ChangeWatcher.watch(map.infoWindow, “content”, infoWindowContentChangeHandler);
}

private function infoWindowContentChangeHandler(event:Event):void
{
map.infoWindow.label = “”;
}

2.3.1 -

At 2.3.1, insert code into the existing method init and add additional handler as follows:

private function init():void
{
existing esri code…

… then

// Edits to fix bug in InfoWindow/PopUpRenderer that
// does not clear out InfoWindow.label property
// This is more of a defensive move!
ChangeWatcher.watch(map.infoWindow, “content”, infoWindowContentChangeHandler);
}

private function infoWindowContentChangeHandler(event:Event):void
{
map.infoWindow.label = “”;
}

About these ads

Responses

  1. Hey…

    I’m having a somewhat similar problem with infowindows. I’ve just upgraded to Flex API 2.3.1 from 2.2 and the infowindows no longer respects setting the width and height values.

    Do you think I could use a similar method to re-set the height and width?

    Sam

  2. Hi Jeff,

    I’m having the same problem with popups. I’m using the uncompiled Flex Viewer 2.3.1 and I’m a bit of a novice, but know enough to be pretty dangerous. I’d like to implement you solution but I can’t figure out where to stick the code you provided.

    Thanks,
    Marc

    • Hi Marc,

      If you’re using the Flex Viewer, a logical place to implement this is in the MapManager.mxml file. Locate the init() function. Copy/paste the ChangeWatcher.watch code from post there. Then copy/paste the infoWindowContentChangeHandler function after the init() function.

  3. Hi Jeff, that did the trick. Thanks for the guidance!

    -Marc

  4. Hi Jeff,
    I am having a little different issue and trying to place my infowindow on a point that is created using an event layer. The click location if not poping up for the event layers location. It shows my popup off the coast of Africa. All other popups work fine, just the point file create by the event layer. Any ideas?

    Thanks…..

  5. Don –
    One more thing

    var anchorPoint:MapPoint = ;

    If you’re popping the window for the first time: _map.infoWindow.show(anchorPoint);

    Otherwise it’s already shown and you need to move it
    var screenPoint:Point = _map.toScreen(anchorPoint);
    _map.infoWindow.anchorX = screenPoint.x;
    _map.infoWindow.anchorY = screenPoint.y;

  6. Hey Jeff,

    Just wanted to thank you very much for posting this solution online in the way that you did. It helped me fix a bug on a project for the U.S. FWS, so it’s benefiting ecology too. Thanks man!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: