Drawing Tool
View live sample | Download as a zip file
Description
Use the drawing tools provided by Supergeo to draw graphics. Use "drawPt()", "drawPolyline()", and "drawPolygon()" to draw points, lines, and polygons, respectively. And use "MapControlEvents.REBUILT" to move the graphics when panning maps.
How To Use
1. Download and include "drawPt.as".
2. Copy and modify the codes below to meet your needs.
Code
                                <?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
			   xmlns:sgw="library://www.supergeotek.com/sgw"
			   
			   initialize="application1_initializeHandler(event)">
	<fx:Script>
 
		<![CDATA[
			import Core.ICommand;
			import Core.IDisplayTransformation;
			import Core.ITool;
			import Geometry.Envelope;
			import MapLayer.MapCachedLayer;
			import MapLayer.MapLayer;
			import MapLayer.MapLayerEvents;
			import MapLayer.MapLayerInner;
			import Tool.*;
			import Tool.FullExtentTool;
			import Tool.Identify;
			import Tool.MapZoomStep;
			import Tool.PanTool;
			import Tool.ZoomLastTool;
			import Tool.ZoomTool;
			import mx.events.FlexEvent;
			
			protected function application1_initializeHandler(event:FlexEvent):void
			{
				var pLyr:MapLayer = new MapLayer();
				pLyr.addEventListener(MapLayerEvents.LOADED, maptilelayer1_LoadedHandler);
				pLyr.Name = "SGW";
				pLyr.Title = "SGW";
				pLyr.ResourcePath="http://sgs.supergeo.com.tw/vietnam/Agent.aspx";
			}
			
			protected function maptilelayer1_LoadedHandler(vEvent:MapLayerEvents):void
			{
				var pStep:MapZoomStep= new MapZoomStep(oMapBase);
				var pLyr:MapLayer = vEvent.currentTarget as MapLayer;
				
				var pExt:Envelope = pLyr.Extent;
				oMapBase.AddLayer(pLyr);
				
				var pTrans:IDisplayTransformation = new LevelTransformation(256 / (pExt.Right - pExt.Left), 0, 15);
				oMapBase.Transformation = pTrans as IDisplayTransformation;
				
				oToolbar.AddTool(new ToolbarItem(new ZoomTool(0), "Images/Button/Zoom_In.png", "Zoom In"));
				oToolbar.AddTool(new ToolbarItem(new ZoomTool(1), "Images/Button/Zoom_Out.png", "Zoom Out"));
				oToolbar.AddTool(new ToolbarItem(new PanTool(), "Images/Button/Move.png", "Pan"));
				oToolbar.AddTool(new ToolbarItem(new FullExtentTool(), "Images/Button/FullExtent.png", "Full Extent"));
				oToolbar.AddTool(new ToolbarItem(new ZoomLastTool(pStep, true), "Images/Button/Zoom_Prev.png", "Prev Extent"));
				oToolbar.AddTool(new ToolbarItem(new ZoomLastTool(pStep, false), "Images/Button/Zoom_Next.png", "Next Extent"));
				
				var pExt1:Envelope = new Envelope(104.662836, 21.605708, 106.444138,20.613185) as Envelope;
				oMapBase.ZoomMapTo(pExt1);
				oMapBase.RefreshMap(true);          
			}
			
			protected function pQuery(vEvent:Tool.Identify):void{
			}
			
			protected function button1_clickHandler(event:MouseEvent):void
			{
				//DRAW POINT TOOL
				oMapBase.SelectMapTool(new drawPt() as ITool);
			}
			
			
			protected function button2_clickHandler(event:MouseEvent):void
			{
				//DRAW LINE TOOL
				oMapBase.SelectMapTool(new drawPolyline() as ITool);
			}
			
			
			protected function button3_clickHandler(event:MouseEvent):void
			{
				//DRAW POLYGON TOOL
				oMapBase.SelectMapTool(new drawPolygon() as ITool);
			}
		]]>
		
	</fx:Script>
	
	<fx:Declarations>
		
	</fx:Declarations>
	
	<sgw:MapControl id="oMapBase" width="100%" height="100%">
		
	</sgw:MapControl>
	<sgw:ToolbarControl id="oToolbar" width="100%" height="40" Map="{oMapBase}">
	</sgw:ToolbarControl>
	<s:Label x="121" y="50" text="Draw Graphics " width="503" height="25"/>
	<s:Button x="26" y="129" label="Polygon" width="67" height="31" click="button3_clickHandler(event)"/>
	<s:Button x="26" y="55" label="Point" width="70" height="28" click="button1_clickHandler(event)"/>
	<s:Button x="27" y="90" label="Polyline" width="67" height="30" click="button2_clickHandler(event)"/>
</s:Application>