I have been attempting to integrate BingMaps into an Aurelia Single Page Application (SPA). My approach involved adding the BingMaps script tag to the Head section of the Index page, like so:
<head>
<meta charset="utf-8">
<script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release'></script>
</head>
Additionally, I have created a Map template and Map controller structured as follows:
map.html
<template>
<div id='mainMap' style='width: 100vw; height: 100vh;'></div>
</template>
map.ts
export class Map
{
map:Microsoft.Maps.Map;
attached(){
this.map = new Microsoft.Maps.Map('#mainMap', {credentials: myKey});
this.map.setView({center: new Microsoft.Maps.Location(45.093,14.114), zoom:15});
}
}
Currently, I am utilizing the Aurelia Typescript WebPack Skeleton for my application. Upon running the application and clicking on the Map menu link, everything works correctly and the map is displayed. However, if I refresh the browser, Aurelia throws an exception:
Unhandled rejection TypeError: Cannot read property 'prototype' of null at k () // additional error lines here...
This issue indicates that the Map script may not be fully loaded before the Attached method in the Map controller executes. How can I instruct Aurelia to wait for the map script to load completely before proceeding with the execution of the Attached method?