Xamarin.Forms.GoogleMaps
Xamarin.Forms.GoogleMaps copied to clipboard
Custom BitmapDescriptor caching not working when FromView used
VERSIONS
- Xamarin.Forms.GoogleMaps - 3.0.5
- Xamarin.Forms - 3.5.0.169
PLATFORMS
- [x] Android
- [ ] iOS
ACTUAL BEHAVIOR
Too low performance map.Add(pin) when used BitmapDescriptorFactory.FromView(on Samsung 8 for 95 pins ~14sec)
My workaround to not to use BitmapDescriptorFactory.FromView()
but use BitmapDescriptorFactory.FromStream(null, some_id)
. You hid Utils class so I was forced to copypaste that code to my project and in CachingNativeBitmapDescriptorFactory cache Created AndroidBitmapDescriptor's from view. In such way performance is very well.
public AndroidBitmapDescriptor ToNative(BitmapDescriptor descriptor)
{
if (!string.IsNullOrEmpty(descriptor.Id))
{
var discountText = descriptor.Id.Split("%");
var cacheEntry = _cache.GetOrAdd(descriptor.Id, _ => Convert(new PinView(discountText[0]+"%", discountText[1] == "1" ? true : false)));
return cacheEntry;
}
return DefaultBitmapDescriptorFactory.Instance.ToNative(descriptor);
}
private AndroidBitmapDescriptor Convert(Xamarin.Forms.View iconView)
{
var nativeView = Utils.ConvertFormsToNative(
iconView,
new Xamarin.Forms.Rectangle(0, 0, Utils.DpToPx((float)iconView.WidthRequest), Utils.DpToPx((float)iconView.HeightRequest)),
Xamarin.Forms.Platform.Android.Platform.CreateRendererWithContext(iconView, CrossCurrentActivity.Current.Activity));
var otherView = new FrameLayout(nativeView.Context);
nativeView.LayoutParameters = new FrameLayout.LayoutParams(Utils.DpToPx((float)iconView.WidthRequest), Utils.DpToPx((float)iconView.HeightRequest));
otherView.AddView(nativeView);
return Utils.ConvertViewToBitmapDescriptor(otherView);
}
hello jocontacter;
can u share the utils library ?
hello jocontacter;
can u share the utils library ?
check message attaches If you want some example - welcome
Hey @jocontacter could you please show me example of using the utils library?