<?xml version="1.0" encoding="utf-8"?>
<viewer:BaseWidget xmlns:esri="http://www.esri.com/2008/ags"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:mxeffects="com.adobe.ac.mxeffects.*"
xmlns:flash="flash.text.*"
xmlns:viewer="com.esri.viewer.*"
xmlns:widgets="widgets.*"
x="600" y="300"
widgetConfigLoaded="init()">
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.Map;
import com.esri.ags.events.GeometryServiceEvent;
import com.esri.ags.layers.GraphicsLayer;
import com.esri.ags.layers.Layer;
import com.esri.ags.symbols.SimpleFillSymbol;
import com.esri.ags.symbols.SimpleLineSymbol;
import com.esri.viewer.ViewerContainer;
import com.esri.viewer.AppEvent;
import flash.display.Sprite;
import flash.net.SharedObject;
import flash.printing.PrintJob;
import flash.text.TextField;
import mx.collections.ArrayCollection;
import mx.containers.Canvas;
import mx.controls.Alert;
import mx.controls.Image;
import mx.core.UIComponent;
import mx.graphics.ImageSnapshot;
import mx.graphics.codec.JPEGEncoder;
import mx.graphics.codec.PNGEncoder;
import mx.managers.CursorManager;
import mx.managers.PopUpManager;
import widgets.myPrint.PrintPreview;
import widgets.myPrint.layouts.A5_Landscape;
import widgets.myPrint.utils.PrintMapUtil;
//labels
[Bindable]
private var image:Image;
[Bindable]
private var graphic:Graphic;
[Bindable]
private var title:String;
[Bindable]
private var titleLabel:String;
[Bindable]
private var mapproduct:String;
[Bindable]
private var maptrait:String;
private function init():void
{
trace("MyPrintWidget init()");
AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated);
}
private function sharedDataUpdated(event:AppEvent):void
{
var data:Object = event.data;
if (data.key == "LayoutTitle")
{
var theObj:Object = data.collection[0];
mapproduct = theObj.mapproduct;
maptrait = theObj.maptrait;
title = mapproduct + maptrait;
}
}
private function landscapePrintPreview():void
{
graphicsLayer.clear();
// create instance of our map layout
var mapLayout:A5_Landscape = new A5_Landscape();
mapLayout.initialize();
mapLayout.map = map;
mapLayout.inputTxt.text = title;
// Create the popup and set its map layout
var popup:PrintPreview = PrintPreview(PopUpManager.createPopUp(map,PrintPreview,false));
popup.mapLayout = mapLayout;
}
private function imageHandler(image:Image):void
{
map.zoomSliderVisible = false;
map.scaleBarVisible = false;
var graphic:Graphic = PrintMapUtil.trimmedExtent(map,
image.width,
image.height);
graphicsLayer.clear();
graphicsLayer.add(graphic);
image.source = PrintMapUtil.trimmedMap(map,
image.width,
image.height);
map.zoomSliderVisible = false;
map.scaleBarVisible = false;
}
private function widgetClosedHandler(event:Event):void
{
graphicsLayer.visible = false;
setMapNavigation(null, null);
}
private function widgetMinimizedHandler(event:Event):void
{
this.widgetClosedHandler(event);
}
private function widgetOpenedHandler(event:Event):void
{
graphicsLayer.visible = true;
}
]]>
</fx:Script>
<fx:Declarations>
<esri:SimpleFillSymbol id="sfs" color="0xE95020" alpha="1" style="solid">
<esri:SimpleLineSymbol color="0xFF0000" width="4" alpha="1" style="solid" />
</esri:SimpleFillSymbol>
<esri:GraphicsLayer id="graphicsLayer" symbol="{sfs}"/>
</fx:Declarations>
<viewer:WidgetTemplate id="wTemplate"
closed="widgetClosedHandler(event)"
open="widgetOpenedHandler(event)"
minimized="widgetMinimizedHandler(event)"
skinClass="com.esri.viewer.skins.WidgetTemplateSkin"
width="260" height="134">
<s:VGroup width="100%" height="100%" verticalAlign="top" horizontalAlign="center">
<mx:Form id="frmPrint" verticalScrollPolicy="off" paddingBottom="0" width="100%" height="86">
<s:HGroup horizontalAlign="center" width="100%" verticalAlign="middle">
<mx:Text id="labelTxt" text="Map Title: " textAlign="right"/>
<s:TextInput id="input" text="{title}"/>
</s:HGroup>
<s:HGroup horizontalAlign="center" width="100%">
<s:Button label="Print Preview" click="landscapePrintPreview()"/>
</s:HGroup>
</mx:Form>
</s:VGroup>
</viewer:WidgetTemplate>
</viewer:BaseWidget>