Skip to content

Commit

Permalink
AdvancedMarkerElement needs GetPosition or equivalent. #346
Browse files Browse the repository at this point in the history
  • Loading branch information
valentasm committed Jul 25, 2024
1 parent ddc8a13 commit 0d5a478
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion GoogleMapsComponents/GoogleMapsComponents.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<RazorLangVersion>3.0</RazorLangVersion>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<PackageId>BlazorGoogleMaps</PackageId>
<Version>4.7.1</Version>
<Version>4.7.2</Version>
<Authors>Rungwiroon</Authors>
<Company>QueueStack Solution</Company>
<Product>BlazorGoogleMaps</Product>
Expand Down
9 changes: 9 additions & 0 deletions GoogleMapsComponents/JsObjectRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ public Task InvokePropertyAsync(string functionName, params object?[] args)
);
}

public Task<T> InvokePropertyAsync<T>(string functionName, params object?[] args)
{
return _jsRuntime.MyInvokeAsync<T>(
"blazorGoogleMaps.objectManager.invokeProperty",
new object[] { _guid.ToString(), functionName }
.Concat(args).ToArray()
);
}

public Task<T> InvokeAsync<T>(string functionName, params object?[] args)
{
return _jsRuntime.MyInvokeAsync<T>(
Expand Down
5 changes: 5 additions & 0 deletions GoogleMapsComponents/Maps/AdvancedMarkerView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public async Task SetContent(string newContent)
{
await _jsObjectRef.InvokePropertyAsync("content", newContent);
}

public async Task<LatLngLiteral> GetPosition()
{
return await _jsObjectRef.InvokePropertyAsync<LatLngLiteral>("position");
}
}

[Obsolete("Use AdvancedMarkerElement")]
Expand Down
11 changes: 10 additions & 1 deletion GoogleMapsComponents/wwwroot/js/objectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
14 changes: 14 additions & 0 deletions ServerSideDemo/Pages/MapAdvancedMarkerViewPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<button @onclick="@UpdatePosition">Recenter last</button>
<button @onclick="@UpdateContent">Update content</button>
<button @onclick="@AddMarkerWithPinElement">Add marker with pin element</button>
<button @onclick="GetMarkerPosition">Get advanced markers position</button>
<br/>
<p>Marker list</p>
<button @onclick="AddMarker1">Add advanced markers part 1</button>
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 0d5a478

Please sign in to comment.