I think encodeLayer does not need to be a member of $scope