quentinlampin / ngx-openlayers

Angular2+ components for Openlayers 4.x
Mozilla Public License 2.0
137 stars 98 forks source link

The map is not showing inside a modal #270

Closed ramiassi closed 2 years ago

ramiassi commented 2 years ago

I was trying to display a map inside a BsModalRef when it didn't show up. I used the basic provided sample:

<aol-map [width]="'100%'" [height]="'300px'">
  <aol-view [zoom]="2">
      <aol-coordinate [x]="5.795122" [y]="45.210225" [srid]="'EPSG:4326'"></aol-coordinate>
  </aol-view>
  <aol-layer-tile>
      <aol-source-osm></aol-source-osm>
  </aol-layer-tile>
</aol-map>

It is showing correctly in all the other components as long as they are not inside a modal. The problem is that there is no errors in the browser console or the compiler.

ramiassi commented 2 years ago

I could force the map to redraw itself by calling the updateSize method. I have chosen to redraw the map After View Initialization:

ngAfterViewInit(): void {
    setTimeout(() => {
      this.map.instance.updateSize();
    }, 200);
  }