You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Sunday, October 4th 2015, 9:59am

Get mouse click point before context menu opens

Hi.

I use the HTML5 viewer (krpano 1.18.5) and have a context menu option for adding a hotspot.

Source code

1
2
3
<contextmenu>
  <item name="addHotspotMenuItem" caption="Add hotspot" onclick="js(createHotspot())"/>
</contextmenu>


In my JavaScript file I have a function to handle the hotspot creation.

Source code

1
2
3
4
5
6
7
8
9
function createHotspot() {
    var krpano = document.getElementById("krpanoViewer");
 
    var mx = krpano.get("mouse.x");
    var my = krpano.get("mouse.y");
    var pt = krpano.screentosphere(mx, my);
 
    window.external.HotspotCreated(pt.x, pt.y);
}


The problem is that the mouse point is the where the mouse is at the moment that the context menuitem is clicked.
I need to get the point where the right-click was as this should be the hotspot point.
How is this best done?

A related question.
In addition to a using context menu for adding a hotspot it would be a nice feature to use a double-click event for adding the hotspot. Is this possible 'out-of-the-box' or is a plugin necessary for handling double-click events?

Thanks.

Best regards
Dan

2

Thursday, October 8th 2015, 8:14am

Hi,
I need to get the point where the right-click was as this should be the hotspot point.
How is this best done?
Good question and idea - there is currently no information or API about that, but I will think about something of the next releases (ideas for how to provide that information are welcome ;-)).


In addition to a using context menu for adding a hotspot it would be a nice feature to use a double-click event for adding the hotspot. Is this possible 'out-of-the-box' or is a plugin necessary for handling double-click events?
Double click events are currently not supported out-of-the-box.

Best regards,
Klaus

Tuur

Sage

Posts: 3,164

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

3

Thursday, October 8th 2015, 11:33am

Hi,

i would use a keycode for this.
So when you press H, put a new hotspot on the mouse location.
Or maybe.
Use the/a 'gaze'.
When right click, select add hotspot and then the 'little cross appears center screen (gaze) So then you can turn and define the location with a second menu option like 'set hotspot here' or keystroke. and the hotspot will be added at that place.

Or maybe: i can imagine that at the moment you do right click there is something that triggers the context menu to show, and position. I guess you only need the catch of that moment.
When possible, it would be the best i think to store the ath/atv of mouse of that moment in some vars before the context menu is shown.. and use them when add hotspot is selected.
(? could be nonsense or not possible of course)
*blink*
*g*

Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

This post has been edited 1 times, last edit by "Tuur" (Oct 8th 2015, 1:27pm)


4

Monday, October 26th 2015, 9:04am

Hi,

just as quick note - the next version (1.19-pr4) will provide 'mouse.downx' and 'mouse.downy' variables and there the position of the last mouse button press (for left and right mouse buttons) will be stored.

Then doing such add hotspot via the contextmenu will be possible.

Best regards,
Klaus

5

Wednesday, November 18th 2015, 8:04am

Thanks for the suggestions (and sorry for the late reply).

As Tuur suggested I'm using a key event for this. Pressing the 'h' or 'H' key will create a hotspot.
I'm also using a double-click event (2 click events within a certain time).

Source code

1
2
3
<events name="addHotspotEvent"
        onclick="js(panoramaClicked())"
        onkeyup="js(panoramaKeyed())" />


Source code

1
2
3
4
5
6
7
8
9
10
function panoramaKeyed(args) {
    var krpano = document.getElementById("krpanoViewer");

    if (window.canAddHotspot) {
        var keyCode = krpano.get("keycode");
        if (keyCode === 72 || keyCode === 104) {
            createHotspot();
        }
    }
}


Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function panoramaClicked(args) {
    if (window.canAddHotspot) {
        window.clickCount++;
        if (window.clickCount == 1) {
            setTimeout(function () {
                if (window.clickCount > 1) {
                    createHotspot();
                }
 
                window.clickCount = 0;
            }, 300);
        }
    }
}


Excellent news about the new variables *thumbsup* , I will be looking forward to it.


Best regards
Dan