mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-03-07 14:03:49 +01:00
Updated MapsforgeTiles
This commit is contained in:
parent
87271f9daf
commit
19ed50bc4a
|
|
@ -20,14 +20,12 @@ namespace MapControl.MapsforgeTiles
|
|||
|
||||
if (pixels != null)
|
||||
{
|
||||
var size = displayModel.getTileSize();
|
||||
|
||||
unsafe
|
||||
{
|
||||
fixed (int* ptr = pixels)
|
||||
{
|
||||
return new Bitmap(PixelFormat.Bgra8888, AlphaFormat.Opaque, (nint)ptr,
|
||||
new PixelSize(size, size), new Vector(96d, 96d), size * 4);
|
||||
new PixelSize(TileSize, TileSize), new Vector(96d, 96d), TileSize * 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,18 +9,17 @@ Java library, which is made accessible to .NET via [IKVM](https://github.com/ikv
|
|||
|
||||
Map files can be downloaded from the [Mapsforge Download Server](https://download.mapsforge.org/).
|
||||
|
||||
`MapsforgeTileSource` is initialized by a static `Initialize` method that takes the file path to either a single map file
|
||||
or a directory containing multiple map files, and a DPI scale factor that controls the size of the rendered map tiles.
|
||||
`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`.
|
||||
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. The second and third optional constructor parameters specify the size of the tile source's
|
||||
internal tile cache and the relative scale of rendered text.
|
||||
for available theme names. An additional constructor parameters specifies the size of the tile source's internal cache.
|
||||
|
||||
Code sample:
|
||||
```
|
||||
MapControl.MapsforgeTiles.MapsforgeTileSource.Initialize(".\mapfiles", 1.5f);
|
||||
MapControl.MapsforgeTiles.MapsforgeTileSource.Initialize(".\mapfiles");
|
||||
|
||||
map.MapLayer = new MapTileLayer
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,35 +17,31 @@ namespace MapControl.MapsforgeTiles
|
|||
{
|
||||
private static ILogger Logger => field ??= ImageLoader.LoggerFactory?.CreateLogger<MapsforgeTileSource>();
|
||||
|
||||
private static DisplayModel displayModel;
|
||||
private static MapDataStore mapDataStore;
|
||||
|
||||
private readonly DisplayModel displayModel;
|
||||
private readonly InMemoryTileCache tileCache;
|
||||
private readonly DatabaseRenderer renderer;
|
||||
private readonly RenderThemeFuture renderThemeFuture;
|
||||
private readonly float renderTextScale;
|
||||
|
||||
public static void Initialize(string mapFile, float dpiScale)
|
||||
public static void LoadMaps(string mapFileOrDirectory)
|
||||
{
|
||||
List<string> mapFiles;
|
||||
|
||||
if (mapFile.EndsWith(".map"))
|
||||
if (mapFileOrDirectory.EndsWith(".map"))
|
||||
{
|
||||
mapFiles = [mapFile];
|
||||
mapFiles = [mapFileOrDirectory];
|
||||
}
|
||||
else
|
||||
{
|
||||
mapFiles = [.. Directory.EnumerateFiles(mapFile, "*.map")];
|
||||
mapFiles = [.. Directory.EnumerateFiles(mapFileOrDirectory, "*.map")];
|
||||
}
|
||||
|
||||
Initialize(mapFiles, dpiScale);
|
||||
LoadMapFiles(mapFiles);
|
||||
}
|
||||
|
||||
public static void Initialize(List<string> mapFiles, float dpiScale)
|
||||
public static void LoadMapFiles(List<string> mapFiles)
|
||||
{
|
||||
DisplayModel.setDeviceScaleFactor(dpiScale);
|
||||
displayModel = new DisplayModel();
|
||||
|
||||
if (mapFiles.Count == 1)
|
||||
{
|
||||
Logger?.LogInformation("Loading {mapFile}", mapFiles[0]);
|
||||
|
|
@ -66,10 +62,10 @@ namespace MapControl.MapsforgeTiles
|
|||
}
|
||||
}
|
||||
|
||||
public MapsforgeTileSource(string theme, int cacheCapacity = 200, float textScale = 1f)
|
||||
public MapsforgeTileSource(string theme, int cacheCapacity = 200)
|
||||
{
|
||||
XmlRenderTheme renderTheme;
|
||||
|
||||
|
||||
if (theme.EndsWith(".xml"))
|
||||
{
|
||||
renderTheme = new ExternalRenderTheme(theme);
|
||||
|
|
@ -79,13 +75,23 @@ namespace MapControl.MapsforgeTiles
|
|||
renderTheme = MapsforgeThemes.valueOf(theme.ToUpper());
|
||||
}
|
||||
|
||||
displayModel = new DisplayModel();
|
||||
tileCache = new InMemoryTileCache(cacheCapacity);
|
||||
renderer = new DatabaseRenderer(mapDataStore, AwtGraphicFactory.INSTANCE, tileCache, null, true, false, null);
|
||||
renderThemeFuture = new RenderThemeFuture(AwtGraphicFactory.INSTANCE, renderTheme, displayModel);
|
||||
renderTextScale = textScale;
|
||||
}
|
||||
|
||||
private int[] RenderTile(int zoomLevel, int column, int row)
|
||||
public float TextScale { get; set; } = 1f;
|
||||
|
||||
public float DpiScale
|
||||
{
|
||||
get => displayModel.getUserScaleFactor();
|
||||
set => displayModel.setUserScaleFactor(value);
|
||||
}
|
||||
|
||||
public int TileSize => displayModel.getTileSize();
|
||||
|
||||
public int[] RenderTile(int zoomLevel, int column, int row)
|
||||
{
|
||||
if (!renderThemeFuture.isDone())
|
||||
{
|
||||
|
|
@ -102,7 +108,7 @@ namespace MapControl.MapsforgeTiles
|
|||
|
||||
int[] imageBuffer = null;
|
||||
var tile = new org.mapsforge.core.model.Tile(column, row, (byte)zoomLevel, displayModel.getTileSize());
|
||||
var job = new RendererJob(tile, mapDataStore, renderThemeFuture, displayModel, renderTextScale, false, false);
|
||||
var job = new RendererJob(tile, mapDataStore, renderThemeFuture, displayModel, TextScale, false, false);
|
||||
var bitmap = tileCache.get(job) ?? renderer.executeJob(job);
|
||||
|
||||
if (bitmap != null)
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ namespace MapControl.MapsforgeTiles
|
|||
|
||||
if (pixels != null)
|
||||
{
|
||||
var size = displayModel.getTileSize();
|
||||
|
||||
bitmap = BitmapSource.Create(size, size, 96d, 96d, PixelFormats.Bgra32, null, pixels, size * 4);
|
||||
bitmap = BitmapSource.Create(TileSize, TileSize, 96d, 96d, PixelFormats.Bgra32, null, pixels, TileSize * 4);
|
||||
bitmap.Freeze();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@ namespace MapControl.MapsforgeTiles
|
|||
public override async Task<ImageSource> LoadImageAsync(int zoomLevel, int column, int row)
|
||||
{
|
||||
ImageSource image = null;
|
||||
var size = displayModel.getTileSize();
|
||||
var bitmap = new WriteableBitmap(size, size);
|
||||
var bitmap = new WriteableBitmap(TileSize, TileSize);
|
||||
using var stream = bitmap.PixelBuffer.AsStream();
|
||||
|
||||
try
|
||||
|
|
|
|||
Loading…
Reference in a new issue