I am trying to move my web site to use ES2015 including the use of export and import to control access to shared resources. This means that javascript files which formerly were explicitly included using HTML tags are now accessed using import statements. So I am moving from pages which include the following:
<script src="/jscripts/util.js" type="application/javascript">
</script>
<script src="/jscripts/CommonForm.js" type="application/javascript">
</script>
<script src="/jscripts/Cookie.js" type="application/javascript">
</script>
<script src="/FamilyTree/Person.js" type="application/javascript">
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?v=3.43&callback=initializeMaps®ion=$GOOGLECC&key=$GOOGLEKEY" type="application/javascript"></script>
to pages that do the following:
<script src="/FamilyTree/Person.js" type="module">
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?v=3.43&callback=initializeMaps®ion=$GOOGLECC&key=$GOOGLEKEY" type="application/javascript"></script>
where Person.js starts off with:
import HTTP from "../jscripts/js20/http6.js";
import {iframe, actMouseOverHelp, openFrame, openSignon, debug, args,
getOffsetLeft, getOffsetTop, popupAlert, show,
showHelp, hideHelp, helpDiv, helpElt, keyDown,
eltMouseOver, eltMouseOut}
from "../jscripts/util6.js";
import {capitalize} from "../jscripts/CommonForm6.js";
import Cookie from "../jscripts/Cookie6.js";
The problem is now my initialization of Google Maps is failing because it cannot find my callback function initializeMaps. That function is still there. The only difference is that farther up that file it contains the import statements.
Uncaught (in promise)
Object { message: "initializeMaps is not a function", name: "InvalidValueError", stack: "ge@https://maps.googleapis.com/maps/api/js?v=3.43&callback=initializeMaps®ion=CA&key=......:70:72\n_.he@https://maps.googleapis.com/maps/api/js?v=3.43&callback=initializeMaps®ion=CA&key=....:70:182\nNj@https://maps.googleapis.com/maps/api/js?v=3.43&callback=initializeMaps®ion=CA&key=.....:146:233\nOj/<@https://maps.googleapis.com/maps/api/js?v=3.43&callback=initializeMaps®ion=CA&key=.....:146:120\n" }
How do I rewrite my Google maps code to work in ES2015?
An example of the production version of the code is https://www.jamescobban.net/FamilyTree/Person.php?idir=90439&lang=en. Hold the mouse over any place name to exploit the Google maps functionality.