This project has moved. For the latest updates, please go here.

Weird Zoom behavior using PushPins

Oct 17, 2016 at 6:33 PM
Edited Oct 17, 2016 at 6:35 PM
Hi Clemens, i think, i found a bug (but i'm not sure) :)

First 2 Code samples:
Correct working Code:
<mapControl:Map Margin="10,10,10,10" Width="340" MinHeight="488" VerticalAlignment="Center"    TileLayer="{Binding SelectionTileLayer}"
 MinZoomLevel="12" ZoomLevel="12" MaxZoomLevel="17" Center="{Binding OsmCenter}">
  <mapControl:MapPanel>
      <mapControl:Pushpin Background="Green" mapControl:MapPanel.Location="{Binding StartLocation}">
         <TextBlock Foreground="WhiteSmoke" FontFamily="Segoe MDL2 Assets" Text="&#xE768;" />
      </mapControl:Pushpin>
  </mapControl:MapPanel>
  <mapControl:MapPanel>
     <mapControl:Pushpin Background="Red" mapControl:MapPanel.Location="{Binding StopLocation}">
        <TextBlock Foreground="WhiteSmoke" FontFamily="Segoe MDL2 Assets" Text="&#xE71A;" />
     </mapControl:Pushpin>
  </mapControl:MapPanel>
</mapControl:Map>
private void MapUpdater(IReadOnlyList<GeoPositions> list)
{
    var startLocation = new Location(Convert.ToDouble(list[0].Latitude), Convert.ToDouble(list[0].Longitude));
    OsmCenter = startLocation;
    StartLocation = startLocation;
    var stopLocation = new Location(Convert.ToDouble(list.Last().Latitude), Convert.ToDouble(list.Last().Longitude));
    StopLocation = stopLocation;
...
}

private Location _osmCenter;
private Location _startLocation;
private Location _stopLocation;

public Location OsmCenter
{
    get { return _osmCenter; }
    set
    {
        _osmCenter = value;
        NotifyPropertyChanged(nameof(OsmCenter));
    }
}

public Location StartLocation
{
    get { return _startLocation; }
    set
    {
        _startLocation = value;
        NotifyPropertyChanged(nameof(StartLocation));
    }   
}

public Location StopLocation
{
    get { return _stopLocation; }
    set
    {
        _stopLocation = value;
        NotifyPropertyChanged(nameof(StopLocation));
    }    
}
Weired working code:

<mapControl:Map Margin="10,10,10,10" Width="340" Height="525" VerticalAlignment="Center" TileLayer="{Binding SelectionTileLayer}"
    MinZoomLevel="14" ZoomLevel="14" MaxZoomLevel="17" Center="{Binding OsmCenter}">
    <mapControl:MapPanel>
        <mapControl:Pushpin Background="Green" mapControl:MapPanel.Location="{Binding StartLocation}">
            <TextBlock Foreground="WhiteSmoke" FontFamily="Segoe MDL2 Assets" Text="&#xE768;" />
        </mapControl:Pushpin>
    </mapControl:MapPanel>
    <mapControl:MapPanel>
        <mapControl:Pushpin Background="Red" mapControl:MapPanel.Location="{Binding StopLocation}">
            <TextBlock Foreground="WhiteSmoke" FontFamily="Segoe MDL2 Assets" Text="&#xE71A;" />
        </mapControl:Pushpin>
    </mapControl:MapPanel>

    <mapControl:MapItemsControl ItemsSource="{Binding Polylines}" Visibility="Visible"
            ItemTemplate="{StaticResource PolylineItemTemplate}" />

    <mapControl:MapPanel VerticalAlignment="Top" Height="30" Width="250"  HorizontalAlignment="Center">
        <Grid Background="White" Height="30" Width="250" BorderThickness="2,0,2,2" BorderBrush="LightGray">
            <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
                <TextBlock Text="Total distance: " VerticalAlignment="Center" />
                <TextBlock FontWeight="SemiBold" Text="10 m"
                                               VerticalAlignment="Center" Margin="5,0,0,0" />
            </StackPanel>
        </Grid>
    </mapControl:MapPanel>
</mapControl:Map>

private void MapUpdater(IReadOnlyList<GeoPositions> list)
{
    var startLocation = new Location(Convert.ToDouble(list[0].Latitude), Convert.ToDouble(list[0].Longitude));
    OsmCenter = startLocation;
    StartLocation = startLocation;
    StopLocation = new Location(Convert.ToDouble(list.Last().Latitude), Convert.ToDouble(list.Last().Longitude));
    ...
}

private Location _osmCenter;
private Location _startLocation;
private Location _stopLocation;

public Location OsmCenter
{
    get { return _osmCenter; }
    set
    {
        _osmCenter = value;
        NotifyPropertyChanged(nameof(OsmCenter));
    }
}

public Location StartLocation
{
    get { return _startLocation; }
    set { _startLocation = value; NotifyPropertyChanged(); }
}

public Location StopLocation
{
    get { return _stopLocation; }
    set { _stopLocation = value; NotifyPropertyChanged(); }
}
The problem: The first sample works like i want. The Pins are at their positions and when i zoom out or in, they stay at their positions. But in the second sample, the Pins are theoretically at the correct positions (i tested it, when i zoomed in with MaxZoomLevel 21 the Pins are at their positions), but with this settings they are not at the positions i want. When i zoom in, the Pins jump towards the setted positions. The center of the weired map is at the correct position, like i set / want. My polyline is also correct :)

I hope you, can fix this strange bug, or when i made a mistake, you can correct me :D

Greetings

Further Information:
UWP, Windows 10 Mobile
Coordinator
Oct 18, 2016 at 6:19 AM
It is not clear what exactly you are observing here. Please provide a small, replicable example including specific coordinate values and a description of how the observed behavior differs from the expected behavior. A screenshot would also be very helpful.
Oct 18, 2016 at 2:19 PM
A example list:
list =
[0](Latitude = 52.034538, Longitude = 5.079042)
[1](Latitude = 52.033991, Longitude = 5.08182)
[2](Latitude = 52.034479, Longitude = 5.082078)

Expected behavior:
Start PushPin (green) should be at the beginning of the route (orange line)
Stop PushPin (red) at the end

Observed behavior:

and some screenshots:
Image

I hope this explains my problem.
Coordinator
Oct 19, 2016 at 7:36 AM
Edited Oct 19, 2016 at 7:44 AM
Honestly I have no idea what's happening.

Here is how it looks in a UWP app on my side:

Screenshot