ThinkGeo.com    |     Documentation    |     Premium Support

ScaleBarAdornmentLayer doesn't work

I managed to have my adornment layer with scale bar to be duplicated across the map after few map view resizes. Those adornments stay where they are (see picture) even though tiles underneath change when panning/zooming.

Adornment should be only on bottom right.
image

Resizing and moving window from monitor to another might also cause infamous “can’t read memory, this is indication that other memory is corrupt” or something along those lines.

-- From Mikko_Viitala

Hi Mikko,

I couldn’t recreate this issue, everything looks good to me. Here is my code:

    private void Map_Loaded(object sender, RoutedEventArgs e)
    {
        wpfMap1.MapUnit = GeographyUnit.Meter;

        OpenStreetMapOverlay baseOverlay = new OpenStreetMapOverlay(@"E:\worldstreets-11-11-2021.mbtiles");
        wpfMap1.CurrentExtent = new RectangleShape(-200000000, 200000000, 200000000, -200000000);
        wpfMap1.Overlays.Add(baseOverlay);

        ScaleLineAdornmentLayer layer = new ScaleLineAdornmentLayer();
        layer.Location = AdornmentLocation.LowerRight;
        wpfMap1.AdornmentOverlay.Layers.Add(layer);

        wpfMap1.Refresh();
    }

I’m using the latest beta ThinkGeo.UI.Wpf 377 under .NET Framework 4.8.

Thanks,
Ben

Hi @Ben

I played around with this, too. Below is the full code using .NET 4.8 and VS2017.

Everything was fine with Wpf 376 but after upgrading to 377 I either get that ^ behavior or alternatively the “corrupt memory” issue or everything just hangs (task manager says process is taking up to 25% of CPU and not responding).

And all this just by starting to debug the application and changing window size a few times. Resizing horizontally usually makes duplicate adornments while vertically resizing usually ends up with lock and/or corrupt memory.

XAML

 <Window x:Class="ThinkGeoWpfSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:uc1="clr-namespace:ThinkGeo.UI.Wpf;assembly=ThinkGeo.UI.Wpf"
        Title="MainWindow" Height="450" Width="800">
        <uc1:MapView
            x:Name="mapView"
            Loaded="mapView_Loaded"/>
</Window>

Code behind

using System.Windows;
using ThinkGeo.Core;

namespace ThinkGeoWpfSample
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void mapView_Loaded(object sender, RoutedEventArgs e)
        {
            mapView.MapUnit = GeographyUnit.Meter;
            var osmOverlay = new ThinkGeoCloudRasterMapsOverlay(
                @"clientId",
                @"clientSecret");
            osmOverlay.TileCache = new FileRasterTileCache(@"C:\Temp", "ThinkGeo");
            mapView.Overlays.Add(osmOverlay);

            var scale = new ScaleLineAdornmentLayer
            {
                UnitSystem = ScaleLineUnitSystem.ImperialAndMetric,
                Location = AdornmentLocation.LowerRight,
                XOffsetInPixel = -70f,
                YOffsetInPixel = -100f
            };
            scale.TextStyle.Font.Size = 10f;
            mapView.AdornmentOverlay.Layers.Add(scale);

            mapView.Refresh();
        }
    }
}

Here’s some screencaps, scalebar is shown four times at the end in both.

Hi Mikko,

Thanks for the detailed description. I’ve recreated the issue and fixed it in WPF Beta 379, please have another try.

Thanks,
Ben

1 Like

Works like a charm, thanks.

Awesome! We will put it into the release version 12.3.* later this week.