ThinkGeo.com    |     Documentation    |     Premium Support

V12.1 - Map object initialization

Hello,

in our project we are using maps that have a very common base layer structure, meaning there is always the same background layer and there are always the same basic foreground layers which are then supplemented by the layers required for the indivdual use case.

In MapSuite 9 I’ve achieved this by inheriting your map object and initializing all the standard layers in the constructor. Afterwards I only had to add the inidividual layers for the use case and saved a lot of time.

When I try this inheritance model in V12 I’m - for instance - greeted by an NullReference exception when I try to add an overlay in the constructor. It seems that the Overlays collection is not initialized at this time.

The only way I could achieve a similar behaviour was by subscribing to the Loaded event in my own child object and setting up all the standard stuff there. But as the control ist already rendered at this time this means that there is a new rendering process required which I would like to avoid.
Is there any way around this?

Thank you.

Peter

Thanks Peter,
We are looking into it. See if we could have the overlay/layer loaded without start the rendering process.

Thanks

Frank

Thanks Peter,
As talked with the development team. Looking into more detail. For the mapview object we have to add it to some WPF control. Basically this is the same as you mentioned.

        FirstMap = new MapView();
        mainGrid.Children.Add(FirstMap);
        FirstMap.Loaded += FirstMap_Loaded;

    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()); 
    }

But if you want to do something in memory instead present the UI. You could use the Layer object. Even do some image process.

For example. The following code you could load the shape file and render it in memory without create a map object.

  GeoImage bitmap = new GeoImage(1024, 512);
            GdalFeatureLayer layer = new GdalFeatureLayer(@"TestData\Shapefile\Countries02.shp");
            layer.EnableEmbeddedStyle = false;
            layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyle.CreateSimpleLineStyle(GeoColor.FromArgb(255, 169, 195, 221), 2F, GeoColors.Black, 4F, false);
            layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 233, 232, 214), GeoColor.FromArgb(255, 156, 155, 154), 1);
            layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            layer.Open();
            RectangleShape extent = layer.GetBoundingBox();

            GeoCanvas canvas = GeoCanvas.CreateDefaultGeoCanvas();
            canvas.BeginDrawing(bitmap, extent, GeographyUnit.DecimalDegree);
            layer.Draw(canvas, new Collection<SimpleCandidate>());
            canvas.EndDrawing();
            var executingFolderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            bitmap.Save($@"{executingFolderPath}\ShapeFileTest.png");

Thanks

Frank

Hello Frank,

thank you for your answer and your inquiry.
I went the way you mentioned and it works. I just have to monitor the performance.

Peter

Thanks Peter,
Good to know it works. Go ahead let us know if you have any more questions.

Thanks

Frank