I've set up my application using angular5 with ngx-leaflet (https://github.com/Asymmetrik/ngx-leaflet).
I start with a blank map. When a user clicks a button, markers appear on the map. When a user selects a marker, that marker is identified to a country and that country is linked with other countries based on some other (non-important) data.
<div id="map-sidebar">
<div class="map-buttons-bar">
<button class="btn btn-primary" (click)="addLayer()">Set Marker</button>
</div>
</div>
In my .ts file, I have
addLayer(){
var n_marker = marker([38.9072, -77.0369], {icon: this.anomalyIcon});
n_marker.on('click', (e)=>{
this.mapToPartnerCountries();
})
this.lLayers.push(n_marker);
}
mapToPartnerCountries(){
var n_marker = marker([39.9072, -78.0369], {icon: this.anomalyIcon});
this.lLayers.push(n_marker);
//var newLayer = geoJSON(geo as any);
//this.lLayers.push(newLayer);
}
My issue is the new layer does not appear when the mapToPartnerCountries() method is run. But if I click the button again, it appears. GeoJson does the same thing as well. Am I doing this the correct way?
Also the this.lLayers field is used in the map element...
<div class="map-container"
leaflet
[leafletOptions]="mapOptions"
[leafletLayersControl]="layersControl"
[leafletLayers]="lLayers"
>