Skip to content

Instantly share code, notes, and snippets.

@tushar30
Last active October 22, 2018 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tushar30/982a353efc07b0207ed3c621a7d37e80 to your computer and use it in GitHub Desktop.
Save tushar30/982a353efc07b0207ed3c621a7d37e80 to your computer and use it in GitHub Desktop.
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