2017-06-25 23:05:48 +02:00
using MapControl ;
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
2017-09-05 23:35:12 +02:00
#if WINDOWS_UWP
2017-06-25 23:05:48 +02:00
using Windows.UI ;
using Windows.UI.Xaml ;
using Windows.UI.Xaml.Media ;
#else
using System.Windows ;
using System.Windows.Media ;
#endif
namespace ViewModel
{
public class MapLayers : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged ;
private readonly Dictionary < string , UIElement > mapLayers = new Dictionary < string , UIElement >
{
{
"OpenStreetMap" ,
MapTileLayer . OpenStreetMapTileLayer
} ,
2018-08-14 23:13:58 +02:00
{
"OpenStreetMap Files" ,
new MapTileLayer
{
SourceName = "OpenStreetMap Files" ,
Description = "© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)" ,
#if WINDOWS_UWP
TileSource = new TileSource { UriFormat = @"C:\Users\Clemens\AppData\Local\Packages\XamlMapControl.UniversalApp_2kan67jdewwkc\TempState\OpenStreetMap\{z}\{x}\{y}.png" } ,
#else
TileSource = new TileSource { UriFormat = @"C:\ProgramData\MapControl\TileCache\OpenStreetMap\{z}\{x}\{y}.png" } ,
#endif
MaxZoomLevel = 19
}
} ,
2017-06-25 23:05:48 +02:00
{
2017-10-07 17:43:28 +02:00
"OpenStreetMap German" ,
2017-06-25 23:05:48 +02:00
new MapTileLayer
{
SourceName = "OpenStreetMap German" ,
2017-10-07 17:43:28 +02:00
Description = "© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)" ,
2017-07-17 21:31:09 +02:00
TileSource = new TileSource { UriFormat = "http://{c}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png" } ,
MaxZoomLevel = 19
2017-06-25 23:05:48 +02:00
}
} ,
{
2017-10-07 17:43:28 +02:00
"Stamen Terrain" ,
2017-06-25 23:05:48 +02:00
new MapTileLayer
{
2017-10-07 17:43:28 +02:00
SourceName = "Stamen Terrain" ,
2017-10-08 17:35:07 +02:00
Description = "Map tiles by [Stamen Design](http://stamen.com/), under [CC BY 3.0](http://creativecommons.org/licenses/by/3.0)\nData by [OpenStreetMap](http://openstreetmap.org/), under [ODbL](http://www.openstreetmap.org/copyright)" ,
2017-10-07 17:43:28 +02:00
TileSource = new TileSource { UriFormat = "http://tile.stamen.com/terrain/{z}/{x}/{y}.png" } ,
MaxZoomLevel = 17
2017-06-25 23:05:48 +02:00
}
} ,
{
2017-10-07 17:43:28 +02:00
"Stamen Toner Light" ,
2017-06-25 23:05:48 +02:00
new MapTileLayer
{
2017-10-07 17:43:28 +02:00
SourceName = "Stamen Toner Light" ,
2017-10-08 17:35:07 +02:00
Description = "Map tiles by [Stamen Design](http://stamen.com/), under [CC BY 3.0](http://creativecommons.org/licenses/by/3.0)\nData by [OpenStreetMap](http://openstreetmap.org/), under [ODbL](http://www.openstreetmap.org/copyright)" ,
2017-10-07 17:43:28 +02:00
TileSource = new TileSource { UriFormat = "http://tile.stamen.com/toner-lite/{z}/{x}/{y}.png" } ,
MaxZoomLevel = 18
2017-06-25 23:05:48 +02:00
}
} ,
{
"Seamarks" ,
new MapTileLayer
{
SourceName = "OpenSeaMap" ,
TileSource = new TileSource { UriFormat = "http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png" } ,
MinZoomLevel = 9 ,
MaxZoomLevel = 18
}
} ,
{
"Bing Maps Road" ,
new BingMapsTileLayer
{
SourceName = "Bing Maps Road" ,
2017-10-08 17:35:07 +02:00
Description = "© [Microsoft](http://www.bing.com/maps/)" ,
Mode = BingMapsTileLayer . MapMode . Road
2017-06-25 23:05:48 +02:00
}
} ,
{
"Bing Maps Aerial" ,
new BingMapsTileLayer
{
SourceName = "Bing Maps Aerial" ,
2017-10-08 17:35:07 +02:00
Description = "© [Microsoft](http://www.bing.com/maps/)" ,
2017-06-25 23:05:48 +02:00
Mode = BingMapsTileLayer . MapMode . Aerial ,
MapForeground = new SolidColorBrush ( Colors . White ) ,
MapBackground = new SolidColorBrush ( Colors . Black )
}
} ,
{
"Bing Maps Aerial with Labels" ,
new BingMapsTileLayer
{
SourceName = "Bing Maps Hybrid" ,
2017-10-08 17:35:07 +02:00
Description = "© [Microsoft](http://www.bing.com/maps/)" ,
2017-06-25 23:05:48 +02:00
Mode = BingMapsTileLayer . MapMode . AerialWithLabels ,
MapForeground = new SolidColorBrush ( Colors . White ) ,
MapBackground = new SolidColorBrush ( Colors . Black )
}
} ,
{
"OpenStreetMap WMS" ,
new WmsImageLayer
{
2017-10-08 17:35:07 +02:00
Description = "© [terrestris GmbH & Co. KG](http://ows.terrestris.de/)\nData © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)" ,
2018-06-11 21:37:36 +02:00
ServiceUri = new Uri ( "http://ows.terrestris.de/osm/service" ) ,
Layers = "OSM-WMS"
2017-06-25 23:05:48 +02:00
}
} ,
{
"OpenStreetMap TOPO WMS" ,
new WmsImageLayer
{
2017-10-08 17:35:07 +02:00
Description = "© [terrestris GmbH & Co. KG](http://ows.terrestris.de/)\nData © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)" ,
2018-06-11 21:37:36 +02:00
ServiceUri = new Uri ( "http://ows.terrestris.de/osm/service" ) ,
Layers = "TOPO-OSM-WMS"
2017-10-08 17:35:07 +02:00
}
} ,
{
"SevenCs ChartServer" ,
new WmsImageLayer
{
Description = "© [SevenCs GmbH](http://www.sevencs.com)" ,
2018-06-11 21:37:36 +02:00
ServiceUri = new Uri ( "http://chartserver4.sevencs.com:8080" ) ,
2018-08-14 23:13:58 +02:00
Layers = "ENC"
2017-06-25 23:05:48 +02:00
}
2018-08-14 23:13:58 +02:00
} ,
{
"ECDIS DAY_BRIGHT" ,
new WmsImageLayer
{
Description = "ECDIS WMS DAY_BRIGHT" ,
ServiceUri = new Uri ( "http://as113121:8080/ECDIS?LAYERS=ENC&LIGHTS=TRUE&COLOR=0&DETAILS=2" )
}
} ,
{
"ECDIS DAY_WHITEBACK" ,
new WmsImageLayer
{
Description = "ECDIS WMS DAY_WHITEBACK" ,
ServiceUri = new Uri ( "http://as113121:8080/ECDIS?LAYERS=ENC&LIGHTS=TRUE&COLOR=1&DETAILS=2" )
}
} ,
{
"ECDIS DAY_BLACKBACK" ,
new WmsImageLayer
{
Description = "ECDIS WMS DAY_BLACKBACK" ,
ServiceUri = new Uri ( "http://as113121:8080/ECDIS?LAYERS=ENC&LIGHTS=TRUE&COLOR=2&DETAILS=2" ) ,
MapForeground = new SolidColorBrush ( Colors . White )
}
} ,
{
"ECDIS DUSK" ,
new WmsImageLayer
{
Description = "ECDIS WMS DUSK" ,
ServiceUri = new Uri ( "http://as113121:8080/ECDIS?LAYERS=ENC&LIGHTS=TRUE&COLOR=3&DETAILS=2" ) ,
MapForeground = new SolidColorBrush ( Colors . Gray ) ,
MapBackground = new SolidColorBrush ( Colors . Black )
}
} ,
{
"ECDIS NIGHT" ,
new WmsImageLayer
{
Description = "ECDIS WMS NIGHT" ,
ServiceUri = new Uri ( "http://as113121:8080/ECDIS?LAYERS=ENC&LIGHTS=TRUE&COLOR=4&DETAILS=2" ) ,
MapForeground = new SolidColorBrush ( Colors . Gray ) ,
MapBackground = new SolidColorBrush ( Colors . Black )
}
} ,
2017-06-25 23:05:48 +02:00
} ;
private string currentMapLayerName = "OpenStreetMap" ;
public string CurrentMapLayerName
{
get { return currentMapLayerName ; }
set
{
currentMapLayerName = value ;
PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( nameof ( CurrentMapLayerName ) ) ) ;
PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( nameof ( CurrentMapLayer ) ) ) ;
}
}
public UIElement CurrentMapLayer
{
get { return mapLayers [ currentMapLayerName ] ; }
}
public UIElement SeamarksLayer
{
get { return mapLayers [ "Seamarks" ] ; }
}
public List < string > MapLayerNames { get ; } = new List < string >
{
"OpenStreetMap" ,
2018-08-14 23:13:58 +02:00
"OpenStreetMap Files" ,
2017-10-07 17:43:28 +02:00
"OpenStreetMap German" ,
"Stamen Terrain" ,
"Stamen Toner Light" ,
2017-06-25 23:05:48 +02:00
"OpenStreetMap WMS" ,
2017-10-08 17:35:07 +02:00
"OpenStreetMap TOPO WMS" ,
2018-08-14 23:13:58 +02:00
"SevenCs ChartServer" ,
"ECDIS DAY_BRIGHT" ,
"ECDIS DAY_WHITEBACK" ,
"ECDIS DAY_BLACKBACK" ,
"ECDIS DUSK" ,
"ECDIS NIGHT" ,
2017-06-25 23:05:48 +02:00
} ;
public MapLayers ( )
{
2018-08-14 23:13:58 +02:00
BingMapsTileLayer . ApiKey = "" ;
2017-06-25 23:05:48 +02:00
// Bing Maps TileLayers with tile URLs retrieved from the Imagery Metadata Service
// (see http://msdn.microsoft.com/en-us/library/ff701716.aspx).
// A Bing Maps API Key (see http://msdn.microsoft.com/en-us/library/ff428642.aspx) is required
// for using these layers and must be assigned to the static BingMapsTileLayer.ApiKey property.
2017-10-08 17:35:07 +02:00
if ( ! string . IsNullOrEmpty ( BingMapsTileLayer . ApiKey ) )
{
MapLayerNames . Add ( "Bing Maps Road" ) ;
MapLayerNames . Add ( "Bing Maps Aerial" ) ;
MapLayerNames . Add ( "Bing Maps Aerial with Labels" ) ;
}
2018-08-14 23:13:58 +02:00
//var t = new System.Windows.Threading.DispatcherTimer { Interval = TimeSpan.FromSeconds(1) };
//t.Tick += async (s, e) =>
//{
// var layers = await ((WmsImageLayer)mapLayers["OpenStreetMap WMS"]).GetLayerNamesAsync();
// System.Diagnostics.Debug.WriteLine(string.Join(", ", layers));
// t.Stop();
//};
//t.Start();
2017-06-25 23:05:48 +02:00
}
}
}