I have managed to (and very easily) add openlayers.js to my project and get it working nicly with the new HTML element.
I did this simply by importing the ol.js and ol.css files, putting the JS file in scripts and I set its purpose as "importforevents". Then I found that in my events I can initialise the map and make changes to it ETC. Great!
My next step was to add another script for "charts", so I did the same but realised that when I set the chart JS file to importForEvents it removes this purpose from the OL.js.
So did some reading up and read I need to import these JS script into main and into a seperate "importForEvents.js" file to make them available inside events.
So to keep things simply I thought I would attempt this with JUST the ol.js but I am having no luck whatsoever.
Current "non working" situation is:
Main.js (purpose set to main)
import * as myMaps from "./ol.js";
importForEvents.js (Purpose set to importForEvents)
import * as myMaps from "./ol.js";
When I try to initiialise the map from within an event script using the following
var map = new myMaps.ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([37.41, 8.82]),
zoom: 4
})
});
I get the following colse error:
Unhandled exception running script Event sheet 1, event 17, action 2: TypeError: Cannot read properties of undefined (reading 'Map')
If I remove the "myMaps." from "var map = new myMaps.ol.Map" in the above code then it works, but surely that is then not referring to the imported script?