You need to sign in to do that
Don't have an account?
Travis McDonald
How to change the color of apex:mapsmarker
Hello, There are many discussions on how to map locations with google maps prior to the spring 2015 release, but now that apex:map and apex:mapmarker are available, I would like to figure out how to modify the marker color using that to bring in a new map rather than the javascript methods that have been previously used.
I currently importing the map to account pages with this code on the visualforce page:
I then have an apex class that uses this code:
This code lets you map multple places on an account page, by selecting the parent/child relationship that the accounts are a part of, translating the address for those accounts to geocode, and then displaying the points on a map of a parent account and it's child accounts..
What I'm running into however, is there is almost no documentation on how to change the color of apex:mapmarker. What I would like to do is set it up so that I can change the color of the mapmarker based on a custom field variable. I would also like to potentially change the color of the markers based on the parent/child relationship. However, any help at all on how to change the color/marker icon of apex:mapmarker would be greatly appreciated.
Thank you!
I currently importing the map to account pages with this code on the visualforce page:
<apex:page standardController="Account" extensions="accountMapExtensionTwo"> <!--This page must be accessed with an Account Id in the URL. --> <apex:map width="600px" height="400px" mapType="roadmap"> <apex:repeat value="{!Accounts}" var="acct"> <apex:mapMarker title="{!acct.name}" position="{!acct.loc}"/> </apex:repeat> </apex:map> </apex:page> <!--<apex:page standardController="Account" extensions="accountMapExtension"> This page must be accessed with an Account Id in the URL. <apex:map width="600px" height="400px" mapType="roadmap"> <apex:repeat value="{!Accounts}" var="acct"> <apex:mapMarker title="{!Accounts[acct].Name}" position="{!Accounts[acct].BillingStreet},{!Accounts[acct].BillingCity},{!Accounts[acct].BillingState}"/> </apex:repeat> </apex:map> </apex:page>-->
I then have an apex class that uses this code:
public class accountMapExtensionTwo { private final Account account; public accountMapExtensionTwo(ApexPages.StandardController stdController) { this.account = (Account)stdController.getRecord(); } List<DisplayAccounts> Accts; public List<DisplayAccounts> getAccounts() { Map<Id,Account> mapList = new Map<Id,Account>(); Set<Account> childList = new Set<Account>(); Set<Id> parentId = new Set<Id>(); Accts = new List<DisplayAccounts>(); for(Account a : [SELECT Name, Location__longitude__s, Location__latitude__s, Parent.Id, BillingStreet, BillingCity, BillingState, (SELECT Name, Location__longitude__s, Location__latitude__s, BillingStreet, BillingCity, BillingState FROM ChildAccounts) FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('Id')]){ accts.add(new DisplayAccounts(a)); mapList.put(a.id,a); parentId.add(a.Parent.id); for(Account acc : a.ChildAccounts){ accts.add(new DisplayAccounts(acc)); mapList.put(acc.id,acc); } } List<Account> mapValueList = new List<Account>(); mapValueList = mapList.values(); for(Account a : [SELECT Name, Location__longitude__s, Location__latitude__s, BillingStreet, BillingCity, BillingState, (SELECT Name, BillingStreet, BillingCity, BillingState FROM ChildAccounts) FROM Account WHERE Id IN :mapValueList]){ for (Account acc : a.ChildAccounts){ accts.add(new DisplayAccounts(acc)); mapList.put(acc.id,acc); } } for(Account a : [SELECT Parent.Id FROM ACCOUNT WHERE Id IN :parentId]){ parentId.add(a.Parent.Id); } for(Account a : [SELECT Name, Location__longitude__s, Location__latitude__s, BillingStreet, BillingCity, BillingState FROM Account WHERE Id IN :parentId]){ accts.add(new DisplayAccounts(a)); mapList.put(a.id,a); } return accts; } public class DisplayAccounts { private Account acct; public DisplayAccounts (Account a){ this.acct = a; } public Map<String,Double> loc { get { return new Map<String,Double>{ 'latitude' => acct.Location__latitude__s, 'longitude' => acct.Location__longitude__s }; } } public String name { get { return acct.Name;} } } }This works perfect for what I'm trying to do, I should note that I'm using geocode for the map marker location.
This code lets you map multple places on an account page, by selecting the parent/child relationship that the accounts are a part of, translating the address for those accounts to geocode, and then displaying the points on a map of a parent account and it's child accounts..
What I'm running into however, is there is almost no documentation on how to change the color of apex:mapmarker. What I would like to do is set it up so that I can change the color of the mapmarker based on a custom field variable. I would also like to potentially change the color of the markers based on the parent/child relationship. However, any help at all on how to change the color/marker icon of apex:mapmarker would be greatly appreciated.
Thank you!
Please see Salesforce Summer '15 Release Notes for the upcoming enhancements that will allow to specify custom icons for markers:
http://releasenotes.docs.salesforce.com/en-us/summer15/release-notes/rn_vf_maps_enhancements_custom_icons.htm?edition=&impact= (http://releasenotes.docs.salesforce.com/en-us/summer15/release-notes/rn_vf_maps_enhancements_custom_icons.htm?edition=&impact=)