0

I currently have a visualforce component in the account details page. In that component is an apex map component which has markers on it for accounts close to the current one of the details page you are currently on. To the left of the map is a list of all the accounts shown on the map. I was wondering if there is anyway that, when I press on the name of an account(to the left of the map, these are outputlinks), I could pan the map to show that account's marker. I have looked at the map class page on salesforce's website and several other places, but have not found any methods that do this. Perhaps y'all know something I do not.

In case my description was lacking here is what the component looks like(obviously with sample info).

enter image description here

EDIT

Le Code

The table that I'm using:

<apex:pageBlockTable ...>
<apex:column ...>
<apex:column ...>
<apex:column >
              <apex:commandLink action="{!setMapCenter}" onclick="setCenter()">
                  <apex:param name="compAcc" value="{!comp.ShippingStreet},{!comp.ShippingCity},{!comp.ShippingState}" assignTo="{!compAddress}"/>Show on map
              </apex:commandLink>
          </apex:column>
</apex:pageBlockTable>

The action function:

<apex:actionFunction name="setCenter">                      
              <apex:variable value="{!center}" var="centerVar"/>
              <apex:outputText value="{!center}" />              
          </apex:actionFunction>
</apex:form>

And then in my controller I have:

public PageReference setMapCenter()
    {
        center = compAddress;
        return null;
    }

That should be all the relevant code.

5
  • do you have two forms on the page or are they both in the same form? – techbusinessman Aug 4 '15 at 14:58
  • It is two different ones. I was under the impression that I could not put an action function in an iterative section (the pageBlockTable) – smurph006 Aug 4 '15 at 15:05
  • I think it's more why have a form in the pageblocktable ? Try wrapping the whole thing in one form. – techbusinessman Aug 4 '15 at 15:08
  • I've updated the question again, I think the only issue now is how I'm passing my param. I'm not sure how to concatenate the whole address in the correct way. I'll try the lat and long. – smurph006 Aug 4 '15 at 15:40
  • for your value just do {!comp.ShippingStreet & "," & comp.ShippingCity & "," & comp.ShippingState} – techbusinessman Aug 4 '15 at 15:50
0

I think you could do some panning by completing the following:

  1. Setup a variable in your class called mapCenter
  2. Assign a null value to the variable
  3. Set the center attribute on the map to the mapCenter variable
  4. onClick for your links, update the mapCenter variable to the lat/long of the account

Please see the documentation for further details on the center attribute of the apex:map component: Apex:Map Component

3
  • I've got this apex:variable which was initially null, I set it to the original center. That worked fine. However, I'm having some trouble setting the center variable from my apex:pageBlockTable. What i'm currently trying is making a column with a apex:form with an apex:commandLink which has an "onclick" to an apex:actionFunction. This action function assignsTo a variable in my controller, then in the same action function I try to set the center variable to what that param was. Does this sound reasonable? It doesn't really work right, but if I'm on the right track I'll keep trying this method. – smurph006 Aug 4 '15 at 14:18
  • It sounds reasonable to me. That said, it would be beneficial to edit your question and add some of the code snippets to give context to what you are doing. – techbusinessman Aug 4 '15 at 14:34
  • I've updated my question – smurph006 Aug 4 '15 at 14:56
1

Here is a simple example that I think is doing what you need.

public class MapController {

private String mapCenter;

public String setMapCenter(String center) {
    return this.mapCenter = center;
}

public String getMapCenter() {
    return this.mapCenter;
}

public PageReference setCenter() {
    return null;
}

}

Visualforce page below displays a map and two links (Los Angeles and San Francisco), once you click the link, the map is re-rendered with center set to the location you clicked on. Since the zoom level is not provided, the Visualforce Map component sets it so that all the markers are visible, but you can set the zoomLevel attribute you want to zoom in to the specific location.

<apex:page controller="MapController">
    <apex:form>
        <apex:commandLink action="{!setCenter}" value="Los Angeles, CA" reRender="map">
            <apex:param name="center" value="Los Angeles, CA" assignTo="{!mapCenter}"/>
        </apex:commandLink>
        <br/>
        <apex:commandLink action="{!setCenter}" value="San Francisco, CA" reRender="map">
            <apex:param name="center" value="San Francisco, CA" assignTo="{!mapCenter}"/>
        </apex:commandLink>
    </apex:form>
    <apex:outputPanel id="map">   
        <apex:map height="400px" width="600px" center="{!mapCenter}"> 
            <apex:mapMarker position="Los Angeles, CA"/>
            <apex:mapMarker position="San Francisco, CA"/>
        </apex:map>
    </apex:outputPanel>
</apex:page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.