Generating a OpenLayers map as a Component

I was able to generate the map as a component thanks to the @robinyo links. What I needed to change was:

Define map variable as the OL Map class in the beggining of the code and load the map inside ngOnInit(). This also loads the styles buttons that don’t load in previous example. I still need to update the size of the map to show him though. The blurry screen in mobile appear to be a device thing, if I try to open the OL online example page it is also blurry.


import { Component, OnInit, Renderer, ViewChild } from '@angular/core';
import { NavController, Platform } from '@ionic/angular';
import { Map } from 'ol';
import { OSM, Vector as VectorSource } from 'ol/source.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';

  selector: 'app-openlayers',
  templateUrl: './openlayers.component.html',
  styleUrls: ['./openlayers.component.scss'],
export class OpenlayersComponent implements OnInit {

	map: Map;
  	constructor() { }
  	ngOnInit() { = new Map({
		  layers: [
		  	new TileLayer({ 
		  		source: new OSM()
		  target: document.getElementById('map'),
		  view: new View({
		    center: [0, 0],
		    zoom: 3
		setTimeout(() => {;
  	  	}, 500);

  	  	  	Ionic Blank
  	<link rel="stylesheet" href="">
	<style>html, body { margin: 0; }</style>



<div id="map" class="map"></div>

1 Like