Skip to content

Commit

Permalink
Small fix that fixes map drawing on Server side Blazor. (#23)
Browse files Browse the repository at this point in the history
* Enabled compilation of OpenLayers.Blazor.Demo.Server project.

* Fix map drawing on Server side Blazor.

* Made invocation use correct async method call.
  • Loading branch information
vrenken authored Dec 18, 2023
1 parent 3d3ef8d commit ea13071
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/OpenLayers.Blazor/Map.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,14 @@ public async Task SetVisibleExtent(Extent extent)
}

[JSInvokable]
public StyleOptions OnGetShapeStyle(Internal.Shape shape)
public Task<StyleOptions> OnGetShapeStyle(Internal.Shape shape)
{
#if DEBUG
Console.WriteLine($"OnGetShapeStyle: {JsonSerializer.Serialize(shape)}");
#endif

return ShapeStyleCallback(new Shape(shape));
var result = ShapeStyleCallback(new Shape(shape));
return Task.FromResult(result);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/OpenLayers.Blazor/wwwroot/openlayers_interop.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,8 @@ MapOL.prototype.setDrawingSettings = function(enableNewShapes, enableEditShapes,
});
this.currentDraw.on("drawend",
function(evt) {
const style = that.getShapeStyle(evt.feature);
evt.feature.setStyle(style);
that.getShapeStyle(evt.feature)
.then(style => evt.feature.setStyle(style));
});

this.Map.addInteraction(this.currentDraw);
Expand Down Expand Up @@ -972,11 +972,11 @@ MapOL.prototype.customImageStyle = function(marker) {
};

// Shape Style
MapOL.prototype.getShapeStyle = function(feature) {
MapOL.prototype.getShapeStyle = async function(feature) {
const that = this;

const shape = this.mapFeatureToShape(feature);
var style = this.Instance.invokeMethod("OnGetShapeStyle", shape);
var style = await this.Instance.InvokeMethodAsync("OnGetShapeStyle", shape);
style = MapOL.transformNullToUndefined(style);

if (feature.getGeometry().getType() == "Point") {
Expand Down

0 comments on commit ea13071

Please sign in to comment.