In this module, you create a Lightning event used by AccountListItem to notify AccountMap that an account has been selected in the list. In response to this event, AccountMap centers the map on the selected account.
In the Developer Console, click File > New > Lightning Event. Specify AccountSelected as the bundle name and click Submit.
Implement the event as follows:
<aura:event type="APPLICATION">
<aura:attribute name="account" Type="Account"/>
</aura:event>
Click File > Save to save the file.
In the developer console, go back to the AccountListItem component.
Add an onclick handler to the anchor tag:
<a onclick="{!c.accountSelected}">{!v.account.Name}</a>
Click File > Save to save the component.
Click CONTROLLER (upper right corner in the code editor).
Define an accountSelected function defined as follows:
({
accountSelected : function(component) {
var event = $A.get("e.c:AccountSelected");
event.setParams({"account": component.get("v.account")});
event.fire();
}
})
Click File > Save to save the controller.
In the developer console, go back to the AccountMap component.
Add the following event registration immediately after the AccountsLoaded handler declaration:
<aura:handler event="c:AccountSelected" action="{!c.accountSelected}"/>
Click File > Save to save the component.
Click CONTROLLER (upper right corner in the code editor), and define a new accountSelected function positioned after accountsLoaded and implemented as follows:
Make sure you add a comma after the accountsLoaded function block.
accountSelected: function(component, event, helper) {
// Center the map on the account selected in the list
var map = component.get('v.map');
var account = event.getParam("account");
map.panTo([account.Location__Latitude__s, account.Location__Longitude__s]);
}
Click File > Save to save the controller.
Go back to the Salesforce1 app and reload Account Locator from the menu to see the changes. Select an account in the list: the map should automatically center on the selected account.