Advertisement
Guest User

customSymbol

a guest
Oct 16th, 2011
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package widgets.test
  2. {
  3.     import com.esri.ags.Map;
  4.     import com.esri.ags.geometry.Geometry;
  5.     import com.esri.ags.geometry.MapPoint;
  6.     import com.esri.ags.symbols.Symbol;
  7.     import flash.display.Sprite;
  8.     import mx.graphics.SolidColorStroke;
  9.    
  10.  
  11.    
  12.     /**
  13.      * Simple custom class with variable color property.
  14.      */
  15.     public class CustomSymbol extends Symbol
  16.     {
  17.        
  18.         protected var redStroke:SolidColorStroke = new SolidColorStroke(0xFF0000,1,1);
  19.    
  20.         private var m_color : Number;
  21.        
  22.         /**
  23.          * Constructor
  24.          * @param color optional color.  Default 0xFF0000
  25.          */
  26.         public function CustomSymbol( color : Number = 0xFF0000 )
  27.         {
  28.             m_color= color;
  29.         }        
  30.  
  31.  
  32.         [Bindable]
  33.         /**
  34.          * Bindable color property. dispatch <code>Event.CHANGE</code> on change.
  35.          */    
  36.         public function get color() : Number
  37.         {
  38.             return m_color;        
  39.         }        
  40.         /**
  41.          * @private
  42.          */
  43.         public function set color( value : Number ) : void
  44.         {
  45.             if( value != m_color )
  46.             {
  47.                 m_color = value;
  48.                 dispatchEventChange();
  49.             }            
  50.         }
  51.        
  52.         /**
  53.          * Clear the sprite.
  54.          * Recommended that you do this here not in the <code>draw</code> function.
  55.          */    
  56.         override public function clear( sprite : Sprite ) : void
  57.         {
  58.             sprite.graphics.clear();
  59.         }
  60.        
  61.         /**
  62.          * Draw the geometry.
  63.          * Here we only render MapPoints.
  64.          */    
  65.         override public function draw(
  66.             sprite : Sprite,
  67.             geometry : Geometry,
  68.             attributes : Object,
  69.             map : Map
  70.         ) : void
  71.         {
  72.             if( geometry is MapPoint )
  73.             {
  74.                 drawMapPoint( sprite, MapPoint(geometry), map);
  75.             }
  76.         }
  77.        
  78.         /**
  79.          * Draw the map point.
  80.          * Here we position the sprite and use raw flash graphics primitive to draw.
  81.          */
  82.         private function drawMapPoint(
  83.             sprite : Sprite,
  84.             mapPoint : MapPoint,
  85.             map : Map
  86.         ) : void
  87.         {
  88.             sprite.x = toScreenX( map, mapPoint.x );
  89.             sprite.y = toScreenY( map, mapPoint.y );
  90.            
  91.        
  92.             sprite.graphics.beginFill( 0x0000FF,1 );
  93.             sprite.graphics.drawCircle(0,0,100);
  94.             sprite.graphics.endFill();  
  95.             sprite.graphics.lineStyle(5,0xFF0000,1);
  96.             sprite.graphics.lineTo(mapPoint.x+100,mapPoint.y+100);
  97.            
  98.         }  
  99.     }
  100. }
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement