About tilelayer render

Nov 8, 2011 at 11:51 AM

In MapBox.cs, the method below will sometime has an exception that white blanks will appear on the map. 

And the exception will be always on Graphics g = Graphics.FromImage(_imageBackground);  because of the _imageBackground is in use.

 

void HandleMapNewTileAvaliable(TileLayer sender, BoundingBox box, Bitmap bm, int sourceWidth, int sourceHeight, ImageAttributes imageAttributes)        {            lock (_imageBackground)            {              try               

{        ..... }             

 catch (Exception ex)   

        {                    Console.WriteLine(ex.ToString());                    //this can be a GDI+ Hell Exception...                   

}           

 

so I change it to the following to recall the method again to make sure it is rendered correctly. Please help me to check, is it ok to change like that?

 

void HandleMapNewTileAvaliable(TileLayer sender, BoundingBox box, Bitmap bm, int sourceWidth, int sourceHeight, ImageAttributes imageAttributes)        {            lock (_imageBackground)            {              try               

  {        ..... }             

  catch (Exception ex)   

        {                    Console.WriteLine(ex.ToString());                    //this can be a GDI+ Hell Exception...              

ThreadPool.QueueUserWorkItem(HandleMapNewTileAvaliable2, new object[] { sender, box, bm, sourceWidth, sourceHeight, imageAttributes });    

  }           

void HandleMapNewTileAvaliable2(object parameter)       

{            object[] p = (object[])parameter;            HandleMapNewTileAvaliable((TileLayer)p[0], (BoundingBox)p[1], (Bitmap)p[2], (int)p[3], (int)p[4], (ImageAttributes)p[5]);         }

Coordinator
Nov 8, 2011 at 12:42 PM

If the error states that _imageBackground is in use, it may be a better idea to lock the other usages of _imageBackground as well.

Hth FObermaier

Nov 8, 2011 at 2:01 PM

Yes, I was going to do that.  But I could not find where to lock the another _imageBackground.

I did not change the other code in MapBox.cs.

Coordinator
Nov 9, 2011 at 6:31 AM

_imageBackground is not locked in 'GetTileLayerAsyncEnd'.

It is not specifically locked in the GetTileLayer() function. It is locked by _map object. I don't know if that is sufficient.

Hth FObermaier