Search code examples
c#xamarin.formsarcgis-runtime-net

Display scale line - ArcGIS Runtime SDK - Xamarin.Forms


I am using the 1st release of the ArcGIS Runtime SDK for .Net - Xamarin.Forms (nuget package here).

One of my requirements is to display a basic scale line on the map. I haven't found any build-in feature for the moment. It seems to be tricky because each device has different size, different resolution... Any idea on how to implement this ?


Solution

  • OK after few hours, I found that the MapView component has a property UnitsPerPixel that do exactly what I needed:

    I've added a small grid (to represent the scale) with a fix width:

    <Grid  HeightRequest="10" WidthRequest="114" x:Name="Legend">
    ...
    </Grid>
    

    Then when the view point changes, I compute the distance representing by this grid:

    MapView.ViewpointChanged += (sender, args) =>
    {
        ScaleVal.Text = $"{Math.Round(Legend.Width * MapView.UnitsPerPixel, 0)}m";
    };
    

    ArcGIS .Net SDK - Xamarin.Forms - Scale Line

    Complete solution here.