Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Create Your Own Custom Map for Power BI.

I try to create own custom visual with bing maps. I added script "https://www.bing.com/api/maps/mapcontrol?callback=InitMap"

and div with Id:

this.divMap = d3.select(options.element)
.append('div')
.classed('map', true)
.attr({ id: "map_id"});
 
But when I want to create a global function InitMap. Power Bi doesn't see it. 
 
I did: 
declare function InitMap():void;
And in Visual constructor:
(window as any).InitMap= this.InitMap;
 
This code doesn't want to work.
 
When  I create a new script with the text of function, it's work:
let scriptMapBody = document.createElement('script');
 scriptMapBody.type = "text/javascript"
 scriptMapBody.text = " function InitMap() \
 var map = new Microsoft.Maps.Map(document.getElementById('map_id'),{ \
 credentials: ''});\
}"
 
 
 
Is there any way to create this function in ts code?
 
1 ACCEPTED SOLUTION
v-viig
Community Champion
Community Champion

Please try using API 1.13.0 if it works there.

 

PBI isolation might break some libraries that work by injecting JS from remote hosts.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

View solution in original post

6 REPLIES 6
v-viig
Community Champion
Community Champion

Our suggestion is to check window.InitMap and window.window.InitMap.

 

What Custom Visuals API version are you using?

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Anonymous
Not applicable

window.InitMap and window.window.InitMap don't help.

v-viig
Community Champion
Community Champion

What API version are you using?

 

Power BI creates a copy of window for isolating Power BI JS from Custom Visual JS. It might be a root cause of this issue.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Anonymous
Not applicable

I use  API v2.3.0

v-viig
Community Champion
Community Champion

Please try using API 1.13.0 if it works there.

 

PBI isolation might break some libraries that work by injecting JS from remote hosts.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Anonymous
Not applicable

Thanks. It's helps

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors