Skip to content

Commit

Permalink
CustomDrawFunctionModel
Browse files Browse the repository at this point in the history
  • Loading branch information
SHAliakbari committed Feb 24, 2024
1 parent 69e4ebb commit 9239b22
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 36 deletions.
32 changes: 6 additions & 26 deletions Examples/WebApp/gdal2tiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public gdal2tiles(string geoTiffPath, GeoLayers geoLayers)
{
geoLayer = geoLayers.Get(geoTiffPath, () =>
{
using Dataset dataset = Gdal.Open(geoTiffPath, Access.GA_ReadOnly);
if (dataset == null)
{
Expand Down Expand Up @@ -105,33 +104,17 @@ public gdal2tiles(string geoTiffPath, GeoLayers geoLayers)
values = bytes.ToArray()
},
customDrawFunction= (
//{g
// tile,
// values,
// context,
// x,
// y,
// width,
// height,
// rasterX,
// rasterY,
// sampleX,
// sampleY,
// sampledRaster
// }
customDrawFunctionModel a
) =>
customDrawFunction= (CustomDrawFunctionModel model) =>
{
SKColor color = SKColors.Transparent;
if (a.values.Length == 3)
if (model.Values.Length == 3)
{
color = new SKColor((byte)a.values[0], (byte)a.values[1], (byte)a.values[2]);
color = new SKColor((byte)model.Values[0], (byte)model.Values[1], (byte)model.Values[2]);
}
if (a.values.Length == 1)
if (model.Values.Length == 1)
{
color = new SKColor(a.values[0]);
color = new SKColor(model.Values[0]);
}
using SKPaint sKPaint = new SKPaint()
Expand All @@ -140,17 +123,14 @@ customDrawFunctionModel a
IsAntialias = true,
Style = SKPaintStyle.Fill
};
a.Canvas.DrawRect((int)a.x, (int)a.y, (int)a.width, (int)a.height, sKPaint);
model.Canvas.DrawRect((int)model.x, (int)model.y, (int)model.width, (int)model.height, sKPaint);
},
debugLevel=4,
resolution= 256 // optional parameter for adjusting display resolution
};
geoLayer tmp = new geoLayer(geoRasterLayerOptions);
tmp.initialize(geoRasterLayerOptions);
return tmp;
Expand Down
4 changes: 2 additions & 2 deletions georaster-layer-for-leaflet-dot-net-core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{68F7D1D7-FA20-4A11-BDF4-23B676551C8F}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{68F7D1D7-FA20-4A11-BDF4-23B676551C8F}.Debug|Any CPU.Build.0 = Release|Any CPU
{68F7D1D7-FA20-4A11-BDF4-23B676551C8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68F7D1D7-FA20-4A11-BDF4-23B676551C8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68F7D1D7-FA20-4A11-BDF4-23B676551C8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68F7D1D7-FA20-4A11-BDF4-23B676551C8F}.Release|Any CPU.Build.0 = Release|Any CPU
{9D5C0291-9157-4C73-B67A-26D2F1058E7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down
28 changes: 28 additions & 0 deletions src/CustomDrawFunctionModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace georaster_layer_for_leaflet_dot_net_core
{
public class CustomDrawFunctionModel
{
public SKCanvas Canvas { get; set; }

Check warning on line 12 in src/CustomDrawFunctionModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Canvas' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public byte[] Values { get; set; }

Check warning on line 13 in src/CustomDrawFunctionModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Values' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public double x { get; set; }
public double y { get; set; }

public double width { get; set; }
public double height { get; set; }

public int rasterX { get; set; }
public int rasterY { get; set; }

public int sampleX { get; set; }
public int sampleY { get; set; }

public byte[][][] sampledRaster { get; set; }

Check warning on line 26 in src/CustomDrawFunctionModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'sampledRaster' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
}
16 changes: 8 additions & 8 deletions src/geoLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum ResampleMethod
public GeoRaster[]? georasters;
public GeoRaster? georaster;
public bool noWrap;
public Action<dynamic> customDrawFunction;
public Action<CustomDrawFunctionModel> customDrawFunction;

public void Dispose()
{
Expand Down Expand Up @@ -902,15 +902,15 @@ public byte[] drawTile(Coords coords, DoneCallback done)

if (options.customDrawFunction != null)
{
options.customDrawFunction(new
options.customDrawFunction(new CustomDrawFunctionModel
{
canvas,
values,
Canvas = canvas,
Values = values,
//context,
x,
y,
width,
height,
x= x,
y=y,
width=width,
height=height,
rasterX = xInRasterPixels,
rasterY = yInRasterPixels,
sampleX = w,
Expand Down

0 comments on commit 9239b22

Please sign in to comment.