ThinkGeo.com    |     Documentation    |     Premium Support

Clearing a layer from a map

There are probably several ways to accomplish what I'm going to describe... but I would like to understand why what I'm doing is not working:


I let the user draw circles, polygons, or whatever on the map as a spatial query filter.   I want that drawn shape to remain visible until they explicitly "Clear" their query.    To do this I:



        
  1. Have a "QueryOverlay" added to my map, which is just a LayerOverlay object.

  2.     
  3. I have a custom "QueryLayer" that only has the "DrawCore" method implement.  That method draws the users query shape.   If there is no user supplied shape, obviously nothing is drawn.   

  4.     
  5. The query layer is forced to "IsVisible" = true at all times.

  6.     
  7. They query layer is added to the QueryOverlay when the program starts, and is never removed.

  8.     
  9. When the user drawn shape is changed, I execute:
        

              
    1. QueryOverlay.Lock.EnterWriteLock() 

    2.         
    3. QueryLayer.Shape = UserShape 

    4.         
    5. QueryOverlay.Lock.ExitWriteLock()

    6.     

        


When the user drawn shape is NOT null, this works perfect.   The map gets redrawn with the user's shape.   However, when the shape is Null (ie, the query is being cancelled), I cannot get the QueryLayer's DrawCore method to be called.   In fact, I don't get the IsVisible property hit, either.   Of course, if I pan the map, then the DrawCore is called, and I draw nothing, so the user shape is effectively cleared.


What are the possible criteria that would cause my layer to get drawn when I have a shape, and skipped when I don't have a shape, if I don't indicate any difference in the layer?


I know I could add and remove the query layer into the query overlay and stuff like that, as options... I'm just baffled as to why the refresh is not occuring when I clear my layer content, though.


 



Never mind :(


I see I needed to add a map.Refresh(QueryOverlay).   Apparently, when setting the user shape, I was still in the event handler of the TrackInteractiveOverlay.TrackEnded event, and I was explicitly refreshing the TrackOverlay, which also caused my QueryOverlay to refresh.


Sorry to bother.



Ted, 
  
 I am glad that you can solve the problem by yourself.  
  
 Many users have the behavior that if they have a problem, first they search the keywords in the forum and then probably can find the answer or some related information, finally they can solve the problem by themselves instead of creating a thread.  
  
 So it’s not bother, you did a great job that is the very useful resource in our forum. The more questions you have the more repository we have. Thank you for your sharing. 
  
 James