// Copyright (C) Stichting Deltares 2016. All rights preserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser 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 preserved.
using System;
using System.IO;
using System.Windows.Forms;
using Core.Components.DotSpatial.Data;
using Core.Components.DotSpatial.Exceptions;
using Core.Components.DotSpatial.Properties;
using DotSpatial.Controls;
using log4net;
namespace Core.Components.DotSpatial
{
///
/// The map view
///
public sealed class BaseMap : Control
{
private static readonly ILog Log = LogManager.GetLogger(typeof(BaseMap));
private MapData data;
private Map map;
///
/// Creates a new instance of
///
public BaseMap()
{
InitializeMapView();
}
///
/// Gets and sets the . When is not empty it will load the data on the map.
///
/// Thrown when is null.
/// Thrown when does not exist.
/// Thrown when the data in is not valid.
public void SetMapData(MapData mapData)
{
if (IsDisposed)
{
return;
}
if (mapData == null)
{
throw new ArgumentNullException("mapData", "MapData is required when adding shapeFiles");
}
if (mapData.IsValid())
{
data = mapData;
LoadData();
}
else
{
throw new MapDataException(Resources.BaseMap_SetMapData_The_data_available_in_MapData_is_not_valid_);
}
}
///
/// Initialize the for the
///
private void InitializeMapView()
{
map = new Map
{
Dock = DockStyle.Fill,
FunctionMode = FunctionMode.Pan,
};
Controls.Add(map);
}
///
/// Loads the data from the files given in and shows them on the .
///
private void LoadData()
{
foreach (string filePath in data.FilePaths)
{
map.AddLayer(filePath);
Log.InfoFormat(Resources.BaseMap_LoadData_Shape_file_on_path__0__is_added_to_the_map_, filePath);
}
}
}
}