0

I have a function that grabs the mouses lat and long in cesium when the mouse is clicked. However, if you drag, it still runs the function. I put an if statement in the function to make sure it runs when my variable, app.drag is false. app.drag is turned to true when the mouse moves. Now I need to check when the mouse has stopped so app.drag can go back to false. Doing !'mousemove' doesn't work so how do you do that? I think this is the best method to check if the mouse is dragged, but if there's a simpler way, please let me know. My code:

    app.drag = false;
    app.viewer.scene.canvas.addEventListener("mousemove", () => app.drag = true);
    app.viewer.scene.canvas.addEventListener("click", function(e) {
      if (!app.drag) {
        let ellipsoid = app.viewer.scene.globe.ellipsoid;
        let cartesian = app.viewer.camera.pickEllipsoid(new Cesium.Cartesian3(e.clientX, e.clientY), ellipsoid);
        let cartographic = ellipsoid.cartesianToCartographic(cartesian);
        let latitude = Cesium.Math.toDegrees(cartographic.latitude);
        let longitude = Cesium.Math.toDegrees(cartographic.longitude);
        document.getElementById("lat").value = Math.round(latitude);
        document.getElementById("lon").value = Math.round(longitude);
      }
    });
  • You could use window.setTimeout() to reset app.drag after, say, 500 milliseconds without movement – Erich Kitzmueller Mar 02 '22 at 21:20
  • https://stackoverflow.com/questions/6042202/how-to-distinguish-mouse-click-and-drag – epascarello Mar 02 '22 at 21:21
  • I would use the Drag & Drop api to handle all this, https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API Why re-invent the wheel with mousedown mousemove etc. – Keith Mar 02 '22 at 21:30

0 Answers0