I created a small application using JavaScript API 4.2 (3D) which works fine. Now, I am trying to replicate the same within WAB. However, I have a problem executing sceneView.hitTest() function. it gave me an "Uncaught TypeError". I am new to WAB so I can't figure out what I am doing wrong. I would greatly appreciate any inputs.
Here is the error I am getting and code.
onOpen: function(){
console.log('onOpen');
this.sceneView.on("click", function(event){
var screenPoint = {x: event.x, y: event.y};
console.log(screenPoint);
this.sceneView.hitTest(screenPoint).then(function(res){
console.log(res.results[0]);
});
});
},
Thank you,
Makiko
Solved! Go to Solution.
Makiko,
Your issue is the scope of "this" has changed inside your sceneView click event handler. So to get past that you need to use lang.hitch:
onOpen: function(){
console.log('onOpen');
this.sceneView.on("click", lang.hitch(this, function(event){
var screenPoint = {x: event.x, y: event.y};
console.log(screenPoint);
this.sceneView.hitTest(screenPoint).then(function(res){
console.log(res.results[0]);
});
}));
},
Makiko,
Your issue is the scope of "this" has changed inside your sceneView click event handler. So to get past that you need to use lang.hitch:
onOpen: function(){
console.log('onOpen');
this.sceneView.on("click", lang.hitch(this, function(event){
var screenPoint = {x: event.x, y: event.y};
console.log(screenPoint);
this.sceneView.hitTest(screenPoint).then(function(res){
console.log(res.results[0]);
});
}));
},
Robert,
Learning lang.hitch is game changing!! Thank you so much!!