0

I have to create the leaflet map where I have used the angular formly .

and I have created the custom component for leaflet map as

leaflet.component.ts

import { Component, OnInit } from '@angular/core';
declare let L: any

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class LeafletComponent implements OnInit {

    constructor() {

    }

    ngOnInit() {
        const map = L.map('map').setView([51.509865,-0.118092], 10);

        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: '© OpenStreetMap contributors'
        }).addTo(map);
    }

}

And I ahve included the css and html for the above map in main Angular formly component as

.formly.component.html

  <mat-tab label="AREAS COVERED">
      
        <div id="map"></div>
      </mat-tab>

.formly.component.css

div{
    height: 500px;
    width: 500px;
}

and In app.module.ts I have added the custom component as

app.module.ts

import { LeafletComponent } from './ang-formly/ang-formly/leaflet-component';

@NgModule({
  declarations: [
    AppComponent,

LeafletComponent,


Now the Map is not loading Can anyone help me how to add this custom component in angular formly

7
  • I have explained it in this page: stackoverflow.com/questions/67667646/… Commented May 31, 2021 at 8:49
  • Yes I have create as You mentiond but facing the problem with how to include in the main (formly component).Can you help me how to include this leaflet component in main formly component
    – user1
    Commented May 31, 2021 at 8:57
  • I explained including it completely. Would you mind you explaining your problem clearly? Commented May 31, 2021 at 9:02
  • I have created the formly component with tabs each tab containing the 3 tabs containing the form fields and fourth tab has to show the map .that is the way In fomly main component I have placed the div from custom leaflet component data as <mat-tab label="AREAS COVERED"> <div id="map "></div> </mat-tab>. But it is not loading the data
    – user1
    Commented May 31, 2021 at 9:07
  • I add Styles to that link . Please add each code part to your project , step by step. Commented May 31, 2021 at 9:38

0