Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Some suggestions #1

@BladeMF

Description

@BladeMF

Hi dude. Nice of you to write and share a renderer. I used your code as a reference to create my own renderer (on WinRT 8.1) and have some suggestions:

  1. Instead of using those messy ZoomToDegrees functions, you can:
    1.1. Use TrySetViewBoundsAsync on VisibleRegion changed

`var nw = new BasicGeoposition() {
Latitude = a.Center.Latitude + a.LatitudeDegrees / 2,
Longitude = a.Center.Longitude - a.LongitudeDegrees / 2,
};
var se = new BasicGeoposition() {
Latitude = a.Center.Latitude - a.LatitudeDegrees / 2,
Longitude = a.Center.Longitude + a.LongitudeDegrees / 2
};

try {
_suspendUpdateVisibleRegion = true;
await this.Control.TrySetViewBoundsAsync(new GeoboundingBox(nw, se), null, MapAnimationKind.Bow);
} finally {
_suspendUpdateVisibleRegion = false;
}
this.UpdateVisibleRegion();`

1.2. Use GetLocationFromOffset on CenterChanged and ZoomLevelChanged

`Geopoint p1;
this.Control.GetLocationFromOffset(new Point(0, 0), out p1);
Geopoint p2;
this.Control.GetLocationFromOffset(new Point(this.Control.ActualWidth, this.Control.ActualHeight), out p2);

var span = new Xamarin.Forms.Maps.MapSpan(new Xamarin.Forms.Maps.Position(this.Control.Center.Position.Latitude, this.Control.Center.Position.Longitude), Math.Abs(p2.Position.Latitude - p1.Position.Latitude), Math.Abs(p2.Position.Longitude - p2.Position.Longitude));
_visibleRegionSetter(this.Element, span);`

  1. This PropertyInfo approach was really clever, but it would help if you created a delegate. It is much more performant:

private void EnsureVisibleRegionSetter() { if (_visibleRegionSetter == null) { foreach (PropertyInfo pi in typeof(Xamarin.Forms.Maps.Map).GetRuntimeProperties()) { if (pi.Name == "VisibleRegion") { _visibleRegionSetter = (Action<Xamarin.Forms.Maps.Map, Xamarin.Forms.Maps.MapSpan>)pi.SetMethod.CreateDelegate(typeof(Action<Xamarin.Forms.Maps.Map, Xamarin.Forms.Maps.MapSpan>)); break; } } } if(_visibleRegionSetter == null) { Debug.WriteLine("Error: Could not find VisibleRegion setter!"); } }

  1. It is probably better to wait for the LoadingStatusChanged event to fire before you check the LastMoveToRegion property and ignore all updates before that.

P.S. I am not sure why my code looks this bad here :( Couldn't fix it so, sorry.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions