ThinkGeo.com    |     Documentation    |     Premium Support

V12 NullReferenceException when adding to MapView

Hello, I have some code that seemed to work prior to the upgrade to V12 involving MapView.

I am attempting to add an Overlay like this:

FirstMap = new MapView();
FirstMap.Overlays?.Add(new LayerOverlay()); // Crash here

I am getting a NullReferenceException everytime I try to .add to this list, I crash out with this exception:

crash

Is there something else I need to do now before adding to the Overlays list?

Thanks,
Matt

Matt,
If you use the wpf mapview programmatically. You need add the map the the wpf container.

        FirstMap = new MapView();
        mainGrid.Children.Add(FirstMap); // Add the map to the wpf container. MainGrid is a wpf grid
        FirstMap.Loaded += FirstMap_Loaded;

After map loaded you could add your overlays.

private void FirstMap_Loaded(object sender, RoutedEventArgs e)
        {
            FirstMap.MapUnit = GeographyUnit.Meter;
            FirstMap.CurrentExtent = new RectangleShape(-10000000, 10000000, 10000000, -10000000); ;
            FirstMap.Overlays?.Add(new LayerOverlay());
        }

Thanks

Frank