ThinkGeo.com    |     Documentation    |     Premium Support

Scale line adornment showing wrong distance

Hey,

While ago I implemented distance measuring tool for our map application, using MapView’s interactive overlay. First I thought there’s something wrong with my implementation since it didn’t show the same length as scale line adornment.

But now, looking more to it I think there’s something wrong with the scale line or maybe something that I’m missing? Here’s the (simplified) code I use to create the scale line.

var scale = new ScaleLineAdornmentLayer()
{
    Name = @"scale",
    UnitSystem = ScaleLineUnitSystem.ImperialAndMetric,
    Location = AdornmentLocation.LowerRight,
    XOffsetInPixel = -54f,
    YOffsetInPixel = -106f
};
scale.TextStyle.Font.Size = 10Le;

First, I checked how random distance looks like in Google Maps

Then I measured the same distance in our application. Background is coming from WMS service in EPSG:3067. Distance looks fine to me.

When I switch over to ThinkGeo Cloud maps (light theme), EPSG:3857, things got weird.

Clearly actual distance and scale line are off. Adornments are cleared, recreated and re-added to MapView when background map is changed.

Thanks.

Hi Mikko,

Thanks for your detailed description.

This problem was caused by lack of Projection. We need to set Projection for ScaleLineAdornmentLayer to get it working accurately.

Just ignore the Layer.Projection.set obsolete warning, we already removed it.

        var scale = new ScaleLineAdornmentLayer()
        {
            Name = @"scale",
            UnitSystem = ScaleLineUnitSystem.ImperialAndMetric,
            Location = AdornmentLocation.LowerRight,
            Projection = new Projection(Projection.GetSphericalMercatorProjString()),
            XOffsetInPixel = -54f,
            YOffsetInPixel = -106f
        };

Thanks,
Leo

1 Like