示例#1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            MapControl = Map;
            if (e.NavigationMode == NavigationMode.Back)
            {
                ChangeViewControl.Map = Map;
            }
            var AllowOverstretch     = SettingsSetters.GetAllowOverstretch();
            var FadeAnimationEnabled = SettingsSetters.GetFadeAnimationEnabled();

            if (InternalHelper.InternetConnection())
            {
                ChangeViewControl.UseGoogleMaps(OnMapControls.ChangeViewUserControl.MapMode.Standard, AllowOverstretch: AllowOverstretch, IsFadingEnabled: FadeAnimationEnabled, ShowTraffic: SettingsSetters.GetShowTrafficOnLaunch());
            }
            else
            {
                Map.TileSources.Add(new MapTileSource(new LocalMapTileDataSource("ms-appdata:///local/MahMaps/mah_x_{x}-y_{y}-z_{zoomlevel}.jpeg"))
                {
                    AllowOverstretch = false, IsFadingEnabled = FadeAnimationEnabled
                });
            }
            inkCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch;
            var drawingAttr = this.inkCanvas.InkPresenter.CopyDefaultDrawingAttributes();

            drawingAttr.PenTip         = PenTipShape.Rectangle;
            drawingAttr.Size           = new Size(4, 4);
            drawingAttr.IgnorePressure = true;
            drawingAttr.Color          = (Color)Resources["SystemControlBackgroundAccentBrush"];
            this.inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttr);
            if (e.Parameter != null)
            {
                //Google Maps Override
                if (e.Parameter.ToString().StartsWith("http"))
                {
                    //Search Uri association handler
                    if (((Uri)e.Parameter).Segments[2].ToLower() == "search/")
                    {
                        //Searchgrid.PopUP = true;
                        //Searchgrid.SearchText = ((Uri)e.Parameter).DecodeQueryParameters().Where(x => x.Key == "query").FirstOrDefault().Value;
                    }
                    //Directions Uri association handler
                    if (((Uri)e.Parameter).Segments[2].ToLower() == "dir/")
                    {
                        var parameters  = ((Uri)e.Parameter).DecodeQueryParameters();
                        var origin      = parameters.Where(x => x.Key == "origin").FirstOrDefault();
                        var destination = parameters.Where(x => x.Key == "destination").FirstOrDefault();
                        var travelmode  = parameters.Where(x => x.Key == "travelmode").FirstOrDefault();
                        var waypoints   = parameters.Where(x => x.Key == "waypoints").FirstOrDefault();
                        ViewModel.DirectionsControls.DirectionsHelper.DirectionModes Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.walking;
                        Geopoint OriginPoint        = null;
                        Geopoint DestinationPoint   = null;
                        List <BasicGeoposition> lst = null;
                        if (travelmode.Value != null)
                        {
                            if (travelmode.Value.ToString() == "driving")
                            {
                                Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.driving;
                            }
                            else if (travelmode.Value.ToString() == "bicycling ")
                            {
                                Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.bicycling;
                            }
                            else if (travelmode.Value.ToString() == "transit")
                            {
                                Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.transit;
                            }
                        }
                        if (origin.Value != null)
                        {
                            var latlng    = origin.Value.Split(',');
                            var Latitude  = Convert.ToDouble(latlng[0]);
                            var Longitude = Convert.ToDouble(latlng[1]);
                            OriginPoint = new Geopoint(new BasicGeoposition()
                            {
                                Latitude  = Latitude,
                                Longitude = Longitude
                            });
                        }
                        if (destination.Value != null)
                        {
                            var latlng    = destination.Value.Split(',');
                            var Latitude  = Convert.ToDouble(latlng[0]);
                            var Longitude = Convert.ToDouble(latlng[1]);
                            DestinationPoint = new Geopoint(new BasicGeoposition()
                            {
                                Latitude  = Latitude,
                                Longitude = Longitude
                            });
                        }
                        if (waypoints.Value != null)
                        {
                            lst = new List <BasicGeoposition>();
                            var latlngs = destination.Value.Split('|');
                            foreach (var item in latlngs)
                            {
                                var latlng             = item.Split(',');
                                BasicGeoposition point = new BasicGeoposition();
                                point.Latitude  = Convert.ToDouble(latlng[0]);
                                point.Longitude = Convert.ToDouble(latlng[1]);
                                lst.Add(point);
                            }
                        }
                        if (OriginPoint != null && DestinationPoint != null)
                        {
                            ViewModel.DirectionsControls.DirectionsHelper.Rootobject Result = null;
                            if (lst == null)
                            {
                                Result = await ViewModel.DirectionsControls.DirectionsHelper.GetDirections(OriginPoint.Position, DestinationPoint.Position, Mode);
                            }
                            else
                            {
                                Result = await ViewModel.DirectionsControls.DirectionsHelper.GetDirections(OriginPoint.Position, DestinationPoint.Position, Mode, lst);
                            }
                            if (Result != null)
                            {
                                Map.MapElements.Add(ViewModel.DirectionsControls.DirectionsHelper.GetDirectionAsRoute(Result, (Color)Resources["SystemControlBackgroundAccentBrush"]));
                            }
                        }
                    }
                    //Display a map
                    if (((Uri)e.Parameter).Segments[2].ToLower().StartsWith("@"))
                    {
                        await Task.Delay(1500);

                        try
                        {
                            if (!e.Parameter.ToString().Contains("searchplace"))
                            {
                                var parameters = ((Uri)e.Parameter).DecodeQueryParameters();
                                var mapaction  = parameters.Where(x => x.Key == "map_action").FirstOrDefault();
                                if (mapaction.Value != null && mapaction.Value == "pano")
                                {
                                    await new MessageDialog("StreetView Not Supported yet").ShowAsync();
                                }
                                var center = parameters.Where(x => x.Key == "center").FirstOrDefault();
                                var zoom   = parameters.Where(x => x.Key == "zoom").FirstOrDefault();
                                var cp     = center.Value.Split(',');
                                BasicGeoposition pointer = new BasicGeoposition()
                                {
                                    Latitude = Convert.ToDouble(cp[0]), Longitude = Convert.ToDouble(cp[1])
                                };
                                Map.Center = new Geopoint(pointer);
                                if (zoom.Value != null)
                                {
                                    await Map.TryZoomToAsync(Convert.ToDouble(zoom.Value));
                                }
                                RunMapRightTapped(Map, new Geopoint(pointer));
                            }
                            else
                            {
                                var search = ((Uri)e.Parameter).ToString().Replace("https://google.com/maps/@searchplace=", "");
                                //var search = parameters.Where(x => x.Key == "searchplace").FirstOrDefault();
                                var res = await ViewModel.PlaceControls.SearchHelper.TextSearch(search, Location : Map.Center, Radius : 15000);

                                if (res == null || res.results.Length == 0)
                                {
                                    await new MessageDialog("No search results found").ShowAsync();
                                    return;
                                }
                                var ploc     = res.results.FirstOrDefault().geometry.location;
                                var geopoint = new Geopoint(new BasicGeoposition()
                                {
                                    Latitude = ploc.lat, Longitude = ploc.lng
                                });
                                Map.Center = geopoint;
                                await MapView.MapControl.TryZoomToAsync(16);

                                SearchResultPoint = geopoint;
                            }
                        }
                        catch
                        {
                        }
                    }
                }

                //Windows Maps Override
                else
                {
                    var    parameters = ((Uri)e.Parameter).DecodeQueryParameters();
                    string cp         = "";
                    int    zoomlevel  = 0;
                    string Querry     = "";
                    string Where      = "";
                    //{bingmaps:?where=Tabarsi Square%2C north side of the Shrine%2C Mashhad%2C 2399%2C Īrān}
                    if (parameters.Where(x => x.Key == "where").Any())
                    {
                        Where = Uri.UnescapeDataString(parameters.Where(x => x.Key == "where").FirstOrDefault().Value.NoHTMLString());
                    }
                    if (parameters.Where(x => x.Key == "cp").Any())
                    {
                        cp = parameters.Where(x => x.Key == "cp").FirstOrDefault().Value;
                    }
                    if (parameters.Where(x => x.Key == "lvl").Any())
                    {
                        zoomlevel = Convert.ToInt32(parameters.Where(x => x.Key == "lvl").FirstOrDefault().Value);
                    }
                    if (parameters.Where(x => x.Key == "q").Any())
                    {
                        Querry = parameters.Where(x => x.Key == "q").FirstOrDefault().Value;
                    }
                    if (parameters.Where(x => x.Key == "collection").Any())
                    {
                        var point     = parameters.Where(x => x.Key == "collection").FirstOrDefault().Value;
                        var pointargs = point.Split('_');
                        var latitude  = pointargs[0].Split('.')[1] + "." + pointargs[0].Split('.')[2];
                        var longitude = pointargs[1];
                        cp = $"{latitude}~{longitude}";
                        if (parameters.Count >= 3)
                        {
                            Map.MapElements.Add(new MapIcon()
                            {
                                Location = new Geopoint(new BasicGeoposition()
                                {
                                    Latitude = Convert.ToDouble(latitude), Longitude = Convert.ToDouble(longitude)
                                }), Title = pointargs[2].Replace("+", " ")
                            });
                        }
                        else
                        {
                            Map.MapElements.Add(new MapIcon()
                            {
                                Location = new Geopoint(new BasicGeoposition()
                                {
                                    Latitude = Convert.ToDouble(latitude), Longitude = Convert.ToDouble(longitude)
                                }), Title = "Point"
                            });
                        }
                    }
                    if (Where != "")
                    {
                        await Task.Delay(500);

                        var res = await SearchHelper.TextSearch(Where);

                        if (res != null)
                        {
                            if (res.results != null && res.results.Any())
                            {
                                var loc = res.results.FirstOrDefault().geometry.location;
                                //var rgc = await ReverseGeoCode.GetLocation(Where);
                                Map.Center = new Geopoint(new BasicGeoposition()
                                {
                                    Latitude = loc.lat, Longitude = loc.lng
                                });
                            }
                            else
                            {
                                var rgc = await ReverseGeoCode.GetLocation(Where);

                                Map.Center = rgc;
                            }
                        }
                        else
                        {
                            var rgc = await ReverseGeoCode.GetLocation(Where);

                            Map.Center = rgc;
                        }
                    }
                    if (cp != "")
                    {
                        await Task.Delay(500);

                        var bgp = new BasicGeoposition();
                        bgp.Latitude  = Convert.ToDouble(cp.Split('~')[0]);
                        bgp.Longitude = Convert.ToDouble(cp.Split('~')[1]);
                        Map.Center    = new Geopoint(bgp);
                        Map.MapElements.Add(new MapIcon()
                        {
                            Location = new Geopoint(bgp), Title = "Point"
                        });
                    }
                    if (zoomlevel != 0)
                    {
                        await Map.TryZoomToAsync(zoomlevel);
                    }
                    else
                    {
                        await MapView.MapControl.TryZoomToAsync(16);
                    }
                    if (Querry != "")
                    {
                        await Task.Delay(1500);

                        Searchbar.SearchQuerry = Querry;
                    }
                }
            }

            if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush"))
            {
                var ac    = new Windows.UI.Xaml.Media.AcrylicBrush();
                var brush = Resources["SystemControlChromeLowAcrylicWindowBrush"] as Windows.UI.Xaml.Media.AcrylicBrush;
                ac                      = brush;
                ac.TintOpacity          = 0.8;
                ac.BackgroundSource     = Windows.UI.Xaml.Media.AcrylicBackgroundSource.HostBackdrop;
                InfoPane.PaneBackground = ac;
            }

            //MapViewVM.LoadPage();
        }
