private void SetGoogleMapControl()
        {
            var mapView = new MapView
            {
                Camera       = CameraPosition.FromCamera(MapTile.MinskLat, MapTile.MinskLong, 11.9f),
                TappedMarker = TappedMarker,
                Settings     =
                {
                    CompassButton = true
                }
            };

            mapView.CameraPositionIdle   += Map_CameraPositionIdle;
            mapView.CoordinateTapped     += Map_CoordinateTapped;
            mapView.PoiWithPlaceIdTapped += Map_PoiWithPlaceIdTapped;
            mapView.WillMove             += Map_WillMove;

            var buckets       = new[] { NSNumber.FromInt32(int.MaxValue) };
            var images        = new[] { UIImage.FromBundle("ic_cluster.png") };
            var iconGenerator = new GMUDefaultClusterIconGenerator(buckets, images);
            var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
            var renderer      = new ClusterRenderer(mapView, iconGenerator);

            ClusterManager = new GMUClusterManager(mapView, algorithm, renderer);

            SetNativeControl(mapView);
        }
Esempio n. 2
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 };
        }
Esempio n. 3
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();
        }
        public override void MovedToWindow()
        {
            base.MovedToWindow();

            if (mapDelegate == null)
            {
                mapDelegate = new MapDelegate(Control);
            }

            if (clusterManager == null)
            {
                var iconGenerator = new GMUDefaultClusterIconGenerator();
                var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
                var renderer      = new GMUDefaultClusterRenderer(Control, iconGenerator)
                {
                    WeakDelegate = mapDelegate
                };
                clusterManager = new GMUClusterManager(Control, algorithm, renderer);
                clusterManager.SetDelegate(mapDelegate, mapDelegate);

                SubscribeToMarkers();

                Element.SetMapReady(DateTime.UtcNow.Ticks);
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public bool DidTapCluster(GMUClusterManager clusterManager, IGMUCluster cluster)
        {
            var newCamera = CameraPosition.FromCamera(cluster.Position, zoom: mapView.Camera.Zoom + 1);
            var update    = CameraUpdate.SetCamera(newCamera);

            mapView.MoveCamera(update);
            return(false);
        }
Esempio n. 7
0
        public void DidTapCluster(GMUClusterManager clusterManager, IGMUCluster cluster)
        {
            var newCamera = CameraPosition.FromCamera(cluster.Position, mapView.Camera.Zoom + 1);

            var update = CameraUpdate.SetCamera(newCamera);

            mapView.MoveCamera(update);
        }
        internal override void Register(MapView oldNativeMap, Map oldMap, MapView newNativeMap, Map newMap)
        {
            //----------------------------------------
            //  Base registration
            //----------------------------------------
            base.Register(oldNativeMap, oldMap, newNativeMap, newMap);

            //----------------------------------------
            //  Instanciate a new cluster manager
            //----------------------------------------

            /* Delegate */
            this._clusterDelegate = new GMUClusterDelegateHandler(this);

            /* Algorithm */
            IGMUClusterAlgorithm algorithm;

            switch (newMap.ClusterOptions.Algorithm)
            {
            case ClusterAlgorithm.GridBased:
                algorithm = new GMUGridBasedClusterAlgorithm();
                break;

            default:
                algorithm = new GMUNonHierarchicalDistanceBasedAlgorithm();
                break;
            }

            /* Icon Generation */
            var iconGenerator = new GMUClusterIconGeneratorHandler(this.Map.ClusterOptions);

            /* Renderer */
            var clusterRenderer = new GMUClusterRendererHandler(newNativeMap, iconGenerator);

            clusterRenderer.WeakDelegate = this._clusterDelegate;

            /* The actual manager */
            this._clusterManager = new GMUClusterManager(newNativeMap, algorithm, clusterRenderer);

            this._clusterManager.SetDelegate(this._clusterDelegate, this._clusterDelegate);

            /* Handle the cluster request by forwarding it to clusterManager.Cluster() */
            this.Map.OnCluster = HandleClusterRequest;

            //----------------------------------------
            //  Register events events
            //----------------------------------------
            if (newNativeMap != null)
            {
                newNativeMap.InfoTapped            += OnInfoTapped;
                newNativeMap.TappedMarker           = HandleGMSTappedMarker;
                newNativeMap.InfoClosed            += InfoWindowClosed;
                newNativeMap.DraggingMarkerStarted += DraggingMarkerStarted;
                newNativeMap.DraggingMarkerEnded   += DraggingMarkerEnded;
                newNativeMap.DraggingMarker        += DraggingMarker;
            }
        }
Esempio n. 9
0
        public override bool DidTapClusterItem(GMUClusterManager clusterManager, IGMUClusterItem clusterItem)
        {
            if (clusterItem is ClusterMarker clusterMarker)
            {
                _clusterMapView?.MarkerSelectedCommand?.Execute(clusterMarker?.Id);
            }

            return(false);
        }
        public void DidTapCluster(GMUClusterManager clusterManager, IGMUCluster cluster)
        {
            IList objs = new List <POIItem>();

            foreach (var item in cluster.Items)
            {
                objs.Add((item as POIItem));
            }
            Map.ClusterClicked(objs);
        }
Esempio n. 11
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();
        }
Esempio n. 12
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();
        }
