Skip to content

Commit 227b692

Browse files
committed
Fix HttpTileMapImageProvider to use BaseStorageFolder
1 parent 53e2ba8 commit 227b692

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

OxyPlot.Core.Cartography/Axes/LatitudeWebMercatorAxis.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace OxyPlot.Axes
22
{
33
/// <summary>
4-
/// Represents an axis with Web Mercator latitude scale.
4+
/// Represents an axis with Web Mercator latitude scale (Y axis).
55
/// <para>
66
/// Web Mercator, Google Web Mercator, Spherical Mercator, WGS 84 Web Mercator or WGS 84/Pseudo-Mercator
77
/// is a variant of the Mercator map projection and is the de facto standard for Web mapping applications.
@@ -22,6 +22,9 @@ public class LatitudeWebMercatorAxis : Axis
2222

2323
/// <summary>
2424
/// Initializes a new instance of the <see cref="LatitudeWebMercatorAxis"/> class.
25+
/// <para>
26+
/// Represents an axis with Web Mercator latitude scale (Y axis).
27+
/// </para>
2528
/// </summary>
2629
public LatitudeWebMercatorAxis()
2730
{

OxyPlot.Core.Cartography/Axes/LongitudeAxis.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
namespace OxyPlot.Axes
22
{
33
/// <summary>
4-
/// Represents an axis with longitude scale.
5-
/// https://en.wikipedia.org/wiki/Web_Mercator_projection
4+
/// Represents an axis with longitude scale (X axis).
5+
/// <para>
6+
/// <see href="https://en.wikipedia.org/wiki/Web_Mercator_projection"/>
7+
/// </para>
68
/// </summary>
79
public class LongitudeAxis : LinearAxis
810
{
911
private const double _maxDefaultValue = 180;
1012

13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="LongitudeAxis"/> class.
15+
/// <para>
16+
/// Represents an axis with longitude scale (X axis).
17+
/// </para>
18+
/// </summary>
1119
public LongitudeAxis() : base()
1220
{
1321
this.FilterMinValue = -_maxDefaultValue;

OxyPlot.Core.Cartography/Data/HttpTileMapImageProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public string Url
114114
{
115115
_url = value;
116116
var uri = new Uri(_url);
117-
_fullStoragePath = CartographyHelper.GetStoragePathFromUri(uri);
117+
_fullStoragePath = Path.Combine(BaseStorageFolder, CartographyHelper.GetStoragePathFromUri(uri));
118118
}
119119
}
120120

SimpleDemo/ViewModels/MapViewModel.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using OxyPlot.Axes;
77
using OxyPlot.Data;
88
using OxyPlot.Legends;
9+
using OxyPlot.Series;
910
using ReactiveUI;
1011
using System;
1112
using System.IO;
@@ -68,28 +69,35 @@ private PlotModel CreateMapPlotView()
6869

6970
var tileMapImageProvider = new HttpTileMapImageProvider(SynchronizationContext.Current)
7071
{
72+
//Url = "https://www.metoffice.gov.uk/public/tiles/map/{Z}/{Y}/{X}.png",
7173
Url = "http://tile.openstreetmap.org/{Z}/{X}/{Y}.png",
7274
//Url = "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}", // https://developers.arcgis.com/documentation/mapping-apis-and-services/data-hosting/services/image-tile-service/
7375
//Url = "https://maptiles.finncdn.no/tileService/1.0.3/norortho/{Z}/{X}/{Y}.png",
7476
//Url = "https://maptiles.finncdn.no/tileService/1.0.3/normap/{Z}/{X}/{Y}.png",
7577

7678
MaxNumberOfDownloads = 2,
7779
UserAgent = "OxyPlot.Cartography",
78-
ImageConverter = new Func<byte[], byte[]>(input =>
80+
ImageConverter = new Func<byte[], byte[]>(bytes =>
7981
{
80-
// Only convert if file format is Jpeg
8182
// https://github.com/oxyplot/oxyplot/blob/205e968870c292ecaeab2cb9e7f34904897126cb/Source/OxyPlot/Imaging/OxyImage.cs#L221
82-
if (input.Length >= 2 && input[0] == 0xFF && input[1] == 0xD8)
83+
if (bytes.Length >= 2 && bytes[0] == 0x42 && bytes[1] == 0x4D)
84+
{
85+
return bytes; // Bmp
86+
}
87+
88+
if (bytes.Length >= 4 && bytes[0] == 0x89 && bytes[1] == 0x50 && bytes[2] == 0x4E && bytes[3] == 0x47)
8389
{
84-
using (var msInput = new MemoryStream(input))
85-
using (var msOutput = new MemoryStream())
86-
{
87-
var bitmap = Bitmap.DecodeToWidth(msInput, 256);
88-
bitmap.Save(msOutput);
89-
return msOutput.ToArray();
90-
}
90+
return bytes; //Png
91+
}
92+
93+
using (var msInput = new MemoryStream(bytes))
94+
using (var msOutput = new MemoryStream())
95+
{
96+
var bitmap = Bitmap.DecodeToWidth(msInput, 256);
97+
bitmap.Save(msOutput);
98+
return msOutput.ToArray();
9199
}
92-
return input;
100+
return bytes;
93101
})
94102
};
95103

0 commit comments

Comments
 (0)