Inside this loop:

as above, you will need to check that the portal is drawn on the map - map.hasLayer(portal)