Zoom after creating route

Topics: WPF
Feb 21, 2012 at 2:12 PM

Hi,

first of all just say that this is awesome control, I've never found something like this.

I'm quite new to mapping applications and I'm having some trouble with routes.

I've created a route, but I can´t manage myself to view the created route with the appropiate zoom. This is my code:

 

private void btnStart_Click(object sender, RoutedEventArgs e) 
{

currentMarker.Position = new PointLatLng (43.062633, -2.504636); 
start = currentMarker.Position;
currentMarker = null ; 
currentMarker =
new GMapMarker (start); 
MainMap.Markers.Add(currentMarker);
 
end =new PointLatLng (42.861134, -2.66794); 
MainMap.Markers.Add(new GMapMarker (end)); 
CalcularRuta();
  
MainMap.ZoomAndCenterMarkers(null); 
}
private void CalcularRuta()
        {
            RoutingProvider rp = MainMap.MapProvider as RoutingProvider;
            if (rp == null)
            {
                rp = GMapProviders.GoogleMap; // use google if provider does not implement routing
            }

            if (MainMap.Markers.IndexOf(m1) > -1)
            {
                MainMap.Markers.RemoveAt(MainMap.Markers.IndexOf(m1));
                            }

            MapRoute route = rp.GetRoute(start, end, false, false, (int)MainMap.Zoom);
            if (route != null)
            {
                mRoute = new GMapMarker(start);
                {
                    mRoute.Route.AddRange(route.Points);
                    mRoute.RegenerateRouteShape(MainMap);
                    mRoute.ZIndex = -1;
                }

                m1 = new GMapMarker(start);
                m1.Shape = new CustomMarkerTaxi(this, m1, "Restante: " + route.Name);
                m1.Offset = new System.Windows.Point(-15, -15);
                m1.ZIndex = int.MaxValue;

                m2 = new GMapMarker(end);
                m2.Shape = new CustomMarkerRed(this, m2, "End: " + start.ToString());
                m2.Offset = new System.Windows.Point(-15, -15);
                m2.ZIndex = int.MaxValue;

                MainMap.Markers.Add(mRoute);
                MainMap.Markers.Add(m1);
                MainMap.Markers.Add(m2);
                

                GDirections dir = new GDirections();
                GMapProviders.GoogleMap.GetDirections(out dir, start, end, false, false, false, false, true);

                txtDirections.Text = txtDirections.Text + "\r\n" + dir.Distance + "- " + dir.Duration;

                MainMap.ZoomAndCenterMarkers(null);
            }
        }
 I'm workin with VS2010 and WPF. I've done lot of changes but I've no success in this.
 
Thanks

 

Feb 21, 2012 at 2:18 PM

what do you mean 'view'?

Feb 21, 2012 at 2:29 PM
Edited Feb 21, 2012 at 2:29 PM

I can't see all the route, it appears with lot of zoom on start point.

I thought that with MainMap.ZoomAndCenterMarkers(null); the zoom was adjusted automatically.

Thanks,

Feb 21, 2012 at 2:59 PM

it was a bug, fixed now

Feb 21, 2012 at 3:15 PM

Thanks, great job and great control.