示例#1
0
        private async void Cluster()
        {
            try
            {
                if (_map != null && _items != null && _items.Count > 0 && _currentZoomLevel <= _maxZoomLevel)
                {
#if WINDOWS_APP
                    var pixels = new List <Windows.Foundation.Point>();
                    _map.TryLocationsToPixels(_allLocations, pixels);

                    Windows.Foundation.Point centerPixel;
                    _map.TryLocationToPixel(new Location(0, 0), out centerPixel);
#elif WPF
                    var pixels = new List <System.Windows.Point>(_allLocations.Count);

                    foreach (var l in _allLocations)
                    {
                        pixels.Add(_map.LocationToViewportPoint(l));
                    }
                    ;

                    System.Windows.Point centerPixel;
                    centerPixel = _map.LocationToViewportPoint(new Location(0, 0));
#elif WINDOWS_PHONE_APP
                    var pixels = new List <Windows.Foundation.Point>(_allLocations.Count);
                    Windows.Foundation.Point p;

                    foreach (var l in _allLocations)
                    {
                        _map.GetOffsetFromLocation(l, out p);
                        pixels.Add(p);
                    }

                    Windows.Foundation.Point centerPixel;
                    _map.GetOffsetFromLocation(new Geopoint(new BasicGeoposition()
                    {
                        Latitude = 0, Longitude = 0
                    }), out centerPixel);
#elif WINDOWS_PHONE
                    var pixels = new List <System.Windows.Point>(_allLocations.Count);

                    foreach (var l in _allLocations)
                    {
                        pixels.Add(_map.ConvertGeoCoordinateToViewportPoint(l));
                    }
                    ;

                    System.Windows.Point centerPixel;
                    centerPixel = _map.ConvertGeoCoordinateToViewportPoint(new GeoCoordinate(0, 0));
#endif
                    switch (ClusterType)
                    {
                    case ClusteringType.Grid:
                        await CalculateGridClusters(pixels, centerPixel);

                        break;

                    case ClusteringType.Point:
                        await CalculatePointClusters(pixels);

                        break;

                    default:
                        break;
                    }
                }

                Render();
            }
            catch { }
        }
示例#2
0
        public void SetUsers()
        {
            if (!App.ViewModel.IsMapVisible)
            {
                return;
            }

            // clean up
            if (MapControl.Layers.Count == 0)
            {
                MapControl.Layers.Add(new MapLayer());
            }
            var layer = MapControl.Layers.First();

            layer.Clear();

            //set me
            var me = App.ViewModel.Coordinate;

            if (me != null)
            {
                var myColor = ConvertHtmlColor("#123123");
                layer.Add(new MapOverlay
                {
                    GeoCoordinate = new GeoCoordinate(me.Lat, me.Lon),
                    Content       = new GeoUser
                    {
                        Name   = "Me",
                        Speed  = me.SpeedKmh.ToString("N0"),
                        Fill   = new SolidColorBrush(myColor),
                        Stroke = new SolidColorBrush(MakeDarker(myColor)),
                        U      = "-1",
                    },
                    ContentTemplate = this.Resources["MeTemplate"] as DataTemplate,
                });
            }

            // set others
            if (App.ViewModel.GroupsModel.Tracks != null)
            {
                foreach (var user in App.ViewModel.GroupsModel.Tracks)
                {
                    var groupUser = App.ViewModel.GroupsModel.Groups.Where(w => w.Active).SelectMany(s => s.Users).FirstOrDefault(f => f.U == user.Key);
                    if (groupUser == null)
                    {
                        continue;
                    }
                    var coordinate    = user.Value[user.Value.Count - 1];
                    var geoCoordinate = new GeoCoordinate(coordinate.Lat, coordinate.Lon);
                    var point         = MapControl.ConvertGeoCoordinateToViewportPoint(geoCoordinate);
                    if (point.X < -100 || point.X > MapControl.RenderSize.Width + 100 || point.Y < -100 || point.Y > MapControl.RenderSize.Height + 100)
                    {
                        continue;
                    }
                    var color = ConvertHtmlColor(groupUser.Color);
                    layer.Add(new MapOverlay
                    {
                        GeoCoordinate = geoCoordinate,
                        Content       = new GeoUser
                        {
                            Name   = groupUser.Name,
                            Speed  = coordinate.SpeedKmh.ToString("N0"),
                            Fill   = new SolidColorBrush(color),
                            Stroke = new SolidColorBrush(MakeDarker(color)),
                            U      = user.Key,
                        },
                        ContentTemplate = this.Resources["UserTemplate"] as DataTemplate
                    });
                }
                ;
            }

            if (LockedUser != null)
            {
                var user = layer.FirstOrDefault(f => (f.Content as GeoUser).U == LockedUser);
                if (user != null)
                {
                    var xcenter  = MapControl.RenderSize.Width / 2;
                    var ycenter  = MapControl.RenderSize.Height / 2;
                    var point    = MapControl.ConvertGeoCoordinateToViewportPoint(user.GeoCoordinate);
                    var distance = Math.Sqrt(Math.Pow(xcenter - point.X, 2) + Math.Pow(ycenter - point.Y, 2));
                    if (distance > 50)
                    {
                        MapControl.Center = user.GeoCoordinate;
                    }
                }
            }
        }
示例#3
0
        private async void Render()
        {
            try
            {
                if (_isLoaded && _map != null)
                {
                    StringBuilder sb = new StringBuilder();

                    if (Locations != null)
                    {
#if WINDOWS_APP
                        var px = new List <Windows.Foundation.Point>();

                        _map.TryLocationsToPixels(Locations, px);

                        await System.Threading.Tasks.Task.Run(() =>
                        {
                            foreach (var p in px)
                            {
                                sb.AppendFormat("{0},{1}|", Math.Round(p.X), Math.Round(p.Y));
                            }
                        });
#elif WINDOWS_PHONE
                        foreach (var l in Locations)
                        {
                            var p = _map.ConvertGeoCoordinateToViewportPoint(l);
                            sb.AppendFormat("{0},{1}|", Math.Round(p.X), Math.Round(p.Y));
                        }
#elif WINDOWS_PHONE_APP
                        await System.Threading.Tasks.Task.Run(() =>
                        {
                            Windows.Foundation.Point p;

                            foreach (var l in Locations.Positions)
                            {
                                _map.GetOffsetFromLocation(new Geopoint(l), out p);
                                sb.AppendFormat("{0},{1}|", Math.Round(p.X), Math.Round(p.Y));
                            }
                        });
#endif
                    }

                    if (sb.Length > 0)
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }

                    //Ground resolution at equator
                    var groudResolution = (2 * Math.PI * 6378135) / Math.Round(256 * Math.Pow(2, _map.ZoomLevel));
                    var radiusInPixels  = _radius / groudResolution;

                    if (radiusInPixels < _minRadius)
                    {
                        radiusInPixels = _minRadius;
                    }

                    string[] args = { sb.ToString(), radiusInPixels.ToString(), _map.ZoomLevel.ToString() };

                    InvokeJS("Render", args);
                }
            }
            catch { }
        }