-
Notifications
You must be signed in to change notification settings - Fork 0
/
hotspot.js
104 lines (74 loc) · 3.09 KB
/
hotspot.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
var fs = require('fs');
var xml2js = require('xml2js');
var utils = require('./libs/utils.js');
var tour_xml = utils.lerArquivo('./tour.xml');
var tour_array = utils.xml2Array(tour_xml);
var scenes_array = tour_array['krpano']['scene'];
// Traduzindo o Carregando
tour_array['krpano']['skin_settings'][0]['$']['loadingtext'] = "Carregando...";
for (let x = 0; x <= Object.keys(scenes_array).length - 1; x++) {
if (Object.keys(tour_array['krpano']['scene'][x]['hotspot']).length > 0) {
console.log(Object.keys(tour_array['krpano']['scene'][x]['hotspot']).length);
for (let y = 0; y <= Object.keys(tour_array['krpano']['scene'][x]['hotspot']).length - 1; y++) {
console.log(tour_array['krpano']['scene'][x]['hotspot'][y]['$']['name']);
if (tour_array['krpano']['scene'][x]['hotspot'][y]['$']['linkedscene'] != null) {
var hotspot = tour_array['krpano']['scene'][x]['hotspot'][y]['$'];
// Retorna o titulo de um texto
var texto_hotspot = returnSceneTitle(hotspot['linkedscene']);
// Verifica se já existe
var existe_hotspot = existeHotspotText(x, hotspot['name'] + '-text');
if (!existe_hotspot.existe) {
tour_array['krpano']['scene'][x]['hotspot'].push(addHotspotText(hotspot['name'], texto_hotspot, hotspot['ath'], hotspot['atv']));
}
/*
// Se existir ele atualiza
else {
console.log(tour_array['krpano']['scene'][x]['hotspot'][existe_hotspot.id]);
tour_array['krpano']['scene'][x]['hotspot'][existe_hotspot.id]['$']
}*/
}
}
}
}
var tour_xml2 = utils.array2Xml(tour_array);
utils.gravarArquivo(__dirname + '/tour_modificado.xml', tour_xml2);
function returnSceneTitle(name_scene) {
for (let i = 0; i <= Object.keys(scenes_array).length - 1; i++) {
if (tour_array['krpano']['scene'][i]['$']['name'] == name_scene) {
return tour_array['krpano']['scene'][i]['$']['title'];
}
}
}
function addHotspotText(name_hotspot, texto, ath, atv) {
atv = Number(atv) + 10;
return {
'$': {
name: name_hotspot + '-text',
type: 'text',
distorted: 'true',
ath: ath,
atv: atv,
html: texto,
css: 'font-family:Arial; font-weight: bolder; padding: 5px; font-size:20px; color:0xFFFFFF; text-align:center;',
wordwrap: 'true',
bg: 'true',
bgcolor: '#000000',
bgalpha: '0.6'
}
};
}
function existeHotspotText(scene_id, name_hotspot_text) {
var retorno = {
existe: false,
id: -1
};
for (let i = 0; i <= Object.keys(tour_array['krpano']['scene'][scene_id]['hotspot']).length - 1; i++) {
if (tour_array['krpano']['scene'][scene_id]['hotspot'][i]['$']['name'] == name_hotspot_text) {
retorno.existe = true;
retorno.id = i;
return retorno;
}
}
return retorno;
}