Skip to content

Commit

Permalink
fix icon not ready when marker added to map - android
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyron18 committed Feb 28, 2019
1 parent c071a80 commit d2fad38
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Android.Gms.Maps;
using Android.Gms.Maps.Model;
using Android.Gms.Maps.Model;
using Android.Runtime;
using System.Collections.Generic;
using TMapViews.Droid;
Expand All @@ -24,7 +23,7 @@ public override MarkerOptions GetMarkerOptionsForPin(IBindingMapAnnotation pin)

internal void GetMvxBindingMarker(Marker marker, IBindingMapAnnotation annotation)
{
var result = GetMvxBindingMarker();
MvxBindingMarker result = GetMvxBindingMarker();
result.Marker = marker;
result.DataContext = annotation;
}
Expand All @@ -38,8 +37,12 @@ public override void AddAnnotation(IBindingMapAnnotation annotation)
MarkerOptions markerOptions = GetMarkerOptionsForPin(annotation);
if (markerOptions != null)
{
MvxBindingMarker result = GetMvxBindingMarker();
result.DataContext = annotation;
markerOptions.SetIcon(result.GetIcon());
Marker marker = MapView.GoogleMap.AddMarker(markerOptions);
GetMvxBindingMarker(marker, annotation);
result.Marker = marker;
//GetMvxBindingMarker(marker, annotation);
marker.Tag = new AnnotationTag
{
Annotation = annotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,22 @@ public float IconScale
}

private void UpdateIcon()
{
var icon = GetIcon();
if (!(icon is null))
Marker.SetIcon(icon);
}

public BitmapDescriptor GetIcon()
{
if (Icon != null)
{
var bitmap = (Icon as BitmapDrawable).Bitmap;
var scaledBitmap = Bitmap.CreateScaledBitmap(bitmap, (int)Math.Round(bitmap.Width * IconScale), (int)Math.Round(bitmap.Height * IconScale), false);
Marker.SetIcon(BitmapDescriptorFactory.FromBitmap(scaledBitmap));
Bitmap bitmap = (Icon as BitmapDrawable).Bitmap;
Bitmap scaledBitmap = Bitmap.CreateScaledBitmap(bitmap, (int)Math.Round(bitmap.Width * IconScale), (int)Math.Round(bitmap.Height * IconScale), false);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.FromBitmap(scaledBitmap);
return bitmapDescriptor;
}
return null;
}
}
}

0 comments on commit d2fad38

Please sign in to comment.