Select to view content in your preferred language

Flex - removing graphics layer

2693
1
10-06-2014 07:03 AM
JimBranch
Emerging Contributor

I hope there is an easy answer to this that my lack of programming skills is just not seeing.

I've modified the default 3.6 Flex Print tool to add a print area box like you can find in Tom Schuller's custom print script, 'PChPrintSOE'.  I've been able to get everything to work - the print area responds to changes in the layout and scale and when you hit print it only prints what is inside the box.  The only problem I'm having now is getting the print area to go away when you close the widget. 

I thought this would be simple but the WidgetTemplate that has the 'closed' event is in a different mxml from where the GraphicsLayer is declared and manipulated.  I just need 'hostBaseWidget.map.removeLayer(printGraphicsLayer);' to run when the 'wTemplate' in 'PrintWidget.mxml' is closed.  But the 'printGraphicsLayer' GraphicsLayer is in ExportWebMapForm.mxml.

I've tried adding an eventListener into 'ExportWebMapForm.mxml' but it either takes the graphic away at the wrong time or not at all.  I've tried declaring the GraphicsLayer in 'PrintWidget.mxml' and passing it to 'ExportWebMapForm.mxml' but haven't got that to work. 

I don't consider myself a flex programmer so I'm hoping I'm missing something really obvious.  Tom's original script contains the WidgetTemplate and GraphicsLayer all in the same .mxml so he just set the 'closed' parameter on the WidgetTemplate to run a function to remove the GraphicsLayer - I just don't know how to do this when the WidgetTemplate and GraphicsLayer are in 2 different .mxml's.

Here is a link to the site with the modified print tool: ArcGIS Viewer for Flex

Thanks for any help,

Jim

Tags (2)
0 Kudos
1 Reply
JimBranch
Emerging Contributor

I figured it out.  Here is the gist of it for anyone interested - or anyone who might want to point at a better way.

Instead of declaring the 'GraphicsLayer' in the ActionScript code I declared it as part of the <fx:Declarations> in the 'ExportWebMapFrom.mxml' that is opened by the 'PrintWidget.mxml'.  This allowed me to reference it from the 'PrintWidget.mxml'.

Then I added the 'closed' and 'open' parameters in the WidgetTemplate inside of the 'PrintWidget.mxml' to open functions to change the visibility of the GraphicsLayer.  The biggest thing I was missing was the 'getLayer' function on the map object to retrieve the layer to change the visibility.  The actual code ended up being simple:

private function wTemplate_closeHandler(event:Event):void

  {

  var myGraphicsLayer:GraphicsLayer = this.map.getLayer("printGraphicsLayer") as GraphicsLayer;

  myGraphicsLayer.visible = false;

  }

If anyone is interested in what this modified print widget does - it creates a graphic on the screen showing the extent of what is actually going to be printed to scale.  You can move the print area box around and it responds to changes from the widget's dropdowns like scale and page size.  For full disclosure, I've lifted all the custom code from Tom Schuller's 'PChPrintSOE' for this functionality.  Thanks Tom!

Once again, here is the sample site showing it live: ArcGIS Viewer for Flex

0 Kudos