Exemple #1
0
        protected Circle GetFormsCircle(ACircle circle)
        {
            Circle targetCircle = null;

            for (int i = 0; i < Element.MapElements.Count; i++)
            {
                var mapElement = Element.MapElements[i];
                if ((string)mapElement.MapElementId == circle.Id)
                {
                    targetCircle = mapElement as Circle;
                    break;
                }
            }

            return(targetCircle);
        }
Exemple #2
0
        protected ACircle GetNativeCircle(Circle circle)
        {
            ACircle targetCircle = null;

            if (_circles != null)
            {
                for (int i = 0; i < _circles.Count; i++)
                {
                    var native = _circles[i];
                    if (native.Id == (string)circle.MapElementId)
                    {
                        targetCircle = native;
                        break;
                    }
                }
            }

            return(targetCircle);
        }
		void UpdateMap (int position)
		{
			if (googleMap == null)
				return;
			
			try {
				MapsInitializer.Initialize (this);
			} catch (GooglePlayServicesNotAvailableException e) {
				Console.WriteLine ("Google Play Services not available:" + e);
				error = true;
				#if !DEBUG
				Xamarin.Insights.Report (e, "GPS", "Not Available");
				#endif
				return;
			}

			if (markerOptions == null)
				markerOptions = new MarkerOptions ();

			if (circleOptions == null)
				circleOptions = new CircleOptions ();

			var place = viewModel.Places [position];
			var markerLatLong = new LatLng (place.Geometry.Location.Latitude, place.Geometry.Location.Longitude);

			if (marker == null) {
				markerOptions.SetTitle (place.Name);
				markerOptions.SetPosition (markerLatLong);
				marker = googleMap.AddMarker (markerOptions);
			} else {
				marker.Position = markerLatLong;
				marker.Title = place.Name;
			}

			var userLocation = new LatLng (viewModel.Position.Latitude, viewModel.Position.Longitude);

			if (locationCircle == null) {
				circleOptions.InvokeCenter (userLocation);
				circleOptions.InvokeRadius (radius);
				circleOptions.InvokeStrokeWidth (0);
				circleOptions.InvokeFillColor (Resources.GetColor (Resource.Color.accent));
				locationCircle = googleMap.AddCircle (circleOptions);
			} else {
				locationCircle.Center = userLocation;
				locationCircle.Radius = radius;
			}

			if (!initMap) {
				var farthest = viewModel.Places [viewModel.Places.Count - 1];
				var distance = farthest.GetDistance (userLocation.Latitude, userLocation.Longitude);

				radius = 20.0 * (distance / .45);
				radius = Math.Min (radius, 40.0);
				locationCircle.Radius = radius;

				var points = new LatLngBounds.Builder ();
				points.Include (userLocation);
				foreach (var p in viewModel.Places)
					points.Include (new LatLng (p.Geometry.Location.Latitude, p.Geometry.Location.Longitude));
				
				var bounds = points.Build ();

				if (mapView.Width == 0) {
					initTry = 0;
					PostDelayInitMap (bounds);
				} else {
					googleMap.MoveCamera (CameraUpdateFactory.NewLatLngBounds (bounds, 0));
				}
				initMap = true;
			}
		}
		void RedrawAddCircle ()
		{
			if (_alarmToAdd != null) {
				if (_circleToAdd == null) {
					_circleToAdd = _map.AddCircle (new CircleOptions ().InvokeCenter (_alarmToAdd.Position));

					_circleToAdd.FillColor = Resources.GetColor (Resource.Color.light);
					_circleToAdd.StrokeColor = Resources.GetColor (Resource.Color.dark);
					_circleToAdd.StrokeWidth = 1.0f;
				} else {
					_circleToAdd.Center = _alarmToAdd.Position;
				}

				_circleToAdd.Radius = (float) Constants.AlarmRadiusValues [_alarmRadiusSpinner.SelectedItemPosition];
			} else {
				if (_circleToAdd != null) {
					_circleToAdd.Remove ();
					_circleToAdd = null;
				}
			}
		}
        private void HandleMarkerClick(object sender, GoogleMap.MarkerClickEventArgs e)
        {
            ClearMapOverlays ();
            Marker marker = e.Marker;
            int index = int.Parse (marker.Title);
            extendedMap.pin_Clicked (index );

            Android.Graphics.Color clrb = new Android.Graphics.Color (12,92,169,130);
            Android.Graphics.Color clrr = new Android.Graphics.Color (204,27,39,130);
            PolygonOptions polygonOptions = new PolygonOptions();
            switch (index)
            {
            case 0:
                CircleOptions circleOptions = new CircleOptions ();
                circleOptions.InvokeCenter (new LatLng (extendedMap.pinDatas [index].lat, extendedMap.pinDatas [index].lng));
                circleOptions.InvokeRadius (2000);

                circleOptions.InvokeFillColor (clrb.ToArgb ());
                circleOptions.InvokeStrokeColor (clrr.ToArgb ());

                circle = map.AddCircle (circleOptions);

                break;
            case 1:
                polygonOptions.Add(new LatLng(extendedMap.pinDatas[index].lat-0.01, extendedMap.pinDatas[index].lng+0.01));
                polygonOptions.Add(new LatLng(extendedMap.pinDatas[index].lat+0.01, extendedMap.pinDatas[index].lng+0.01));
                polygonOptions.Add(new LatLng(extendedMap.pinDatas[index].lat+0.01, extendedMap.pinDatas[index].lng-0.01));
                polygonOptions.Add(new LatLng(extendedMap.pinDatas[index].lat-0.01, extendedMap.pinDatas[index].lng-0.01));
                polygonOptions.InvokeFillColor (clrb.ToArgb());
                polygonOptions.InvokeStrokeColor (clrr.ToArgb());
                polygon = map.AddPolygon(polygonOptions);
                break;
            case 2:
                polygonOptions.Add(new LatLng(extendedMap.pinDatas[index].lat-0.01, extendedMap.pinDatas[index].lng+0.01));
                polygonOptions.Add(new LatLng(extendedMap.pinDatas[index].lat+0.01, extendedMap.pinDatas[index].lng+0.01));
                polygonOptions.Add(new LatLng(extendedMap.pinDatas[index].lat+0.005, extendedMap.pinDatas[index].lng));
                polygonOptions.Add(new LatLng(extendedMap.pinDatas[index].lat+0.02, extendedMap.pinDatas[index].lng-0.02));
                polygonOptions.Add(new LatLng(extendedMap.pinDatas[index].lat-0.01, extendedMap.pinDatas[index].lng-0.01));
                polygonOptions.InvokeFillColor (clrb.ToArgb());
                polygonOptions.InvokeStrokeColor (clrr.ToArgb());
                polygon = map.AddPolygon(polygonOptions);
                break;
                default:
                CircleOptions circleOptions2 = new CircleOptions ();
                circleOptions2.InvokeCenter (new LatLng (extendedMap.pinDatas [index].lat, extendedMap.pinDatas [index].lng));
                circleOptions2.InvokeRadius (2000);

                circleOptions2.InvokeFillColor (clrb.ToArgb ());
                circleOptions2.InvokeStrokeColor (clrr.ToArgb ());

                circle = map.AddCircle (circleOptions2);

                break;
            }
        }