Skip to content

Instantly share code, notes, and snippets.

@juucustodio
Created October 11, 2017 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juucustodio/34cea36fc2cac14319dd08de85a72393 to your computer and use it in GitHub Desktop.
Save juucustodio/34cea36fc2cac14319dd08de85a72393 to your computer and use it in GitHub Desktop.
Exemplo de como destacar uma região específica no mapa com Xamarin.Forms http://julianocustodio.com/regioes-maps-xamarin-forms
using System.Collections.Generic;
using Android.Views;
using App.Droid;
using App;
using Xamarin.Forms;
using Xamarin.Forms.Maps.Android;
using Xamarin.Forms.Maps;
using Android.Gms.Maps.Model;
[assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
namespace App.Droid
{
public class CustomMapRenderer : MapRenderer
{
List<Position> shapeCoordinates;
bool isDrawn;
protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Map> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
// Unsubscribe
}
if (e.NewElement != null)
{
var formsMap = (CustomMap)e.NewElement;
shapeCoordinates = formsMap.ShapeCoordinates;
Control.GetMapAsync(this);
}
}
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName.Equals("VisibleRegion") && !isDrawn)
{
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));
}
NativeMap.AddPolygon(polygonOptions);
isDrawn = true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment