Skip to content

Commit

Permalink
Cannot extract Text from the MarkerLabel Object. #380
Browse files Browse the repository at this point in the history
Update nuget
  • Loading branch information
valentasm committed Nov 16, 2024
1 parent f44ecff commit 88b1955
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
6 changes: 3 additions & 3 deletions ClientSideDemo/Pages/MapEvents.razor
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
private bool DisablePoiInfoWindow { get; set; } = false;

private Stack<Marker> _markers = new Stack<Marker>();
private string _labelText = "";
private string? _labelText = "";

protected override void OnInitialized()
{
Expand Down Expand Up @@ -302,7 +302,7 @@

await marker.AddListener<MouseEvent>("click", async e =>
{
string markerLabelText = await marker.GetLabelText();
var markerLabelText = await marker.GetLabelText();
_events.Add("click on " + markerLabelText);
StateHasChanged();
await e.Stop();
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions ClientSideDemo/Pages/MapMarker.razor
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

private MapEventList _eventList = default!;

private string _labelText = "";
private string? _labelText = "";

private MarkerClustering _markerClustering = default!;

Expand Down Expand Up @@ -92,7 +92,7 @@
await marker.AddListener<MouseEvent>("click", async e =>
{
await e.Stop();
string markerLabelText = await marker.GetLabelText();
var markerLabelText = await marker.GetLabelText();
_events.Add("click on " + markerLabelText);
StateHasChanged();

Expand Down
10 changes: 5 additions & 5 deletions 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.14</Version>
<Version>4.7.15</Version>
<Authors>Rungwiroon</Authors>
<Company>QueueStack Solution</Company>
<Product>BlazorGoogleMaps</Product>
Expand All @@ -29,7 +29,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="..\README.md" Pack="true" PackagePath="\"/>
<None Include="..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -55,9 +55,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.6" />
<PackageReference Include="Microsoft.JSInterop" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.11" />
<PackageReference Include="Microsoft.JSInterop" Version="8.0.11" />
<PackageReference Include="OneOf" Version="3.0.271" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>
Expand Down
37 changes: 29 additions & 8 deletions GoogleMapsComponents/Maps/Marker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,44 @@ public async Task<OneOf<string, Icon, Symbol>> GetIcon()
return result;
}

public Task<OneOf<string, MarkerLabel>> GetLabel()
public async Task<OneOf<string, MarkerLabel>> GetLabel()
{
return _jsObjectRef.InvokeAsync<string, MarkerLabel>("getLabel");
var markerLabel = await MarkerLabelInternal();
return markerLabel;
}

public async Task<string> GetLabelText()
public async Task<string?> GetLabelText()
{
OneOf<string, MarkerLabel> markerLabel = await GetLabel();
OneOf<string, MarkerLabel> markerLabel = await MarkerLabelInternal();
return markerLabel.IsT0 ? markerLabel.AsT0 : markerLabel.AsT1.Text;
}

public async Task<MarkerLabel> GetLabelMarkerLabel()
{
OneOf<string, MarkerLabel> 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<OneOf<string, MarkerLabel>> MarkerLabelInternal()
{
var markerLabel = await _jsObjectRef.InvokeAsync<string, MarkerLabel>("getLabel");

if (markerLabel.IsT0
&& markerLabel.AsT0.Contains("dotnetTypeName")
&& markerLabel.AsT0.Contains("GoogleMapsComponents.Maps.MarkerLabel"))
{
var stringValue = markerLabel.AsT0;
var markerLabelObj = Helper.DeSerializeObject<MarkerLabel>(stringValue);
if (markerLabelObj != null)
{
return markerLabelObj;
}
}

return markerLabel;
}

public Task<LatLngLiteral> GetPosition()
Expand Down
12 changes: 10 additions & 2 deletions ServerSideDemo/Pages/MapMarker.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -270,7 +278,7 @@ private async Task AddMarker()

_markers.Push(marker);

var labelText = await marker.GetLabelText();
var labelText = await marker.GetLabelMarkerLabel();

await marker.AddListener<MouseEvent>("click", async e =>
{
Expand Down

0 comments on commit 88b1955

Please sign in to comment.