function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Angel Montiel 6Angel Montiel 6 

Problems solving "Using Events to Center the Map" trailhead

Hi,

This is the error that appears: 

Step Not yet complete... here's what's wrong: 
AccountListItem's JS controller doesn't get a reference to the AccountSelected event 
Note: you may run into errors if you've skipped previous steps.

I´ve done every step as they told me to do. If you could help me see the erro I would really appreciate it guys.

Hereare the screen shots of the part of the code that's been giving me problems:

- AccountList component:

<aura:component controller="AccountController">
<aura:registerEvent name="accountsLoaded" type="c:AccountsLoaded"/>
<aura:registerEvent name="accountSelected" type="c:AccountSelected"/>

    <aura:attribute name="accounts" type="Account[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

    <ul>
    <aura:iteration items="{!v.accounts}" var="account">
        <c:AccountListItem account="{!account}"/>
    </aura:iteration>
    </ul>
<li><a onclick="{!c.accountSelected}">{!v.account.Name}</a></li>

</aura:component>

- AccountList Controller:

({
    accountSelected : function(component) {
        var event = $A.get("e.c:AccountSelected");
        event.setParams({"account": component.get("v.account")});
        event.fire();
    }
})

Thank you guys.
david roberts UKdavid roberts UK
You've put the
<li><a onclick="{!c.accountSelected}">{!v.account.Name}</a></li>
in AccountList component.
I think it should go in AccountList Item component.
I got a bit further but got an error on selecting an account:
-------
Something has gone wrong. Action failed: c$AccountMap$controller$accountSelected [TypeError: Unable to get property 'reuseTiles' of undefined or null reference]
Failing descriptor: {c$AccountMap$controller$accountSelected}.
-------
Will have to look at it again.
Ken StantonKen Stanton
Anyone else have any ideas?  I'm completely stuck here, too.  
 
BennyStevensBennyStevens
same issue :-/
Jason NiebauerJason Niebauer
I ran into the same issue. I've worked through the steps again and was able to pass the verification step with the following code. Both the AccountMapController and the AccountListItemController have an accountSelected function. 

AccountMap.cmp
<aura:component >
    
    <aura:attribute name="map" type="Object"/>
    <aura:handler event="c:AccountsLoaded" action="{!c.accountsLoaded}"/>
	<aura:handler event="c:AccountSelected" action="{!c.AccountSelected}"/>
    
    <ltng:require styles="/resource/leaflet/leaflet.css"
                  scripts="/resource/leaflet/leaflet.js"
                  afterScriptsLoaded="{!c.jsLoaded}" />
    
    <div id="map"></div>
    
</aura:component>

AccountMapController.js
({
    jsLoaded: function(component, event, helper) {

        setTimeout(function() {
            var map = L.map('map', {zoomControl: false}).setView([37.784173, -122.401557], 14);
            L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
                {
                    attribution: 'Tiles © Esri'
                }).addTo(map);
            component.set("v.map", map);
        });
    },

    accountsLoaded: function(component, event, helper) {

        // Add markers
        var map = component.get('v.map');
        var accounts = event.getParam('accounts');
        for (var i=0; i<accounts.length; i++) {
            var account = accounts[i];
            var latLng = [account.Location__Latitude__s, account.Location__Longitude__s];
            L.marker(latLng, {account: account}).addTo(map);
        }  
    },

    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]);
    }
})

AccountList.cmp
<aura:component controller="AccountController">
	
    <aura:registerEvent name="accountsLoaded" type="c:AccountsLoaded"/>
    <aura:attribute name="accounts" type="Account[]" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    
    <ul>
        <aura:iteration items="{!v.accounts}" var="account" >
            <c:AccountListItem account="{!account}" />
        </aura:iteration>
    </ul>
    
</aura:component>

AccountListController.js
({
	doInit : function(component, event, helper) {
		var action = component.get("c.findAll");
        action.setCallback(this, function(a){
            component.set("v.accounts", a.getReturnValue());
            var event = $A.get("e.c:AccountsLoaded");
            event.setParams({"accounts": a.getReturnValue()});
            event.fire();
        });
        $A.enqueueAction(action);
	}
})

AccountListItem.cmp
<aura:component >
    
    <aura:registerEvent name="accountSelected" type="c:AccountSelected"/>
    <aura:attribute name="account" type="Account"/>
    
    <li><a onclick="{!c.accountSelected}">{!v.account.Name}</a></li>
    
</aura:component>

AccountListItemController.js
({
    accountSelected : function(component) {
        var event = $A.get("e.c:AccountSelected");
        event.setParams({"account": component.get("v.account")});
        event.fire();
    }
})


However, selecting an account from the list gives me a different error when testing the account selection functionality.

Error: Uncaught Assertion Failed!: Unkown conroller action 'AccountSelected' : undefined

I'll try reaching out to Trailhead support to see if they can identify why the code passes the verification, but does not work as expected.
david roberts UKdavid roberts UK
I've tried all sorts.
The list of accounts is correct but it doesn't draw the markers.
I tried creating a new marker but that didn't work.
Trailhead support?
BennyStevensBennyStevens
I have the feeling that since the Winter 17 release additional issues are occuring to this module... Before it was only the error messages, now it is also not mapping the markers anymore (similar to post David Robers UK)

Same Trailhead Project Module, other topic: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000kHVhIAM