Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot extract Text from the MarkerLabel Object. #380

Open
Axium7 opened this issue Oct 27, 2024 · 3 comments
Open

Cannot extract Text from the MarkerLabel Object. #380

Axium7 opened this issue Oct 27, 2024 · 3 comments

Comments

@Axium7
Copy link

Axium7 commented Oct 27, 2024

I've only been coding in C# / Blazor for 3 months but I don't believe this is working as intended. I am unable to extract the Text from the Marker Label. Please advise. Thank you for building BlazorGoogleMaps.

// Directly get the MarkerLabel object
var markerLabel = await marker.GetLabelMarkerLabel();

image

// Access the Text property directly

strMarkerRank = markerLabel.Text;

strMarkerRank = "{\"color\":\"white\",\"fontSize\":\"12px\",\"text\":\"1\",\"className\":\"markerIconLabel\",\"dotnetTypeName\":\"GoogleMapsComponents.Maps.MarkerLabel\"}"

This is how I create my label.

var markerOptions = new MarkerOptions
	{
		Position = genCoordinates,
		Map = refGoogleMap.InteropObject,
		Title = generator.GenName,
		Icon = new Icon { Url = "https://maps.google.com/mapfiles/ms/icons/purple.png" },
		Draggable = true,
		Label = new MarkerLabel
		{
			Text = generator.Rank.ToString(),
			Color = "white",
			FontSize = "12px",
			ClassName = "markerIconLabel"
		}
	};

// Create the marker
var marker = await Marker.CreateAsync(refGoogleMap.JsRuntime, markerOptions);

@valentasm1
Copy link
Collaborator

valentasm1 commented Oct 28, 2024

Strange not sure which part to fix. Why js is serilized as element not object or add extra check if if marker response contains dotnetTypeName and then serilize to it.
Probably will do second one since doing fixes in first part could break. Strange it should happen to many more parts.

Found one more interesting code in related part " //Basically fails for marker GetLabel if skip this" :).
Need to check/write test for others OneOf parts where one is string other is object. If it return object or string

@valentasm1
Copy link
Collaborator

Temp solution for you would be serialize to MarkerLabel when found such key in js "dotnetTypeName":"GoogleMapsComponents.Maps.MarkerLabel

@Axium7
Copy link
Author

Axium7 commented Oct 29, 2024

Thanks for your response Valentasm. I'll think about what you said tomorrow and attempt to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants