Skip to content

Commit ceb9823

Browse files
authored
Merge pull request #13 from memsom/feature/explore-why-land-is-rendered-as-sea
Feature/explore why land is rendered as sea
2 parents 764646d + 2655dc9 commit ceb9823

File tree

16 files changed

+287
-149
lines changed

16 files changed

+287
-149
lines changed

Directory.Packages.props

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4-
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
4+
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageVersion Include="BruTile" Version="5.0.6" />
@@ -11,11 +11,13 @@
1111
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
1212
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
1313
<PackageVersion Include="NLog" Version="5.0.0" />
14-
<PackageVersion Include="SkiaSharp" Version="2.88.7" />
14+
<PackageVersion Include="SkiaSharp" Version="2.88.9" />
1515
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
1616
<PackageVersion Include="Svg" Version="3.4.7" />
1717
<PackageVersion Include="Svg.Skia" Version="1.0.0.3" />
1818
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
19+
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
20+
<PackageVersion Include="System.Text.Json" Version="6.0.10" />
1921
<PackageVersion Include="VexTile.Clipper" Version="6.4.0" />
2022
<PackageVersion Include="VexTile.Mapbox.VectorTile.ExtensionMethods" Version="1.0.6" />
2123
<PackageVersion Include="VexTile.Mapbox.VectorTile.Geometry" Version="1.0.6" />

source/AliFlux/VexTile.Renderers.Mvt.AliFlux.Tests/RenderTest.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Diagnostics;
2+
using System.Drawing;
13
using System.IO;
24
using System.Threading.Tasks;
35
using SQLite;
@@ -101,4 +103,37 @@ public async Task BasicTileRendererTest()
101103

102104
await File.WriteAllBytesAsync("test2.png", tile);
103105
}
106+
107+
108+
[Fact]
109+
public async Task BasicFactoryRenderTest_WaterOnly()
110+
{
111+
var canvas = new SkiaCanvas();
112+
var style = new VectorStyle(VectorStyleKind.Default);
113+
114+
string path = "zurich.mbtiles";
115+
Assert.True(File.Exists(path));
116+
117+
SQLiteConnectionString val = new(path, SQLiteOpenFlags.ReadOnly, false);
118+
var dataSource = new SqliteDataSource(val);
119+
var provider = new VectorTilesSource(dataSource);
120+
style.SetSourceProvider("openmaptiles", provider);
121+
122+
var info = new TileInfo(3, 1, 2, layerWhiteList:["water"]); // australia
123+
var tile = await TileRendererFactory.RenderAsync(style, canvas, info);
124+
125+
Assert.NotNull(tile);
126+
Assert.True(tile.Length > 0);
127+
128+
// tile should be a PNG image
129+
130+
Assert.True(IsPng(tile));
131+
132+
if (File.Exists("wateronly.png"))
133+
{
134+
File.Delete("wateronly.png");
135+
}
136+
137+
await File.WriteAllBytesAsync("wateronly.png", tile);
138+
}
104139
}

source/AliFlux/VexTile.Renderers.Mvt.AliFlux/DoubleExtension.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@
22

33
namespace VexTile.Renderer.Mvt.AliFlux;
44

5-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S125:Sections of code should not be commented out", Justification = "<Pending>")]
65
internal static class DoubleExtension
76
{
87
//private const double DefaultPrecision = 0.0001;
98

10-
internal static bool BasicallyEqualTo(this double a, double b)
11-
{
12-
return a.BasicallyEqualTo(b, 0.0001);
13-
}
9+
internal static bool BasicallyEqualTo(this double a, double b) => a.BasicallyEqualTo(b, 0.0001);
1410

15-
private static bool BasicallyEqualTo(this double a, double b, double precision)
16-
{
17-
return Math.Abs(a - b) <= precision;
18-
}
11+
private static bool BasicallyEqualTo(this double a, double b, double precision) => Math.Abs(a - b) <= precision;
1912
}

source/AliFlux/VexTile.Renderers.Mvt.AliFlux/Drawing/VisualLayer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ public class VisualLayer
1515

1616
public Brush Brush { get; set; }
1717

