Contents
Exercise outline
The goal of this exercise is to visualize multiple data sets on one single map; doing so, different data sets can be compared at the same geospatial position(s) and/or for the same modeling time step(s).
As an example, after this exercise it should be possible to show both the input data and the output data of a volume model in one and the same map view.
Create a new map layer provider
Add a new folder to the plugin project named Layers. In this folder, create a new class named VolumeModelLayerProvider.cs and add the following code:
using System.Collections.Generic; using DelftTools.Shell.Gui; using DeltaShell.Plugin.DemoApp.Models; using SharpMap.Api.Layers; using SharpMap.Layers; namespace DeltaShell.Plugin.DemoApp.Layers { public class VolumeModelMapLayerProvider : IMapLayerProvider { /// <summary> /// Defines that layers can be provided for volume models /// </summary> public bool CanCreateLayerFor(object data, object parentData) { return data is VolumeModel; } /// <summary> /// Creates a volume model group layer /// </summary> public ILayer CreateLayer(object data, object parentData) { var volumeModel = data as VolumeModel; if (volumeModel != null) { return new GroupLayer(volumeModel.Name); } return null; } /// <summary> /// Returns all children for which a child layer should be created in volume model group layers /// </summary> public IEnumerable<object> ChildLayerObjects(object data) { var volumeModel = data as VolumeModel; if (volumeModel != null) { // In the end a child layer should be created for both the catchment input data and the volume output data yield return volumeModel.Basin; yield return volumeModel.Volume; } } } }
The map layer provider class derives the IMapLayerProvider interface.........
Furthermore, the comments in the code should explain the different parts of the model implementation.
A description on the backgrounds and usage of (group) layers is not part of this tutorial.
[TODO] Add links to some wiki pages?
Fixme
Fixme
Exercise results
[TODO] Description of the exercise results
1. Create a new class named "DemoAppMapLayerProvider"
2. Add the following contents to this class:
using System.Collections.Generic; using System.Linq; using DelftTools.Shell.Gui; using DeltaShell.Plugin.DemoApp.Models; using SharpMap.Api.Layers; using SharpMap.Layers; namespace DeltaShell.Plugin.DemoApp { public class DemoAppMapLayerProvider : IMapLayerProvider { public ILayer CreateLayer(object data, object parentData) { var myModel = data as VolumeModel; if (myModel != null) { return new GroupLayer(myModel.Name); } return null; } public bool CanCreateLayerFor(object data, object parentData) { return data is VolumeModel; } public IEnumerable<object> ChildLayerObjects(object data) { var myModel = data as VolumeModel; if (myModel != null) { return myModel.DataItems.Select(d => d.Value); } return Enumerable.Empty<object>(); } } }
3. Register the map layer provider in the gui plugin class by adding the following code to DemoAppGuiPlugin:
public override IMapLayerProvider MapLayerProvider { get { return new DemoAppMapLayerProvider(); } }
4. Run the application and create a volume model: a dialog to select a view for the volume model will automatically be opened Image Select Central map