Select to view content in your preferred language

About PictureFillSymbol

967
3
04-28-2013 05:33 AM
BinbinWang
New Contributor
I using ArcGIS API for flex 3.2+flash builder 4.6
I want to draw a Bitmap on a map. I used the PictureFillSymbol, but the polygon didn't been filled by the Bitmap, the polygon is empty. Can you help me?
My codes :
<?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"
      xmlns:esri="http://www.esri.com/2008/ags"
      pageTitle="Example #1">
 <fx:Declarations>
  <esri:SimpleLineSymbol id = "sls" color="0xff0000">
  </esri:SimpleLineSymbol>
 </fx:Declarations>
 <esri:Map id="map" clickRecenterEnabled="false" crosshairVisible="true" logoVisible="false" >
  <esri:ArcGISTiledMapServiceLayer
   url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
  
  <esri:extent>
   <esri:Extent id="esriMapExtent" xmin="10" ymin="39.5"
       xmax="116.5" ymax="40.5"/>
  </esri:extent>
 </esri:Map>
 <mx:Button label="button" click="initApp()" x="121" y="96" fontSize="12"
      width="209"/>
 <fx:Script>
  <![CDATA[
   import com.esri.ags.Graphic;
   import com.esri.ags.SpatialReference;
   import com.esri.ags.geometry.Extent;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.geometry.Polygon;
   import com.esri.ags.geometry.Polyline;
   import com.esri.ags.layers.GraphicsLayer;
   import com.esri.ags.symbols.PictureFillSymbol;
   import com.esri.ags.symbols.SimpleFillSymbol;
   
   import flash.display.Bitmap;
   import flash.display.BitmapData;  
   import mx.controls.Alert;

   public function initApp():void{
    
    var bmd:BitmapData = new BitmapData(30, 30, true,0x10ff0011);
    var bitmap:Bitmap =  new Bitmap(bmd,"auto",true);
    
    var graphicsLayer:GraphicsLayer = new GraphicsLayer();
    var graphic:Graphic = new Graphic();
    var polygon:Polygon = new Polygon();

    var ring:Array = new Array();
    ring.push(new MapPoint(30,60));
    ring.push(new MapPoint(120,60));
    ring.push(new MapPoint(120,0));
    ring.push(new MapPoint(30,0));
    ring.push(new MapPoint(30,60));
    polygon.addRing(ring);
    polygon.spatialReference = map.spatialReference;
    graphic.geometry = polygon;
    var extent:Extent = polygon.extent;
    var resolution:Number = map.lods[map.level].resolution;
    var width:Number = extent.width/resolution;
    var height:Number = extent.height/resolution;
    
    var fill:PictureFillSymbol = new PictureFillSymbol();
    fill.source = bitmap; 
    fill.outline=sls;
    fill.width = width;
    fill.height = height;
    fill.xoffset = width/2;
    fill.yoffset = height/2;
    //var fill:SimpleFillSymbol = new SimpleFillSymbol("solid",0xFF0000,0.5);

    graphic.symbol = fill;

    graphicsLayer.add(graphic);
    map.addLayer(graphicsLayer);
   }
  ]]>
 </fx:Script>
 
</s:Application>
Tags (2)
0 Kudos
3 Replies
BinbinWang
New Contributor
Do you have any ideas to draw a Bitmap on the map ?
Please .
0 Kudos
BinbinWang
New Contributor
Use the agslib-3.0-2012-06-06.swc won't have the problem .
The agslib-3.2-2013-03-19.swc will have the problem .
0 Kudos
YannCabon
Esri Contributor
Hi,

There is actually a bug, thanks for reporting.
I have a workaround in the meantime.
Encode the BitmapData into a ByteArray, like this:

var pngEncoder:PNGEncoder = new PNGEncoder();
var bmd:BitmapData = new BitmapData(30, 30, true,0x10ff0011);
var bytes:ByteArray = pngEncoder.encode(bmd);
var fill:PictureFillSymbol = new PictureFillSymbol();
fill.source = bytes;
fill.outline=sls;
fill.width = 30;
fill.height = 30;
0 Kudos