From 6a449c655da720baa8d7f0844e3b42a27e58477b Mon Sep 17 00:00:00 2001 From: Valentas Date: Tue, 2 Jul 2024 11:59:26 +0300 Subject: [PATCH] Added way to set AdvancedMarker content property #338 --- GoogleMapsComponents/GoogleMapsComponents.csproj | 2 +- GoogleMapsComponents/Maps/AdvancedMarkerView.cs | 5 +++++ GoogleMapsComponents/wwwroot/js/objectManager.js | 6 ++++++ .../Pages/MapAdvancedMarkerViewPage.razor | 13 +++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/GoogleMapsComponents/GoogleMapsComponents.csproj b/GoogleMapsComponents/GoogleMapsComponents.csproj index 98423c68..e0d0d2c4 100644 --- a/GoogleMapsComponents/GoogleMapsComponents.csproj +++ b/GoogleMapsComponents/GoogleMapsComponents.csproj @@ -15,7 +15,7 @@ 3.0 true BlazorGoogleMaps - 4.6.1 + 4.6.2 Rungwiroon QueueStack Solution BlazorGoogleMaps diff --git a/GoogleMapsComponents/Maps/AdvancedMarkerView.cs b/GoogleMapsComponents/Maps/AdvancedMarkerView.cs index a82e7066..accb15f2 100644 --- a/GoogleMapsComponents/Maps/AdvancedMarkerView.cs +++ b/GoogleMapsComponents/Maps/AdvancedMarkerView.cs @@ -34,6 +34,11 @@ public async Task SetPosition(LatLngLiteral newPosition) { await _jsObjectRef.InvokePropertyAsync("position", newPosition); } + + public async Task SetContent(string newContent) + { + await _jsObjectRef.InvokePropertyAsync("content", newContent); + } } [Obsolete("Use AdvancedMarkerElement")] diff --git a/GoogleMapsComponents/wwwroot/js/objectManager.js b/GoogleMapsComponents/wwwroot/js/objectManager.js index 23bad666..f59e51a2 100644 --- a/GoogleMapsComponents/wwwroot/js/objectManager.js +++ b/GoogleMapsComponents/wwwroot/js/objectManager.js @@ -599,6 +599,12 @@ } } + //Could be issue in future. Currently now it is used by AdvancedMarkerElement + let advancedMarkerElementContent = getAdvancedMarkerElementContent("google.maps.marker.AdvancedMarkerElement", functionToInvoke == "content" ? args2[0] : null); + if (advancedMarkerElementContent !== null) { + args2[0] = advancedMarkerElementContent; + } + try { obj[functionToInvoke] = args2[0]; } catch (e) { diff --git a/ServerSideDemo/Pages/MapAdvancedMarkerViewPage.razor b/ServerSideDemo/Pages/MapAdvancedMarkerViewPage.razor index b3f98c28..3a5cd849 100644 --- a/ServerSideDemo/Pages/MapAdvancedMarkerViewPage.razor +++ b/ServerSideDemo/Pages/MapAdvancedMarkerViewPage.razor @@ -9,6 +9,7 @@ +

Marker list

@@ -272,4 +273,16 @@ await lastMarker.SetPosition(mapCenter); await _bounds.Extend(mapCenter); } + + private async Task UpdateContent() + { + if (!_markers.Any()) + { + return; + } + + const string newContent = "\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n"; + var lastMarker = _markers.Peek(); + await lastMarker.SetContent(newContent); + } }