ThinkGeo.com    |     Documentation    |     Premium Support

Overlays.MoveToTop() not working as expected

The application is adding a shaded layer to an overlay, then adding the overlay to the overlay collection of the map.  I want the shaded layer to draw first so the base map is on top.  I tried


winformsMap1.Overlays.MoveToTop(1);

with 1 being the index of the new overlay.  The order of the collection is not changed, nor the drawing order.   Any suggestions?




Hi Ed, 
  
 The following code works for me, theOverlay is the one that I want to move to the top: 
  
 theOverlay.Lock.EnterWriteLock(); 
 try 
 { 
   // … other stuffs 
   theMap.Overlays.MoveToTop(theOverlay); 
 } 
 finally 
 { 
   theOverlay.Lock.ExitWriteLock(); 
 } 
 theMap.Refresh(); 
  
 Hope this helps. 
  
 Patrick.

oups … here is the code 
  
 theOverlay.Lock.EnterWriteLock();  
 try  
 {  
 // … other stuffs  
 theMap.Overlays.MoveToTop(theMap.Overlays.IndexOf(theOverlay));  
 }  
 finally  
 {  
 theOverlay.Lock.ExitWriteLock();  
 }  
 theMap.Refresh();  


I missed the lock code.  THanks.

Ed & Patrick, 
  
 Thanks for your posts and sharing! I appreciate it very much! 
  
 Let me know if any more questions. 
  
 Thanks. 
  
 Yale