javascript - Bing Maps V8 Web Control and CommonJS -


i using bing maps v8 web control in web application. using brunch manage static assets, including javascript. default, brunch wraps non-vendor javascript code in commonjs modules.

microsoft's documentation says initialize control callback parameter in script import url, this:

<script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release&callback=loadmapscenario' async defer></script> 

with loadmapscenario defined this:

microsoft.maps.loadmodule('microsoft.maps.autosuggest', {     callback: onload,     errorcallback: onerror,     credentials: 'your bing maps key' }); function onload() {     var options = { maxresults: 5 };     var manager = new microsoft.maps.autosuggestmanager(options);     manager.attachautosuggest('#searchbox', '#searchboxcontainer', selectedsuggestion); } function onerror(message) {     document.getelementbyid('printoutpanel').innerhtml = message; } function selectedsuggestion(suggestionresult) {     document.getelementbyid('printoutpanel').innerhtml =         'suggestion: ' + suggestionresult.formattedsuggestion +             '<br> lat: ' + suggestionresult.location.latitude +             '<br> lon: ' + suggestionresult.location.longitude; } 

the issue error api saying callback function invalid.

is there better way this? there way web control call commonjs-wrapped function in manner?

see issues code below:

  1. <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release&callback=loadmapscenario' async defer></script> in line callback function loadmapscenario defined not exists.

  2. map functions call after including bing map library js.

solution

there sample code provided bing maps. see http://www.bing.com/api/maps/sdk/mapcontrol/isdk#autosuggestuiwithoutmap+html

if unable see above link see below code. use bing map api key connect. sample code provided here auto suggest without loading map. can see different options in above link.

<!doctype html> <html> <head>     <title>autosuggestuiwithoutmaphtml</title>     <meta http-equiv='content-type' content='text/html; charset=utf-8'/> </head> <body>     <div id='printoutpanel'></div>     <div id='searchboxcontainer'><input type= 'text' id= 'searchbox'/></div>      <div id='mymap' style='width: 100vw; height: 100vh;'></div>     <script type='text/javascript'>         function loadmapscenario() {             microsoft.maps.loadmodule('microsoft.maps.autosuggest', {                 callback: onload,                 errorcallback: onerror,                 credentials: 'your bing maps key'             });             function onload() {                 var options = { maxresults: 5 };                 var manager = new microsoft.maps.autosuggestmanager(options);                 manager.attachautosuggest('#searchbox', '#searchboxcontainer', selectedsuggestion);             }             function onerror(message) {                 document.getelementbyid('printoutpanel').innerhtml = message;             }             function selectedsuggestion(suggestionresult) {                 document.getelementbyid('printoutpanel').innerhtml =                     'suggestion: ' + suggestionresult.formattedsuggestion +                         '<br> lat: ' + suggestionresult.location.latitude +                         '<br> lon: ' + suggestionresult.location.longitude;             }          }     </script>     <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release&callback=loadmapscenario' async defer></script> </body> 


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -