Пример #1
0
        void AddCluster()
        {
            var googleMapView = mapView;             //use the real mapview init'd somewhere else instead of this
            var iconGenerator = new GMUDefaultClusterIconGenerator();
            var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
            var renderer      = new GMUDefaultClusterRenderer(googleMapView, iconGenerator);

            renderer.WeakDelegate = this;

            clusterManager = new GMUClusterManager(googleMapView, algorithm, renderer);

            for (var i = 0; i <= kClusterItemCount; i++)
            {
                var lat = kCameraLatitude + extent * GetRandomNumber(-1.0, 1.0);

                var lng = kCameraLongitude + extent * GetRandomNumber(-1.0, 1.0);

                var name = $"Item {i}";

                IGMUClusterItem item = new POIItem(lat, lng, name);

                clusterManager.AddItem(item);
            }

            clusterManager.Cluster();

            clusterManager.SetDelegate(this, this);
        }
Пример #2
0
        public override void LoadView()
        {
            var camera = CameraPosition.FromCamera(latitude: kCameraLatitude, longitude: kCameraLongitude, zoom: 10);

            mapView   = MapView.FromCamera(frame: CGRect.Empty, camera: camera);
            this.View = mapView;

            // Set up the cluster manager with default icon generator and renderer.
            var iconGenerator = new GMUDefaultClusterIconGenerator();
            var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
            var renderer      = new ClusterRenderer(mapView: mapView, iconGenerator: iconGenerator)
            {
                Delegate = this
            };

            clusterManager = new GMUClusterManager(mapView: mapView, algorithm: algorithm, renderer: renderer);

            // Add people to the cluster manager.
            foreach (Person person in randomPeople())
            {
                clusterManager.AddItem(person);
            }

            // Call cluster() after items have been added to perform the clustering and rendering on map.
            clusterManager.Cluster();
        }
Пример #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Set up the cluster manager with default icon generator and renderer.
            var iconGenerator = new GMUDefaultClusterIconGenerator();
            var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
            var renderer      = new GMUDefaultClusterRenderer(mapView: mapView, iconGenerator: iconGenerator);

            clusterManager = new GMUClusterManager(mapView: mapView, algorithm: algorithm, renderer: renderer);

            // Generate and add random items to the cluster manager.
            generateClusterItems();

            // Call cluster() after items have been added to perform the clustering and rendering on map.
            clusterManager.Cluster();

            // Register self to listen to both GMUClusterManagerDelegate and GMSMapViewDelegate events.
            var mapDelegate = new MapDelegate();

            clusterManager.SetDelegate(this, mapDelegate: mapDelegate);

            UIBarButtonItem removeButton = new UIBarButtonItem("Remove", UIBarButtonItemStyle.Plain, this, new ObjCRuntime.Selector("removeClusterManager"));

            NavigationItem.RightBarButtonItems = new UIBarButtonItem[] { removeButton };
        }
Пример #4
0
        private void SetClusterManager()
        {
            var iconGenerator = new GMUDefaultClusterIconGenerator();
            var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
            var renderer      = new ClusterRenderer(mapView, iconGenerator)
            {
                Delegate = this
            };

            clusterManager = new GMUClusterManager(mapView, algorithm, renderer);
            RandomPeople();
            clusterManager.Cluster();
        }
Пример #5
0
        private void SetClusterManager()
        {
            mapDelegate = new MapDelegate(mapView);
            var iconGenerator = IconGeneratorWithImages();
            var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
            var renderer      = new GMUDefaultClusterRenderer(mapView, iconGenerator)
            {
                WeakDelegate = mapDelegate
            };

            clusterManager = new GMUClusterManager(mapView, algorithm, renderer);
            clusterManager.SetDelegate(mapDelegate, mapDelegate);
            GenerateClusterItem();
            clusterManager.Cluster();
        }
        private void UpdatePins()
        {
            var mapTile  = Element;
            var map      = Control;
            var pinItems = mapTile.PinList;

            ClusterManager.ClearItems();
            map.Clear();

            var clusterItems = pinItems.Select(i => new ClusterItem(i)).Cast <IGMUClusterItem>().ToArray();

            ClusterManager.AddItems(clusterItems);

            ClusterManager.Cluster();

            LocationMarker.Map = map;

            UpdateLocationPinPosition();
        }
