Sie sind nicht angemeldet.

1

Donnerstag, 26. November 2009, 01:21

OnDoubleClick -- MoveTo() -- ScreenToSphere()

Hi,

This thread comes in trying to answer to a post from Richard.
I would just like it to "move to and center" on double-click - just like Google street view.

After some search in the forum it seems there is a way to do...
Look at these post from KLAUS.
Explanation of jsmouse.swf plugin
Example to download
Also, it seems that an ondoubleclick event it is not yet implemented (but planned)... see here for reference: Any way to "double-click" to zoom?

So, as Klaus explains on the post above, I have used the jsmouse.swf plugin to be able to retrieve the mouse coordinates mouse.x and mouse.y and the screentosphere() function (note: these variables seem to be already implemented in Krpano 1.0.8 beta9 but the screentosphere() function does not... so the jsmouse.swf plugin is needed ) ...
And I have made a pseudo krpanodbclick() function to simulate an ondoubleclick event ...
So a code would be:
xml file: (Edited: I forgot the jsmouse.swf plugin)

Quellcode

1
2
3
4
5
6
7
8
9
10
11
<krpano version="1.0.8">

<events onclick="js(krpanodbclick(movetoscreentosphere()));" />

<plugin name="jsmouse" url="jsmouse.swf" keep="true" />

<image>
    <cubestrip  url="pano.jpg" />
</image>

</krpano>


JavaScript to be added inside the html file:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<script type="text/javascript">
// <![CDATA[

function krpano() 
{
return document.getElementById("krpanoSWFObject");
}

function krpanodbclick(arg) {
setTimeout("numclick = 0",300);
numclick = numclick + 1;
if (numclick == 2) {
eval(arg);
}
}

function movetoscreentosphere(){

var mousex = krpano().get("mouse.x");
var mousey = krpano().get("mouse.y");
var hvs = krpano().get("screentosphere("+mousex +","+mousey +")");
var hva = hvs.split(",");

var ath = Number( hva[0] );
var atv = Number( hva[1] );

krpano().call("moveto("+ ath +","+ atv +")");

}

// ]]>
</script>


I have tried this and it works ;-) ...


SAlut.

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »michel« (26. November 2009, 12:11)


bulp

Fortgeschrittener

Beiträge: 390

Wohnort: Malaysia

  • Nachricht senden

2

Donnerstag, 26. November 2009, 07:27

tq michel.. i will try that code.... :)

3

Donnerstag, 26. November 2009, 12:04

Hi,

SORRY.... I forgot to put the jsmouse.swf plugin in the xml file example....
So, the xml would be:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
<krpano version="1.0.8">

	<events onclick="js(krpanodbclick(movetoscreentosphere()));" />
	
	<plugin name="jsmouse" url="jsmouse.swf" keep="true" />

	<image>
    	<cubestrip  url="pano.jpg" />
	</image>
	
</krpano>


The jsmouse.swf plugin is needed on krpano 1.0.8 beta 8 and bellow... BUT NOT on krpano 1.0.8 beta 9


SAlut.

4

Donnerstag, 26. November 2009, 23:36

Move to mouse position on double click - examples

Hi,

Following, two examples online of the explained above:

SAlut

5

Dienstag, 1. Dezember 2009, 12:46

Michel,

This is fantastic work :-) 'm surprised there is not more reaction to this.

I will be trying it on my next panorama next week. I notice that the beta8 version seems a bit smoother, perhaps because of the extra mouse plugin ?

Thanks for looking into this, I know many people have talked about it.

ps: Is that the view from your house ? very nice *g*

6

Mittwoch, 2. Dezember 2009, 15:19

Hi Michel,

great work!
right, in 1.0.8 beta 9, there the "mouse.x" and "mouse.y" is already implemented,
so no need for an plugin there,

ps: Is that the view from your house ? very nice *g*
that's an holiday apartment in Croatia where I was making holidays some years ago
see here for "Balkon Apartment Rabac / Kroatien":
http://krpano.com/examples/multires/

best regards,
Klaus

7

Mittwoch, 10. November 2010, 10:53

Addition

I have an addition to the script provided in this thread, which is more production ready:

An action is defined as such:

Quellcode

1
2
3
4
5
  <action name="_onmousedown">
    js(Pano.registerClick());

    <!-- Do more magic -->
  </action>


And defined in javascript:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Pano is the component that we use to communicate between the actions in the .xml file and our javascript
// Pano.ui is a reference to the inner working of our plugin

Pano.registerClick = function() {
    // expose the current location of the mousepointer. This function is defined as
    // return { x: panoControl.get('mouse.x'), y: panoControl.get('mouse.y') };
    var loc = Pano.ui.getMouseFromViewer();
 
    // holder component to keep count of the clicks
    if (!Pano.clickRegister) Pano.clickRegister = { count: 0, x: 0, y: 0, fired: new Date().getTime() };

    // add 1 to the current clicks and check whether it's greater or equal to 2
    if (++Pano.clickRegister.count >= 2) {
        // The delta-x and delta-y should be within 20 pixels of the last click position, to prevent one from clicking
        // both in the left and right corner within 300 ms. and still have a doubleclick
        if (Math.abs(Pano.clickRegister.x - loc.x) < 20 && Math.abs(Pano.clickRegister.y - loc.y) < 20) {
            // the clicks should be within 300 ms.
            if (new Date().getTime() - Pano.clickRegister.fired < 300) {
                // here's the callback, do magic here
                Pano.ui.onSurfaceDoubleClick(loc.x, loc.y);
                // reset the number of clicks
                Pano.clickRegister.count = 0;
            }
        }
        else {
            // when the delta-x, delta-y is not within boundaries, set the number of clicks to 1
            Pano.clickRegister.count = 1;
        }
    }

    // set the meta-information about this last click
    Pano.clickRegister.x = loc.x;
    Pano.clickRegister.y = loc.y;
    Pano.clickRegister.fired = new Date().getTime();
}