BIMsurfer icon indicating copy to clipboard operation
BIMsurfer copied to clipboard

mouse position problem when scrolling

Open wisoo opened this issue 5 years ago • 1 comments

Hello Rubendel,

I noticed a problem in cameracontrol.js i've been using bimsurfer, i inserted the canvas in a custom webpage when scrolling the scroll offset was not taken into account so i had to click above or below the objects to be able to select them.

a quick fix to this is using your getCanvasPosFromEvent() function before executing pick()

    canvasMouseUp(e) {
        this.camera.orbitting = false;
        this.viewer.overlay.update();

~~this.getCanvasPosFromEvent(e, this.mousePos);~~

        var canvasMousePos = this.getCanvasPosFromEvent(e, this.mousePos);

        let dt = e.timeStamp - this.mouseDownTime;
        this.mouseDown = false;

        switch (e.which) {
            case 1:
                if (dt < 500. && this.closeEnoughCanvas(this.mouseDownPos, this.mousePos)) {
                  console.log(this.mousePos)
                    var viewObject = this.viewer.

~~canvasPos: this.mousePos,~~

                        canvasPos: canvasMousePos,
                        // Changed: for multiselect is used Ctrl key
                        shiftKey: e.ctrlKey
                    });
                    if (viewObject && viewObject.object) {
                        console.log("Picked", viewObject.object);
                    }
                    this.viewer.drawScene();
                }
                break;
        }
        e.preventDefault();
    } 

Hope this helps keep up the good work !

wisoo avatar Jun 19 '19 15:06 wisoo

At the current version (0.0.6 beta - 8/8/2022), the above fix no longer works.

this.getCanvasPosFromEvent(e, this.mousePos) is modified this.mousePos and then return that exact value => so the new var canvasMousePos will be the same as this.mousePos.

The problem here is in CameraControl.getCanvasPosFromEvent(), we're using event.pageX and event.pageY subtract the offset from event.target.getBoundingClientRect() to get the click position on the canvas. -> But getBoundingClientRect is provides the information of the canvas related to the viewport, not to the page -> My fix is to change any pageX to clientX and pageY to clientY in that getCanvasPosFromEvent method.

Thanks ^^

anhle1476 avatar Aug 08 '22 11:08 anhle1476