[英]Touch Screen Tap fires onClick Event twice
I developed a Javascript web application using dojo
and the ESRI Javascript API. 我使用dojo
和ESRI Javascript API开发了Javascript Web应用程序。 The main page of the application is a map view where the user can add points on the map. 应用程序的主页是一个地图视图,用户可以在其中添加地图上的点。
On my desktop web browser, when I click the map a single new point is added and if I debug I can see that my onClick
handler is called only once. 在桌面Web浏览器上,当我单击地图时,将添加一个新点,并且如果进行调试,我可以看到我的onClick
处理程序仅被调用一次。
On my iPad, when I tap the map 2 points are added in the exact same location. 在我的iPad上,当我点击地图时,会在完全相同的位置添加2个点。 When I debug the app on the iPad via Safari on my Macbook Pro I can see that the onClick
handler is being called twice. 当我通过Macbook Pro上的Safari在iPad上调试应用程序时,我看到onClick
处理程序被调用了两次。 Upon further debugging, I have made sure that the code that creates my onClick
handler is only being called once. 经过进一步调试,我确保创建我的onClick
处理程序的代码仅被调用一次。
startEditing : function(template) {
main.selectHandle.pause();
main.moveHandle.pause();
var drawingTool = template.template.drawingTool;
switch(drawingTool) {
case FeatureTemplate.TOOL_POINT:
drawingTool = Draw.POINT;
break;
}
this.drawEndHandle = on(this.drawingToolbar, "draw-end", lang.hitch(this, this.createFeature, template));
this.drawingToolbar.activate(drawingTool);
},
stopEditing : function() {
this.drawingToolbar.deactivate();
this.drawEndHandle.remove();
main.selectHandle.resume();
main.moveHandle.resume();
},
createFeature : function(template, evt) {
var featureLayer = template.featureLayer;
template = template.template;
var prototype = template.prototype;
var geometry = evt.geometry;
var graphic = new Graphic(prototype.toJson());
graphic.setGeometry(geometry);
this.initAttributes(graphic, featureLayer).then(function() {
var features = [graphic];
featureLayer.applyEdits(features).then(function(addResults) {
var objectIds = array.map(addResults, function(addResult) {
return addResult.objectId;
});
var q = new Query();
q.objectIds = objectIds;
featureLayer.selectFeatures(q).then(function(features) {
main.openForm(features);
});
});
});
},
The drawingToolbar
in the startEditing
function above is provided by the ESRI Javascript API, but handles the onClick
event internally and passes it onto the onDrawEnd
event that I am handling in my code. 上面的startEditing
函数中的drawingToolbar
由ESRI Javascript API提供,但在内部处理onClick
事件,并将其传递给我在代码中处理的onDrawEnd
事件。 I have other code that handles the onClick
event directly and it also fires twice. 我还有其他代码可直接处理onClick
事件,并且还会触发两次。
UPDATE 更新
I just tested the same functionality on my Android smartphone and it is also firing the onClick
event twice with a single tap. 我刚刚在Android智能手机上测试了相同的功能,并且一次单击就触发了两次onClick
事件。
I have the exact same issue in an application I am building. 我正在构建的应用程序中存在完全相同的问题。 I am also using the ESRI Javascript API. 我也在使用ESRI Javascript API。
I feel like there must be an event handler in either the map, the feature layer, or one of the dijit containers that passes along a tap event differently than the click. 我觉得在地图,要素图层或一个dijit容器中必须有一个事件处理程序,该事件处理程序通过点击事件的方式与单击不同。
In the end, I just debounced my click handler as described here: http://unscriptable.com/2009/03/20/debouncing-javascript-methods/ 最后,我只是按照以下说明对点击处理程序进行了反跳处理: http : //unscriptable.com/2009/03/20/debouncing-javascript-methods/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.