mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
Updated MapsforgeTileSource
This commit is contained in:
parent
f367faa209
commit
8130f8ea9c
3 changed files with 51 additions and 47 deletions
|
|
@ -3,7 +3,7 @@
|
|||
<Product>XAML Map Control</Product>
|
||||
<Authors>Clemens Fischer</Authors>
|
||||
<Copyright>Copyright © 2026 Clemens Fischer</Copyright>
|
||||
<Version>16.1.0</Version>
|
||||
<Version>16.2.0</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
|
|
|
|||
|
|
@ -12,19 +12,18 @@ Map files can be downloaded from the [Mapsforge Download Server](https://downloa
|
|||
`MapsforgeTileSource` is initialized by a static `LoadMaps` method that takes the file path to either a single map file
|
||||
or a directory containing multiple map files.
|
||||
|
||||
The `MapsforgeTileSource` instance constructor takes a string parameter that specifies a Mapsforge theme. This is either
|
||||
the full path of an XML `rendertheme` file, or the name of one of the built-in themes (ignoring case), e.g. `Default`.
|
||||
The class has a `Theme` property that specifies a Mapsforge theme. This is either the path of an XML `rendertheme` file,
|
||||
the path of a ZIP file containing a render theme, or the name of one of the built-in themes (ignoring case), e.g. `Default`.
|
||||
See [MapsforgeThemes.java](https://github.com/mapsforge/mapsforge/blob/master/mapsforge-themes/src/main/java/org/mapsforge/map/rendertheme/internal/MapsforgeThemes.java)
|
||||
for available theme names. An additional constructor parameters specifies the size of the tile source's internal cache.
|
||||
for available theme names.
|
||||
|
||||
Code sample:
|
||||
```
|
||||
MapControl.MapsforgeTiles.MapsforgeTileSource.LoadMaps(".\mapfiles");
|
||||
|
||||
map.MapLayer = new MapTileLayer
|
||||
{
|
||||
TileSource = new MapControl.MapsforgeTiles.MapsforgeTileSource("Default")
|
||||
};
|
||||
var tileSource = new MapControl.MapsforgeTiles.MapsforgeTileSource { Theme = "Default" };
|
||||
|
||||
map.MapLayer = new MapTileLayer { TileSource = tileSource };
|
||||
```
|
||||
|
||||
---
|
||||
|
|
|
|||
|
|
@ -83,45 +83,7 @@ namespace MapControl.MapsforgeTiles
|
|||
{
|
||||
if (renderThemeFuture == null)
|
||||
{
|
||||
lock (displayModel)
|
||||
{
|
||||
if (renderThemeFuture == null)
|
||||
{
|
||||
if (mapDataStore == null)
|
||||
{
|
||||
throw new InvalidOperationException("No map files loaded.");
|
||||
}
|
||||
|
||||
Logger?.LogInformation("Loading render theme \"{theme}\".", Theme);
|
||||
|
||||
ZipInputStream zipInputStream = null;
|
||||
XmlRenderTheme renderTheme;
|
||||
|
||||
if (Theme.EndsWith(".zip"))
|
||||
{
|
||||
zipInputStream = new ZipInputStream(new FileInputStream(Theme));
|
||||
renderTheme = new ZipRenderTheme(
|
||||
Path.GetFileName(Theme).Replace(".zip", ".xml"),
|
||||
new ZipXmlThemeResourceProvider(zipInputStream));
|
||||
}
|
||||
else if (Theme.EndsWith(".xml"))
|
||||
{
|
||||
renderTheme = new ExternalRenderTheme(Theme);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderTheme = MapsforgeThemes.valueOf(Theme.ToUpper());
|
||||
}
|
||||
|
||||
tileCache = new InMemoryTileCache(CacheCapacity);
|
||||
renderer = new DatabaseRenderer(mapDataStore, AwtGraphicFactory.INSTANCE, tileCache, null, true, false, null);
|
||||
renderThemeFuture = new RenderThemeFuture(AwtGraphicFactory.INSTANCE, renderTheme, displayModel);
|
||||
renderThemeFuture.run();
|
||||
zipInputStream?.close();
|
||||
|
||||
Logger?.LogInformation("Loading render theme done.");
|
||||
}
|
||||
}
|
||||
Initialize();
|
||||
}
|
||||
|
||||
int[] imageBuffer = null;
|
||||
|
|
@ -141,5 +103,48 @@ namespace MapControl.MapsforgeTiles
|
|||
|
||||
return imageBuffer;
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
lock (displayModel)
|
||||
{
|
||||
if (renderThemeFuture == null)
|
||||
{
|
||||
if (mapDataStore == null)
|
||||
{
|
||||
throw new InvalidOperationException("No map files loaded.");
|
||||
}
|
||||
|
||||
Logger?.LogInformation("Loading render theme \"{theme}\".", Theme);
|
||||
|
||||
ZipInputStream zipInputStream = null;
|
||||
XmlRenderTheme renderTheme;
|
||||
|
||||
if (Theme.EndsWith(".zip"))
|
||||
{
|
||||
zipInputStream = new ZipInputStream(new FileInputStream(Theme));
|
||||
renderTheme = new ZipRenderTheme(
|
||||
Path.GetFileName(Theme).Replace(".zip", ".xml"),
|
||||
new ZipXmlThemeResourceProvider(zipInputStream));
|
||||
}
|
||||
else if (Theme.EndsWith(".xml"))
|
||||
{
|
||||
renderTheme = new ExternalRenderTheme(Theme);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderTheme = MapsforgeThemes.valueOf(Theme.ToUpper());
|
||||
}
|
||||
|
||||
tileCache = new InMemoryTileCache(CacheCapacity);
|
||||
renderer = new DatabaseRenderer(mapDataStore, AwtGraphicFactory.INSTANCE, tileCache, null, true, false, null);
|
||||
renderThemeFuture = new RenderThemeFuture(AwtGraphicFactory.INSTANCE, renderTheme, displayModel);
|
||||
renderThemeFuture.run();
|
||||
zipInputStream?.close();
|
||||
|
||||
Logger?.LogInformation("Loading render theme done.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue