Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class ChildContactMapController {
@AuraEnabled
public static List<Address> contactAddressMap(String recordId) {
List<Address> adressList = new List<Address>();
List<Contact> conList = [SELECT ID, Name, MailingStreet, MailingCity, MailingState, MailingCountry, MailingPostalCode from Contact
WHERE AccountID =: recordId];
for(Contact con : conList) {
location location = new location(con.MailingStreet, con.MailingCity,con.MailingState,con.MailingCountry,con.MailingPostalCode);
adressList.add(new Address(location, con.Name));
}
return adressList;
}
public class Address {
@AuraEnabled
public location location;
@AuraEnabled
public string icon;
@AuraEnabled
public string title;
@AuraEnabled
public string description;
public address(location locTemp, string titleTemp) {
location = locTemp;
title = titleTemp;
icon = 'standard:contact';
}
}
public class location {
@AuraEnabled
public string Street;
@AuraEnabled
public string City;
@AuraEnabled
public string PostalCode;
@AuraEnabled
public string State;
@AuraEnabled
public string Country;
public location(string StreetTemp, string CityTemp, string StateTemp, string CountryTemp, string PostalCodeTemp) {
Street = StreetTemp;
City = CityTemp;
PostalCode = PostalCodeTemp;
State = StateTemp;
Country = CountryTemp;
}
}
}
<aura:component controller="ChildContactMapController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
<!-- attributes -->
<aura:attribute name="mapMarkers" type="Object"/>
<aura:attribute name="center" type="Object" />
<aura:attribute name="zoomLevel" type="Integer" />
<aura:attribute name="markersTitle" type="String" />
<aura:attribute name="showFooter" type="Boolean" />
<!-- handlers-->
<aura:handler name="init" value="{! this }" action="{! c.init }"/>
<aura:if isTrue="{!v.mapMarkers.length > 0}" >
<lightning:map
mapMarkers="{! v.mapMarkers }"
center="{! v.center }"
zoomLevel="{! v.zoomLevel }"
markersTitle="{! v.markersTitle }"
showFooter="{ !v.showFooter }" >
</lightning:map>
</aura:if>
</aura:component>
({
init: function (cmp, event, helper) {
var action = cmp.get('c.contactAddressMap');
var recordId = cmp.get('v.recordId');
action.setParams({recordId: recordId});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === 'SUCCESS') {
cmp.set('v.mapMarkers',response.getReturnValue() );
cmp.set('v.center', {
location: {
City: 'Denver'
}
});
cmp.set('v.zoomLevel', 4);
cmp.set('v.markersTitle', 'Contact Locations Marker');
cmp.set('v.showFooter', true);
}
});
$A.enqueueAction(action);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.