mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
Rework Map/WmsImageLayer
This commit is contained in:
parent
c3e1ffd685
commit
9db1987ee5
7 changed files with 265 additions and 103 deletions
|
|
@ -2,6 +2,7 @@
|
|||
// © 2022 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
|
@ -55,5 +56,53 @@ namespace MapControl
|
|||
|
||||
return bitmapImage;
|
||||
}
|
||||
|
||||
internal static async Task<ImageSource> LoadMergedImageAsync(Uri uri1, Uri uri2, IProgress<double> progress)
|
||||
{
|
||||
ImageSource image = null;
|
||||
IProgress<double> progress1 = null;
|
||||
IProgress<double> progress2 = null;
|
||||
|
||||
if (progress != null)
|
||||
{
|
||||
var p1 = 0d;
|
||||
var p2 = 0d;
|
||||
progress1 = new Progress<double>(p => { p1 = p; progress.Report((p1 + p2) / 2d); });
|
||||
progress2 = new Progress<double>(p => { p2 = p; progress.Report((p1 + p2) / 2d); });
|
||||
}
|
||||
|
||||
var images = await Task.WhenAll(LoadImageAsync(uri1, progress1), LoadImageAsync(uri2, progress2));
|
||||
|
||||
if (images.Length == 2 &&
|
||||
images[0] is BitmapSource image1 &&
|
||||
images[1] is BitmapSource image2 &&
|
||||
image1.PixelHeight == image2.PixelHeight &&
|
||||
image1.Format == image2.Format &&
|
||||
image1.Format.BitsPerPixel % 8 == 0)
|
||||
{
|
||||
var format = image1.Format;
|
||||
var width = image1.PixelWidth + image2.PixelWidth;
|
||||
var height = image1.PixelHeight;
|
||||
var stride1 = image1.PixelWidth * format.BitsPerPixel / 8;
|
||||
var stride2 = image2.PixelWidth * format.BitsPerPixel / 8;
|
||||
var buffer1 = new byte[stride1 * height];
|
||||
var buffer2 = new byte[stride2 * height];
|
||||
var stride = stride1 + stride2;
|
||||
var buffer = new byte[stride * height];
|
||||
|
||||
image1.CopyPixels(buffer1, stride1, 0);
|
||||
image2.CopyPixels(buffer2, stride2, 0);
|
||||
|
||||
for (var i = 0; i < height; i++)
|
||||
{
|
||||
Array.Copy(buffer1, i * stride1, buffer, i * stride, stride1);
|
||||
Array.Copy(buffer2, i * stride2, buffer, i * stride + stride1, stride2);
|
||||
}
|
||||
|
||||
image = BitmapSource.Create(width, height, 96, 96, format, null, buffer, stride);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace MapControl
|
|||
set => SetValue(ItemsSourceProperty, value);
|
||||
}
|
||||
|
||||
protected override async Task<ImageSource> GetImageAsync(IProgress<double> progress)
|
||||
protected override async Task<ImageSource> GetImageAsync(BoundingBox boundingBox, IProgress<double> progress)
|
||||
{
|
||||
ImageSource image = null;
|
||||
var projection = ParentMap?.MapProjection;
|
||||
|
|
@ -37,17 +37,17 @@ namespace MapControl
|
|||
|
||||
if (projection != null && items != null)
|
||||
{
|
||||
image = await Task.Run(() => GetImage(projection, items));
|
||||
image = await Task.Run(() => GetImage(projection, boundingBox, items));
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
private DrawingImage GetImage(MapProjection projection, IEnumerable<IMapDrawingItem> items)
|
||||
private DrawingImage GetImage(MapProjection projection, BoundingBox boundingBox, IEnumerable<IMapDrawingItem> items)
|
||||
{
|
||||
var scale = ParentMap.ViewTransform.Scale;
|
||||
var rotation = ParentMap.ViewTransform.Rotation;
|
||||
var mapRect = projection.BoundingBoxToRect(BoundingBox);
|
||||
var mapRect = projection.BoundingBoxToRect(boundingBox);
|
||||
var drawings = new DrawingGroup();
|
||||
|
||||
foreach (var item in items)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue