Skip to content

Commit

Permalink
GeoJsonDataLayer: expose the properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Sören Kuklau committed Jul 15, 2020
1 parent 3f51631 commit b0e9711
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 42 deletions.
85 changes: 46 additions & 39 deletions BlazorLeaflet/BlazorLeaflet.Samples/Pages/GeoJson.razor
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,48 @@
{
var badEuropeMap = @"
{
""type"": ""FeatureCollection"",
""features"": [
{
""type"": ""Feature"",
""properties"": {},
""geometry"": {
""type"": ""Point"",
""coordinates"": [
-82.44140625,
22.917922936146045
]
}
},
{
""type"": ""Feature"",
""properties"": {},
""geometry"": {
""type"": ""Point"",
""coordinates"": [
-80.244140625,
25.720735134412106
]
}
},
{
""type"": ""Feature"",
""properties"": {},
""geometry"": {
""type"": ""Point"",
""coordinates"": [
-68.9501953125,
12.211180191503997
]
}
}
]
""type"": ""FeatureCollection"",
""features"": [
{
""type"": ""Feature"",
""properties"": {
""country"": ""Cuba""
},
""geometry"": {
""type"": ""Point"",
""coordinates"": [
-82.44140625,
22.917922936146045
]
}
},
{
""type"": ""Feature"",
""properties"": {
""country"": ""USA""
},
""geometry"": {
""type"": ""Point"",
""coordinates"": [
-80.244140625,
25.720735134412106
]
}
},
{
""type"": ""Feature"",
""properties"": {
""country"": ""Venezuela""
},
""geometry"": {
""type"": ""Point"",
""coordinates"": [
-68.9501953125,
12.211180191503997
]
}
}
]
}
";

Expand All @@ -74,12 +80,13 @@
GeoJsonData = badEuropeMap
};

dataLayer.PointToLayer = new Func<object, LatLng, Marker>((point, latLng) =>
dataLayer.PointToLayer = new Func<GeoJsonFeature, LatLng, Marker>((feature, latLng) =>
{
return new Marker(latLng) {
return new Marker(latLng)
{
Icon = new Icon
{
Size = new System.Drawing.Size(24, 24),
Size = new System.Drawing.Size(24, 24),
Url = "https://upload.wikimedia.org/wikipedia/commons/thumb/5/56/Run.svg/200px-Run.svg.png",
ClassName = "map-icon",
},
Expand Down
12 changes: 9 additions & 3 deletions BlazorLeaflet/BlazorLeaflet/Models/GeoJsonDataLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ public class GeoJsonDataLayer : InteractiveLayer
public bool HasPointToLayerFunc => PointToLayer != null;

[System.Text.Json.Serialization.JsonIgnore]
public Func<object, LatLng, Marker> PointToLayer { get; set; }
public Func<GeoJsonFeature, LatLng, Marker> PointToLayer { get; set; }

[JSInvokable]
public object CallPointToLayer(object point, LatLng latLng)
public object CallPointToLayer(GeoJsonFeature feature, LatLng latLng)
{
var layer = PointToLayer(point, latLng);
var layer = PointToLayer(feature, latLng);

if (!(layer is Marker))
throw new NotSupportedException("Only Marker layers are currently implemented for PointToLayer.");

return new { Layer = layer, Ref = DotNetObjectReference.Create(layer) };
}
}

public class GeoJsonFeature
{
public object Geometry { get; set; }
public Dictionary<string, object> Properties { get; set; }
}
}

0 comments on commit b0e9711

Please sign in to comment.