Initializing leaflet map in angular2 component after DOM object exists

后端 未结 2 1317
南方客
南方客 2021-01-14 05:36

I\'m currently trying to create a leaflet map inside an angular material2 tab-group as below

import {Component, NgModule} from \'@angular/core\         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-14 06:10

    Looks like referencing directly the map container Element (through @ViewChild) is working without issue.

    import {Component, ViewChild} from '@angular/core';
    import 'leaflet';
    
    @Component({
        selector: 'minimap',
        template: `
    ` }) export class MiniMap implements OnInit { @ViewChild('mapDiv') mapContainer; ngOnInit() { this.map = L.map(this.mapContainer.nativeElement); } }

    Updated Plunk: https://plnkr.co/edit/HGWb3J1f5HL8shFW9EUN?p=preview

    However, it seems that you need to re-initialize the map size once the tab is revealed (at least the first time). See Data-toggle tab does not download Leaflet map

提交回复
热议问题