I'm using leaflet to build custom styles for my different map features in Angular.
export class MapComponent {
protected _map: Map; // leaflet map
public pads: string[] = [];
.
.
.
.
L.geoJSON(geojsonFeature, {
onEachFeature: this.onEachFeature,
style: function (layer, feature, pads) {
return {color: "#FFF"}
}
}).addTo(this._map);
In the style: call, I pass in pads
as a parameter, but it's undefined within the function
if I make the function no longer in-line,
styler(feature, layer) {
console.log(this.pads);
}
Then update the call to:
L.geoJSON(geojsonFeature, {
onEachFeature: this.onEachFeature,
style: this.styler;
}
}).addTo(this._map);
I cannot access the this
keyword. I'm incredibly confused by the scoping of how all of this is interacting. I need to access my pads
array from either an inline or outside function.