Reputation: 1
I am new to Javascript and Thingsboard, I was trying to implement Bing Maps into a Thingsboard widget, and I am facing an issue where the widget does not successfully load everytime issue
Here is my JS snippet:
var map;
$.getScript(
'https://www.bing.com/maps/sdkrelease/mapcontrol'
);
function GetMap() {
map = new Microsoft.Maps.Map('#myMap', {
credentials: 'Replaced with bing api access token'
});
console.log(Microsoft);
}
self.onInit = function() {
GetMap();
}
I tried to run the same code offline, I do not face any issue, i.e., the Bing map loads everytime
Am I implementing the Bing maps API the wrong way on Thingsboard? Does anyone have a hint where the error lies?
Kind regards, SriHari BG
Upvotes: 0
Views: 58
Reputation: 18003
Most likely issue is that the Bing Maps scripts haven't finished loading into the browser before you are trying to create the map instance. The Bing Maps script loads several other scripts and resources internally that you need to wait for. Modifying your code as follows should work better, assuming GetMap
is globally accessible:
var map;
function GetMap() {
map = new Microsoft.Maps.Map('#myMap', {
credentials: 'Replaced with bing api access token'
});
console.log(Microsoft);
}
$.getScript(
'http://www.bing.com/api/maps/mapcontrol?callback=GetMap'
);
Upvotes: 0