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);
		}
        private void PositionPolarBearGroundOverlay(LatLng position)
        {
            if (_polarBearOverlay == null)
            {
                BitmapDescriptor image = BitmapDescriptorFactory.FromResource(Resource.Drawable.polarbear);
                GroundOverlayOptions groundOverlayOptions = new GroundOverlayOptions()
                    .Position(position, 150, 200)
                    .InvokeImage(image);
                _polarBearOverlay = _map.AddGroundOverlay(groundOverlayOptions);

                PolygonOptions rectOptions = new PolygonOptions();

                rectOptions.Add(position);
                rectOptions.Add(new LatLng(37.45, -122.0));
                rectOptions.Add(new LatLng(37.45, -122.2));
                rectOptions.Add(new LatLng(37.35, -122.2));
                // notice we don't need to close off the polygon
                _map.AddPolygon(rectOptions);
            }
            else
            {
                _polarBearOverlay.Position = InMaui;
            }
        }
		private void HandleInfoWindowClick(object sender, GoogleMap.InfoWindowClickEventArgs e)
		{
			// Draw a circle on the map
		    CircleOptions circleOptions = new CircleOptions();
		    circleOptions.InvokeCenter(Location_NewYork);
		    circleOptions.InvokeRadius(100000.0);
		    circleOptions.InvokeFillColor(Android.Graphics.Color.White);
		    _map.AddCircle(circleOptions);

			// Draw a polygon (Wyoming) on the map
		    PolygonOptions 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.Purple);
		    polygonOptions.InvokeStrokeWidth(2);
		    _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));
        }
		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);
				}
			};


		}
        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;
            }));
        }
		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")
			{
			}
		}
Beispiel #8
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;
            }
        }