MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.24k stars 21.41k forks source link

Azure Maps "atlas.min.js" Attempts to Initialise AppInsights Without Checking For Existing Instance #14350

Closed KallumTanton closed 5 years ago

KallumTanton commented 6 years ago

I'm attempting to use the Azure Maps Javascript control by using the simple instructions in this article.

Both the script (atlas.min.js) and the styles (atlas.min.css) are retrieved fine however, when I create a new map I receive the following error:

applicationinsights_js_1.AppInsights.downloadAndSetup is not a function
    at new e (atlas.min.js?api-version=1.0:435)
    at baa00b3f-f03c-47ac-a6e8-cd17688ca021:159

The application this is being used in already has its own AppInsights initialisation in the header, long before this JS if ever executed. According to this issue "The call to downloadAndSetup can fail if the SDK is already downloaded and initialized". The solution then is simply to check if the function "downloadAndSetup" exists before calling it. That's fine, but "atlas.min.js" doesn't perform this check and always executes this function regardless of its availability.

My code:

[Some HTML]
<div id="map"></div>
[More HTML]
<script src="https://atlas.microsoft.com/sdk/js/atlas.min.js?api-version=1.0"></script>
<script>
        var map = new atlas.Map("map", {
            "subscription-key": "YD----------------------------------------A",
            center: [-122.33263, 47.59093],
            zoom: 12
        });
</script>
[Closing HTML]

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Mike-Ubezzi-MSFT commented 6 years ago

@KallumTanton Thank you very much for the feedback on this. I have assigned this to the content owner to make an enhancement to the .js sample found in the tutorial.

KingdomOfEnds commented 6 years ago

@KallumTanton - I tried a few examples and could not reproduce the error using your or the supplied example code in either of the two articles:

1. https://docs.microsoft.com/en-us/azure/azure-maps/map-create. 
2. https://docs.microsoft.com/en-us/azure/azure-maps/how-to-use-map-control

It seems the real culprit has less to do with initialization and more to do with loading two of the same dependencies (or slightly different versions of the same dependencies) within your app? If so, that's mostly a dependency and architectural situation. Have you tried removing one of those dependencies and seeing if it works?

Please review the examples above and let us know if you run into additional issues!

asergaz commented 6 years ago

We will now proceed to close this thread. If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue.

rybkov commented 5 years ago

@sergaz-msft I have an example of a simple HTML page if insert these scripts after AppInsight code it breaks the map

<link href="https://atlas.microsoft.com/sdk/css/atlas.min.css?api-version=1" rel="stylesheet" type="text/css" />
  <script src="https://atlas.microsoft.com/sdk/js/atlas.min.js?api-version=1"></script>

If insert them before AppInsight script - it is OK.

ToniaDemchuk commented 5 years ago

I have the same issue, but I don't want to load this scripts in the head - it is blocking operation and atlas.min.js load near 2 sec. That is not applicable to my application to wait 2 sec for map if I use SPA and don't use map on the main page.

I tried to load the atlas.min.js via scriptjs library asynchronously. But it fails with applicationinsights_js_1.AppInsights.downloadAndSetup is not a function btw, appinsights scripts are loaded in the head.

Please, reopen this issue or provide the workaround for this case.

asergaz commented 5 years ago

@dsk-2015 @KingdomOfEnds can you take a look? Thanks!

KingdomOfEnds commented 5 years ago

@sergaz-msft - This has been directed to the current document maintainers. Thanks!

asergaz commented 5 years ago

Thanks @KingdomOfEnds please let us know when the issue is addressed.

rbrundritt commented 5 years ago

@haywoodsloan just came across this issue on GitHub, do you know if this is something we have addressed already?

haywoodsloan commented 5 years ago

Yes, as of version 2.0.2 the map control sdk no longer relies on a global AppInsights instance. Now pages can use AppInsights via the downloadAndSetup method alongside the map control.

rbrundritt commented 5 years ago

Great, thanks Sloan. Admins, can we close this issue now as it is fixed in the latest version of Azure Maps.

rbrundritt commented 5 years ago

close

rbrundritt commented 5 years ago

please-close