cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Call function based on visability of an image

SOLVED
Highlighted

Call function based on visability of an image

I'd like to call the function below base on the visibility of an image but i am unaware of how to do this. Could someone help please? 

$scope.intro = function() {
	var labelText = $scope.view.wdg['checkstart'].text;      
	var spokenText = labelText.substr(labelText.indexOf(" ") + 1);
	$scope.app.speech.synthesizeSpeech({ 'text': spokenText });	
}

Thanks

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Call function based on visability of an image

It depends on what you mean by "visability".

 

If you mean "when the visability parameter is set to true", then yes, you can do that using $scope.$watch, something like this:

$scope.$watch('view.wdg["image-1"].visible', function (val) {
    if (val) {
        $scope.intro();
    }
}

However, if you mean "when the user moves their device around so the image enters their field of view", then I think the answer is no. I don't think there's a way to detect whether an object is in the viewport or not. (I would be happy to be proven wrong, if there is a way to do this!) I also don't know of a way to get the location of the camera relative to the 3D view origin, so you can't try to derive it that way.

1 REPLY 1

Re: Call function based on visability of an image

It depends on what you mean by "visability".

 

If you mean "when the visability parameter is set to true", then yes, you can do that using $scope.$watch, something like this:

$scope.$watch('view.wdg["image-1"].visible', function (val) {
    if (val) {
        $scope.intro();
    }
}

However, if you mean "when the user moves their device around so the image enters their field of view", then I think the answer is no. I don't think there's a way to detect whether an object is in the viewport or not. (I would be happy to be proven wrong, if there is a way to do this!) I also don't know of a way to get the location of the camera relative to the 3D view origin, so you can't try to derive it that way.