Markers and Zoom problems with MVVM

Topics: WPF
May 30, 2013 at 10:40 AM

I try to use the MVVM version of this great tool.

But I have a few problems. First of all, my markers are not visible.

Here is the XAML code:
<WindowsPresentation:GMapControl Name="MainMap"
                Zoom="{Binding Zoom}"
                Position="{Binding Position}"
                ItemsSource="{Binding Path=Markers, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" 
And my ViewModel Code
    public ObservableCollection<GMapMarker> Markers
                    return _markers;

                    if (_markers == value)

                    _markers = value;
        Zoom = 15;
        Position = new GMap.NET.PointLatLng(48, 2);
    Markers = new ObservableCollection<GMapMarker>();
    Markers.Add(new GMapMarker(new GMap.NET.PointLatLng(48, 2)));
the position is well changed, but not markers are visible.

My other problem is that the zoom change works fine, but only if I don't use the tag EnableMouseWheelZooming="True".


Thanks a lot for the answers....
May 31, 2013 at 1:38 PM
you have to assign some UIElement to marker.Shape
Jun 12, 2013 at 5:32 PM

Ok, now I have created a custom marker factory:
public static GMapMarker Get(WaterObject wo)
            GMapMarker m = new GMapMarker(new PointLatLng(((PointGeo)wo.PositionGeo).YLat.Value, ((PointGeo)wo.PositionGeo).XLon.Value));
            //m.Offset = new System.Windows.Point(-15, -15);
            //m.ZIndex = int.MaxValue;

            //string[] all = System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceNames();

            // On récupère le nom de l'icone, en fonction du champs Desc Modsim, l'icone portant le champs Desc comme nom de fichier
            Stream stream = (System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream("OMR_Client.Resources.Icones.7.png"));
            PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
            BitmapSource bitmapSource = decoder.Frames[0];

            // Draw the Image
            Image myImage = new Image();
            myImage.Source = bitmapSource;
            //myImage.Stretch = Stretch.None;
            //myImage.Margin = new Thickness(20);

            m.Shape = myImage;

            return m;
and then, in my view model, is add the marker in the binded property:
The problem is that nothing is displayed until i change the zoom, and when I change it, I can only see a label on the map showing ""...
Jun 13, 2013 at 8:08 AM
var bitmapDecoder = new PngBitmapDecoder(stream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);
Jun 13, 2013 at 8:16 AM

It's not working better...

And I've tried to import the CustomMarkerRed class in my project, and the result is the same...
Jun 13, 2013 at 8:17 AM
you are doing something wrong...
Jun 13, 2013 at 2:42 PM
So, now, I tried to use the "normal" version, not the fork.

My xaml code is like that
     <WindowsPresentation:GMapControl Name="MainMap"
And on the code behing:
GMapMarker gm = new GMapMarker(new PointLatLng(((PointGeo)wo.PositionGeo).YLat.Value, ((PointGeo)wo.PositionGeo).XLon.Value));
                    gm.Shape = new CustomMarkerRed(MainMap, gm, "test");
                    gm.Offset = new System.Windows.Point(-15, -15);
                    gm.ZIndex = int.MaxValue;

but now, I have an execution error:
Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.
Jun 13, 2013 at 2:47 PM
Edited Jun 13, 2013 at 2:48 PM
Ok, it's seems to work if I use MainMap.Markers.Add(gm);