Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjOWM3MzYxZS0xNDg5LTRhYzgtOTE3ZS1hMTgyNmFmNzY5ZDIiLCJpZCI6MTYwNTYsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1Njk0NzMxMjl9.QT-UwdXK6VZyYMhtznEEIru0AEQEzMPxDlxQw96mTlA'; var viewer = new Cesium.Viewer('cesiumContainer'); //鹰眼方式1 var viewer1 = new Cesium.Viewer('eye',{}); //设置鹰眼图属性 var control = viewer1.scene.screenSpaceCameraController; control.enableRotate = false; control.enableTranslate = false; control.enableZoom = false; control.enableTilt = false; control.enableLook = false; var syncViewer = function(){ viewer1.camera.flyTo({ destination : viewer.camera.position, orientation : { heading : viewer.camera.heading, pitch : viewer.camera.pitch, roll : viewer.camera.roll }, duration : 0.0 }); }; //同步鹰眼 //viewer.scene.preRender.addEventListener(syncViewer); //鹰眼方式2 viewer.entities.add({ position : Cesium.Cartesian3.fromDegrees(0,0), label : { text : new Cesium.CallbackProperty( function(){ syncViewer(); return ""; }, true ) } }); /* var viewer = new Cesium.Viewer('cesiumContainer',{ geocoder : false, homeButton : false, sceneModePicker : false, baseLayerPicker : false, navigationHelpButton : false, animation : false, timeline : false, fullscreenButton : false, vrButton : false, //Cesium本地服务 //imageryProvider : Cesium.createTileMapServiceImageryProvider({ // url : Cesium.buildModuleUrl('http://Build/Cesium/Assets/Textures/NaturalEarthII') // }) }); */ //显示帧速 viewer.scene.debugShowFramesPerSecond = true; //关闭大气层显示 //viewer.scene.skyAtmosphere.show = false; //控制视角不转到地下 viewer.scene.globe.depthTestAgainstTerrain = true; /* var thePosition = Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0); //方向 var theHeading = Cesium.Math.toRadians(20.0); //倾斜角度 var thePitch = Cesium.Math.toRadians(-90.0); var theRoll = 0; var redBox = viewer.entities.add({ name : 'red box with black outline', position : thePosition, box : { dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0), material : Cesium.Color.RED.withAlpha(0.5), outline : true, outlineColor : Cesium.Color.BLACK } }); //viewer.zoomTo(viewer.entities); var translation = Cesium.Cartesian3.fromArray([]); //加载3dtiles建筑物模型 var tileset =viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ //数据路径 url : 'http://localhost:8080/apps/sampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json', //最大的屏幕空间误差 maximumScreenSpaceError : 2, //最大加载瓦片个数 maximumNumberOfLoadedTiles : 1000 })); var m = tileset.modelMatrix; /* //旋转x角度,转为弧度再参与运算 var RotateX = 90.0; var m1 = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(RotateX)); //矩阵计算 Cesium.Matrix4.multiplyByMatrix3(m,m1,m); //赋值 tileset.modelMatrix = m; */ /* var defaultStyle = new Cesium.Cesium3DTileStyle({ color : 'rgba(255,255,255,0.5)', show : true }); tileset.style = defaultStyle; //视点看向3dtile模型 //viewer.zoomTo(tileset); /* //Cartesian3方式计算视角 viewer.camera.setView({ destination : thePosition, orientation : { heading : theHeading, pitch: thePitch, roll : theRoll } }); */ /* //rectangle方式计算视角 viewer.camera.setView({ //西南东北 destination : Cesium.Rectangle.fromDegrees(0.0,20.0, 10.0, 30.0), orientation : { heading : theHeading, pitch: thePitch, roll : theRoll } }); */ /* //flyto改变视角 viewer.camera.flyTo({ destination : thePosition, orientation : { heading : theHeading, pitch: thePitch, roll : theRoll }, //设置飞行持续时间,默认会根据距离来计算 duration : 5, //到达位置后执行的回调函数 complete :function(){ }, //如果取消飞行则会调用此函数 cancle : function() { }, //如果摄像机飞越高于该值,则调整俯仰角度, pitchAdjustHeight : -90, //相机最大飞行高度 maximumHeight : 5000, //如果到达目的地有两种方式,设置具体值后会强制选择方向飞过这个经度 flyOverLongitude : 100 }); */ //lookAt方式控制 //var theRange = 5000.0; //viewer.camera.lookAt(thePosition, new Cesium.HeadingPitchRange(theHeading, thePitch, theRange)); /* //加载topojson viewer.dataSources.add(Cesium.GeoJsonDataSource.load('http://localhost:8080/apps/sampleData/ne_10m_us_states.topojson',{ stroke : Cesium.Color.HOTPINK, fill : Cesium.Color.PINK.withAlpha(0.5), strokeWidth : 3 })); //纹理图绘制 function getColorRamp(elevationRamp){ var ramp = document.createElement('canvas'); ramp.width = 1; ramp.height = 100; var ctx = ramp.getContext('2d'); var values = elevationRamp; var grd = ctx.createLinearGradient(0,0,0,100); grd.addColorStop(values[0], '#000000'); //黑色 grd.addColorStop(values[1], '#2747E0'); //蓝色 grd.addColorStop(values[2], '#D33B7D'); //粉色 grd.addColorStop(values[3], '#D33038'); //红色 grd.addColorStop(values[4], '#FF9742'); //橘色 grd.addColorStop(values[5], '#ffd700'); //黄色 grd.addColorStop(values[6], '#ffffff'); //白色 ctx.fillStyle = grd; ctx.fillRect(0, 0, 1000, 10000); return ramp; } //渐变纹理填充墙 var redWall = viewer.entities.add({ name : 'Red wall at height', wall :{ positions : Cesium.Cartesian3.fromDegreesArrayHeights([ 121.444409, 31.247417, 200.0, 121.533521, 31.235685, 200.0, 121.563273, 31.190347, 200.0, 121.546744, 31.194054, 200.0, 121.516705, 31.191459, 200.0, 121.502188, 31.203074, 200.0 ]), minimumHeights :[ 3000.0, 2000.0, 2000, 2000, 2000, 3000], material : getColorRamp([0.0, 0.045, 0.1, 0.15, 0.37, 0.54, 1.0], true ) } }); //viewer.zoomTo(redWall); /* //贴地线 var yellowLine = viewer.entities.add({ name : 'Red line on the surface', corridor : { positions : Cesium.Cartesian3.fromDegreesArray([ 112.82436, 23.071506, 112.82742, 23.067512, 112.828878, 23.064659, 112.830799, 23.060947, 112.832166, 24.058329 ]), width : 200, material : Cesium.Color.YELLOW } }); viewer.zoomTo(yellowLine); */ /* var rectanglePrimitive = viewer.scene.primitives.add( new Cesium.GroundPrimitive({ geometryInstances : new Cesium.GeometryInstance({ geometry : new Cesium.CorridorGeometry({ vertexFormat : Cesium.VertexFormat.POSITION_ONLY, positions : Cesium.Cartesian3.fromDegreesArray([ 112.82436, 23.071506, 112.82742, 23.067512, 112.828878, 23.064659, 112.830799, 23.060947, 112.832166, 24.058329 ]), width : 40000 }), attributes : { color : Cesium.ColorGeometryInstanceAttribute.fromColor( new Cesium.Color(0.0, 1.0, 0.0, 0.5)) } }), classificationType : Cesium.ClassificationType.TERRAIN })); */
因篇幅问题不能全部显示,请点此查看更多更全内容