diff --git a/examples/Community.Blazor.MapLibre.Examples/Examples/AddMarker.razor b/examples/Community.Blazor.MapLibre.Examples/Examples/AddMarker.razor
index eced5d2..cd12269 100644
--- a/examples/Community.Blazor.MapLibre.Examples/Examples/AddMarker.razor
+++ b/examples/Community.Blazor.MapLibre.Examples/Examples/AddMarker.razor
@@ -10,11 +10,17 @@
Height="600px">
-
+
+
+
+
Try drag a marker!
+
+
@DragInfo
+
@code {
private MapLibre _mapListener { get; set; } = new MapLibre();
-
+ public string DragInfo { get; set; } = "";
private readonly MapOptions _mapOptions = new()
{
Style = "https://demotiles.maplibre.org/style.json"
@@ -24,6 +30,8 @@
{
var options = new MarkerOptions
{
+ Draggable = true,
+ OnDragEndAsync = OnMarkerDragEnd,
Extensions = new MarkerOptionsExtensions
{
HtmlContent = "
",
@@ -33,5 +41,14 @@
await _mapListener.AddMarker(options, new LngLat(Random.Shared.NextDouble() * 180 - 90, Random.Shared.Next(-90, 90)));
}
+
+ private Task OnMarkerDragEnd(MarkerEvent arg)
+ {
+ DragInfo = $"Lat: {arg.LngLat.Latitude}, Lng: {arg.LngLat.Longitude}";
+ Console.WriteLine($"Marker dragged to: Lat={arg.LngLat.Latitude}, Lng={arg.LngLat.Longitude}");
+ StateHasChanged();
+
+ return Task.CompletedTask;
+ }
}
diff --git a/src/Community.Blazor.MapLibre/MapLibre.razor.cs b/src/Community.Blazor.MapLibre/MapLibre.razor.cs
index 01b337b..d135d17 100644
--- a/src/Community.Blazor.MapLibre/MapLibre.razor.cs
+++ b/src/Community.Blazor.MapLibre/MapLibre.razor.cs
@@ -146,7 +146,8 @@ await JsRuntime.InvokeAsync("import",
Options.Container = MapId;
// Initialize the MapLibre map
- _mapObject = await _jsModule.InvokeAsync("initializeMap", Options, _dotNetObjectReference);
+ _mapObject =
+ await _jsModule.InvokeAsync("initializeMap", Options, _dotNetObjectReference);
// Load the plugins after the map has been initialized
foreach (var plugin in _plugins)
@@ -239,7 +240,7 @@ public Task OnClick(string? layerId, Action handler) =>
/// The asynchronous callback.
/// A task of type .
public Task OnClick(string? layerId, Func handler) =>
- AddAsyncListener("click", handler, layerId);
+ AddAsyncListener("click", handler, layerId);
#endregion
@@ -276,6 +277,7 @@ public async ValueTask AddImage(string id, string url, StyleImageMetadata? optio
_bulkTransaction.Add("addImage", id, url, options);
return;
}
+
await _jsModule.InvokeVoidAsync("addImage", MapId, id, url, options);
}
@@ -292,6 +294,7 @@ public async ValueTask AddLayer(Layer layer, string? beforeId = null)
_bulkTransaction.Add("addLayer", layer, beforeId);
return;
}
+
await _jsModule.InvokeVoidAsync("addLayer", MapId, layer, beforeId);
}
@@ -308,6 +311,7 @@ public async ValueTask AddSource(string id, ISource source)
_bulkTransaction.Add("addSource", id, source);
return;
}
+
await _jsModule.InvokeVoidAsync("addSource", MapId, id, source);
}
@@ -324,6 +328,7 @@ public async ValueTask SetSourceData(string id, GeoJsonSource source)
_bulkTransaction.Add("setSourceData", id, dataNode);
return;
}
+
await _jsModule.InvokeVoidAsync("setSourceData", MapId, id, dataNode);
}
@@ -341,6 +346,7 @@ public async ValueTask AddSprite(string id, string url, StyleSetterOptions? opti
_bulkTransaction.Add("addSprite", id, url, options);
return;
}
+
await _jsModule.InvokeVoidAsync("addSprite", MapId, id, url, options);
}
@@ -390,7 +396,8 @@ await _jsModule.InvokeAsync("calculateCameraOptionsFromTo", MapId
/// The geographical bounding box to be fitted.
/// Optional parameters to customize the calculation.
/// A task that represents the asynchronous operation, containing the resulting center, zoom, and bearing.
- public async ValueTask CameraForBounds(LngLatBounds bounds, CameraForBoundsOptions? options = null) =>
+ public async ValueTask CameraForBounds(LngLatBounds bounds,
+ CameraForBoundsOptions? options = null) =>
await _jsModule.InvokeAsync("cameraForBounds", MapId, bounds, options);
///
@@ -939,7 +946,8 @@ public async ValueTask