You are not logged in.

1

Thursday, February 7th 2019, 3:02pm

getattributes usage

Hi,

I would like to browse attributes of a given hotspot to copy only a subset of them to another hotspot. Like copyattributes() but with a way to say "copy this, not that". I tried to run around the getattributes() function, but I couldn't get it work from krpano itself.

Best shot I could give was to copy paste it, but the result looks so ugly...

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<action name="skd_SetStyleFromConfig" type="Javascript"> 

<![CDATA[ 
   var configobject = krpano.get(caller.configobjectname); 
   var entriesArray = Object.entries(configobject); 
   entriesArray.forEach(([key, value]) => {
        if ((typeof value !== 'function') && (typeof value !== 'object') && (key.charAt(0) !== '_') ) { 
               console.log(`${key} ${value}`); 
              <!-- get/set in progress --> 
         } 
    }); 
 ]]> 

 </action>


I'm sure I got the wrong way... I'm new to using js/krpano together, it's tough to get into it when one is not a js expert.

Thanks

Florian

This post has been edited 5 times, last edit by "lerayfle" (Feb 7th 2019, 5:57pm)


2

Wednesday, February 20th 2019, 11:42pm

Hi Florian,
I'm solving this issue by following code. It's part of my current Work In Proggress so please focus on the tagattributes in the panotag_settings:

Source code

1
2
3
<panotag_settings ... 
tagattributes="'name', 'newname', 'style', 'title', 'subtitle', 'note', 'tagstate', 'scenename', 'tagfileurl', 'ath', 'atv', 'tagsize'" 
/>

How I use it in krpano JS action see my snipet below. First I create an Array, and then I use the array to copy, or so:

Source code

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
36
37
38
39
40
41
42
 	<action name="panotagging_install" type="Javascript" autorun="onstart" devices="html5"><![CDATA[

		// convert panotag_settings.tagattributes to panotag_settings.tagAttrArr
		var tagAttrArr = [];
		krpano.get('global.panotag_settings.tagattributes').split(',').forEach(function(tagattr){
				tagattr = tagattr.replace(/[\' ]/g, "");
	            tagAttrArr.push(tagattr);
		});
		krpano.set('global.panotag_settings.tagattrarr', tagAttrArr)
		

		// add an 'panotags_save' action to krpano
		krpano.panotags_save = function(method, subject, datasrc, callback)	{

			// Action call 
			var _action_call = 'panotags_save.js' + '(', a = arguments;
			for (var i = 0; i < a.length; i++) _action_call += a[i] + ', '; _action_call = _action_call.replace(/, $/,')');  //>
			var Now = function () { return( new Date().toTimeString().slice(0,9)) };  	//clasic function

	 		var sc = krpano.get('global.scene[get(global.xml.scene)]');
//console.log(sc); 		
			var scdata = {};
			scdata.name = sc.name;
			scdata.index = sc.index;
			scdata.tagfileurl = sc.tagfileurl;
			scdata.tagAttrArr = krpano.get('global.panotag_settings.tagattrarr');			

			var tagList = [];

			// panotags to save 
			krpano.get(datasrc).getArray().forEach(function(tag){
				var hotspotObj = krpano.get('hotspot[' + tag.name + ']');
				if(hotspotObj.ispanotag) {
					var tagObj = {};
					tagAttrArr.forEach(function(tagattr){
						if (hotspotObj[tagattr]) tagObj[tagattr] = hotspotObj[tagattr] + "";	//convert to string!
					});
		            tagList.push(tagObj);
				}
			});
			scdata.tags2save = tagList;
...



Hoping it helps!
Pavel

3

Saturday, March 2nd 2019, 12:00pm

Hi,

Thanks

I don't really get what the _action_callback is for, nor approx 50% of your code, your example is way beyond my js knowledge lol.

However I think your line with the getArray() method inspires me.


Source code

1
 krpano.get(datasrc).getArray().forEach(function(tag){...


I need to check that.

Huge thanks,

Florian

4

Tuesday, March 5th 2019, 10:15pm

Florian,
Sorry for perplexing you, but what copies attributes from tagAttrArr is just here:

Source code

1
2
3
tagAttrArr.forEach(function(tagattr){
  if (hotspotObj[tagattr]) tagObj[tagattr] = hotspotObj[tagattr] + "";	//convert to string!
  });

Pavel

5

Thursday, March 7th 2019, 10:47pm

Thank you for that precision!

My initial request was to manage to use getattributes(), which I still haven't managed to do *sad*
Of course -your code shows it, , we can code it back from scratch. It's just that well, I wanted to use the higher level functions krpano was providing.