The problem is that I am using Typescript 3.4.3 and the OpenLayer API is been documented only for Javascript. Somewhere I found that I need to install @types/ol": "^5.3.3" in order to use Openlayer with Typescript.
I have the following code but I do not get any error but also the map is not visible. I can not understand where the problem is.
I Did try some solutions that other users found useful like:
a) Ionic-Framework (4) - Openlayers map not working/visible (using a setTimeout)
b) https://stackoverflow.com/a/54281422/11873024
None of them works
map.page.ts
import Tile from 'ol/layer/Tile';
import Map from 'ol/Map';
import View from 'ol/View';
import OSM from 'ol/source/OSM';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
private map: Map;
// @ts-ignore
// b) @ViewChild('mapElementRef') mapElementRef: ElementRef;
constructor() {}
initializeMap() {
this.map = new Map({
target: 'map',
layers: [
new Tile({
source: new OSM()
}),
],
view: new View({
center: [0, 0],
zoom: 3
}),
});
}
ngOnInit() {
this.initializeMap();
// b) this.map.setTarget(this.mapElementRef.nativeElement);
}
}
map.page.html
<ion-content>
<div class="ion-padding">
<h3>Map Here!</h3>
</div>
<div id="map" class="map">
</div>
</ion-content>
I expected an error or a map, but i got nothing so I don't know what to search.