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

AdvancedMarkerElementOptions - Content Invalid (not an instance of Node) #332

Closed
EGInsider opened this issue Jun 11, 2024 · 13 comments
Closed

Comments

@EGInsider
Copy link

@valentasm1 I'm using recently implemented AdvancedMarkerElement class in my code and setting AdvancedMarkerElementOptions.Content = HTML element but I'm getting the error Unhandled exception rendering component: AdvancedMarkerElement: "content" invalid: not an instance of Node;

Sample Code:

        this.marker = await AdvancedMarkerElement.CreateAsync(Map.JsRuntime, new AdvancedMarkerElementOptions()
        {
            Position = position,
            Map = this.Map.InteropObject,
            Content = $"<div style='background-color:blue'>{position.Lat},{position.Lng}</div>",
        });
@EGInsider
Copy link
Author

Screenshot 2024-06-11 at 10 50 38 AM

@valentasm1
Copy link
Collaborator

Found issue. Will release fix soon.

@valentasm1
Copy link
Collaborator

I feel really bad of releasing such bug. We just did some changes to advanced marked and forgot to test it.
Sorry and let me know if this version works better
https://www.nuget.org/packages/BlazorGoogleMaps/4.4.1

@EGInsider
Copy link
Author

@valentasm1 Thanks for resolving the issue.

@EGInsider
Copy link
Author

EGInsider commented Jun 11, 2024

@valentasm1 the issue still persists when we use a list of markers instead of a single marker

@EGInsider
Copy link
Author

EGInsider commented Jun 11, 2024

@valentasm1

Sample code from my project :

            if (markerList == null)
            {
                markerList = await AdvancedMarkerElementList.CreateAsync(this.Map.JsRuntime, cordDic);
            }
            else
            {
                await markerList.AddMultipleAsync(cordDic);
            }

ig CreateAsync and AddMultipleAsync are the root cause

@valentasm1
Copy link
Collaborator

I updated server side demo. It works for me.
What error appears in console for you?

@valentasm1
Copy link
Collaborator

Also one more issue that AdvancedMarker dont have nor Draggable, nor Visible properties, so if you set them then map will fail.
Not very sure how to solve it since it need some refactoring. Maybe ovveride them and throw exception of trying to set.
We did bad architecture in this case

@EGInsider
Copy link
Author

@valentasm1 I'm getting the same error as above content invalid not an instance of Node.

Yes you're right the above mentioned properties aren't present in AdvanceMarkerElement class

@EGInsider
Copy link
Author

Here's my sample code that throws out the same content invalid error

var cordDic = this.checkins
                .Where(x => selectedAgentsAndLocations.Any() ? (selectedAgentsAndLocations.Contains(x.city) || selectedAgentsAndLocations.Contains(x.user_name)) : true)
                .ToDictionary(x => Guid.NewGuid().ToString(), x =>
                {
                    var label = $" {x.user_name} ({x.created_at:dMMM h:mtt})";
                    return new AdvancedMarkerElementOptions
                    {
                        Position = new LatLngLiteral() { Lng = (double)x.@long, Lat = (double)x.lat },
                        Map = this.Map.InteropObject,
                        Title = x.address_line,
                        Content = label.GetMarkerHtml("http://maps.google.com/mapfiles/kml/shapes/man.png"),
                    };
                });

            if (markerList == null)
            {
                markerList = await AdvancedMarkerElementList.CreateAsync(this.Map.JsRuntime, cordDic);
            }
            else
            {
                await markerList.AddMultipleAsync(cordDic);
            }

            public static string GetMarkerHtml(this string label, string imgSource = null)
            {
                var html = $@"<div style='grid-area: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 8px; height: 8px;'>
                                <img src={imgSource} aria-hidden='true' height='40px' width='40px'>
                                <div class='fa-sr-only' style=""color: #00FFD1; font-weight: bold; font-family: 'Trebuchet MS';"">{label}</div>
                           </div>";
        
                return html;
            }

@EGInsider
Copy link
Author

@valentasm1 ig a page to simulate AdvancedMarkerElementList can be implemented

@valentasm1
Copy link
Collaborator

You are right. Demo was without content. Fixed
https://www.nuget.org/packages/BlazorGoogleMaps/4.4.2

@EGInsider
Copy link
Author

EGInsider commented Jun 12, 2024

@valentasm1 Thanks! for the help

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