I tried to call the setMarker() function in another function. But the markers ain´t set. I don´t know why, but maybe because the setMarker() function is async because of the Promise.
getCities()
getCities(rawData) {
for (const index in rawData['data']) {
if (rawData.meta.c0Name == 'city') {
const city: string = rawData['data'][index]['c0'];
if (city != undefined) {
this.setMarker(city);
}
}
}
setMarker()
setMarker(location: string) {
const provider = new OpenStreetMapProvider();
const query_promise = provider.search({
query: location,
});
query_promise.then(
(value) => {
// Success!
const x_coor = value[0].x;
const y_coor = value[0].y;
const label = value[0].label;
this.citiesLayer = [
L.marker([y_coor, x_coor])
.bindPopup('<b>Found location</b><br>' + label)
.addTo(this.citiesLayerGroup),
];
},
(reason) => {
console.log(reason); // Error!
}
);
}
The rawData I get from my webDataRocksComponent
getDataForMap() {
this.child.webDataRocks.getData(
{},
(rawData) => {
this.mapComponent.getCities(rawData);
},
(rawData) => {
this.mapComponent.getCities(rawData);
}
);
}