page2.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>全景标记设置(自动参数)</title>
  6. <script src="three.js"></script>
  7. <script src="/origin/tpanorama.js"></script>
  8. <style>
  9. body {
  10. margin: 0;
  11. overflow: hidden;
  12. }
  13. </style>
  14. <script>
  15. var opt, s, img;
  16. window.onload = function () {
  17. //默认参数
  18. opt = {
  19. container: 'set',//setting容器
  20. imgUrl: 'img/p3.png',
  21. width: '1000px',//指定宽度,高度自适应
  22. showGrid: true,//是否显示格网
  23. showPosition: true,//是否显示经纬度提示
  24. lableColor: '#9400D3',//标记颜色
  25. gridColor: '#48D1CC',//格网颜色
  26. lables: [
  27. { lon: -72.00, lat: 9.00, text: '蓝窗户' }, { lon: 114.12, lat: 69.48, text: '一片云彩' }, { lon: 132.48, lat: -12.24, text: '大海' }
  28. ],//标记 {lon:114,lat:38,text:'标记一'}
  29. addLable: true,//开启后双击添加标记 (必须开启经纬度提示)
  30. getLable: true,//开启后右键查询标记 (必须开启经纬度提示)
  31. deleteLbale: true//开启后中键删除(必须开启经纬度提示)
  32. };
  33. s = new tpanoramaSetting(opt);
  34. s.init();
  35. }
  36. function getAll() {
  37. var arr = s.getAllLables();
  38. var str = "";
  39. for (var i in arr) {
  40. str += "</br>" + "经度:" + arr[i].lon + ",纬度:" + arr[i].lat + ",标记:" + arr[i].text;
  41. }
  42. document.getElementById('info').innerHTML = str;
  43. }
  44. function changeImg(name) {
  45. if (name == "p1") {
  46. opt.lables = [{ lon: 178.56, lat: -15.84, text: '神像' }]
  47. }
  48. if (name == "p2") {
  49. opt.lables = [{ lon: -80.64, lat: -16.92, text: '蓝色' }, { lon: 46.80, lat: 10.44, text: '绿色' }]
  50. }
  51. if (name == "p4") {
  52. opt.lables = [{ lon: 48.96, lat: -20.16, text: '樱花' }]
  53. }
  54. img = 'img/' + name + '.png';
  55. opt.imgUrl = img;
  56. s.clean();
  57. s.config(opt);
  58. s.init();
  59. }
  60. function preview() {
  61. document.getElementById('set').innerHTML = '';
  62. var lables = s.getAllLables();
  63. s.clean();
  64. lables = lables.map((l) => ({
  65. position: { lon: l.lon, lat: l.lat },
  66. text: l.text
  67. }))
  68. opt = {
  69. container: 'set',//容器
  70. url: img || 'img/p3.png',
  71. lables: lables,
  72. widthSegments: 60,//水平切段数
  73. heightSegments: 40,//垂直切段数(值小粗糙速度快,值大精细速度慢)
  74. pRadius: 1000,//全景球的半径,推荐使用默认值
  75. minFocalLength: 6,//镜头最小拉近距离
  76. maxFocalLength: 100,//镜头最大拉近距离
  77. }
  78. tp = new tpanorama(opt);
  79. }
  80. </script>
  81. </head>
  82. <body>
  83. <div id="set"></div>
  84. </br>
  85. <button onclick="getAll()">获取所有标记</button>
  86. &nbsp;&nbsp;
  87. <button onclick="preview()">预览</button>
  88. &nbsp;&nbsp;
  89. <button onclick="changeImg('p1')">图1</button>
  90. &nbsp;&nbsp;
  91. <button onclick="changeImg('p2')">图2</button>
  92. &nbsp;&nbsp;
  93. <button onclick="changeImg('p4')">图4</button>
  94. </br>
  95. <div id="info"></div>
  96. </body>
  97. </html>