I want to use the following code in an HTML document:
<html>
<script type="module">
import Dms from 'https://cdn.jsdelivr.net/npm/[email protected]/dms.js';
alert(Dms.toLat(-3.62, 'dms'));
</script>
<script type="text/">
alert(Dms.toLat(-3.62, 'dms'));
</script>
</html>
The first alert works fine, but the second one in type="text/javascript" does not because it is out of scope. How can I call the Dms class from the second script?
I also tried
<script type="module">
import Dms from './geodesy/dms.js';
alert (Dms.toLat(-3.62, 'dms'));
window.dms = Dms;
</script>
<script type="text/javascript">
alert (dms.toLat(-3.62, 'dms'));
</script>
After all I use
<script>
(async () => {
const {default: Dms} = await import('https://cdn.jsdelivr.net/npm/[email protected]/dms.js');
alert(Dms.toLat(-3.62, 'dms'));
})();
</script>
But now I have the next problem: how to use a second module? I want to use
import Mgrs, { LatLon } from 'geodesy/mgrs.js';
(see https://github.com/chrisveness/geodesy)
How must the const declaration must look for it?
I'm not firm with this.
typeattribute for anything other than "module", or when you explicitly want to make the<script>block be ignored (with some random not-real type).window.dmsexport, the symbol will be missing because the module script won't have finished yet. You can (probably) make the plain script a module also, which might work.document.body.onload = initialize;from inside the module scope instead.