<!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%; } #add{ position: absolute; left: 0; color: #333; background-color: #f1f1f1; padding: 15px; width: 260px; right: 0; } .bmgl-widget-credits{display:none} </style> <title>part_test</title> </head> <body> <div id='container'></div> <div id="add"> 这是一个div </div> <script> bmgl.Config.HTTP_URL = 'http://bigemap.com:9000'; var viewer = new bmgl.Viewer('container', { terrainId: 'bigemap.9af15d8e', mapId: 'bigemap.zhongkexingtu' }); var position=bmgl.Cartesian3.fromDegrees(104,30,520); viewer.camera.setView({ destination:bmgl.Cartesian3.fromDegrees(104,30,20000000) }); viewer.scene.preRender.addEventListener(function () { var p_2d=viewer.scene.cartesianToCanvasCoordinates(position); if (bmgl.defined(p_2d)){ var div_dom=document.getElementById('add'); div_dom.style.left=p_2d.x+'px'; div_dom.style.top=p_2d.y+'px'; var c_p=viewer.scene.camera.position; if (viewer.scene.globe.ellipsoid.cartesianToCartographic(c_p).height+viewer.scene.globe.ellipsoid.maximumRadius>bmgl.Cartesian3.distance(position,c_p)){ div_dom.style.display='block'; }else{ div_dom.style.display='none'; } } }); </script> </body> </html>
源码