I've got a parent-child-relationship where the parent is called portfolio and the child called property object. All child objects have geolocation and address information.
I am implementing a lightning-map on the parent object and want to show all property objects by geolocation on the map.
The current problem is: When I do this dynamically with soql (by an apex class) no markers are shown. When I do this statically the markers are show.
That is my structure returning from the query (console.log):
[
{
"Name": "Hanseatic Trade Center Tower (Columbus Haus)",
"Geolocation__Latitude__s": 53.542909,
"Geolocation__Longitude__s": 9.985547,
"Street__c": "Am Sandtorkai 38 – 41",
"PostalCode__c": "20457",
"City__c": "Hamburg",
"Country__c": "Germany"
}
]
This is the content from the map marker array:
[
{
"location": {
"City": "Hamburg",
"Country": "Germany",
"PostalCode": "20457",
"Street": "Am Sandtorkai 38 – 41"
}
}
]
My code looks like the following:
import { LightningElement, api, track, wire } from 'lwc';
import relatedObjects from '@salesforce/apex/LWCPortfolioHelper.relatedObjects';
export default class PortfolioMap extends LightningElement {
@api recordId;
@track mapMarkers = [];
hasRendered = false;
renderedCallback(){
console.log('>>>PortfolioMap -- renderedCallback.');
if(! this.hasRendered){
this.hasRendered = true;
this.handleLoad();
}
}
handleLoad(){
relatedObjects({recordId: this.recordId})
.then(result => {
result.forEach(record => {
let marker = {
location: {
City: record.City__c,
Country: record.Country__c,
PostalCode: record.PostalCode__c,
Street: record.Street__c,
}
};
this.mapMarkers.push(marker);
})
})
.catch(error => {
console.error('>>>error: ' + error);
})
}
}
My template looks like the following (No marker on map):
<template>
<lightning-map
map-markers={mapMarkers}
markers-title='All related objects to this portfolio'
list-view='visible'
></lightning-map>
</template>