How do I access variables from the first script in the second script — in this case, map
?
I can’t do this in a single script because:
- The first script must be of the
module
type; without it,import
does not work. - The second script cannot be of the
module
type, because the function inside must be visible in HTML. (The functions in the module script are not visible.)
Map loading script:
<script type="module">
import { Map, NavigationControl, Marker, LngLatBounds } from 'https://cdn.skypack.dev/maplibre-gl';
var map = new Map({
container: 'map',
center: [ myLatLng.lng, myLatLng.lat ],
zoom: 13
});
</script>
Another script in the same file:
<script>
function setReaction(reactionNumber) {
// code
}
</script>