ThinkGeo.com    |     Documentation    |     Premium Support

Changing Marker of InMemoryMarkerOverlay

Hi all,


I'm wondering if it's possible to change the a Marker's WebImage on the fly (namely the rotation of it).  Since I'm using the 'Custom' mode, I've been adding my markers through a FeatureSource (collection of Features, not Markers), but I don't see anyway to change the Marker placed from anything other than the DefaultMarker that's set on the creation of the Layer. Could anyone offer assistance?  Thanks!


-Dustin



Dustin, 
  
  Map1.CustomOverlays is a collection of Overlay, which is the base class of all kinds of overlays (like inMemoryMarkerOverlay). So if you want to call a method specific in derived class, you need to do the casting first. 
  
 Here is the code how to convert the base overlay to a derived inMemoryMarkerOverlay. 
  
 
InMemoryMarkerOverlay inMemoryMarkerOverlay = (InMemoryMarkerOverlay)Map1.CustomOverlays["MarkerOverLay"];
 
  
 Thanks, 
  
 Ben

Hi Ben, 
 Thanks for the reply. Unfortunately, I think the way I asked my question may have been convoluted.  I have the InMemoryMarkerOverlay that I need to work with, and cast as such.  The problem I’m facing is adding markers to it with different WebImages.  The default marker web image is already set, so all the markers I add end up with that web image. Since the InMemoryMarkerOverlay only takes Features, however, I can’t figure out how to have more than one WebImage per Overlay.  Am I just going about this in the wrong way?  Thanks for the help! 
 -Dustin

Dustin, 
  
 Sorry for the confusing, I understand your questions now. You are right that when using InMemoryMarkerOverlay or FeatureSourceMarkerOverlay, every markers share the same (style) web image. If you want to use another one, you can create a new overlay, use marker ValueStyle or use SimpleMarkerOverlay. 
  
 Marker ValueStyle is almost the same as the normal ValueStyle. You need to add a column to the overlay and add that field for every feature. For example, we add a column named “Color”, and for every feature we add a color for this field. In the marker value style, we can say if that field equals to “Red”, we use the red image; if it’s Blue, we use the Blue one. ……In this way we can render features in different ways. 
  
 SimpleMarkerOverlay (see the sample “Draggable Markers”) is kind of a markers collection; each marker is independent and can be different. However it doesn’t have ZoomLevels and it’s not supposed to include many markers as we didn’t have the optimization for its performance. For example, if I added 10 Markers to the map but I zoom in to a small extent and only one marker is within the viewport, all the 10 markers will still be rendered. 
  
 If neither of the above solves your problem, can you let me know your scenario in detail, maybe we can find some good ways to work around? 
  
 Thanks, 
  
 Ben 


Thanks Ben, I’m going to try and give the ValueStyle a shot.  In the meanwhile, what I’m trying to achieve is a direction to a marker.  I have points that each have a particular direction associated with them, so I’d like my marker (an arrow) to point in that direction.  I recall this being very simple to do with the standard MarkerLayer in simple mode, but it seems like much more of a challenge in custom mode.  If you can think of anything else that might help me, I’d appreciate it.  Thank you!

Actually, I changed my mind and when with the SimpleMarkerOverlay, as is seems to be a little more straight forward.  I notice that SMO.Markers has a method for ‘Contains’ with a parameter of ‘key’, just as the InMemoryMarkerLayer has.  However, I can’t seem to find a way to set the key value for a Marker, neither on Marker construction, or when it’s added to the Markers collection of the SMO.   Is this feature fully implemented, or am I missing something?  Thanks again.

Dustin, 
  
 That’s the property Marker.Id. Set a key to this property and you can use it in the marker.Contains collection. 
  
 I don’t know if you still need this but the custom mode should be able to accomplish any function in simple mode. If you want to use ValueStyle, you can set different values with web images having different directions. With the property webImage.RotationAngle you can easily set that new images. 
  
 Thanks, 
  
 Ben 


Ah, I see.  I was confused because the parameter was labeled ‘key’, not ‘id’.  Thanks for clarifying that and for all the help!

Dustin, 
  
 I remembered there is a reason we didn’t choose ‘key’, maybe because of the duplicated name or something. Anyway, we will add more comments to the Id property and make people easier to understand Id is also the ‘key’ used in the markers collection.  
  
 Thanks, 
  
 Ben