|
@@ -1,30 +1,28 @@
|
|
-import Vue from 'vue'
|
|
|
|
-import { convertJQHotspot } from './hotspot'
|
|
|
|
|
|
+import Vue from "vue";
|
|
|
|
+import { convertJQHotspot } from "./hotspot";
|
|
|
|
|
|
-let vue = new Vue()
|
|
|
|
|
|
+let vue = new Vue();
|
|
|
|
|
|
export default class Utils {
|
|
export default class Utils {
|
|
- constructor() {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ constructor() {}
|
|
/**
|
|
/**
|
|
* 设置初始视角
|
|
* 设置初始视角
|
|
*/
|
|
*/
|
|
setInitView(krpano, canvas) {
|
|
setInitView(krpano, canvas) {
|
|
let url = this.setInitAngleImg(canvas);
|
|
let url = this.setInitAngleImg(canvas);
|
|
- var sceneName = krpano.get('xml.scene');
|
|
|
|
|
|
+ var sceneName = krpano.get("xml.scene");
|
|
var hlookat = krpano.get("view.hlookat");
|
|
var hlookat = krpano.get("view.hlookat");
|
|
var vlookat = krpano.get("view.vlookat");
|
|
var vlookat = krpano.get("view.vlookat");
|
|
return {
|
|
return {
|
|
sceneName,
|
|
sceneName,
|
|
hlookat,
|
|
hlookat,
|
|
vlookat,
|
|
vlookat,
|
|
- url
|
|
|
|
- }
|
|
|
|
|
|
+ url,
|
|
|
|
+ };
|
|
}
|
|
}
|
|
|
|
|
|
scaleCanvas(canvas, width, height) {
|
|
scaleCanvas(canvas, width, height) {
|
|
- let w = canvas.width
|
|
|
|
|
|
+ let w = canvas.width;
|
|
let h = canvas.height;
|
|
let h = canvas.height;
|
|
|
|
|
|
if (width == undefined) {
|
|
if (width == undefined) {
|
|
@@ -33,8 +31,8 @@ export default class Utils {
|
|
if (height == undefined) {
|
|
if (height == undefined) {
|
|
height = h;
|
|
height = h;
|
|
}
|
|
}
|
|
- var retCanvas = document.createElement('canvas');
|
|
|
|
- var retCtx = retCanvas.getContext('2d');
|
|
|
|
|
|
+ var retCanvas = document.createElement("canvas");
|
|
|
|
+ var retCtx = retCanvas.getContext("2d");
|
|
retCanvas.width = width;
|
|
retCanvas.width = width;
|
|
retCanvas.height = height;
|
|
retCanvas.height = height;
|
|
retCtx.drawImage(canvas, 0, 0, w, h, 0, 0, width, height);
|
|
retCtx.drawImage(canvas, 0, 0, w, h, 0, 0, width, height);
|
|
@@ -48,7 +46,7 @@ export default class Utils {
|
|
|
|
|
|
setInitAngleImg(mycanvas) {
|
|
setInitAngleImg(mycanvas) {
|
|
var url = this.getDataURL(mycanvas, "image/jpeg", 600, 400);
|
|
var url = this.getDataURL(mycanvas, "image/jpeg", 600, 400);
|
|
- return url
|
|
|
|
|
|
+ return url;
|
|
}
|
|
}
|
|
radarRotate() {
|
|
radarRotate() {
|
|
// console.log(sceneName,hlookat);
|
|
// console.log(sceneName,hlookat);
|
|
@@ -65,10 +63,10 @@ export default class Utils {
|
|
try {
|
|
try {
|
|
const hotspot = convertJQHotspot(param);
|
|
const hotspot = convertJQHotspot(param);
|
|
const hotspotStyle = Object.values(hotspot.style);
|
|
const hotspotStyle = Object.values(hotspot.style);
|
|
- const hotspotString = hotspotStyle.join('|');
|
|
|
|
|
|
+ const hotspotString = hotspotStyle.join("|");
|
|
|
|
|
|
const hotspotSize = (Number(hotspot.size) || 1) * 40;
|
|
const hotspotSize = (Number(hotspot.size) || 1) * 40;
|
|
- let icon = hotspot.icon.replace(/,/g, '|');
|
|
|
|
|
|
+ let icon = hotspot.icon.replace(/,/g, "|");
|
|
let title = this.htmlEncode(hotspot.title);
|
|
let title = this.htmlEncode(hotspot.title);
|
|
const callString = `editJQHotspot(
|
|
const callString = `editJQHotspot(
|
|
${hotspot.id},
|
|
${hotspot.id},
|
|
@@ -85,11 +83,10 @@ export default class Utils {
|
|
// krpano.stopcall(callString);
|
|
// krpano.stopcall(callString);
|
|
krpano.call(callString);
|
|
krpano.call(callString);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('error', error);
|
|
|
|
|
|
+ console.error("error", error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 添加热点
|
|
* 添加热点
|
|
*/
|
|
*/
|
|
@@ -99,16 +96,18 @@ export default class Utils {
|
|
* type: 0,系统图标 , 1.自定义图际. 2.序列帧 3.个性标签
|
|
* type: 0,系统图标 , 1.自定义图际. 2.序列帧 3.个性标签
|
|
*/
|
|
*/
|
|
try {
|
|
try {
|
|
- krpano.set("curscreen_x", krpano.get('stagewidth') / 2);
|
|
|
|
- krpano.set("curscreen_y", krpano.get('stageheight') / 2);
|
|
|
|
- krpano.call("screentosphere(curscreen_x, curscreen_y, curscreen_ath, curscreen_atv);");
|
|
|
|
|
|
+ krpano.set("curscreen_x", krpano.get("stagewidth") / 2);
|
|
|
|
+ krpano.set("curscreen_y", krpano.get("stageheight") / 2);
|
|
|
|
+ krpano.call(
|
|
|
|
+ "screentosphere(curscreen_x, curscreen_y, curscreen_ath, curscreen_atv);"
|
|
|
|
+ );
|
|
const hotspot = convertJQHotspot(param);
|
|
const hotspot = convertJQHotspot(param);
|
|
const hotspotStyle = Object.values(hotspot.style);
|
|
const hotspotStyle = Object.values(hotspot.style);
|
|
- const hotspotString = hotspotStyle.join('|');
|
|
|
|
|
|
+ const hotspotString = hotspotStyle.join("|");
|
|
const hotspotSize = (Number(hotspot.size) || 1) * 40;
|
|
const hotspotSize = (Number(hotspot.size) || 1) * 40;
|
|
- const ath = hotspot.ath != '' ? hotspot.ath : krpano.get("curscreen_ath");
|
|
|
|
- const atv = hotspot.atv != '' ? hotspot.atv : krpano.get("curscreen_atv");
|
|
|
|
- let icon = hotspot.icon.replace(/,/g, '|');
|
|
|
|
|
|
+ const ath = hotspot.ath != "" ? hotspot.ath : krpano.get("curscreen_ath");
|
|
|
|
+ const atv = hotspot.atv != "" ? hotspot.atv : krpano.get("curscreen_atv");
|
|
|
|
+ let icon = hotspot.icon.replace(/,/g, "|");
|
|
let title = this.htmlEncode(hotspot.title);
|
|
let title = this.htmlEncode(hotspot.title);
|
|
const callString = `addJQHotspot(
|
|
const callString = `addJQHotspot(
|
|
${hotspot.id},
|
|
${hotspot.id},
|
|
@@ -124,7 +123,7 @@ export default class Utils {
|
|
)`;
|
|
)`;
|
|
krpano.call(callString);
|
|
krpano.call(callString);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('error', error);
|
|
|
|
|
|
+ console.error("error", error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -133,23 +132,22 @@ export default class Utils {
|
|
*/
|
|
*/
|
|
|
|
|
|
getCurrentMousePosition(krpano, hotspotName) {
|
|
getCurrentMousePosition(krpano, hotspotName) {
|
|
- let panoW = krpano.get('stagewidth')
|
|
|
|
- let panoH = krpano.get('stageheight')
|
|
|
|
|
|
+ let panoW = krpano.get("stagewidth");
|
|
|
|
+ let panoH = krpano.get("stageheight");
|
|
|
|
|
|
- let stagex = krpano.get('mouse.stagex')
|
|
|
|
- let stagey = krpano.get('mouse.stagey')
|
|
|
|
|
|
+ let stagex = krpano.get("mouse.stagex");
|
|
|
|
+ let stagey = krpano.get("mouse.stagey");
|
|
|
|
|
|
if (stagex < 0 || stagex > panoW || stagey < 0 || stagey > panoH) {
|
|
if (stagex < 0 || stagex > panoW || stagey < 0 || stagey > panoH) {
|
|
- return
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- krpano.call('screentosphere(mouse.stagex, mouse.stagey, toh, tov)')
|
|
|
|
|
|
+ krpano.call("screentosphere(mouse.stagex, mouse.stagey, toh, tov)");
|
|
// const toh = krpano.get('toh');
|
|
// const toh = krpano.get('toh');
|
|
// const tov = krpano.get('tov');
|
|
// const tov = krpano.get('tov');
|
|
// console.log('toh', toh);
|
|
// console.log('toh', toh);
|
|
// console.log('tov', tov);
|
|
// console.log('tov', tov);
|
|
- krpano.set(`hotspot[${hotspotName}].ath`, krpano.get('toh'));
|
|
|
|
- krpano.set(`hotspot[${hotspotName}].atv`, krpano.get('tov'));
|
|
|
|
-
|
|
|
|
|
|
+ krpano.set(`hotspot[${hotspotName}].ath`, krpano.get("toh"));
|
|
|
|
+ krpano.set(`hotspot[${hotspotName}].atv`, krpano.get("tov"));
|
|
}
|
|
}
|
|
|
|
|
|
htmlEncode(str) {
|
|
htmlEncode(str) {
|
|
@@ -160,69 +158,67 @@ export default class Utils {
|
|
s = s.replace(/\(/g, "(");
|
|
s = s.replace(/\(/g, "(");
|
|
s = s.replace(/\)/g, ")");
|
|
s = s.replace(/\)/g, ")");
|
|
s = s.replace(/,/g, ",");
|
|
s = s.replace(/,/g, ",");
|
|
|
|
+ s = s.replace(/</g, "◻");
|
|
|
|
+ s = s.replace(/>/g, "◻");
|
|
|
|
+ s = s.replace(/\*/g, "◻");
|
|
|
|
+ s = s.replace(/\*/g, "◻");
|
|
|
|
+
|
|
return s;
|
|
return s;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- *
|
|
|
|
- * @param {*} 定位热点
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param {*} 定位热点
|
|
*/
|
|
*/
|
|
|
|
|
|
looktohotspot(krpano, hotspotName) {
|
|
looktohotspot(krpano, hotspotName) {
|
|
- var curFov = krpano.get('view.fov');
|
|
|
|
- krpano.call('looktohotspot(' + hotspotName + ',' + curFov + ')');
|
|
|
|
|
|
+ var curFov = krpano.get("view.fov");
|
|
|
|
+ krpano.call("looktohotspot(" + hotspotName + "," + curFov + ")");
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
- *
|
|
|
|
- * @param {*} 定位热点
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param {*} 定位热点
|
|
*/
|
|
*/
|
|
|
|
|
|
getHotspotHV(krpano, hotspotName) {
|
|
getHotspotHV(krpano, hotspotName) {
|
|
var ath = krpano.get(`hotspot[${hotspotName}].ath`);
|
|
var ath = krpano.get(`hotspot[${hotspotName}].ath`);
|
|
var atv = krpano.get(`hotspot[${hotspotName}].atv`);
|
|
var atv = krpano.get(`hotspot[${hotspotName}].atv`);
|
|
- return { ath, atv }
|
|
|
|
|
|
+ return { ath, atv };
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 打开热点链接
|
|
* 打开热点链接
|
|
*/
|
|
*/
|
|
|
|
|
|
linkopen(sceneCode, id) {
|
|
linkopen(sceneCode, id) {
|
|
- if (window.location.pathname.indexOf('show') > -1) {
|
|
|
|
- vue.$bus.emit('clickHotspot', id)
|
|
|
|
- }
|
|
|
|
- else if (window.location.pathname.indexOf('edit') > -1) {
|
|
|
|
- vue.$bus.emit('openHotspot', id)
|
|
|
|
|
|
+ if (window.location.pathname.indexOf("show") > -1) {
|
|
|
|
+ vue.$bus.emit("clickHotspot", id);
|
|
|
|
+ } else if (window.location.pathname.indexOf("edit") > -1) {
|
|
|
|
+ vue.$bus.emit("openHotspot", id);
|
|
|
|
+ } else {
|
|
|
|
+ window.parent.postMessage(
|
|
|
|
+ { event: "hotspot", targetCode: sceneCode },
|
|
|
|
+ "*"
|
|
|
|
+ );
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- window.parent.postMessage({ event: 'hotspot', targetCode: sceneCode }, '*')
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 初始化
|
|
* 初始化
|
|
*/
|
|
*/
|
|
|
|
|
|
initHotspot(krpano, someData, type) {
|
|
initHotspot(krpano, someData, type) {
|
|
-
|
|
|
|
if (!someData) {
|
|
if (!someData) {
|
|
- return
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- let mysd = someData
|
|
|
|
- if (typeof someData == 'string') {
|
|
|
|
- mysd = JSON.parse(someData)
|
|
|
|
|
|
+ let mysd = someData;
|
|
|
|
+ if (typeof someData == "string") {
|
|
|
|
+ mysd = JSON.parse(someData);
|
|
}
|
|
}
|
|
|
|
|
|
- mysd.hotspots.forEach(item => {
|
|
|
|
- this.addhotspot(krpano, item, type)
|
|
|
|
|
|
+ mysd.hotspots.forEach((item) => {
|
|
|
|
+ this.addhotspot(krpano, item, type);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -234,17 +230,15 @@ export default class Utils {
|
|
try {
|
|
try {
|
|
krpano.call(`set_hotspot_visible(${toggle})`);
|
|
krpano.call(`set_hotspot_visible(${toggle})`);
|
|
} catch (e) {
|
|
} catch (e) {
|
|
- e
|
|
|
|
|
|
+ e;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 显示隐藏热点
|
|
* 显示隐藏热点
|
|
*/
|
|
*/
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// toggleHotspot(krpano,someData,toggle){
|
|
// toggleHotspot(krpano,someData,toggle){
|
|
// if (!someData) {
|
|
// if (!someData) {
|
|
// return
|
|
// return
|
|
@@ -253,4 +247,4 @@ export default class Utils {
|
|
// mysd.hotspots.forEach(item => {
|
|
// mysd.hotspots.forEach(item => {
|
|
// krpano.set(`hotspot[${item.name}].visible`,toggle);
|
|
// krpano.set(`hotspot[${item.name}].visible`,toggle);
|
|
// });
|
|
// });
|
|
-// }
|
|
|
|
|
|
+// }
|