18-
public string Id { get; set; } = "";
18+
public string Id => $"{LayerId} :: {SourceName} :: {SourceLayer}";
19+
public string LayerId { get; set; }
20+
public string SourceName { get; set; }
21+
public string SourceLayer { get; set; }
1922
}

source/AliFlux/VexTile.Renderers.Mvt.AliFlux/ICanvas.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using SkiaSharp;
23
using VexTile.Renderer.Mvt.AliFlux.Drawing;
34

45
namespace VexTile.Renderer.Mvt.AliFlux;
@@ -9,11 +10,13 @@ public interface ICanvas
910

1011
void StartDrawing(double width, double height);
1112

12-
void DrawBackground(Brush style);
13+
SKColor BackgroundColor { get; }
14+
15+
void DrawBackground(SKColor color);
1316

1417
void DrawLineString(List<Point> geometry, Brush style);
1518

16-
void DrawPolygon(List<Point> geometry, Brush style);
19+
void DrawPolygon(List<Point> geometry, Brush style, SKColor? background);
1720

1821
void DrawPoint(Point geometry, Brush style);
1922

@@ -25,5 +28,7 @@ public interface ICanvas
2528

2629
void DrawUnknown(List<List<Point>> geometry, Brush style);
2730

31+
void DrawDebugBox(TileInfo tileData, SKColor color);
32+
2833
byte[] FinishDrawing();
2934
}

source/AliFlux/VexTile.Renderers.Mvt.AliFlux/LineClipper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace VexTile.Renderer.Mvt.AliFlux;
88

99
internal static class LineClipper
1010
{
11-
static readonly NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
11+
private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();
1212

1313
private static OutCode ComputeOutCode(double x, double y, Rect r)
1414
{
@@ -37,7 +37,7 @@ private static OutCode ComputeOutCode(double x, double y, Rect r)
3737
return code;
3838
}
3939

40-
private static OutCode ComputeOutCode(Point p, Rect r) { return ComputeOutCode(p.X, p.Y, r); }
40+
private static OutCode ComputeOutCode(Point p, Rect r) => ComputeOutCode(p.X, p.Y, r);
4141

4242
private static Point CalculateIntersection(Rect r, Point p1, Point p2, OutCode clipTo)
4343
{
@@ -216,7 +216,7 @@ public static List<Point> ClipPolyline(List<Point> polyLine, Rect bounds)
216216
}
217217
else
218218
{
219-
log.Debug("Segment is null");
219+
Log.Debug("Segment is null");
220220
}
221221
}
222222

source/AliFlux/VexTile.Renderers.Mvt.AliFlux/SKColorFactory.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ namespace VexTile.Renderer.Mvt.AliFlux;
77
// ReSharper disable once InconsistentNaming
88
public static class SKColorFactory
99
{
10-
private static readonly Dictionary<string, SKColor> _colours = new();
10+
private static readonly Dictionary<string, SKColor> Colours = new();
1111

1212
// try to centralise this as tracking down where colours ar made is hard
1313
public static SKColor MakeColor(byte red, byte green, byte blue, byte alpha = 255, [CallerMemberName] string callerName = "<unknown>")
1414
{
1515
string key = MakeKey(red, green, blue, alpha);
1616

17-
if (!_colours.TryGetValue(key, out SKColor color))
17+
if (!Colours.TryGetValue(key, out SKColor color))
1818
{
1919
color = new SKColor(red, green, blue, alpha);
20-
_colours[key] = color;
20+
Colours[key] = color;
2121

2222
#if DEBUG_COLORS
2323
log.Debug($"{callerName} -> Created {key} :: SKColorFactory.MakeColor({red}, {green}, {blue}, {alpha})");
@@ -44,9 +44,9 @@ public static SKColor LogColor(SKColor color, [CallerMemberName] string callerNa
4444
{
4545
string key = MakeKey(color.Red, color.Green, color.Blue, color.Alpha);
4646

47-
if (!_colours.TryGetValue(key, out _))
47+
if (!Colours.TryGetValue(key, out _))
4848
{
49-
_colours.Add(key, color);
49+
Colours.Add(key, color);
5050
}
5151
return color;
5252
}

0 commit comments

Comments
 (0)