资源下载:pannellum
预览图:
利用pannellum.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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title></title> <link rel="stylesheet" href="./dist/pannellum.css" /> <script type="text/javascript" src="./dist/pannellum.js"></script> <style> body, html { height: 100%; width: 100%; margin: 0 } #panorama { height: 100%; width: 100%; position: relative; } #controls { position: absolute; bottom: 0; z-index: 2; text-align: center; width: 100%; padding-bottom: 3px; } .ctrl { padding: 8px 5px; width: 30px; text-align: center; background: rgba(200, 200, 200, 0.8); display: inline-block; cursor: pointer; } .ctrl:hover { background: rgba(200, 200, 200, 1); } .container { height: 100% } .container ul { width: 220px; padding: 15px; height: 100%; background-color: #292929; display: block; float: left; border: 1px solid #bbb; margin: 0; } .container ul li { display: block; float: left; width: 100%; height: 35px; line-height: 35px; border-radius: 4px; margin: 0; padding: 0; list-style: none; background-color: #fff; margin-bottom: 10px; -moz-user-select: none; user-select: none; text-indent: 10px; color: #555; } .listContainer { width: 250px; float: left; height: 100% } .panoramaContainer { margin-left: 250px; height: 100% } .ul-context-menu { list-style: none; position: absolute; top: 0; left: 0; z-index: 9999; padding: 5px 0; min-width: 80px; margin: 0; display: none; font-family: "寰蒋闆呴粦"; font-size: 14px; background-color: #fff; border: 1px solid rgba(0, 0, 0, .15); box-sizing: border-box; border-radius: 4px; -webkit-box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); -moz-box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); -ms-box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); -o-box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); } .ul-context-menu .ui-context-menu-item { margin: 0; padding: 0; } .ul-context-menu .ui-context-menu-item a { display: block; padding: 0 10px; color: #333; white-space: nowrap; text-decoration: none; } .ul-context-menu .ui-context-menu-item a:hover { text-decoration: none; color: #262626; } .ul-context-menu .ui-context-menu-item .icon { width: 16px; height: 16px; margin-right: 8px; vertical-align: sub; border: 0; } </style> </head> <body id="body"> <div class="listContainer"> <div class="container"> <ul> <li>热点1</li> <li>热点2</li> <li>地图1</li> </ul> </div> </div> <div class="panoramaContainer"> <div id="panorama"> <div id="controls"> <div class="ctrl" id="pan-up">▲</div> <div class="ctrl" id="pan-down">▼</div> <div class="ctrl" id="pan-left">◀</div> <div class="ctrl" id="pan-right">▶</div> <div class="ctrl" id="zoom-in">+</div> <div class="ctrl" id="zoom-out">−</div> <div class="ctrl" id="fullscreen">⤢</div> </div> </div> </div> <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script> <script src="http://www.jq22.com/demo/jqueryContextMenu201707230044/js/jquery.contextMenu.min.js"></script> <script> var viewer = pannellum.viewer('panorama', { "default": { "firstScene": "circle", "author": "hywel", //作者 "sceneFadeDuration": 1000, "title": "全景图", //标题 "compass": true, //显示指南针 // "hotSpotDebug": true, "autoLoad": true, //自动加载 }, "scenes": { "circle": { "title": "房间", "hfov": 110, "pitch": -3, "yaw": 117, "type": "equirectangular", "panorama": "./403.jpg", "hotSpots": [{ "pitch": 2.8472794849336323, "yaw": -3.5066628798940442, "type": "scene", "text": "楼道", "sceneId": "house" }] }, "house": { "title": "房间", "hfov": 110, "yaw": 5, "type": "equirectangular", "panorama": "./Sample5-stitched.jpg", "hotSpots": [{ "pitch": 0.8797735985790178, "yaw": -10.00259738381312, "type": "scene", "text": "房间", "sceneId": "circle", "targetYaw": -23, "targetPitch": 2 }] } } }); // Make buttons work document.getElementById('pan-up').addEventListener('click', function (e) { viewer.setPitch(viewer.getPitch() + 10); }); document.getElementById('pan-down').addEventListener('click', function (e) { viewer.setPitch(viewer.getPitch() - 10); }); document.getElementById('pan-left').addEventListener('click', function (e) { viewer.setYaw(viewer.getYaw() - 10); }); document.getElementById('pan-right').addEventListener('click', function (e) { viewer.setYaw(viewer.getYaw() + 10); }); document.getElementById('zoom-in').addEventListener('click', function (e) { viewer.setHfov(viewer.getHfov() - 10); }); document.getElementById('zoom-out').addEventListener('click', function (e) { viewer.setHfov(viewer.getHfov() + 10); }); document.getElementById('fullscreen').addEventListener('click', function (e) { viewer.toggleFullscreen(); }); $(function () { //出入允许拖拽节点的父容器,一般是ul外层的容器 drag.init('container'); }); var drag = { class_name: null, //允许放置的容器 permitDrag: false, //是否允许移动标识 _x: 0, //节点x坐标 _y: 0, //节点y坐标 _left: 0, //光标与节点坐标的距离 _top: 0, //光标与节点坐标的距离 old_elm: null, //拖拽原节点 tmp_elm: null, //跟随光标移动的临时节点 new_elm: null, //拖拽完成后添加的新节点 //初始化 init: function (className) { //允许拖拽节点的父容器的classname(可按照需要,修改为id或其他) drag.class_name = className; //监听鼠标按下事件,动态绑定要拖拽的节点(因为节点可能是动态添加的) $('.' + drag.class_name).on('mousedown', 'ul li', function (event) { //当在允许拖拽的节点上监听到点击事件,将标识设置为可以拖拽 drag.permitDrag = true; //获取到拖拽的原节点对象 drag.old_elm = $(this); //执行开始拖拽的操作 drag.mousedown(event); return false; }); //监听鼠标移动 $(document).mousemove(function (event) { //判断拖拽标识是否为允许,否则不进行操作 if (!drag.permitDrag) return false; //执行移动的操作 drag.mousemove(event); return false; }); //监听鼠标放开 $(document).mouseup(function (event) { //判断拖拽标识是否为允许,否则不进行操作 if (!drag.permitDrag) return false; //拖拽结束后恢复标识到初始状态 drag.permitDrag = false; //执行拖拽结束后的操作 drag.mouseup(event); return false; }); }, //按下鼠标 执行的操作 mousedown: function (event) { console.log('我被mousedown了'); //1.克隆临时节点,跟随鼠标进行移动 drag.tmp_elm = $(drag.old_elm).clone(); //2.计算 节点 和 光标 的坐标 drag._x = $(drag.old_elm).offset().left; drag._y = $(drag.old_elm).offset().top; var e = event || window.event; drag._left = e.pageX - drag._x; drag._top = e.pageY - drag._y; //3.修改克隆节点的坐标,实现跟随鼠标进行移动的效果 $(drag.tmp_elm).css({ 'position': 'absolute', // 'background-color': '#FF8C69', 'left': drag._x, 'top': drag._y, }); // console.log(drag.tmp_elm) //4.添加临时节点 tmp = $(drag.old_elm).parent().append(drag.tmp_elm); drag.tmp_elm = $(tmp).find(drag.tmp_elm); $(drag.tmp_elm).css('cursor', 'move'); $(drag.tmp_elm).css('z-index', '9999'); $(drag.tmp_elm).css('width', '220px'); }, //移动鼠标 执行的操作 mousemove: function (event) { console.log('我被mousemove了'); //2.计算坐标 var e = event || window.event; var x = e.pageX - drag._left; var y = e.pageY - drag._top; var maxL = $(document).width() - $(drag.old_elm).outerWidth(); var maxT = $(document).height() - $(drag.old_elm).outerHeight(); //不允许超出浏览器范围 x = x < 0 ? 0 : x; x = x > maxL ? maxL : x; y = y < 0 ? 0 : y; y = y > maxT ? maxT : y; //3.修改克隆节点的坐标 $(drag.tmp_elm).css({ 'left': x, 'top': y, }); }, //放开鼠标 执行的操作 mouseup: function (event) { console.log('我被mouseup了'); //移除临时节点 coords = viewer.mouseEventToCoords(event); var pitch = viewer.getPitch(); var yaw = viewer.getYaw(); var hfov = viewer.getHfov(); console.log(coords) viewer.addHotSpot({ "id": 'hotspot' + $(drag.tmp_elm).text(), "pitch": coords[0], "yaw": coords[1], "type": "info", "text": $(drag.tmp_elm).text(), "URL": "javascript:void(0);" }); $(drag.tmp_elm).remove(); }, }; //阻止浏览器默认右键点击事件 $(document).bind("contextmenu", function () { return false; }) var curHot = []; $(document).on('mousedown', '#panorama', function (event) { curHot[0] = ''; curHot[1] = ''; event.stopPropagation(); }); $(document).on('mousedown', 'a', function (event) { // console.log(event.which) if (3 == event.which) { $(this).contextMenu({ menu: [{ text: "新增", callback: function () { alert("新增"); } }, { text: "复制", callback: function () { alert("复制"); } }, { text: "粘贴", callback: function () { alert("粘贴"); } }, { text: "删除", callback: function () { alert("删除"); } } ] }); } else if (1 == event.which) { curHot[0] = 'hotspot' + $(this).find('span').text(); curHot[1] = $(this).find('span').text(); var temp = $(this).clone(); var c = viewer.mouseEventToCoords(event); var e = event || window.event; var scrollX = $("#panorama").offset().left; var scrollY = $("#panorama").offset().top; var x = e.clientX - scrollX; var y = e.clientY - scrollY; $(temp).attr('id', 'mousemoveId') $(temp).children('div').css({ "position": 'absolute', "left": x - 13, "top": y - 13, "z-index": 9999, "width": 26, "height": 26, "transform": '' }) $("#panorama").append(temp) $(this).hide(); } event.stopPropagation(); }); $(document).on('mousemove', '#panorama', function (event) { if (3 == event.which) { } else if (1 == event.which) { var e = event || window.event; var scrollX = $("#panorama").offset().left; var scrollY = $("#panorama").offset().top; var x = e.clientX - scrollX; var y = e.clientY - scrollY; $("#mousemoveId").children('div').css({ "position": 'absolute', "left": x - 13, "top": y - 13, "z-index": 9999, "width": 26, "height": 26, "transform": '' }) } }); $(document).on('mouseup', '#panorama', function (event) { if (3 == event.which) { } else if (1 == event.which) { $("#mousemoveId").remove(); if (curHot[0] != '') { var oldcoords = coords; coords = viewer.mouseEventToCoords(event); if (coords[0] != oldcoords[0]) { viewer.removeHotSpot(curHot[0]); viewer.addHotSpot({ "id": curHot[0], "pitch": coords[0], "yaw": coords[1], "type": "info", "text": curHot[1], "URL": "javascript:void(0);", // "OnClick": 'text()' }); } } } }); </script> </body> </html> |