Пример #7
0
        private void GenerateClusters(TripsClusterMapView mapView)
        {
            if (mapView == null)
            {
                return;
            }

            if (_clusterManager.Delegate == null)
            {
                _clusterManager.SetDelegate(new ClusterDelegate(mapView), new MapDelegate());
            }

            _clusterManager.ClearItems();
            var random = new Random();

            mapView.Trips.ForEach(x => _clusterManager.AddItem(new ClusterMarker(x.Route.Average(y => y.Latitude), x.Route.Average(y => y.Longitude))
            {
                Id    = x.Id,
                Title = x.Name
            }));
            _clusterManager.Cluster();
        }
        void UpdateAllPins()
        {
            var googleMapView = nativeMap;
            var iconGenerator = new GMUDefaultClusterIconGenerator();
            var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
            GMUDefaultClusterRenderer renderer = null;

            try
            {
                renderer = new GMUDefaultClusterRenderer(googleMapView, iconGenerator);

                renderer.WeakDelegate = this;
                clusterManager        = new GMUClusterManager(googleMapView, algorithm, renderer);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            for (var i = 0; i < Map.Pins.Count; i++)
            {
                Pin pin = (Map.Pins[i] as Pin);
                var lat = pin.Position.Latitude;

                var lng = pin.Position.Longitude;

                var name = pin.Label;

                IGMUClusterItem item = new POIItem(lat, lng, name);

                clusterManager.AddItem(item);
            }

            clusterManager.Cluster();

            clusterManager.SetDelegate(this, this);
        }
Пример #9
0
        private void ItemsChanged(object sender, EventArgs e)
        {
            if (mapView == null)
            {
                return;
            }

            var clusterChanged = false;

            foreach (var newItem in ViewModel.Items.Value)
            {
                var exitingCi = clusterItems.FirstOrDefault(x => x.AnimalId == newItem.AnimalId);
                if (exitingCi != null)
                {
                    exitingCi.Position = new CLLocationCoordinate2D(newItem.Coordinate.Latitude, newItem.Coordinate.Longitude);
                    clusterChanged     = true;
                }
                else
                {
                    AnimalClusterItem item = new AnimalClusterItem(
                        new CLLocationCoordinate2D(newItem.Coordinate.Latitude, newItem.Coordinate.Longitude), newItem.AnimalId, newItem.Name,
                        newItem.ImageUrl);
                    clusterItems.Add(item);
                    clusterManager.AddItem(item);
                    clusterChanged = true;
                }
            }
            if (clusterChanged)
            {
                clusterManager.Cluster();
            }



            //List<Animal> addableItems = new List<Animal>();
            ////foreach (var newItem in ViewModel.Items.Value)
            ////{
            ////    var equals = false;
            ////    if (oldItems.Count > 0)
            ////        foreach (var oldItem in oldItems)
            ////        {
            ////            if (newItem.AnimalId == oldItem.AnimalId)
            ////                equals = true;
            ////        }

            ////    if (!equals)
            ////        addableItems.Add(newItem);
            ////}

            //clusterManager.ClearItems();
            //AnimalClusterItem[] items = ViewModel.Items.Value.Select(x => new AnimalClusterItem(
            //       new CLLocationCoordinate2D(x.Coordinate.Latitude, x.Coordinate.Longitude), x.AnimalId, x.Name,
            //       x.ImageUrl)).ToArray();
            //clusterManager.AddItems(items);
            //oldItems.AddRange(addableItems);
            ////if (addableItems.Count > 0)
            ////{
            //    clusterManager.Cluster();
            //    if (mapView.SelectedMarker != null)
            //        SelectMarker(mapView.SelectedMarker);
            //}
        }
Пример #10
0
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();

            var googleMapView = mapView; //use the real mapview init'd somewhere else instead of this
            var iconGenerator = new GMUDefaultClusterIconGenerator();
            var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
            var renderer      = new GMUDefaultClusterRenderer(googleMapView, iconGenerator);

            renderer.WeakDelegate = this;

            clusterManager = new GMUClusterManager(googleMapView, algorithm, renderer);

            JsonSerializer _serializer = new JsonSerializer()
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            };

            using (HttpClient httpClient = new HttpClient(new HttpClientHandler {
                AutomaticDecompression = DecompressionMethods.GZip
            }))
            {
                Token token = null;
                httpClient.BaseAddress = new Uri(AppSettings.BaseAddress);
                FormUrlEncodedContent formUrlEncodedContent = new FormUrlEncodedContent(new Dictionary <String, String> {
                    { "client_id", AppSettings.Client_id },
                    { "client_secret", AppSettings.Client_secret },
                    { "grant_type", AppSettings.Grant_type }
                });
                using (HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/connect/token"))
                {
                    httpRequestMessage.Content = formUrlEncodedContent;
                    using (HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(httpRequestMessage))
                    {
                        if (httpResponseMessage.IsSuccessStatusCode == true)
                        {
                            using (System.IO.Stream stream = await httpResponseMessage.Content.ReadAsStreamAsync())
                            {
                                using (System.IO.StreamReader streamReader = new System.IO.StreamReader(stream))
                                {
                                    using (JsonTextReader json = new JsonTextReader(streamReader))
                                    {
                                        token = _serializer.Deserialize <Token>(json);
                                    }
                                }
                            }
                        }
                    }
                }
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token.token_type, token.access_token);

                using (HttpResponseMessage httpResponseMessage = await httpClient.GetAsync("/api/v1/pl/Locations/lots"))
                {
                    if (httpResponseMessage.IsSuccessStatusCode == true)
                    {
                        using (System.IO.Stream stream = await httpResponseMessage.Content.ReadAsStreamAsync())
                        {
                            using (System.IO.StreamReader streamReader = new System.IO.StreamReader(stream))
                            {
                                using (JsonTextReader json = new JsonTextReader(streamReader))
                                {
                                    Response <Lot[]> lots = _serializer.Deserialize <Response <Lot[]> >(json);
                                    for (int i = 0; i < lots.result.Length; i++)
                                    {
                                        IGMUClusterItem item = new POIItem(lots.result[i].latitude, lots.result[i].longitude, lots.result[i].name);
                                        clusterManager.AddItem(item);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            clusterManager.Cluster();

            clusterManager.SetDelegate(this, this);
        }