Markers and Zoom problems with MVVM

Topics: WPF
May 30, 2013 at 9:40 AM
Hi,

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"
                MaxZoom="17" 
                MinZoom="1" 
                Zoom="{Binding Zoom}"
                Position="{Binding Position}"
                ItemsSource="{Binding Path=Markers, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" 
/>
And my ViewModel Code
    public ObservableCollection<GMapMarker> Markers
            {
                get
                {
                    return _markers;
                }

                set
                {
                    if (_markers == value)
                    {
                        return;
                    }

                    _markers = value;
                    RaisePropertyChanged("Markers");
                }
            } 
and
        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".

Why?

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

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:
Markers.Add(MarkerFactory.Get(wo));
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 "Gmap.net.windowsPresentation.GmapMarker"...
Coordinator
Jun 13, 2013 at 7:08 AM
var bitmapDecoder = new PngBitmapDecoder(stream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);
Jun 13, 2013 at 7:16 AM
Hi,

It's not working better...

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

My xaml code is like that
     <WindowsPresentation:GMapControl Name="MainMap"
                MaxZoom="17" 
                MinZoom="1"/>
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;

MainMap.Items.Add(gm);
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 1:47 PM
Edited Jun 13, 2013 at 1:48 PM
Ok, it's seems to work if I use MainMap.Markers.Add(gm);