I am trying to extend OpenLayers class with es6 syntax in typescript.
I have run a few tests in jest to verify that my new class is a VectorLayer instance. I have been able to use methods like setSource and they appear to work in tests. However, when I add my class to the map it doesn't seem to work (there are no features on the map as expected). I removed the features from the context of the class and added them to a Vector Layer the normal way and the features work.
export class GridLayer extends VectorLayer {
constructor () {
super()
const axisX = new LineString([[0, 1000], [1000, 1000]])
const axisY = new LineString([[1000, 0], [1000, 1000]])
const featureX = new Feature({ geometry: axisX })
const featureY = new Feature({ geometry: axisY })
this.setSource(new VectorSource({
features: [
featureX,
featureY
],
}))
}
}
expected, should see some LineString on the map. actual, nothing on the map.
I made a mistake in my import when importing the class to the file where the map was. Typescript didn't pick it up for some reason.
This is possible though. Very cool!