Esempio n. 13
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            var set = this.CreateBindingSet <MapView, MapViewModel>();

            set.Apply();
            CameraPosition camera = CameraPosition.FromCamera(GetInitialCameraPosition(),
                                                              GetInitialCameraZoom());

            mapView = Google.Maps.MapView.FromCamera(CGRect.Empty, camera);
            mapView.MyLocationEnabled         = true;
            mapView.Settings.MyLocationButton = true;
            mapView.CameraPositionIdle       += MapView_CameraPositionIdle;
            mapView.InfoTapped       += MapView_InfoTapped;
            mapView.CoordinateTapped += MapView_CoordinateTapped;
            //mapView.WillMove += MapView_WillMove;
            ViewModel.Items.Changed += ItemsChanged;
            View.AddSubview(mapView);
            mapView.Frame = MapPlaceHolderView.Frame;

            var iconGenerator = new GMUDefaultClusterIconGenerator();
            var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();

            renderer = new GMUDefaultClusterRenderer(mapView, iconGenerator)
            {
                Delegate = new JunctionXClusterRendererDelegate(this)
            };

            clusterManager        = new GMUClusterManager(mapView, algorithm, renderer);
            mapView.TappedMarker += (map, marker) => SelectMarker(marker);

            ActivityButton.TouchDown  += ActivityButton_TouchDown;
            ActivityButton2.TouchDown += ActivityButton_TouchDown;
            AdoptButton.TouchDown     += AdoptButton_TouchDown;
            DetailsButton.TouchDown   += DetailsButton_TouchDown;
            DetailsButton2.TouchDown  += DetailsButton_TouchDown;
            CloseButton.TouchDown     += CloseButton_TouchDown;

            //var gest = new UITapGestureRecognizer(() => { View.SendSubviewToBack(MarkerInfoView);});
            //TapView.AddGestureRecognizer(gest);
        }
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                markerSubscription.Clear();

                clusterManager?.Dispose();
                mapDelegate?.Dispose();

                clusterManager = null;
                mapDelegate    = null;

                foreach (var item in renderedMarkers)
                {
                    item.Value.Dispose();
                }

                renderedMarkers.Clear();
            }
        }
            public bool DidTapCluster(GMUClusterManager clusterManager, IGMUCluster cluster)
            {
                // zoom to expand the cluster
                var bounds = new CoordinateBounds(cluster.Position, cluster.Position);

                foreach (var item in cluster.Items)
                {
                    bounds = bounds.Including(item.Position);
                }

                try
                {
                    var cameraUpdate = CameraUpdate.FitBounds(bounds, 100);
                    mapView.MoveCamera(cameraUpdate);
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }

                return(true);
            }
Esempio n. 16
0
        protected override void OnElementChanged(ElementChangedEventArgs <TripsClusterMapView> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement == null)
            {
                return;
            }

            if (e.OldElement != null)
            {
                var mapView = e.OldElement;
                mapView.Trips.CollectionChanged -= Trips_CollectionChanged;
            }

            var newMapView = e.NewElement;

            newMapView.Trips.CollectionChanged += Trips_CollectionChanged;
            if (_control == null)
            {
                _control = new MapView
                {
                    MapStyle = MapStyle.FromJson(Constants.MapStyleJson, null),
                };

                _control.MoveCamera(CameraUpdate.ZoomToZoom(0));
            }

            if (_clusterManager == null)
            {
                _clusterManager = new GMUClusterManager(_control,
                                                        new GMUNonHierarchicalDistanceBasedAlgorithm(),
                                                        new GMUDefaultClusterRenderer(_control, new GMUDefaultClusterIconGenerator()));
            }

            SetNativeControl(_control);
            GenerateClusters(newMapView);
        }
        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);
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
 public bool DidTapCluster(GMUClusterManager clusterManager, IGMUCluster cluster)
 {
     mapView.MoveCamera(CameraUpdate.SetTarget(cluster.Position, mapView.Camera.Zoom + 1));
     return(true);
 }
Esempio n. 20
0
 private void removeClusterManager()
 {
     Console.WriteLine(@"Removing cluster manager. Cluster related markers should be cleared.");
     clusterManager = null;
 }
Esempio n. 21
0
 void RemoveButton_Clicked(object sender, EventArgs e)
 {
     clusterManager = null;
 }
        public void DidTapClusterItem(GMUClusterManager clusterManager, IGMUClusterItem clusterItem)
        {
            POIItem poitem = clusterItem as POIItem;

            Map.ClusterItemClicked(poitem);
        }