Markers Don't Show Up Until I Zoom

Jan 4, 2010 at 8:39 PM

I'm using the WPF version of the mapping control and having an issue getting markers to display.

I don't set a current position on the map until after the user clicks on a button. At that point I set the current position then add a handful of markers to the map control. These markers aren't displaying until I zoom the map in or out. Dragging the map does not get the markers to display.

I've going through the source code, trying to figure out what the zoom is doing that needs to be done from my code. The demo WPF code doesn't do anything special and it's markers display automatically.

Any ideas?

Coordinator
Jan 4, 2010 at 8:42 PM

try marker.ForceUpdateLocalPosition(myMap);

Jan 5, 2010 at 2:26 PM

Thanks, that works!

I also noticed that the first time I resize the map control, the markers disappear. I could look for the resize event and call ForceUpdateLocalPosition on each marker, but that would cause performance issues. Any ideas on why this happens?

 

Coordinator
Jan 5, 2010 at 3:24 PM

can you zip and share you project demo?

Jan 5, 2010 at 6:06 PM

This works, and I don't think I'll have enough markers at any one time to cause perf issues.

foreach (var marker in _map.Markers)
    marker.ForceUpdateLocalPosition(_map);

Coordinator
Jan 5, 2010 at 7:11 PM

i see, ok'

Mar 18, 2010 at 1:51 PM

Same problem here. When I add a marker (after all maps/markers are displayed) it won't show up until I change the zoom level. Mattcasto's workaround works, but shouldn't be needed.

 

Coordinator
Mar 18, 2010 at 7:58 PM

what is your solution?

Mar 18, 2010 at 10:21 PM

If I look at your source code it looks like two properties (LocalPositionX,LocalPositionY) per marker in ForceUpdateLocalPosition are updated. When I follow Mattcasto's workaround ALL markers are repainted (unless I perform a ForceUpdateLocalPosition for only the new markers).

One solution might be to override the Add method of the ObservableCollection for the markers. After adding the marker to the list, make it visible (depending on the Visibility).

 

Coordinator
Mar 18, 2010 at 11:04 PM

can it be forked? ;}

Mar 18, 2010 at 11:29 PM

Not tested, but something like this might work:

This is what you now have:

public readonly ObservableCollection<GMapMarker> Markers = new ObservableCollection<GMapMarker>();

Make a new class:

 

public class GMapMarkerCollection : ObservableCollection<GMapMarker>
{
public new void Add(GMapMarker marker)
{
base.Add(marker);
if (marker.Shape.Visibility == Visibility.Visible)
marker.ForceUpdateLocalPosition(null); // or something more efficient } }

 

And also override the Insert method.

 

Coordinator
Mar 19, 2010 at 9:01 AM

"Not tested, but something like this might work:" whats the point of your code then ;}

Mar 19, 2010 at 12:16 PM

You're right. I tested it, and came with another approach that works.

In the main public GMapControl() add just before:

this.ItemsSource = Markers;

this line:

Markers.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Markers_CollectionChanged);

and add the following method to GMapControl:

void Markers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
      {
          if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
          {
              foreach (GMapMarker marker in e.NewItems)
                  marker.ForceUpdateLocalPosition(this);
          }
      }

Coordinator
Mar 24, 2010 at 2:48 PM

perfect!