Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.Maps.loadModule is not a function #14

Closed
drewteachout opened this issue Dec 5, 2017 · 6 comments
Closed

Microsoft.Maps.loadModule is not a function #14

drewteachout opened this issue Dec 5, 2017 · 6 comments

Comments

@drewteachout
Copy link

Is there a reason I am getting this error? I was trying to load SpatialMath because my application wouldn't recognize getGeodesicPath and getHeading because I assumed it wasn't loading the SpatialMath module.

These are my import statements

/// <reference  path="..\..\..\..\node_modules\bingmaps\scripts\MicrosoftMaps\Microsoft.Maps.d.ts"/>
/// <reference  path="..\..\..\..\node_modules\bingmaps\scripts\MicrosoftMaps\Modules\SpatialMath.d.ts"/>

This is my block of code where the error occurs:

Microsoft.Maps.loadModule('Microsoft.Maps.SpatialMath',() => {
    this.generateLines();
});
@rbrundritt
Copy link
Member

I suspect the issue is the "this" may not have the same context in the callback function. Try this:

var self = this;
Microsoft.Maps.loadModule('Microsoft.Maps.SpatialMath',() => {
self.generateLines();
});

@drewteachout
Copy link
Author

The error says Uncaught TypeError: Microsoft.Maps.loadModule is not a function. It's occuring before the code gets to this.generateLines(). I tried your solution, but had no luck. Still getting the same error

@drwestco
Copy link

drwestco commented Dec 6, 2017 via email

@rbrundritt
Copy link
Member

Have you added a script reference to the Bing Maps API?

<script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=YourBingMapsKey' async defer></script>

Note that this project is on the typescript definitions, not the actual API. You need to add a script reference to the Bing Maps API to your application.

@drewteachout
Copy link
Author

I've only seen how to do that in javascript. How do you add a script reference in typescript, specifically an Angular 2+ application?

@rbrundritt
Copy link
Member

Your application must have some HTML somewhere, you can add the script tag there. Here is a basic example: https://github.com/Microsoft/BingMapsV8CodeSamples/blob/master/Samples/Other/Basic%20Angular%201.6%20Map.html

There is also an Angular 2 example here: https://stackoverflow.com/questions/37550278/how-to-add-bing-maps-v8-to-angular-2-0

Don't worry about these samples putting their code in JavaScript, TypeScript is converted into JavaScript when you build your app, so it makes no real difference.

You can also lazy load the map control in JavaScript if you prefer: https://github.com/Microsoft/BingMapsV8CodeSamples/blob/master/Samples/Map/Lazy%20Loading%20the%20Map.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants