public void OnMapReady (GoogleMap googleMap)
		{
			map = googleMap;

			var polygonOptions = new PolygonOptions ();
			polygonOptions.InvokeFillColor (0x66FF0000);
			polygonOptions.InvokeStrokeColor (0x660000FF);
			polygonOptions.InvokeStrokeWidth (30.0f);

			foreach (var position in shapeCoordinates) {
				polygonOptions.Add (new LatLng (position.Latitude, position.Longitude));
			}

			map.AddPolygon (polygonOptions);
		}
        /// <summary>
        /// Adds a polygon to the map
        /// </summary>
        /// <param name="polygon">The polygon to add</param>
        private void AddPolygon(TKPolygon polygon)
        {
            polygon.PropertyChanged += OnPolygonPropertyChanged;

            var polygonOptions = new PolygonOptions();

            if (polygon.Coordinates != null && polygon.Coordinates.Any())
            {
                polygonOptions.Add(polygon.Coordinates.Select(i => i.ToLatLng()).ToArray());
            }
            if (polygon.Color != Color.Default)
            {
                polygonOptions.InvokeFillColor(polygon.Color.ToAndroid().ToArgb());
            }
            if (polygon.StrokeColor != Color.Default)
            {
                polygonOptions.InvokeStrokeColor(polygon.StrokeColor.ToAndroid().ToArgb());
            }
            polygonOptions.InvokeStrokeWidth(polygonOptions.StrokeWidth);

            this._polygons.Add(polygon, this._googleMap.AddPolygon(polygonOptions));
        }
Example #3
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);
			Inicializa_MapFragment ();
			//Definimos las ciudades en las cuales pondremos nuestros marcadores en el mapa
			MisCiudades.Add ( new Ciudad_Marca ("MÉXICO D.F.","En su forma abreviada México, D. F., es la capital y sede de los poderes federales de los Estados Unidos Mexicanos.",new LatLng (19.430334, -99.13599),"p1"));
			MisCiudades.Add ( new Ciudad_Marca ("LEÓN","Es una ciudad mexicana localizada  en el Estado de Guanajuato,México, en la región del Bajío.",new LatLng ( 21.12806,-101.689163),"p2"));
			MisCiudades.Add ( new Ciudad_Marca ("LAGOS DE MORENO"," Es un municipio y la ciudad más grande y poblada de la Región denominada Los Altos de Jalisco, ubicados en el estado mexicano de Jalisco.",new LatLng ( 21.36453,-101.939076),"p3"));
			MisCiudades.Add ( new Ciudad_Marca ("GUADALAJARA","es una ciudad mexicana, capital del estado de Jalisco, así como principal localidad del área urbana denominada Zona Metropolitana de Guadalajara.",new LatLng ( 20.663626,-103.343754),"p4"));

			CargamosMarcadores ();

			Button btnLinea = FindViewById<Button> (Resource.Id.btnLinea);
			Button btnCirculo = FindViewById<Button> (Resource.Id.btnCirculo);
			Button btnPoligono = FindViewById<Button> (Resource.Id.btnPoligono);
			txtPosicion=(TextView) FindViewById (Resource.Id.txtPosicion);



			btnLinea.Click += delegate {
				PolylineOptions rectOptions = new PolylineOptions();
				if (mMap != null)
				{
					foreach (Ciudad_Marca ciudad in MisCiudades) 
					{
						rectOptions.Add (ciudad.Ubicacion );
					}

					rectOptions.InvokeColor(Color.Red.ToArgb());
					rectOptions.InvokeWidth(25);
					rectOptions.Geodesic(true) ;

					mMap.AddPolyline(rectOptions);
				}
			};

			btnCirculo.Click += delegate {
				if (mMap != null)
				{
					foreach (Ciudad_Marca ciudad in MisCiudades) 
					{
						CircleOptions circleOptions = new CircleOptions();
						circleOptions.InvokeCenter(ciudad.Ubicacion);
						circleOptions.InvokeRadius(10000);

						circleOptions.InvokeStrokeWidth(10);
						circleOptions.InvokeStrokeColor(Color.Blue.ToArgb() );

						Color micolorfill=Color.FromArgb(150,149,153,225);
						circleOptions.InvokeFillColor(micolorfill.ToArgb() );

						mMap.AddCircle(circleOptions);

					}
				}

			};

			btnPoligono.Click += delegate {
				if (mMap != null) {
					PolygonOptions Poligono = new PolygonOptions ();
					foreach (Ciudad_Marca ciudad in MisCiudades) {
						Poligono.Add (ciudad.Ubicacion);
					}

					Poligono.InvokeStrokeWidth(10);
					Poligono.InvokeStrokeColor(Color.Green.ToArgb ());

					Color micolorfill=Color.FromArgb(150,0,255,51);
					Poligono.InvokeFillColor(micolorfill.ToArgb() );

					mMap.AddPolygon (Poligono);
				}
			};


		}
		// TODO: Step 4c - handle info popup tap
        private void HandleInfoWindowClick(object sender, GoogleMap.InfoWindowClickEventArgs e)
        {
            // Draw a circle on the map
            var circleOptions = new CircleOptions();

            circleOptions.InvokeCenter(Location_NewYork);
            circleOptions.InvokeRadius(100000.0);
            circleOptions.InvokeFillColor(Android.Graphics.Color.Argb(150, 59, 153, 212));
            circleOptions.InvokeStrokeColor(Android.Graphics.Color.Rgb(159, 153, 212));
            circleOptions.InvokeStrokeWidth(2);

            _map.AddCircle(circleOptions);

            // Draw a polygon (Wyoming) on the map
            var polygonOptions = new PolygonOptions();
            polygonOptions.Add(new LatLng[]
            {
                new LatLng(45.00, -111.00),
                new LatLng(45, -104),
                new LatLng(41, -104),
                new LatLng(41, -111)
            });

            polygonOptions.InvokeFillColor(Android.Graphics.Color.Argb(150, 21, 48,78));
            polygonOptions.InvokeStrokeColor(Android.Graphics.Color.Rgb(21, 48, 78));
            polygonOptions.InvokeStrokeWidth(2);
            _map.AddPolygon(polygonOptions);
        }
        /// <summary>
        /// Gets the polygon.
        /// </summary>
        /// <returns>The polygon.</returns>
        /// <param name="coordinates">Cordinates iterable.</param>
        /// <param name="fillColor">Fill color.</param>
        /// <param name="boundaryColor">Boundary color.</param>
        private static PolygonOptions GetPolygon(Java.Lang.IIterable coordinates, Android.Graphics.Color fillColor, Android.Graphics.Color boundaryColor)
        {
            var polygonOptions = new PolygonOptions();
            polygonOptions.InvokeFillColor(fillColor);
            polygonOptions.InvokeStrokeWidth(4);
            polygonOptions.InvokeStrokeColor(boundaryColor);
            polygonOptions.AddAll(coordinates);

            return polygonOptions;
        }
        /// <summary>
        /// Gets the polygon.
        /// </summary>
        /// <returns>The polygon.</returns>
        /// <param name="coordinates">Coordinates iterable.</param>
        /// <param name="color">Android Color.</param>
        private static PolygonOptions GetPolygon(Java.Lang.IIterable coordinates, Android.Graphics.Color color)
        {
            var polygonOptions = new PolygonOptions();
            polygonOptions.InvokeFillColor(color);
            polygonOptions.InvokeStrokeWidth(1);
            polygonOptions.InvokeStrokeColor(Color.Black.ToAndroid());
            polygonOptions.AddAll(coordinates);

            return polygonOptions;
        }
		/// <summary>
		/// Replaces the already visible zone or creates a new one.
		/// </summary>
		/// <param name="z">The z coordinate.</param>
		/// <param name="replace">The z coordinate.</param>
		void CreateZone (Zone z, Polygon replace = null)
		{
			IList<LatLng> points = new List<LatLng>(z.Points.Count);
			if (replace != null) {
				// Replace the points from the old polygon
				foreach (var zp in z.Points) {
					points.Add(new LatLng(zp.Latitude, zp.Longitude));
					replace.Points = points;
				}
			} else {
				// Create a new polygon for zone
				PolygonOptions po = new PolygonOptions ();
				foreach (var zp in z.Points) {
					po.Points.Add (new LatLng (zp.Latitude, zp.Longitude));
				}
				po.InvokeStrokeColor (Color.Argb (160, 255, 0, 0));
				po.InvokeStrokeWidth (2);
				po.InvokeFillColor (Color.Argb (80, 255, 0, 0));
				po.InvokeZIndex(1);

				// Add polygon to list of active zones
				zones.Add (z.ObjIndex, _map.AddPolygon (po));
			}
		}
        void AddPolygons (IList polygons)
        {
            var map = NativeMap;
            if (map == null)
                return;

            if (_polygons == null)
                _polygons = new List<APolygon> ();

            _polygons.AddRange (polygons.Cast<Polygon> ().Select (polygon => {
                var opts = new PolygonOptions ();

                foreach (var p in polygon.Positions)
                    opts.Add (new LatLng (p.Latitude, p.Longitude));

                opts.InvokeStrokeWidth(polygon.StrokeWidth * _scaledDensity); // TODO: convert from px to pt. Is this collect? (looks like same iOS Maps) 
                opts.InvokeStrokeColor(polygon.StrokeColor.ToAndroid());
                opts.InvokeFillColor(polygon.FillColor.ToAndroid());
                opts.Clickable (polygon.IsClickable);

                var nativePolygon = map.AddPolygon(opts);

                // associate pin with marker for later lookup in event handlers
                polygon.Id = nativePolygon;
                return nativePolygon;
            }));
        }
