diff --git a/ClientSideDemo/Pages/MapEvents.razor b/ClientSideDemo/Pages/MapEvents.razor index 39bea6a0..4a9275d9 100644 --- a/ClientSideDemo/Pages/MapEvents.razor +++ b/ClientSideDemo/Pages/MapEvents.razor @@ -26,7 +26,7 @@ private bool DisablePoiInfoWindow { get; set; } = false; private Stack _markers = new Stack(); - private string _labelText = ""; + private string? _labelText = ""; protected override void OnInitialized() { @@ -302,7 +302,7 @@ await marker.AddListener("click", async e => { - string markerLabelText = await marker.GetLabelText(); + var markerLabelText = await marker.GetLabelText(); _events.Add("click on " + markerLabelText); StateHasChanged(); await e.Stop(); @@ -312,7 +312,7 @@ private async Task OnMakerDragEnd(Marker m, MouseEvent e) { - string markerLabelText = await m.GetLabelText(); + var markerLabelText = await m.GetLabelText(); _events.Insert(0, $"OnMakerDragEnd ({markerLabelText}): ({e.LatLng})."); StateHasChanged(); await e.Stop(); diff --git a/ClientSideDemo/Pages/MapMarker.razor b/ClientSideDemo/Pages/MapMarker.razor index e566baa8..ba010a0f 100644 --- a/ClientSideDemo/Pages/MapMarker.razor +++ b/ClientSideDemo/Pages/MapMarker.razor @@ -30,7 +30,7 @@ private MapEventList _eventList = default!; - private string _labelText = ""; + private string? _labelText = ""; private MarkerClustering _markerClustering = default!; @@ -92,7 +92,7 @@ await marker.AddListener("click", async e => { await e.Stop(); - string markerLabelText = await marker.GetLabelText(); + var markerLabelText = await marker.GetLabelText(); _events.Add("click on " + markerLabelText); StateHasChanged(); diff --git a/GoogleMapsComponents/GoogleMapsComponents.csproj b/GoogleMapsComponents/GoogleMapsComponents.csproj index d8c0dcb8..cc1cd75c 100644 --- a/GoogleMapsComponents/GoogleMapsComponents.csproj +++ b/GoogleMapsComponents/GoogleMapsComponents.csproj @@ -15,7 +15,7 @@ 3.0 true BlazorGoogleMaps - 4.7.14 + 4.7.15 Rungwiroon QueueStack Solution BlazorGoogleMaps @@ -29,7 +29,7 @@ - + @@ -55,9 +55,9 @@ - - - + + + diff --git a/GoogleMapsComponents/Maps/Marker.cs b/GoogleMapsComponents/Maps/Marker.cs index 6c664e65..83202b6d 100644 --- a/GoogleMapsComponents/Maps/Marker.cs +++ b/GoogleMapsComponents/Maps/Marker.cs @@ -51,23 +51,44 @@ public async Task> GetIcon() return result; } - public Task> GetLabel() + public async Task> GetLabel() { - return _jsObjectRef.InvokeAsync("getLabel"); + var markerLabel = await MarkerLabelInternal(); + return markerLabel; } - public async Task GetLabelText() + public async Task GetLabelText() { - OneOf markerLabel = await GetLabel(); + OneOf markerLabel = await MarkerLabelInternal(); return markerLabel.IsT0 ? markerLabel.AsT0 : markerLabel.AsT1.Text; } public async Task GetLabelMarkerLabel() { - OneOf markerLabel = await GetLabel(); - return markerLabel.IsT1 ? - markerLabel.AsT1 : - new MarkerLabel { Text = markerLabel.AsT0 }; + var markerLabel = await MarkerLabelInternal(); + + return markerLabel.IsT1 + ? markerLabel.AsT1 + : new MarkerLabel { Text = markerLabel.AsT0 }; + } + + private async Task> MarkerLabelInternal() + { + var markerLabel = await _jsObjectRef.InvokeAsync("getLabel"); + + if (markerLabel.IsT0 + && markerLabel.AsT0.Contains("dotnetTypeName") + && markerLabel.AsT0.Contains("GoogleMapsComponents.Maps.MarkerLabel")) + { + var stringValue = markerLabel.AsT0; + var markerLabelObj = Helper.DeSerializeObject(stringValue); + if (markerLabelObj != null) + { + return markerLabelObj; + } + } + + return markerLabel; } public Task GetPosition() diff --git a/ServerSideDemo/Pages/MapMarker.razor.cs b/ServerSideDemo/Pages/MapMarker.razor.cs index 1406f654..38cacbd3 100644 --- a/ServerSideDemo/Pages/MapMarker.razor.cs +++ b/ServerSideDemo/Pages/MapMarker.razor.cs @@ -244,7 +244,15 @@ private async Task AddMarker() Map = _map1.InteropObject, //Label = $"Test {markers.Count}", ZIndex = ZIndex, - Label = "test 01", + //Label = "test 01", + Label = new MarkerLabel + { + Text = $"Test {_markers.Count()}", + FontWeight = "bold", + Color = "#5B32FF", + FontSize = "24", + ClassName = "map-marker-label", + }, //CollisionBehavior = CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY,//2021-07 supported only in beta google maps version //Animation = Animation.Bounce //Icon = new Icon() @@ -270,7 +278,7 @@ private async Task AddMarker() _markers.Push(marker); - var labelText = await marker.GetLabelText(); + var labelText = await marker.GetLabelMarkerLabel(); await marker.AddListener("click", async e => {