From 0d5a47826a6e0012d482df156baded7e9e5f3c93 Mon Sep 17 00:00:00 2001 From: Valentas Date: Thu, 25 Jul 2024 21:37:42 +0300 Subject: [PATCH] AdvancedMarkerElement needs GetPosition or equivalent. #346 --- GoogleMapsComponents/GoogleMapsComponents.csproj | 2 +- GoogleMapsComponents/JsObjectRef.cs | 9 +++++++++ GoogleMapsComponents/Maps/AdvancedMarkerView.cs | 5 +++++ GoogleMapsComponents/wwwroot/js/objectManager.js | 11 ++++++++++- .../Pages/MapAdvancedMarkerViewPage.razor | 14 ++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/GoogleMapsComponents/GoogleMapsComponents.csproj b/GoogleMapsComponents/GoogleMapsComponents.csproj index 10050f01..abc0fe17 100644 --- a/GoogleMapsComponents/GoogleMapsComponents.csproj +++ b/GoogleMapsComponents/GoogleMapsComponents.csproj @@ -15,7 +15,7 @@ 3.0 true BlazorGoogleMaps - 4.7.1 + 4.7.2 Rungwiroon QueueStack Solution BlazorGoogleMaps diff --git a/GoogleMapsComponents/JsObjectRef.cs b/GoogleMapsComponents/JsObjectRef.cs index 8ca1c635..6f498006 100644 --- a/GoogleMapsComponents/JsObjectRef.cs +++ b/GoogleMapsComponents/JsObjectRef.cs @@ -203,6 +203,15 @@ public Task InvokePropertyAsync(string functionName, params object?[] args) ); } + public Task InvokePropertyAsync(string functionName, params object?[] args) + { + return _jsRuntime.MyInvokeAsync( + "blazorGoogleMaps.objectManager.invokeProperty", + new object[] { _guid.ToString(), functionName } + .Concat(args).ToArray() + ); + } + public Task InvokeAsync(string functionName, params object?[] args) { return _jsRuntime.MyInvokeAsync( diff --git a/GoogleMapsComponents/Maps/AdvancedMarkerView.cs b/GoogleMapsComponents/Maps/AdvancedMarkerView.cs index accb15f2..3d4836c7 100644 --- a/GoogleMapsComponents/Maps/AdvancedMarkerView.cs +++ b/GoogleMapsComponents/Maps/AdvancedMarkerView.cs @@ -39,6 +39,11 @@ public async Task SetContent(string newContent) { await _jsObjectRef.InvokePropertyAsync("content", newContent); } + + public async Task GetPosition() + { + return await _jsObjectRef.InvokePropertyAsync("position"); + } } [Obsolete("Use AdvancedMarkerElement")] diff --git a/GoogleMapsComponents/wwwroot/js/objectManager.js b/GoogleMapsComponents/wwwroot/js/objectManager.js index 90577b44..87ab4de5 100644 --- a/GoogleMapsComponents/wwwroot/js/objectManager.js +++ b/GoogleMapsComponents/wwwroot/js/objectManager.js @@ -532,7 +532,16 @@ } try { - obj[functionToInvoke] = processedArgs[0]; + if (processedArgs.length > 0) { + obj[functionToInvoke] = processedArgs[0] + } else { + const result = obj[functionToInvoke]; + if (result && typeof result === "object") { + return JSON.parse(extendableStringify(result, getCircularReplacer())); + } else { + return result; + } + } } catch (e) { console.error(`Error invoking property: Function: ${functionToInvoke} Arguments: ${JSON.stringify(processedArgs)} Error: ${e}`); } diff --git a/ServerSideDemo/Pages/MapAdvancedMarkerViewPage.razor b/ServerSideDemo/Pages/MapAdvancedMarkerViewPage.razor index 29044ac3..35e74d95 100644 --- a/ServerSideDemo/Pages/MapAdvancedMarkerViewPage.razor +++ b/ServerSideDemo/Pages/MapAdvancedMarkerViewPage.razor @@ -11,6 +11,7 @@ +

Marker list

@@ -285,4 +286,17 @@ var lastMarker = _markers.Peek(); await lastMarker.SetContent(newContent); } + + private async Task GetMarkerPosition() + { + if (!_markers.Any()) + { + return; + } + + var lastMarker = _markers.Peek(); + var position = await lastMarker.GetPosition(); + _events.Add($"Marker position {position.Lat} {position.Lng}"); + StateHasChanged(); + } }