<!DOCTYPE html> <html> <head> <meta charset='UTF-8'/> <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/> <link href='http://bigemap.com:9000/bigemap-gl.js/v1.1.0/Widgets/widgets.css' rel='stylesheet'/> <script src='http://bigemap.com:9000/bigemap-gl.js/v1.1.0/bigemap-gl.js'></script> <style> body { margin: 0; padding: 0; } #container { position: absolute; top: 0; bottom: 0; width: 100%; } .info{ position: fixed; top:0; color: #8a6d3b; z-index: 99; margin: 0; background-color: #fcf8e3; border-color: #faebcc; left: 0; right: 0; text-align: center; } #button{ position: absolute; top:50px; right: 20px; z-index: 999; } .info{ position: fixed; top:0; color: #8a6d3b; z-index: 99; margin: 0; background-color: #fcf8e3; border-color: #faebcc; left: 0; right: 0; text-align: center; } .bmgl-widget-credits{display:none} </style> <title>获取相机的位置</title> </head> <body> <div class="info"> 当前相机的位置: </div> <button id="button">获取相机的位置,并还原</button> <div id='container'></div> <script> bmgl.Config.HTTP_URL = 'http://bigemap.com:9000'; var viewer = new bmgl.Viewer('container', { // terrainId: 'bigemap.9af15d8e', //timeline:true, //animation:true, mapId: 'bigemap.zhongkexingtu' }); var cacheData=localStorage.getItem('cameraPosition'); if (cacheData){ try{ cacheData=JSON.parse(cacheData); viewer.camera.setView({ destination:bmgl.Cartesian3.fromDegrees(cacheData.destination.lng,cacheData.destination.lat,cacheData.destination.height), orientation:cacheData.orientation }); }catch (e){ console.log(e); } } document.getElementById('button').onclick=function (){ //获取最新的位置 var view={}; var p=bmgl.Cartographic.fromCartesian(viewer.camera.position); view.destination={lng:bmgl.Math.toDegrees(p.longitude),lat:bmgl.Math.toDegrees(p.latitude),height:p.height} view.orientation={heading:viewer.camera.heading,roll:viewer.camera.roll,pitch:viewer.camera.pitch} console.log(view); var info=['lng:',view.destination.lng,'lat:',view.destination.lat,'height:',view.destination.height,'heading:',view.orientation.heading,'pitch:',view.orientation.pitch,'roll:',view.orientation.roll]; document.querySelector('.info').innerHTML='当前相机的位置:'+info.join(" "); localStorage.setItem('cameraPosition',JSON.stringify(view)); } </script> </body> </html>
源码