Select to view content in your preferred language

Getting a bitmap of a DynamicMapServiceLayer

998
4
04-20-2010 01:54 PM
MichaelHayden
Emerging Contributor
Hello,
In the API for DynamicMapServiceLayer class there is the following entry in protected methods:
 
zoomStartHandler(event:ZoomEvent):void
Prepares the zoom animation by taking a bitmap of the layer.

My question is as follows:
How can I get a bitmap of a DynamicMapServiceLayer?

Thank You
Tags (2)
0 Kudos
4 Replies
MichaelHayden
Emerging Contributor
So I got the layer as a bitmap. Here's the code (any comments would be appreciated):

public class GraphicLayerThresholding extends ArcGISDynamicMapServiceLayer
{
     private  function _init():void
     {
          _thresholdLayerBitmapData = getLayerAsBitmap(this as UIComponent);
     }

     static public function getLayerAsBitmap(fromTarget:UIComponent, area:Rectangle = null):BitmapData
     {
            var bd : BitmapData = new BitmapData( _map.width, _map.height, true, 0x00000000 );
     bd.draw( fromTarget, m );
     return bd;
     }
}
0 Kudos
MichaelHayden
Emerging Contributor
One of the master programmers here at work pointed out the method exportMapImage which returns a url reference to the image that fills the ArcGISDynamicMapServiceLayer that I am extending. I then load that image usingactionscripts Loader class. from there I can get the bitmapdata of the image/layer. This worked out perfectly for me. Now I can do bitmap manipulation on the layer. Any response or words of advise would be greatly appreciated.

public class GraphicLayerThresholding extends ArcGISDynamicMapServiceLayer
{
  override protected function updateLayer():void
  {
   graphics.clear();
   
   var imageParams:ImageParameters = new ImageParameters();
   imageParams.height = map.height;
   imageParams.width = map.width;
   imageParams.format = 'png32';

   var mapImage:MapImage = new MapImage();
   this.exportMapImage(imageParams, new AsyncResponder(onResult, onFault));
  }
  private function onFault(info:Object, token:Object = null):void
  {
   Alert.show(info.toString(), "Export Problem");
  }
  private function onResult(mi:MapImage, token:Object = null):void
  {
   
   var loader:Loader = new Loader();
   loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
   loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
   
   var request:URLRequest = new URLRequest(mi.href);
   loader.load(request);
  }
  
  
  private function completeHandler(event:Event):void {
   var loader:Loader = Loader(event.target.loader);
   _image = Bitmap(loader.content);
   _updateGraphic(_image, _thresholdValue);
   
  }
}


Michael L. Hayden
Web Application Developer

Data Transfer Solutions
Fort Collins, Denver
(970) 472-0032 (phone)
www.dtsagile.com
0 Kudos
DasaPaddock
Esri Regular Contributor
Here's an example of getting to the loaded tiles in a tiled layer and modifying their bitmapData. The same could be done for a dynamic layer.

http://forums.esri.com/Thread.asp?c=158&f=2421&t=303099#948090
0 Kudos
MichaelHayden
Emerging Contributor
Thanks for replying dpaddock,
I did happen upon the link you suggested when I first started creating this widget. The example did serve me well. Then I was introduced to extending the ArcGISDynamicMapServiceLayer and that made for a more elegant solution. In my overriding of the updateLayer() method (which fires when changes occur to the layer i.e. map extent change, pan, etc), I'm retrieving an image copy of the layer from the esri server, clearing this layers graphics (this.graphics.clear()),  applying thresholding adjustments and filling my layer's graphics parameter with the thresholding adjustment's resulting bitmapData.

Michael L. Hayden
Web Application Developer

Data Transfer Solutions
Fort Collins, Denver
(970) 472-0032 (phone)
www.dtsagile.com
0 Kudos