问题
I'm moving stuff from the v7 to the v8 Bing Maps API.
I'm using the async load and a callback to trigger the map.
However, in my "site" page I'm getting the following error (in a simple test page it all works fine with nearly the identical code):
mapcontrol?callback=loadMap:12 Uncaught TypeError: n.open is not a function
at Object.send (mapcontrol?callback=loadMap:12)
at y (mapcontrol?callback=loadMap:12)
at v (mapcontrol?callback=loadMap:12)
at i.c [as resolve] (mapcontrol?callback=loadMap:12)
at f (mapcontrol?callback=loadMap:12)
at n.p [as downloadDependency] (mapcontrol?callback=loadMap:12)
at t.d [as downloadDependency] (mapcontrol?callback=loadMap:12)
at mapcontrol?callback=loadMap:14
at mapcontrol?callback=loadMap:15
Does anyone know what this means? I'm guessing that the callback isn't available when the map loads, but I can call the callback from devtools console and it runs it (but doesn't seem to find the Bing Maps methods, which is weird-- seems almost like an odd scope problem?).
回答1:
Try adding the map script after the rest of your code. When using async defer when loading the map script, it will first the callback as soon as the map code is available which, if cached, would be before anything else in the page below it.
来源:https://stackoverflow.com/questions/44061241/bing-maps-api-v8