i start from the scratch to build a Rails 6 Application with Openlayers 6.1.1. with Webpacker and Turbolinks. Many things are working fine, also with turbolinks. But one thing will not work fine: Openlayers. I add openlayers with yarn an it is basically working. So i can create a map as i expected, but i am not able to add a VectorLayer. If i do this i will get a console message with :
target.addEventListener is not a function
I mean i am importing all required libs. In my application.js
require("@openlayers/pepjs")
require("ol")
In my map.js
import 'ol/ol.css';
import Feature from 'ol/Feature';
import Map from 'ol/Map';
import MVT from 'ol/format/MVT';
import View from 'ol/View';
import GeoJSON from 'ol/format/GeoJSON';
import Circle from 'ol/geom/Circle';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
//import { Circle as CircleStyle, Fill, Stroke, Style } from 'ol/style';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
And my map object:
var vectorLayer = new VectorLayer({
source: new VectorSource({
url: 'v1/track/journey',
format: new GeoJSON()
}),
});
var OSMMap = new TileLayer({
source: new OSM({
attributions: [
'(c) OpenStreetMap'
],
opaque: false,
url: 'http://10.232.200.17/tiles/osm/{z}/{x}/{y}.png'
})
});
// OL Test
var map = new Map({
layers: [
OSMMapHLC1,
VectorLayer
],
target: 'map',
view: new View({
center: [0, 0],
zoom: 2
})
});
- I tried it without turbolinks
- I added pepjs
- I added jquery manually
- I tried Leaflet. Result VectorLayers an Realtime Plugin working fine.
Hint. I have to use Openlayers not Leaflet.
Many thanks to everyone who can help.
Regards Marco