<div id="bubble" class="bubble" style="bottom:0;left:82%;display:none;" > <div style="height:50px" id="title"></div> </div> <script type="text/javascript"> function onload(Cesium) { //气泡相关 var infoboxContainer = document.getElementById("bubble"); var viewer = new Cesium.Viewer('cesiumContainer'); //console.log(viewer); var scene = viewer.scene; var canvas = scene.canvas; var widget = viewer.cesiumWidget; var scenePosition = null; // 记录在场景中点击的笛卡尔坐标点 var dock = false; // 是否停靠 var handlerPoint_ellipse = new Cesium.DrawHandler(viewer,Cesium.DrawMode.Point); handlerPoint_ellipse.activate() handlerPoint_ellipse.drawEvt.addEventListener(function(evt){ var point = evt.object; var position = point.position; handlerPoint_ellipse.clear(); var boxEntity = viewer.entities.add({ position : position, box : {//换成billboard dimensions : new Cesium.Cartesian3(20.0, 20.0, 20.0), //material : color, fill : true, outline : false, outlineColor : Cesium.Color.BLACK, outlineWidth : 4 }, id:'yy' }); console.log(evt); }) //初始化viewer部件 scene.postRender.addEventListener(function(){ // 每一帧都去计算气泡的正确位置 if (scenePosition && !dock) { var canvasHeight = scene.canvas.height; var windowPosition = new Cesium.Cartesian2(); Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, scenePosition, windowPosition); infoboxContainer.style.bottom = (canvasHeight - windowPosition.y + 45) + 'px'; infoboxContainer.style.left = (windowPosition.x - 70) + 'px'; infoboxContainer.style.visibility = "visible"; } }); $('#loadingbar').remove(); try { //添加S3M图层服务 var promise = scene.open('http://localhost:8090/iserver/services/3D-CBD/rest/realspace'); Cesium.when(promise, function (layers) { if(!scene.pickPositionSupported){ alert('不支持深度拾取,属性查询功能无法使用!'); } var text=document.getElementById('title') // var layer = scene.layers.find('Building@CBD'); //设置相机视角 screenSpaceEventHandler.setInputAction(function(e) { viewer._.addEventListener(function(entity){ console.log(entity); var position = scene.pickPosition(e.position); scenePosition = position; text.innerText='我的ID是'+entity._id; $('#bubble').show(); }) // // // },Cesium.ScreenSpaceEventType.LEFT_CLICK)
再请教一个问题 为什么我在超图官网示例上面编辑添加点是没有问题 ; 同样的代码,复制粘贴过来 点就出不来 也没有报错
这两个错误是一直都有的 我用了IServer 的marker来添加点 是可以的
不是通过鼠标去点击的 是地图加载后直接加上去的 点位坐标都是正确的 如在超图官网里面能出来 但是到了本地就出不来了 所有都一样 只修改了图片的地址 图片地址也检查很多遍 是没有问题的
换了版本后报这个