Bing 地图 AJAX Control V7 - 如何检测点击但不检测拖动?

发布于 2024-12-02 02:33:47 字数 87 浏览 2 评论 0原文

我的网页上有一个 Bing 地图,我想检测用户何时单击窗口。但是,我不希望检测用户何时拖动地图(这也会生成“单击”事件)。仅获取“纯”点击事件的最佳方法是什么?

I have a Bing map on my web page, and I want to detect when the user clicks in the window. However, I do not wish to detect when the user drags the map (this also generates a "click" event) . What is the best way to get only "pure" click events?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘虞初梦 2024-12-09 02:33:47

我的解决方案最终是手动检查单击位置是否接近鼠标被按下的位置。

Microsoft.Maps.Events.addHandler(map, "click", clickHandler);
Microsoft.Maps.Events.addHandler(map, "mousedown", function(me) { lastMouseDownPoint = new Microsoft.Maps.Point(me.getX(), me.getY());});


function clickHandler(mouseEventArgs){
  var point = new Microsoft.Maps.Point(mouseEventArgs.getX(), mouseEventArgs.getY());

  //Drag detection

  // Edited since the comma is incorrect, should be a plus as per pythagorean theorem
  var dist = Math.sqrt(Math.pow(point.x-lastMouseDownPoint.x,2) + Math.pow(point.y-lastMouseDownPoint.y,2));
  if(dist > 5) {
    // We call this a drag
    return;
  }

// We have a "pure" click and can process it

}

My solution ended up beeing a manual check if the click position was close to the position where the mouse was pushed down.

Microsoft.Maps.Events.addHandler(map, "click", clickHandler);
Microsoft.Maps.Events.addHandler(map, "mousedown", function(me) { lastMouseDownPoint = new Microsoft.Maps.Point(me.getX(), me.getY());});


function clickHandler(mouseEventArgs){
  var point = new Microsoft.Maps.Point(mouseEventArgs.getX(), mouseEventArgs.getY());

  //Drag detection

  // Edited since the comma is incorrect, should be a plus as per pythagorean theorem
  var dist = Math.sqrt(Math.pow(point.x-lastMouseDownPoint.x,2) + Math.pow(point.y-lastMouseDownPoint.y,2));
  if(dist > 5) {
    // We call this a drag
    return;
  }

// We have a "pure" click and can process it

}
送舟行 2024-12-09 02:33:47

非常简单:

Microsoft.Maps.Events.addHandler(map, 'click', onClick);

function onClick(e) {
    if (e.mouseMoved === false && e.isPrimary === true) {
        // Left click not being a drag
        ...
    }
}

mouseMoved 在拖放时为 true,否则为 false。

MouseEventArgs 文档 http://msdn.microsoft.com/en-us/library/ gg406731.aspx 不引用 mouseMoved :/

Very simple:

Microsoft.Maps.Events.addHandler(map, 'click', onClick);

function onClick(e) {
    if (e.mouseMoved === false && e.isPrimary === true) {
        // Left click not being a drag
        ...
    }
}

mouseMoved is true with a drag and drop and false otherwise.

The MouseEventArgs documentation http://msdn.microsoft.com/en-us/library/gg406731.aspx does not reference mouseMoved :/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文