// Copyright (C) Stichting Deltares 2025. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections; using System.Drawing; using Deltares.Dam.Data; using Deltares.Standard.Forms.DExpress; using Deltares.Standard.Forms.Maps; using Deltares.Standard.Logging; using Deltares.Standard.Maps; using DotSpatial.Projections; using DotSpatial.Symbology; using DotSpatial.Topology; namespace Deltares.Dam.Forms { public class DamMapEditor { private readonly MapEditor mapEditor; private readonly LocationJobSymbol symbol; private DamProjectData project; public DamMapEditor(MapEditor mapEditor, LocationJobSymbol symbol) { this.mapEditor = mapEditor; this.symbol = symbol; // uncomment this call to enable the button to open the OpenStreetMap background layer //mapEditor.EnableOpenStreetMapSupport(); mapEditor.RegisterLayer(typeof(LocationJob), new MapLayerDefinition(FeatureType.Point, "Locations", GetLocationScheme())); mapEditor.RegisterLayer(typeof(BackgroundRepositoryFeature), new MapLayerDefinition(FeatureType.Polygon, "Background", Color.LightGray, false)); } public DamProjectData Project { get { return project; } set { if (project != value) { project = value; mapEditor.Clear(); if (project.DataSourceEsriProjection != null) { // esri projection definition comes from the DataSourceEsriProjection attribute defined in the .defx file ProjectionInfo projectionInfo = ProjectionInfo.FromEsriString(project.DataSourceEsriProjection); if (Math.Abs(projectionInfo.Unit.Meters - 1.0d) > 0.001) { LogManager.Add(new LogMessage(LogMessageType.Warning, project, "The imported geographic data is using a Non-Metric coordinate system, this may lead to incorrect calculations in DAM !")); } MapProjectionManager.Instance.SetActiveMapProjectionAsDotSpatial(projectionInfo); mapEditor.MapControl.Projection = projectionInfo; mapEditor.StatusBarProjection = MapProjection.Custom; } mapEditor.AddLayer((IList) project.Dike.BackgroundRepositoryFeatures); mapEditor.AddLayer(project.LocationJobs); mapEditor.ZoomData(); mapEditor.MapControl.Refresh(); mapEditor.ShowWebLayer = true; // Following line commented out, because it is the default setting. // Kept here as placeholder when we want to change the default //this.mapEditor.WebLayerType = MapEditor.WebLayerTypes.OpenStreetMapnik; mapEditor.ShowSelectWebLayer = true; } } } private IFeatureScheme GetLocationScheme() { var scheme = new PointScheme(); var notCalculatedCategory = new PointCategory(symbol.GetImage(JobResultInterpreter.GetJobResultColor(JobResult.NoRun), false), 16); notCalculatedCategory.FilterExpression = string.Format("[Result] = {0}", (int) JobResult.NoRun); notCalculatedCategory.LegendText = "Not calculated"; LocalizationSupport.Register(GetType(), notCalculatedCategory); notCalculatedCategory.SelectionSymbolizer = new PointSymbolizer(symbol.GetImage(JobResultInterpreter.GetJobResultColor(JobResult.NoRun), true), 16); scheme.AddCategory(notCalculatedCategory); var failedCategory = new PointCategory(symbol.GetImage(JobResultInterpreter.GetJobResultColor(JobResult.Failed), false), 16); failedCategory.FilterExpression = string.Format("[Result] = {0}", (int) JobResult.Failed); failedCategory.LegendText = "Failed"; LocalizationSupport.Register(GetType(), failedCategory); failedCategory.SelectionSymbolizer = new PointSymbolizer(symbol.GetImage(JobResultInterpreter.GetJobResultColor(JobResult.Failed), true), 16); scheme.AddCategory(failedCategory); var goodCategory = new PointCategory(symbol.GetImage(JobResultInterpreter.GetJobResultColor(JobResult.Good), false), 16); goodCategory.FilterExpression = string.Format("[Result] = {0}", (int) JobResult.Good); goodCategory.LegendText = "Good"; LocalizationSupport.Register(GetType(), goodCategory); goodCategory.SelectionSymbolizer = new PointSymbolizer(symbol.GetImage(JobResultInterpreter.GetJobResultColor(JobResult.Good), true), 16); scheme.AddCategory(goodCategory); var badCategory = new PointCategory(symbol.GetImage(JobResultInterpreter.GetJobResultColor(JobResult.Bad), false), 16); badCategory.FilterExpression = string.Format("[Result] = {0}", (int) JobResult.Bad); badCategory.LegendText = "Bad"; LocalizationSupport.Register(GetType(), badCategory); badCategory.SelectionSymbolizer = new PointSymbolizer(symbol.GetImage(JobResultInterpreter.GetJobResultColor(JobResult.Bad), true), 16); scheme.AddCategory(badCategory); var percentages = new double[3]; percentages[0] = 33; percentages[1] = 34; percentages[2] = 33; var values = new double[3]; values[0] = 0.5; values[1] = 1.0; values[2] = 3.0; var mixedCategory = new PointCategory(symbol.GetPieImage(percentages, values, false), 16); mixedCategory.FilterExpression = string.Format("[Result] = {0}", (int) JobResult.Mixed); mixedCategory.LegendText = "Mixed"; LocalizationSupport.Register(GetType(), mixedCategory); mixedCategory.SelectionSymbolizer = new PointSymbolizer(symbol.GetPieImage(percentages, values, true), 16); scheme.AddCategory(mixedCategory); return scheme; } } }