ThinkGeo.com    |     Documentation    |     Premium Support

ScaleLine issue 'NaN' is not a valid value for property 'X1'

Hi Team,

When I go to zoomlevel 1 I am facing issue with ScaleLine,

System.ArgumentException: 'NaN' is not a valid value for property 'X1'.
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at ThinkGeo.Core.ScaleLineMapTool.aUM=(RectangleShape extent)
   at ThinkGeo.Core.MapTools.Refresh()
   at ThinkGeo.Core.MapViewBase.<DrawAsyncCore>d__302.MoveNext()

ThinkGeo Version : 14.2.6

Could you please guide me.

Hi,

Can you check if MapView.MapUnit is set correctly? It will lead to this issue if it’s set to GeographyUnit.Unknown. We will add some null-check making sure it raises better exceptions in the future releases. Let me know if you still see the issue after this change.

Since v14.3.0, we enhanced the ScaleLine map tool to allow setting a projection for more precise calculations. I’d recommend to upgrade to the latest release if possible. Here is the changelog: Changelog - ThinkGeo Docs.

Thanks,
Ben

Hi Ben,

The issue persists even after configuring the MapUnit.
Could you please provide further assistance?

Thanks,
Jayshree

Hi Jayshree,

We couldn’t recreate the issue. Can you upgrade to the latest v14.3.1 and have another try? If it still has the issue, can you let me know more about your project, including:

  1. are you using custom mapScales, or what the scale when zoomLevel is 1?
    2, what’s the unit of the map?
    3, show us more code how the scaleline is initialized.

Thanks,
Ben

Hi Ben,

Thanks for the message.

Yes we do use custom scales. And they are as follow,
scale 1 => 590591790 scale 20=> 1126.46

Thanks,
Jayshree

Hi Jayshree,

We couldn’t recreate this issue. We used the following code to create a custom ZoomLevelSet using v14.2.6

 mapView.MapTools.ScaleLine.IsEnabled = true;

 var zoomLevelSet = new ZoomLevelSet();
 var scale = 590591790;
 for (int i = 0; i < 20; i++)
 {
     zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(scale));
     scale = scale / 2;
 }

 mapView.ZoomLevelSet = zoomLevelSet;

The ScaleLine shows fine without any exceptions. We did the similar thing using the latest version and it’s also good.

Can you send us a demo / code snippet recreating this issue?

Thanks,
Ben

Hi Ben,

I am still facing the issue even after updating to version 14.3.1.

If you look at the stack trace provided earlier, it points to the function below, which appears to be causing the issue. Code to check uEM_003D.X1 = num9; and ukM_003D.X1 = num10;

private void vkM_003D(RectangleShape extent)
{
    if (!(base.CurrentMap.MapWidth <= 0.0))
    {
        double num = ((Projection != null) ? v0M_003D(Projection, base.CurrentMap.MapWidth, base.CurrentMap.CurrentExtent) : (base.CurrentMap.MapUnit switch
        {
            GeographyUnit.DecimalDegree => v0M_003D(u0M_003D[4326], base.CurrentMap.MapWidth, base.CurrentMap.CurrentExtent),
            GeographyUnit.Feet => v0M_003D(u0M_003D[3857], base.CurrentMap.MapWidth, base.CurrentMap.CurrentExtent) / 3.28084,
            _ => v0M_003D(u0M_003D[3857], base.CurrentMap.MapWidth, base.CurrentMap.CurrentExtent),
        }));
        double num2 = 100.0 * num * MapUtil.GetInchesPerGeographyUnit(GeographyUnit.Meter);
        DistanceUnit targetUnit = DistanceUnit.Meter;
        DistanceUnit targetUnit2 = DistanceUnit.Feet;
        if (num2 > 100000.0)
        {
            targetUnit = DistanceUnit.Kilometer;
            targetUnit2 = DistanceUnit.Mile;
        }

        double num3 = num2 / MapUtil.GetInchesPerDistanceUnit(targetUnit);
        double num4 = num2 / MapUtil.GetInchesPerDistanceUnit(targetUnit2);
        int num5 = wEM_003D((int)num3);
        int num6 = wEM_003D((int)num4);
        double num7 = (double)num5 / MapUtil.GetInchesPerGeographyUnit(base.CurrentMap.MapUnit) * MapUtil.GetInchesPerDistanceUnit(targetUnit);
        double num8 = (double)num6 / MapUtil.GetInchesPerGeographyUnit(base.CurrentMap.MapUnit) * MapUtil.GetInchesPerDistanceUnit(targetUnit2);
        double num9 = num7 / num;
        double num10 = num8 / num;
        tUM_003D.Text = string.Format(CultureInfo.InvariantCulture, $"{num5} {MapUtil.GetShortUnitString(targetUnit)}");
        tkM_003D.Text = string.Format(CultureInfo.InvariantCulture, $"{num6} {MapUtil.GetShortUnitString(targetUnit2)}");
        uEM_003D.X1 = num9;
        uEM_003D.X2 = num9;
        uUM_003D.X2 = Math.Max(num9, num10);
        ukM_003D.X1 = num10;
        ukM_003D.X2 = num10;
    }
}

Hi Jayshree,

Yes, that X1 is a property of System.Windows.Shapes.Line, which we were using for the ScaleLine. But we have no clue why an NaN was passed over in ZoomLevel1, and still we cannot recreate it. Can you create a demo or send us the code snippet recreating this issue?

Thanks,
Ben

Hi Jayshree,

Still, we cannot recreate the issue. What’s the difference between your main map and the one with issues? When you say “background map,” are you referring to an underlying overlay? Could you share a code snippet showing how you initialize and configure the map?

Thanks,
Ben

Hi Ben,

On further investigation I found that,

Following details are getting Passed to private void aUM_003D(RectangleShape extent) in
ScaleLineMapTool.cs

base.CurrentMap.ActualWidthWidth = 506
base.CurrentMap.Extent {-4509728.87429452,5691456.35446475,5373757.87429452,-5129594.35446475}
ProjectionString => +proj=tmerc  +lat_0=49  +lon_0=-2  +k=0.9996012717  +x_0=400000  +y_0=-100000  +ellps=airy  +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489  +units=m  +no_defs
Srid = 27700

Possibly projection 27700 is causing issue, When we dont pass the projection it works.

Could you please help here?

Thanks,
Jayshree

Hi Jayshree,

I input the exact same values to the method but still couldn’t recreate it. Anyway you can you recreate it with in a small demo and send over to us?

Thanks,
Ben