...
Add to the plugin project a new folder named Layers. In this folder, create a new class named DrainageBasinFeatureCollection.cs and adapt the contents as shown below:
Code Block | ||
---|---|---|
| ||
using System.Collections; using System.ComponentModel; using DeltaShell.Plugins.VolumeModel.Models; using NetTopologySuite.Extensions.Features; using SharpMap.Data.Providers; namespace DeltaShell.Plugins.VolumeModel.Layers { /// <summary> /// Defines a feature collection (used by layers for rendering) for a DrainageBasin /// </summary> public class DrainageBasinFeatureCollection : FeatureCollection { private readonly DrainageBasin drainageBasin; public DrainageBasinFeatureCollection(DrainageBasin drainageBasin) : base((IList)drainageBasin.Catchments, typeof(Feature)) { this.drainageBasin = drainageBasin; // copy coordinatesystem and for monitor changes of the coordinatesystem CoordinateSystem = (GeoAPI.Extensions.CoordinateSystems.ICoordinateSystem) drainageBasin.CoordinateSystem; drainageBasin.PropertyChanged += DrainageBasinPropertyChanged; } private void DrainageBasinPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "CoordinateSystem") { CoordinateSystem = (GeoAPI.Extensions.CoordinateSystems.ICoordinateSystem) drainageBasin.CoordinateSystem; } } public override void Dispose() { // Desubscribe from drainageBasin so this DrainageBasinFeatureCollection can be disposed drainageBasin.PropertyChanged -= DrainageBasinPropertyChanged; base.Dispose(); } } } |
...
Then create a new class VolumeModelLayerProvider.cs in the same folder
Code Block | ||
---|---|---|
| ||
using System.Collections.Generic; using DelftTools.Shell.Gui; using DeltaShell.Plugins.VolumeModel.Models; using SharpMap.Api.Layers; using SharpMap.Layers; namespace DeltaShell.Plugins.VolumeModel.Layers { public class VolumeModelMapLayerProvider : IMapLayerProvider { /// <summary> /// Defines that layers can be provided for volume models and DrainageBasins /// </summary> public bool CanCreateLayerFor(object data, object parentData) { return data is Models.VolumeModel || data is DrainageBasin; } /// <summary> /// Creates a volume model group layer and DrainageBasin layer /// </summary> public ILayer CreateLayer(object data, object parentData) { var volumeModel = data as Models.VolumeModel; if (volumeModel != null) { return new GroupLayer(volumeModel.Name); } var drainageBasin = data as DrainageBasin; if (drainageBasin != null) { return new VectorLayer("Drainage basin") { DataSource = new DrainageBasinFeatureCollection(drainageBasin) }; } 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 Models.VolumeModel; if (volumeModel != null) { // In the end a child layer should be created for both the basin input data and the volume output data yield return volumeModel.Basin; yield return volumeModel.Volume; } } } } |
...
Register the map layer provider in the gui plugin by adding the following code to VolumeModelGuiPlugin.cs:
Code Block | ||
---|---|---|
| ||
using DeltaShell.Plugins.VolumeModel.Layers; |
and
Code Block | ||
---|---|---|
| ||
public override IMapLayerProvider MapLayerProvider { get { return new VolumeModelMapLayerProvider(); } } |
...