简体   繁体   中英

How to add overlay color on the BitmapDescriptor for Android project in Xamarin Forms Maps

So, I implemented custom renderer for Android regarding XF Maps, everything is ok, and now I want to add overlay for my pin.

protected override MarkerOptions CreateMarker(Pin pin)
{
      CustomPin customPin = (CustomPin)pin;
      var marker = new MarkerOptions();
      marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
      marker.SetTitle(pin.Label);
      marker.SetSnippet(pin.Address);
      marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pin));
           
      return marker;
}

How to add an overlay color on pin image? for example Color.FromHex("#34ee16")

There is currently no way to set the pin color in Xamarin.Forms.Maps.But you could do like below to change the color of your custom pin.

protected override MarkerOptions CreateMarker(Pin pin)
 {
    CustomPin customPin = (CustomPin)pin;
    var marker = new MarkerOptions();
    marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
    marker.SetTitle(pin.Label);
    marker.SetSnippet(pin.Address);
    Color color = Color.FromHex("#34ee16");
    float hue = color.ToAndroid().GetHue() % 360.0f;
    marker.SetIcon(BitmapDescriptorFactory.DefaultMarker(hue));      
    return marker;
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM