I would like to develop a Blazor component to wrap Azure Maps javascript. The first step is to display the map on the page.
Usually, with javascript, it is done this way :
let map = new atlas.Map('mapContainer', {
view: 'Auto',
maxZoom:22,
zoom:4,
center: [2.35405, 43.855103],
style:'road',
showLogo:false,
showFeedbackLink:false,
authOptions: {
authType:atlas.AuthenticationType.subscriptionKey,
subscriptionKey: <subscriptionKey>
}
});
With Blazor, JS cannot be directly handle this way. So, I have to use JSRuntime to write this code :
mapsModule = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.js");
// The following is using custom c# code
MapAuthOptions authOptions = new MapAuthOptions();
authOptions.subscriptionKey = this.subscriptionKey;
authOptions.authType = AuthenticationType.subscriptionKey;
MapOptions options = new MapOptions();
options.authOptions = authOptions;
options.showFeedbackLink = false;
options.showLogo = false;
options.maxZoom = 22;
options.zoom = 4;
options.view = "Auto";
options.style = "road";
// this line crash
await mapsModule.InvokeAsync<object>("atlas.Map", "mapContainer", options);
I wonder how to call classic JS constructor. To be more precise, how to call new atlas.Map() with InvokeAsync and Blazor ?