// Copyright (C) Stichting Deltares 2021. 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.Generic; using System.Drawing; using System.Collections; using System.Windows.Forms; using Deltares.Dam.Data; using Deltares.Geographic; using Deltares.Standard.Forms.DExpress; using Deltares.Standard.Forms.Maps; using Deltares.Standard.Maps; using Deltares.Standard.Logging; using DotSpatial.Data; using DotSpatial.Projections; using DotSpatial.Symbology; using DotSpatial.Topology; namespace Deltares.Dam.Forms { public class DamMapEditor { private DamProjectData project = null; private MapEditor mapEditor = null; private LocationJobSymbol symbol = null; 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", this.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; this.mapEditor.Clear(); if (project.DataSourceEsriProjection != null) { // esri projection definition comes from the DataSourceEsriProjection attribute defined in the .defx file var 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); this.mapEditor.MapControl.Projection = projectionInfo; this.mapEditor.StatusBarProjection = MapProjection.Custom; } this.mapEditor.AddLayer((IList)project.WaterBoard.BackgroundRepositoryFeatures); this.mapEditor.AddLayer(project.LocationJobs); this.mapEditor.ZoomData(); this.mapEditor.MapControl.Refresh(); this.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; this.mapEditor.ShowSelectWebLayer = true; } } } private IFeatureScheme GetLocationScheme() { PointScheme scheme = new PointScheme(); PointCategory 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(this.GetType(), notCalculatedCategory); notCalculatedCategory.SelectionSymbolizer = new PointSymbolizer(symbol.GetImage(JobResultInterpreter.GetJobResultColor(JobResult.NoRun), true), 16); scheme.AddCategory(notCalculatedCategory); PointCategory 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(this.GetType(), failedCategory); failedCategory.SelectionSymbolizer = new PointSymbolizer(symbol.GetImage(JobResultInterpreter.GetJobResultColor(JobResult.Failed), true), 16); scheme.AddCategory(failedCategory); PointCategory 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(this.GetType(), goodCategory); goodCategory.SelectionSymbolizer = new PointSymbolizer(symbol.GetImage(JobResultInterpreter.GetJobResultColor(JobResult.Good), true), 16); scheme.AddCategory(goodCategory); PointCategory 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(this.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; PointCategory mixedCategory = new PointCategory(symbol.GetPieImage(percentages, values, false), 16); mixedCategory.FilterExpression = string.Format("[Result] = {0}", (int)JobResult.Mixed); mixedCategory.LegendText = "Mixed"; LocalizationSupport.Register(this.GetType(), mixedCategory); mixedCategory.SelectionSymbolizer = new PointSymbolizer(symbol.GetPieImage(percentages,values, true), 16); scheme.AddCategory(mixedCategory); return scheme; } } }