Skip to content

Commit

Permalink
better bitmap managment
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyron18 committed Mar 7, 2019
1 parent 6266a5b commit c3792c2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
2 changes: 2 additions & 0 deletions TMapViews/TMapViews.Droid/Adapters/BindingMapAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public virtual void RemoveAnnotation(IBindingMapAnnotation item)
{
marker.Remove();
_markers.Remove(marker);
marker.Dispose();
marker = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ public override void AddAnnotation(IBindingMapAnnotation annotation)
{
if (annotation is IBindingMapAnnotation mMarker)
{
MarkerOptions markerOptions = GetMarkerOptionsForPin(annotation);
if (markerOptions != null)
{
MvxBindingMarker result = GetMvxBindingMarker();
result.DataContext = annotation;
markerOptions.SetIcon(result.GetIcon());
Marker marker = MapView.GoogleMap.AddMarker(markerOptions);
result.Marker = marker;
marker.Tag = new AnnotationTag
using (MarkerOptions markerOptions = GetMarkerOptionsForPin(annotation))
if (markerOptions != null)
{
Annotation = annotation
};
if (_markers == null)
_markers = new List<Marker>();
_markers.Add(marker);
}
MvxBindingMarker result = GetMvxBindingMarker();
result.DataContext = annotation;
markerOptions.SetIcon(result.GetIcon());
Marker marker = MapView.GoogleMap.AddMarker(markerOptions);
result.Marker = marker;
marker.Tag = new AnnotationTag
{
Annotation = annotation
};
if (_markers == null)
_markers = new List<Marker>();
_markers.Add(marker);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public Marker Marker
set
{
_marker = value;
_marker.SetAnchor(_anchor.X, _anchor.Y);
if(!(_anchor is null))
_marker.SetAnchor(_anchor.X, _anchor.Y);
}
}

Expand Down Expand Up @@ -61,25 +62,30 @@ public PointF Anchor
set
{
_anchor = value;
_marker?.SetAnchor(_anchor.X, _anchor.Y);
if(!(_anchor is null))
_marker?.SetAnchor(_anchor.X, _anchor.Y);
}
}

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

public BitmapDescriptor GetIcon()
{
if (Icon != null)
{
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;
using (Bitmap bitmap = (Icon as BitmapDrawable).Bitmap)
using (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;
}
Expand Down

0 comments on commit c3792c2

Please sign in to comment.