Created
October 17, 2018 06:58
-
-
Save amitastreait/885fcefeceb6cd04e451b6ee6086e742 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AllAccounts_MapController { | |
@AuraEnabled | |
public static List<Account> getAccList(){ | |
List<Account> accList = new List<Account>(); | |
accList = [Select Id, Name, ShippingStreet, ShippingCity, ShippingState, | |
ShippingPostalCode, ShippingCountry From Account | |
Where ShippingStreet!=null AND ShippingCity!= null AND ShippingState != null | |
AND ShippingPostalCode!= null AND ShippingCountry!=null]; | |
return accList; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
init: function (cmp, event, helper) { | |
var action = cmp.get('c.getAccList'); | |
action.setCallback(this, function(response){ | |
var state = response.getState(); | |
//alert(state); | |
if( state === 'SUCCESS'){ | |
var responseValue = response.getReturnValue(); | |
var mapArray = []; | |
for(var i = 0; i < responseValue.length; i++){ | |
console.log(' responseValue ', responseValue[i]); | |
mapArray.push( | |
{ | |
location: { | |
City: responseValue[i].ShippingCity, | |
Country: responseValue[i].ShippingCountry, | |
PostalCode: responseValue[i].ShippingPostalCode, | |
State: responseValue[i].ShippingState, | |
Street: responseValue[i].ShippingStreet | |
}, | |
icon: 'standard:account', | |
title: responseValue[i].Name | |
} | |
); | |
} | |
cmp.set('v.mapMarkers', mapArray); | |
cmp.set('v.center', { | |
location: { | |
City: 'Denver' | |
} | |
}); | |
cmp.set('v.zoomLevel', 4); | |
cmp.set('v.markersTitle', 'Salesforce locations in United States'); | |
cmp.set('v.showFooter', true); | |
//cmp.set('v.zoomLevel', 10); | |
} | |
}); | |
$A.enqueueAction(action); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component controller="AllAccounts_MapController" | |
implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" 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 }"/> | |
<!-- the map component --> | |
<aura:if isTrue="{!v.mapMarkers.length > 0}"> | |
<!-- the map component --> | |
<lightning:map | |
mapMarkers="{! v.mapMarkers }" | |
center="{! v.center }" | |
zoomLevel="{! v.zoomLevel }" | |
markersTitle="{! v.markersTitle }" | |
showFooter="{ !v.showFooter }" > | |
</lightning:map> | |
</aura:if> | |
</aura:component> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment