Select to view content in your preferred language

Manually fire mapClick with infoWindowRenderersEnabled=true

952
4
11-29-2012 06:45 AM
NicholasRanicar
Emerging Contributor
Hi,
if you click the map in the Flex Viewer when infoWindowRenderersEnabled is true, a popup is displayed that contains details of all features found at that location.

If I programatically dispatch a MapMouseEvent.MAP_CLICK event to the map, nothing happens.

Does anyone know which object is handling this map click event, or how I can programatically fire it to get the infoWindow to display?

thanks,
Nic
Tags (2)
0 Kudos
4 Replies
NicholasRanicar
Emerging Contributor
I have managed to dispatch a MapMouseEvent and get the relevent handler to fire but am getting an exception thrown:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
 at com.esri.ags.events::MapMouseEvent/get stageX()
 at com.esri.ags.handlers::InfoWindowRendererHandler/map_clickHandler()
 at flash.events::EventDispatcher/dispatchEventFunction()
 at flash.events::EventDispatcher/dispatchEvent()
 at mx.core::UIComponent/dispatchEvent()


It would appear that the InfoWindowRendererHandler.map_clickHandler() requires the stageX/Y values to be set on the MapMouseEvent but there's no way to programatically do this (that I can figure out). Instantiating a new MapMouseEvent doesn't set these values and they're read-only on the object once it's been created.

This feels like a bug / shortcoming of either the MapMouseEvent constructor for not populating these values, or of the InfoWindowRendererHandler.map_clickHandler() for requiring these values.

Ideas on workarounds or solutions would be greatly appreciated! Unfortunately, the code for the MapMouseEvent and the InfoWindowRendererHandler is compiled into the API and not available to me.
0 Kudos
NicholasRanicar
Emerging Contributor
I've done some more investigation and playing around...

If I do this:
var mme:MapMouseEvent = new MapMouseEvent(MapMouseEvent.MAP_CLICK, map, idResult.point);
var result:Boolean = dispatchEvent(mme);

No exceptions are thrown but nothing happens either.


If I do this:
var mme:MapMouseEvent = new MapMouseEvent(MapMouseEvent.MAP_CLICK, map, idResult.point);
var result:Boolean = map.dispatchEvent(mme);

Then I get the exception listed in the original posting.
Conclusion: it looks like the event needs to be dispatched by the map object as well as the event having a reference to the map object.


If I do this:
var result:Boolean = map.dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));

No exceptions are thrown but nothing happens either.
Conclusion: it looks like the event needs to be a MapMouseEvent, not just a regular MouseEvent.


Finally, if I do this:
var mme:MapMouseEvent = new MapMouseEvent(MapMouseEvent.MAP_CLICK, map, idResult.point);
var sp:Point = map.toScreen(idResult.point);
mme.localX = sp.x;
mme.localY = sp.y;
var result:Boolean = map.dispatchEvent(mme);

I still get the exception thrown in the original posting.
Conclusion: setting coordinates on the MapMouseEvent makes no difference, so I'm really not sure how to prevent the exception thrown in the original posting...
0 Kudos
DasaPaddock
Esri Regular Contributor
Can you please explain your use case?

Also, this sample may help you:
http://resources.arcgis.com/en/help/flex-api/samples/index.html#/Display_popups_programmatically/01n...
0 Kudos
NicholasRanicar
Emerging Contributor
Hi Dasa,
I've found an alternative solution which is working well, however, what I was trying to do was to programatically launch the default map infoWindowRenderer at a given map point. I wanted to use the Identify task to find features within an extent and then use the mouseOver event for each of the found features to display all features falling under the center point of that feature.

I knew that I could manually build up popup renderers from the Identify task results but was hoping to make use of all of the configuration work already done for popups for each layer in the default map viewer config.xml. It would be nice to be able to configure layer definitions just once in the application and use that throughout the application, rather than have each widget need its own configuration.
Nic
0 Kudos