You are not logged in.

1

Thursday, August 23rd 2018, 5:13pm

How to limit dragable map image in its container layer?

Hello!

Recently I am trying to find a solution to limit the dragable map layer in my tour, I add a layer as map container, and in which there is a map image with the action draglayer(), everything goes well but the map can be dragged out of the screen. I am wondering if there is a method to limit the draggable map image in the map container all the time. Is there an example source code of limiting draglayer for me take study? Or someone could teach me how to make it happen? I will be very appreciated for your any response on my question. Thanks very much!!

By the way, the tour is at http://www.cnvtgo.com/shangxi/tourmap.html
and the source xml is at http://www.cnvtgo.com/shangxi/tour_map.xml
The following codes are for the action draylayer, I take them in the krpano examples *smile* , I think it should be to add some lines in the following codes but I have no idea what to add *confused* :

<action name="draglayer">
if(%1 != dragging,
copy(drag_currentx, x);
copy(drag_currenty, y);
copy(drag_stagex, mouse.stagex);
copy(drag_stagey, mouse.stagey);
set(drag_sx, +1);
set(drag_sy, +1);
if(align == righttop, set(drag_sx,-1); );
if(align == right, set(drag_sx,-1); );
if(align == rightbottom, set(drag_sx,-1); set(drag_sy,-1); );
if(align == bottom, set(drag_sy,-1); );
if(align == leftbottom, set(drag_sy,-1); );
draglayer(dragging);
,
if(pressed,
sub(dx, mouse.stagex, drag_stagex);
sub(dy, mouse.stagey, drag_stagey);
mul(dx, drag_sx);
mul(dy, drag_sy);
add(x, drag_currentx, dx);
add(y, drag_currenty, dy);
delayedcall(0, draglayer(dragging) );
);
);
</action>

San7

Professional

Posts: 626

Occupation: coding in krpano

  • Send private message

2

Friday, August 24th 2018, 12:45pm

Hi, I'm using this code to drag and drop with a constraint.
But you can have a larger map window and this will not work correctly, try to scale the map size under the preview window.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
	<action name="draglayer">
		    copy(drag_currentx, x);
		    copy(drag_currenty, y);
		    copy(drag_stagex, mouse.stagex);
		    copy(drag_stagey, mouse.stagey);
		    indexoftxt(align_contains_right, get(align), 'right');
		    indexoftxt(align_contains_bottom, get(align), 'bottom');
		    calc(drag_align_x, align_contains_right GE 0 ? -1 : +1);
		    calc(drag_align_y, align_contains_bottom GE 0 ? -1 : +1);
		    asyncloop(pressed,
			          calc(x, drag_currentx + (mouse.stagex - drag_stagex)*drag_align_x);
			          calc(y, drag_currenty + (mouse.stagey - drag_stagey)*drag_align_y);
                                  clamp(x, 0, calc(stagewidth - layer[calc('' + name + '')].width));
                                  clamp(y, 0, calc(stageheight - layer[calc('' + name + '')].height));
		             );
	</action>

3

Sunday, August 26th 2018, 10:20pm

Hi Jasonliu,

Based on San7's code who helped me in October (thank San7 for sharing it) I made small vtourskin.xml enhancement to resize the map container:
https://krpano.com/forum/wbb/index.php?p…ight=#post76162
Maybe it's solving (partially) your problem. The height of the map container in the krpano vtourskin.xml is not so easy to change so I'm changing just the width. And the problem of running out of area limit is solved, too. Just download the vtourskin.xml and read

Source code

1
<action name="skin_map_resize" >


Have a great day!
Pavel

4

Sunday, September 2nd 2018, 6:01pm

Thanks very much for pur and San7's sharing *smile* *smile* , I use scrollarea plugin to limit the map dragged out of the screen area but the map is not able to be zoomed in and out.