Select to view content in your preferred language

Copy coordinates from context menu in FlexViewer 2.1

1555
8
10-04-2010 05:22 AM
MattiasEkström
Regular Contributor
Hello!
In my SFV 1.3 site I added the functionality to right click the map and copy coordinates to clipboard, based on code I found in the old forum, I think it was code from Robert Scheitlin.
I want the same thing in my new FlexViewer 2.1 site, I've come so far that I've added a custom item to the context menu that copies a hard-coded string to the clipboard.
I need some help figuring out how to get the coordinates, from the mapmanager.mxml.

In the SFV 1.3 the coordinates came from the banner (roberts modified banner that shows the coordinates) and the code looked like this:
var myString:String = SiteContainer.getInstance().controller.banner.mapXY;

I'm using the Coordinatewidget and I guess the best way is to get the coordinates from the 'coords' label in CoordinateWidget. But I don't know how to access that wigdet and label from the mapmanager.
Tags (2)
0 Kudos
8 Replies
EjayLai
New Contributor II
I'd like to see that too. Thanks.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Mattias,

    This is probably not the most elegant solution but it will require the least amount of changes to the framework.

    In the WidgetManager change line 66 from private to public.
public var controlContainer:Group;


Then in the MapManger.mxml add this to your context menu item click function
for (var c:int = 0; c < ViewerContainer.getInstance().widgetManager.controlContainer.numElements; c++){
                    try{
                        var cw:* = ViewerContainer.getInstance().widgetManager.controlContainer.getElementAt(c);
                        System.setClipboard(cw.coords.text); 
                    } catch(error:Error){}
                }
0 Kudos
MattiasEkström
Regular Contributor
Thanks Robert! That works great, even though I don't completely understand how it works, but am happy as long as it works 🙂
0 Kudos
MattiasEkström
Regular Contributor
I thought this worked, until I realized this morning that the coordinates that is copied to the clipboard is not the point were I right clicked but the point behind the context menu were I click when selecting the copy coordinates menu item.
The coordinates in the coordinate widget seems to "freeze" when I right click the map, but apparently they're not, not the ones I'm getting from the function that is triggered from my context menu item.

I guess I somehow need to first save the coordinate when right clicking and then access that saved coordinates from the functions that's triggered from my context menu item.

Does anyone have a solution for this??
0 Kudos
DasaPaddock
Esri Regular Contributor
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Dasa,

   So is it possible to get the stage XY from a ContextMenuEvent?
0 Kudos
MattiasEkström
Regular Contributor
I'm not skilled enough to figure out how to use the mouseX and localToGlobal() to get the coordinates from a ContextMenuEvent.
But I added an EventListener for the MENU_SELECT
map.contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, menuSelectHandler);
And put Roberts code to access the coordinates from the coordinatewidget in the menuSelectHandler function. Except I don't set the Clipboard just store it in another String that is set to Clipboard when the user clicks that specific menu item. I thought that made better sense 🙂
So now the correct coordinates are copied, so that works for now.

Thanks Dasa and Robert.
0 Kudos