rungwiroon / BlazorGoogleMaps

Blazor interop for GoogleMap library
MIT License
309 stars 99 forks source link

Accessing the map object via javascript #317

Closed ham187 closed 4 months ago

ham187 commented 4 months ago

Hello,

Sorry, I know this is a pain,

I need to be able to access the javascript Map object, so that I can run some custom JavaScript Code, is there anyway to do this?

I have been trying like below; await JS.InvokeVoidAsync("displayTickerAlert1", pO.Paths, map1.JsRuntime);

and then in a javascript function: window.displayTickerAlert1 = (paths, themap) => { themap.setCenter(new google.maps.LatLng(-34, 151)); } setCenter, is just an example of what i'm trying to achieve being able to access the map object and do something with it.

valentasm1 commented 4 months ago

Basically it exist in mapObjects array and you access it by map id. Here is comments with examples.

https://github.com/rungwiroon/BlazorGoogleMaps/issues/306#issuecomment-1909767569 https://github.com/rungwiroon/BlazorGoogleMaps/issues/241#issuecomment-1417994421

valentasm1 commented 4 months ago

Sorry i dont have exact example. I could send later since i am unable get it now.

ham187 commented 4 months ago

Yes please, if you could that would be very helpful

valentasm1 commented 4 months ago

This is pseudo code. Sorry that it is not the exact working example. I dont have enough time and will to go into specific details. Use friends and stackoverflow for programing help.

c# _jsObjectRef.InvokeAsync("displayTickerAlert1", map.Id);

Js function displayTickerAlert1(mapId){ var mapObj = mapObjects [mapId]; }

If you want pass more info to js please read ms documentation https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/?view=aspnetcore-8.0