I'm trying to use the HitTest() method to have one kind of popup whenever the user clicks on a feature, and another kind of popup when they click anywhere else on the map. However, the HitTest method seems to be firing both the callback AND the errback methods when I click on a feature, so it is showing the non-feature popup every time I click on a feature. How do I get it to do something only when the hit test fails?
I tested something similar in js bin, and it's doing the same thing when I use the popup function I'm trying to use, but not when I just had it print to the console for the errback instead. So maybe the problem is my AddPointGraphic function somehow. Am I using this wrongly somehow?
https://jsbin.com/jakumihuwa/1/edit?html,output
Just the view: https://output.jsbin.com/jakumihuwa/
//Why is it firing both the callback and errback?
var screenPoint = {
x: event.x,
y: event.y
}
view.hitTest(screenPoint).then(
//callback
function (response) {
alert("hit")
}).otherwise(AddPointGraphic(event));
function AddPointGraphic(event) {
//clear previous graphics
view.graphics.removeAll();
//create new graphic
//console.log(event.mapPoint);
var pointGeometry = event.mapPoint;
var commentPointAtt = {
long: event.mapPoint.longitude,
lat: event.mapPoint.latitude
}
var commentPoint = new Graphic({
geometry: pointGeometry,
symbol: symbol,
attributes: commentPointAtt,
popupTemplate: commentPopupTemplate
});
view.graphics.add(commentPoint);
view.popup.open({
features: [commentPoint],
location: event.mapPoint
});
}
I tried using it in the hitTest(screenPoint).then(callback, errback) errback spot, but it did the same thing. I am new to 4.x and would appreciate any help.