Example #9
0
		protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
		{
			base.OnElementPropertyChanged(sender, e);

			if (nativeMap == null)
			{
				return;
			}

			if (e.PropertyName == "MapOrientation")
			{
				UpdateMapOrientation();
			}

			if (e.PropertyName == "Polygons")
			{
				if (polygons != null)
				{
					foreach (var polygon in polygons)
					{
						polygon.Remove();
					}

					foreach (var polygonName in polygonNames)
					{
						polygonName.Remove();
					}

					polygons = null;
					polygonNames = null;
				}

				if (((ExtendedMap)Element).Polygons == null)
				{
					return;
				}

				polygons = new List<Polygon>();
				polygonNames = new List<Marker>();

				foreach (var z in ((ExtendedMap)Element).Polygons)
				{
					var polygonOptions = new Android.Gms.Maps.Model.PolygonOptions();

					polygonOptions.InvokeStrokeWidth(2f);
					polygonOptions.InvokeStrokeColor(Color.Red.MultiplyAlpha(0.7).ToAndroid());
					polygonOptions.InvokeFillColor(Color.Red.MultiplyAlpha(0.3).ToAndroid());

					foreach (var p in z.Points)
					{
						polygonOptions.Add(p.ToLatLng());
					}

					polygons.Add(nativeMap.AddPolygon(polygonOptions));

					var markerOptions = new MarkerOptions();

					markerOptions.SetPosition(z.Label.Point.ToLatLng());
					markerOptions.SetTitle(z.Label.Name);

					polygonNames.Add(nativeMap.AddMarker(markerOptions));
				}
			}

			if (e.PropertyName == "Points")
			{
			}
		}
Example #10
0
        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;
            }
        }