示例#2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            inkCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch;
            var drawingAttr = this.inkCanvas.InkPresenter.CopyDefaultDrawingAttributes();

            drawingAttr.PenTip         = PenTipShape.Rectangle;
            drawingAttr.Size           = new Size(4, 4);
            drawingAttr.IgnorePressure = true;
            drawingAttr.Color          = (Color)Resources["SystemControlBackgroundAccentBrush"];
            this.inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttr);
            if (e.Parameter != null)
            {
                //Google Maps Override
                if (e.Parameter.ToString().StartsWith("http"))
                {
                    //Search Uri association handler
                    if (((Uri)e.Parameter).Segments[2].ToLower() == "search/")
                    {
                        //Searchgrid.PopUP = true;
                        //Searchgrid.SearchText = ((Uri)e.Parameter).DecodeQueryParameters().Where(x => x.Key == "query").FirstOrDefault().Value;
                    }
                    //Directions Uri association handler
                    if (((Uri)e.Parameter).Segments[2].ToLower() == "dir/")
                    {
                        var parameters  = ((Uri)e.Parameter).DecodeQueryParameters();
                        var origin      = parameters.Where(x => x.Key == "origin").FirstOrDefault();
                        var destination = parameters.Where(x => x.Key == "destination").FirstOrDefault();
                        var travelmode  = parameters.Where(x => x.Key == "travelmode").FirstOrDefault();
                        var waypoints   = parameters.Where(x => x.Key == "waypoints").FirstOrDefault();
                        ViewModel.DirectionsControls.DirectionsHelper.DirectionModes Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.walking;
                        Geopoint OriginPoint        = null;
                        Geopoint DestinationPoint   = null;
                        List <BasicGeoposition> lst = null;
                        if (travelmode.Value != null)
                        {
                            if (travelmode.Value.ToString() == "driving")
                            {
                                Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.driving;
                            }
                            else if (travelmode.Value.ToString() == "bicycling ")
                            {
                                Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.bicycling;
                            }
                            else if (travelmode.Value.ToString() == "transit")
                            {
                                Mode = ViewModel.DirectionsControls.DirectionsHelper.DirectionModes.transit;
                            }
                        }
                        if (origin.Value != null)
                        {
                            var latlng    = origin.Value.Split(',');
                            var Latitude  = Convert.ToDouble(latlng[0]);
                            var Longitude = Convert.ToDouble(latlng[1]);
                            OriginPoint = new Geopoint(new BasicGeoposition()
                            {
                                Latitude  = Latitude,
                                Longitude = Longitude
                            });
                        }
                        if (destination.Value != null)
                        {
                            var latlng    = destination.Value.Split(',');
                            var Latitude  = Convert.ToDouble(latlng[0]);
                            var Longitude = Convert.ToDouble(latlng[1]);
                            DestinationPoint = new Geopoint(new BasicGeoposition()
                            {
                                Latitude  = Latitude,
                                Longitude = Longitude
                            });
                        }
                        if (waypoints.Value != null)
                        {
                            lst = new List <BasicGeoposition>();
                            var latlngs = destination.Value.Split('|');
                            foreach (var item in latlngs)
                            {
                                var latlng             = item.Split(',');
                                BasicGeoposition point = new BasicGeoposition();
                                point.Latitude  = Convert.ToDouble(latlng[0]);
                                point.Longitude = Convert.ToDouble(latlng[1]);
                                lst.Add(point);
                            }
                        }
                        if (OriginPoint != null && DestinationPoint != null)
                        {
                            ViewModel.DirectionsControls.DirectionsHelper.Rootobject Result = null;
                            if (lst == null)
                            {
                                Result = await ViewModel.DirectionsControls.DirectionsHelper.GetDirections(OriginPoint.Position, DestinationPoint.Position, Mode);
                            }
                            else
                            {
                                Result = await ViewModel.DirectionsControls.DirectionsHelper.GetDirections(OriginPoint.Position, DestinationPoint.Position, Mode, lst);
                            }
                            if (Result != null)
                            {
                                Map.MapElements.Add(ViewModel.DirectionsControls.DirectionsHelper.GetDirectionAsRoute(Result, (Color)Resources["SystemControlBackgroundAccentBrush"]));
                            }
                        }
                    }
                    //Display a map
                    if (((Uri)e.Parameter).Segments[2].ToLower().StartsWith("@"))
                    {
                        await Task.Delay(1500);

                        try
                        {
                            if (!e.Parameter.ToString().Contains("searchplace"))
                            {
                                var parameters = ((Uri)e.Parameter).DecodeQueryParameters();
                                var mapaction  = parameters.Where(x => x.Key == "map_action").FirstOrDefault();
                                if (mapaction.Value != null && mapaction.Value == "pano")
                                {
                                    await new MessageDialog("StreetView Not Supported yet").ShowAsync();
                                }
                                var center = parameters.Where(x => x.Key == "center").FirstOrDefault();
                                var zoom   = parameters.Where(x => x.Key == "zoom").FirstOrDefault();
                                var cp     = center.Value.Split(',');
                                BasicGeoposition pointer = new BasicGeoposition()
                                {
                                    Latitude = Convert.ToDouble(cp[0]), Longitude = Convert.ToDouble(cp[1])
                                };
                                Map.Center = new Geopoint(pointer);
                                if (zoom.Value != null)
                                {
                                    Map.ZoomLevel = Convert.ToDouble(zoom.Value);
                                }
                                RunMapRightTapped(Map, new Geopoint(pointer));
                            }
                            else
                            {
                                var search = ((Uri)e.Parameter).ToString().Replace("https://google.com/maps/@searchplace=", "");
                                //var search = parameters.Where(x => x.Key == "searchplace").FirstOrDefault();
                                var res = await ViewModel.PlaceControls.SearchHelper.TextSearch(search, Location : Map.Center, Radius : 15000);

                                if (res == null || res.results.Length == 0)
                                {
                                    await new MessageDialog("No search results found").ShowAsync();
                                    return;
                                }
                                var ploc     = res.results.FirstOrDefault().geometry.location;
                                var geopoint = new Geopoint(new BasicGeoposition()
                                {
                                    Latitude = ploc.lat, Longitude = ploc.lng
                                });
                                Map.Center        = geopoint;
                                Map.ZoomLevel     = 16;
                                SearchResultPoint = geopoint;
                            }
                        }
                        catch
                        {
                        }
                    }
                }

                //Windows Maps Override
                else
                {
                    var    parameters = ((Uri)e.Parameter).DecodeQueryParameters();
                    string cp         = "";
                    int    zoomlevel  = 0;
                    string Querry     = "";
                    if (parameters.Where(x => x.Key == "cp").Any())
                    {
                        cp = parameters.Where(x => x.Key == "cp").FirstOrDefault().Value;
                    }
                    if (parameters.Where(x => x.Key == "lvl").Any())
                    {
                        zoomlevel = Convert.ToInt32(parameters.Where(x => x.Key == "lvl").FirstOrDefault().Value);
                    }
                    if (parameters.Where(x => x.Key == "q").Any())
                    {
                        Querry = parameters.Where(x => x.Key == "q").FirstOrDefault().Value;
                    }
                    if (parameters.Where(x => x.Key == "collection").Any())
                    {
                        var point     = parameters.Where(x => x.Key == "collection").FirstOrDefault().Value;
                        var pointargs = point.Split('_');
                        var latitude  = pointargs[0].Split('.')[1] + "." + pointargs[0].Split('.')[2];
                        var longitude = pointargs[1];
                        cp = $"{latitude}~{longitude}";
                    }
                    if (cp != "")
                    {
                        await Task.Delay(500);

                        var bgp = new BasicGeoposition();
                        bgp.Latitude  = Convert.ToDouble(cp.Split('~')[0]);
                        bgp.Longitude = Convert.ToDouble(cp.Split('~')[1]);
                        Map.Center    = new Geopoint(bgp);
                    }
                    if (zoomlevel != 0)
                    {
                        Map.ZoomLevel = zoomlevel;
                    }
                    else
                    {
                        Map.ZoomLevel = 16;
                    }
                    if (Querry != "")
                    {
                        await Task.Delay(1500);

                        Searchbar.SearchQuerry = Querry;
                    }
                }
            }
            if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush"))
            {
                var ac    = new Windows.UI.Xaml.Media.AcrylicBrush();
                var brush = Resources["SystemControlChromeLowAcrylicWindowBrush"] as Windows.UI.Xaml.Media.AcrylicBrush;
                ac                      = brush;
                ac.TintOpacity          = 0.8;
                ac.BackgroundSource     = Windows.UI.Xaml.Media.AcrylicBackgroundSource.HostBackdrop;
                InfoPane.PaneBackground = ac;
            }
        }