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.
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.
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 = “”;
}
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
By: Sam Rideout on May 19, 2011
at 10:32 pm
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
By: Marc on August 2, 2011
at 5:00 am
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.
By: Jeff Germain on August 3, 2011
at 5:13 pm
Hi Jeff, that did the trick. Thanks for the guidance!
-Marc
By: Marc on August 21, 2011
at 11:45 pm
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…..
By: Don Copple on September 22, 2011
at 10:16 pm
Don – sounds like your event layer is in a different projection than your map. Consider looking at the following classes since it may just be a simple geographic (wkid:4326) to web mercator (wkid:102100) issue. If so, this can be resolved client-side without calls to a geometry service.
WebMercatorMapPoint:
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/geometry/WebMercatorMapPoint.html
WebMercatorUtil:
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/utils/WebMercatorUtil.html
Good luck!
Jeff
By: Jeff Germain on September 23, 2011
at 12:48 am
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;
By: Jeff Germain on September 23, 2011
at 5:39 pm
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!
By: Chas Warner on February 3, 2012
at 4:29 am