/* 引入Cesium */ // import * as Cesium from 'Cesium'; import { setSessionid, getHeigthByPointsMostDetailed, getHeigthByPointMostDetailed } from "./common/common.js"; /** * 点对象 */ class PointObject { /** * 默认初始化 */ constructor(viewer) { if (!viewer) throw new Cesium.DeveloperError('no viewer object!'); this._viewer = viewer; } } /** * 通用对外公开函数 */ Object.assign(PointObject.prototype, /** @lends PointObject.prototype */ { /** * @description 根据坐标绘制文字 * @param {Array/Cesium.Cartesian3} points 坐标位置[lng,lat,height]经度,以度为单位,纬度,以度为单位 * @param {Object} options * * @param {Object} [options.id] 用于移除 * * @param {Object} [options.label] label的样式,具有以下属性: * @param {Number} [options.label.text=""] 文字 * @param {String} [options.label.font="24px Helvetica"] 组合字体样式 * 组合字体 * font:font-style font-weight font-size/line-height font-family; * font:italic bolder 20px/10px Arial; * @param {String} [options.label.fillColor=[255,255,255,0]] 字体颜色 * @param {String} [options.label.outlineColor=[255,255,255,0]] 字体边框颜色 * @param {Number} [options.label.outlineWidth=1] 边框宽度 * @param {Number} [options.label.showBackground=false] 是否显示背景颜色 * @param {Number} [options.label.backgroundColor=[255,255,255,0]] 背景颜色 * @param {Number} [options.label.backgroundPadding=0] 背景内边距 * @param {Number} [options.label.pixelOffset] 偏移像素 * @param {Number} [options.label.pixelOffset.x=0] 横向偏移像素 * @param {Number} [options.label.pixelOffset.y=0] 纵向偏移像素 * @param {Number} [options.label.scale=1] 尺寸 * @param {Number} [options.label.scaleByDistance] 相机范围 * @param {Number} [options.label.scaleByDistance.near=1.5e2] 相机范围的下界。 * @param {String} [options.label.scaleByDistance.nearValue=1] 相机范围下界的值。 * @param {String} [options.label.scaleByDistance.far=2400] 相机范围的上限。 * @param {Number} [options.label.scaleByDistance.farValue=0] 该值位于摄像机范围的上界。 */ addLabel(points, options) { //异步函数 return new Promise((resolve, reject) => { let _self = this; if (!Cesium.defined(points)) { throw new Cesium.DeveloperError("points is required."); } //坐标位置 let position; if (points instanceof Cesium.Cartesian3) { position = points; } else { position = Cesium.Cartesian3.fromDegrees(points[0], points[1], points[2] || 0); } options = options || {}; options.id = options.id || setSessionid(); let label = options.label || {}; //文字内容 label.text = Cesium.defaultValue(label.text, "金田CIM三维基础平台"); //组合字体样式 label.font = Cesium.defaultValue(label.font, "24px Helvetica"); //字体颜色 if (label.fillColor instanceof Array) { label.fillColor = new Cesium.Color(label.fillColor[0] / 255, label.fillColor[1] / 255, label.fillColor[2] / 255, label.fillColor[3]); } else if (typeof(label.fillColor) === 'string') { label.fillColor = new Cesium.Color.fromCssColorString(label.fillColor); } else { label.fillColor = new Cesium.Color.fromCssColorString("#FFFF00"); } //字体边框颜色 if (label.outlineColor instanceof Array) { label.outlineColor = new Cesium.Color(label.outlineColor[0] / 255, label.outlineColor[1] / 255, label.outlineColor[2] / 255, label.outlineColor[3]); } else if (typeof(label.outlineColor) === 'string') { label.outlineColor = new Cesium.Color.fromCssColorString(label.outlineColor); } else { label.outlineColor = new Cesium.Color.fromCssColorString("#FFF"); } //字体边框宽度 label.outlineWidth = Cesium.defaultValue(label.outlineWidth, 1); //是否显示背景颜色 label.showBackground = Cesium.defaultValue(label.showBackground, false); //背景颜色 if (label.backgroundColor instanceof Array) { label.backgroundColor = new Cesium.Color(label.backgroundColor[0] / 255, label.backgroundColor[1] / 255, label.backgroundColor[2] / 255, label.backgroundColor[3]); } else if (typeof(label.backgroundColor) === 'string') { label.backgroundColor = new Cesium.Color.fromCssColorString(label.backgroundColor); } else { label.backgroundColor = new Cesium.Color.fromCssColorString("#FFF"); } //背景内边距 if (label.backgroundPadding) { label.backgroundPadding = new Cesium.Cartesian2(label.backgroundPadding, label.backgroundPadding); } let entity = new Cesium.Entity({ id: options.id, position: position, label: { text: label.text, font: label.font, //字体样式 fillColor: label.fillColor, //字体颜色 outlineColor: label.outlineColor, //字体边框颜色 outlineWidth: label.outlineWidth, //边框宽度 style: Cesium.LabelStyle.FILL_AND_OUTLINE, //FILL不要轮廓 , OUTLINE只要轮廓,FILL_AND_OUTLINE轮廓加填充 verticalOrigin: Cesium.VerticalOrigin.BOTTOM, showBackground: label.showBackground, //是否显示背景颜色 backgroundColor: label.backgroundColor, // 背景颜色 backgroundPadding: label.backgroundPadding, //指定以像素为单位的水平和垂直背景填充padding disableDepthTestDistance: Number.POSITIVE_INFINITY, heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, } }); //偏移量 if (label.pixelOffset) { label.pixelOffset.x = Cesium.defaultValue(label.pixelOffset.x, 0); label.pixelOffset.y = Cesium.defaultValue(label.pixelOffset.y, 0); entity.label.pixelOffset = new Cesium.Cartesian2(label.pixelOffset.x, label.pixelOffset.y); } if (label.scaleByDistance) { label.scaleByDistance.near = Cesium.defaultValue(label.scaleByDistance.near, 0); label.scaleByDistance.nearValue = Cesium.defaultValue(label.scaleByDistance.nearValue, 0); label.scaleByDistance.far = Cesium.defaultValue(label.scaleByDistance.far, 1); label.scaleByDistance.farValue = Cesium.defaultValue(label.scaleByDistance.farValue, 0); entity.label.scaleByDistance = new Cesium.NearFarScalar(label.scaleByDistance.near, label.scaleByDistance.nearValue, label.scaleByDistance.far, label.scaleByDistance.farValue) //按距离缩放,即距离大于180米时,图标不显示 Cesium.NearFarScalar(near, nearValue, far, farValue)相机范围的下界。相机范围下界的值。相机范围的上限。该值位于摄像机范围的上界。 } _self._viewer.entities.add(entity); resolve(entity) }); }, /** * @description 根据坐标绘制点及文字 * @param {Array/Cesium.Cartesian3} points 坐标位置[lng,lat,height]经度,以度为单位,纬度,以度为单位 * @param {Object} options * * @param {Object} [options.id] 用于移除 * * @param {Object} [options.point] 点的样式,具有以下属性: * @param {Number} [options.point.pixelSize=10] 指定点的大小,以像素为单位 * @param {Array} [options.point.color=[255,255,255,0]] 点位颜色,颜色数组,[0~255,0~255,0~255,0~1],[red 红色,green 绿色,blue 蓝色,alpha 透明度] * @param {String} [options.point.outlineColor=[255,255,255,0]] 指定点轮廓的颜色,,颜色数组,[0~255,0~255,0~255,0~1],[red 红色,green 绿色,blue 蓝色,alpha 透明, * @param {Number} [options.point.outlineWidth=0] 指定点轮廓的宽度 * * @param {Object} [options.label] label的样式,具有以下属性: * @param {Number} [options.label.text=""] 文字 * @param {String} [options.label.font="24px Helvetica"] 字体样式 * @param {String} [options.label.fillColor=[255,255,255,0]] 字体颜色 * @param {String} [options.label.outlineColor=[255,255,255,0]] 字体边框颜色 * @param {Number} [options.label.outlineWidth=1] 边框宽度 * @param {Number} [options.label.showBackground=false] 是否显示背景颜色 * @param {Number} [options.label.backgroundColor=[255,255,255,0]] 背景颜色 * @param {Number} [options.label.pixelOffset] 偏移像素 * @param {Number} [options.label.pixelOffset.x=0] 横向偏移像素 * @param {Number} [options.label.pixelOffset.y=0] 纵向偏移像素 * @param {Number} [options.label.scaleByDistance] 相机范围 * @param {Number} [options.label.scaleByDistance.near=1.5e2] 相机范围的下界。 * @param {String} [options.label.scaleByDistance.nearValue=1] 相机范围下界的值。 * @param {String} [options.label.scaleByDistance.far=2400] 相机范围的上限。 * @param {Number} [options.label.scaleByDistance.farValue=0] 该值位于摄像机范围的上界。 */ addPoint(points, options) { //异步函数 return new Promise((resolve, reject) => { let _self = this; if (!Cesium.defined(points)) { throw new Cesium.DeveloperError("points is required."); } //坐标位置 let position; if (points instanceof Cesium.Cartesian3) { position = points; } else { position = Cesium.Cartesian3.fromDegrees(points[0], points[1], points[2] || 0); } options = options || {}; options.id = options.id || setSessionid(); let point = options.point || {}; //点的大小 point.pixelSize = Cesium.defaultValue(point.pixelSize, 10); //点位颜色 if (point.color instanceof Array) { point.color = new Cesium.Color(point.color[0] / 255, point.color[1] / 255, point.color[2] / 255, point.color[3]); } else if (typeof(point.color) === 'string') { point.color = new Cesium.Color.fromCssColorString(point.color); } else { point.color = new Cesium.Color.fromCssColorString("#FFF"); } //点位轮廓颜色 if (point.outlineColor instanceof Array) { point.outlineColor = new Cesium.Color(point.outlineColor[0] / 255, point.outlineColor[1] / 255, point.outlineColor[2] / 255, point.outlineColor[3]); } else if (typeof(point.outlineColor) === 'string') { point.outlineColor = new Cesium.Color.fromCssColorString(point.outlineColor); } else { point.outlineColor = new Cesium.Color.fromCssColorString("#FFF"); } //点位轮廓宽度 point.outlineWidth = Cesium.defaultValue(point.outlineWidth, 1); let entity = new Cesium.Entity({ id: options.id, position: position, point: { pixelSize: point.pixelSize, //点的大小 color: point.color, //点位颜色 outlineColor: point.outlineColor, //点位轮廓颜色 outlineWidth: point.outlineWidth, //点位轮廓宽度 heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, //指定高度相对于什么的属性。CLAMP_TO_GROUND可使点贴地,地就是地形。NONE是绝对高程.RELATIVE_TO_GROUND是设置距离地形的相对高度。 disableDepthTestDistance: Number.POSITIVE_INFINITY, //指定距离相机的距离,在这个距离上禁用深度测试。通过设置相机到圆要素的距离阈值来判断是否开启深度检测,这里设置为1000.0米正常,但是当相机距离超过阈值时,就会开启深度检测,圆还是会只显示一半。将阈值设置为无穷大时:Number.POSITIVE_INFINITY。虽然无论相机距离远近,圆都可以正常显示,但是没有圆的深度检测,不同要素之间的遮挡无法得到有效判断,有的在建筑物后的点会在建筑物前显示,造成视觉误差与干扰。 // disableDepthTestDistance: updatedPositions[0].height, //指定距离相机的距离,在这个距离上禁用深度测试。通过设置相机到圆要素的距离阈值来判断是否开启深度检测,这里设置为1000.0米正常,但是当相机距离超过阈值时,就会开启深度检测,圆还是会只显示一半。将阈值设置为无穷大时:Number.POSITIVE_INFINITY。虽然无论相机距离远近,圆都可以正常显示,但是没有圆的深度检测,不同要素之间的遮挡无法得到有效判断,有的在建筑物后的点会在建筑物前显示,造成视觉误差与干扰。 } }); /* 判断是否需要绘制文字 */ if (options.label) { let label = options.label || {}; label.text = Cesium.defaultValue(label.text, ""); label.font = Cesium.defaultValue(label.font, "24px Helvetica"); //字体样式 //字体颜色 if (label.fillColor instanceof Array) { label.fillColor = new Cesium.Color(label.fillColor[0] / 255, label.fillColor[1] / 255, label.fillColor[2] / 255, label.fillColor[3]); } else if (typeof(label.fillColor) === 'string') { label.fillColor = new Cesium.Color.fromCssColorString(label.fillColor); } else { label.fillColor = new Cesium.Color.fromCssColorString("#FFFF00"); } //字体边框颜色 if (label.outlineColor instanceof Array) { label.outlineColor = new Cesium.Color(label.outlineColor[0] / 255, label.outlineColor[1] / 255, label.outlineColor[2] / 255, label.outlineColor[3]); } else if (typeof(label.outlineColor) === 'string') { label.outlineColor = new Cesium.Color.fromCssColorString(label.outlineColor); } else { label.outlineColor = new Cesium.Color.fromCssColorString("#FFF"); } //字体边框宽度 label.outlineWidth = Cesium.defaultValue(label.outlineWidth, 1); //是否显示背景颜色 label.showBackground = Cesium.defaultValue(label.showBackground, false); //背景颜色 if (label.backgroundColor instanceof Array) { label.backgroundColor = new Cesium.Color(label.backgroundColor[0] / 255, label.backgroundColor[1] / 255, label.backgroundColor[2] / 255, label.backgroundColor[3]); } else if (typeof(label.backgroundColor) === 'string') { label.backgroundColor = new Cesium.Color.fromCssColorString(label.backgroundColor); } else { label.backgroundColor = new Cesium.Color.fromCssColorString("#FFF"); } if (label.backgroundPadding) { label.backgroundPadding = new Cesium.Cartesian2(label.backgroundPadding, label.backgroundPadding); } // label.pixelOffset.x = Cesium.defaultValue(label.pixelOffset.x, 0); // label.pixelOffset.y = Cesium.defaultValue(label.pixelOffset.y, 0); entity.label = { text: label.text, font: label.font, //字体样式 fillColor: label.fillColor, //字体颜色 outlineColor: label.outlineColor, //字体边框颜色 outlineWidth: label.outlineWidth, //边框宽度 style: Cesium.LabelStyle.FILL_AND_OUTLINE, //FILL不要轮廓 , OUTLINE只要轮廓,FILL_AND_OUTLINE轮廓加填充 verticalOrigin: Cesium.VerticalOrigin.BOTTOM, showBackground: label.showBackground, //是否显示背景颜色 backgroundColor: label.backgroundColor, // 背景颜色 backgroundPadding: new Cesium.Cartesian2(6, 6), //指定以像素为单位的水平和垂直背景填充padding disableDepthTestDistance: Number.POSITIVE_INFINITY, // pixelOffset: new Cesium.Cartesian2(label.pixelOffset.x, label.pixelOffset.y), //偏移量 } if (label.scaleByDistance) { label.scaleByDistance.near = Cesium.defaultValue(label.scaleByDistance.near, 0); label.scaleByDistance.nearValue = Cesium.defaultValue(label.scaleByDistance.nearValue, 0); label.scaleByDistance.far = Cesium.defaultValue(label.scaleByDistance.far, 1); label.scaleByDistance.farValue = Cesium.defaultValue(label.scaleByDistance.farValue, 0); entity.label.scaleByDistance = new Cesium.NearFarScalar(label.scaleByDistance.near, label.scaleByDistance.nearValue, label.scaleByDistance.far, label.scaleByDistance.farValue) //按距离缩放,即距离大于180米时,图标不显示 Cesium.NearFarScalar(near, nearValue, far, farValue)相机范围的下界。相机范围下界的值。相机范围的上限。该值位于摄像机范围的上界。 } } _self._viewer.entities.add(entity); resolve(entity) }); }, /** * 根据坐标绘制广告牌及文字 * @param {Object} points 坐标位置[lng,lat,height]经度,以度为单位,纬度,以度为单位,高程 * @param {Object} options * @param {String} [options.id] 用于移除 * @param {Object} options.billboard 广告牌的样式,具有以下属性: * @param {Number} options.billboard.imgUrl 广告牌图片 * @param {Number} [options.billboard.scale=1] 尺寸 * @param {Number} [options.billboard.pixelOffset] 偏移像素 * @param {Number} [options.billboard.pixelOffset.x=0] 横向偏移像素 * @param {Number} [options.billboard.pixelOffset.y=0] 纵向偏移像素 * @param {Object} [options.billboard.scaleByDistance] 距离相机的距离缩放点。 * @param {Number} [options.billboard.scaleByDistance.near=0] 相机范围的下界。 * @param {String} [options.billboard.scaleByDistance.nearValue=0] 相机范围下界的值。 * @param {String} [options.billboard.scaleByDistance.far=1] 相机范围的上限。 * @param {Number} [options.billboard.scaleByDistance.farValue=0] 该值位于摄像机范围的上界。 * * @param {Object} [options.label] label的样式,具有以下属性: * @param {Number} [options.label.text="注记"] 文字 * @param {String} [options.label.font="24px Helvetica"] 指定CSS字体的属性,字体大小及样式 * @param {String} [options.label.fillColor=[255,255,255,1]] 字体颜色 * @param {String} [options.label.outlineColor=[255,255,255,1]] 字体边框颜色 * @param {Number} [options.label.outlineWidth=1] 边框宽度 * @param {Number} [options.label.showBackground=false] 是否显示背景颜色 * @param {Number} [options.label.backgroundColor=[255,255,255,1]] 背景颜色 * @param {Number} [options.label.pixelOffset] 偏移像素 * @param {Number} [options.label.pixelOffset.x=0] 横向偏移像素 * @param {Number} [options.label.pixelOffset.y=0] 纵向偏移像素 * @param {Object} [options.label.scaleByDistance] 距离相机的距离缩放点。 * @param {Number} [options.label.scaleByDistance.near=0] 相机范围的下界。 * @param {String} [options.label.scaleByDistance.nearValue=0] 相机范围下界的值。 * @param {String} [options.label.scaleByDistance.far=1] 相机范围的上限。 * @param {Number} [options.label.scaleByDistance.farValue=0] 该值位于摄像机范围的上界。 */ addBillboard(points, options) { //异步函数 return new Promise((resolve, reject) => { let _self = this; if (!Cesium.defined(points)) { throw new Cesium.DeveloperError("points is required."); } //坐标位置 let position; if (points instanceof Cesium.Cartesian3) { position = points; } else { position = Cesium.Cartesian3.fromDegrees(points[0], points[1], points[2] || 0); } options = options || {}; options.id = options.id || setSessionid(); let billboard = options.billboard || {}; billboard.image = billboard.imgUrl || "jt3dSDK/imgs/point/point3.png"; billboard.scale = Cesium.defaultValue(billboard.scale, 1); billboard.pixelOffset = Cesium.defaultValue(billboard.pixelOffset, 0); // label.pixelOffset.x = Cesium.defaultValue(label.pixelOffset.x, 0); // label.pixelOffset.y = Cesium.defaultValue(label.pixelOffset.y, 0); let entity = new Cesium.Entity({ id: options.id, name: "add billboard", //位置 position: position, //图片标签 billboard: { image: billboard.image, horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平 verticalOrigin: Cesium.VerticalOrigin.BOTTOM, //垂直位置 scale: billboard.scale, //尺寸 pixelOffset: new Cesium.Cartesian2(0, billboard.pixelOffset), heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, disableDepthTestDistance: Number.POSITIVE_INFINITY, } }); if (billboard.scaleByDistance) { billboard.scaleByDistance.near = Cesium.defaultValue(billboard.scaleByDistance.near, 0); billboard.scaleByDistance.nearValue = Cesium.defaultValue(billboard.scaleByDistance.nearValue, 0); billboard.scaleByDistance.far = Cesium.defaultValue(billboard.scaleByDistance.far, 1); billboard.scaleByDistance.farValue = Cesium.defaultValue(billboard.scaleByDistance.farValue, 0); entity.billboard.scaleByDistance = new Cesium.NearFarScalar(billboard.scaleByDistance.near, billboard.scaleByDistance.nearValue, billboard.scaleByDistance.far, billboard.scaleByDistance.farValue) //按距离缩放,即距离大于180米时,图标不显示 Cesium.NearFarScalar(near, nearValue, far, farValue)相机范围的下界。相机范围下界的值。相机范围的上限。该值位于摄像机范围的上界。 } /* 判断是否需要绘制文字 */ if (options.label) { let label = options.label || {}; label.text = Cesium.defaultValue(label.text, ""); label.font = Cesium.defaultValue(label.font, "24px Helvetica"); if (label.fillColor instanceof Array) { label.fillColor = new Cesium.Color(label.fillColor[0] / 255, label.fillColor[1] / 255, label.fillColor[2] / 255, label.fillColor[3]); } else if (typeof(label.fillColor) === 'string') { label.fillColor = new Cesium.Color.fromCssColorString(label.fillColor); } else { label.fillColor = new Cesium.Color.fromCssColorString("#ff0000"); } if (label.outlineColor instanceof Array) { label.outlineColor = new Cesium.Color(label.outlineColor[0] / 255, label.outlineColor[1] / 255, label.outlineColor[2] / 255, label.outlineColor[3]); } else if (typeof(label.outlineColor) === 'string') { label.outlineColor = new Cesium.Color.fromCssColorString(label.outlineColor); } else { label.outlineColor = new Cesium.Color.fromCssColorString("#FFFF00"); } label.outlineWidth = Cesium.defaultValue(label.outlineWidth, 1); //是否显示背景颜色 label.showBackground = Cesium.defaultValue(label.showBackground, false); //背景颜色 if (label.backgroundColor instanceof Array) { label.backgroundColor = new Cesium.Color(label.backgroundColor[0] / 255, label.backgroundColor[1] / 255, label.backgroundColor[2] / 255, label.backgroundColor[3]); } else if (typeof(label.backgroundColor) === 'string') { label.backgroundColor = new Cesium.Color.fromCssColorString(label.backgroundColor); } else { label.backgroundColor = new Cesium.Color.fromCssColorString("#FFFF00"); } if (label.backgroundPadding) { label.backgroundPadding = new Cesium.Cartesian2(label.backgroundPadding, label.backgroundPadding); } entity.label = { text: label.text, font: label.font, fillColor: label.fillColor, //填充颜色 outlineColor: label.outlineColor, //边框颜色 outlineWidth: label.outlineWidth, //边框宽度 style: Cesium.LabelStyle.FILL_AND_OUTLINE, //FILL不要轮廓 , OUTLINE只要轮廓,FILL_AND_OUTLINE轮廓加填充 verticalOrigin: Cesium.VerticalOrigin.BOTTOM, showBackground: label.showBackground, //指定标签后面背景的可见性 backgroundColor: label.backgroundColor, // 背景颜色 backgroundPadding: label.backgroundPadding, //指定以像素为单位的水平和垂直背景填充padding disableDepthTestDistance: Number.POSITIVE_INFINITY, } //偏移量 if (label.pixelOffset) { label.pixelOffset.x = Cesium.defaultValue(label.pixelOffset.x, 0); label.pixelOffset.y = Cesium.defaultValue(label.pixelOffset.y, 0); entity.label.pixelOffset = new Cesium.Cartesian2(label.pixelOffset.x, label.pixelOffset.y); } //相机距离 if (label.scaleByDistance) { label.scaleByDistance.near = Cesium.defaultValue(label.scaleByDistance.near, 0); label.scaleByDistance.nearValue = Cesium.defaultValue(label.scaleByDistance.nearValue, 0); label.scaleByDistance.far = Cesium.defaultValue(label.scaleByDistance.far, 1); label.scaleByDistance.farValue = Cesium.defaultValue(label.scaleByDistance.farValue, 0); entity.label.scaleByDistance = new Cesium.NearFarScalar(label.scaleByDistance.near, label.scaleByDistance.nearValue, label.scaleByDistance.far, label.scaleByDistance.farValue) //按距离缩放,即距离大于180米时,图标不显示 Cesium.NearFarScalar(near, nearValue, far, farValue)相机范围的下界。相机范围下界的值。相机范围的上限。该值位于摄像机范围的上界。 } } this._viewer.entities.add(entity); resolve(entity) }); }, /** * 加载GLTF/GLB模型数据 * @param {Array/Cesium.Cartesian3} points 坐标位置[lng,lat,height]经度,以度为单位,纬度,以度为单位 * @param {Object} options * @param {Object} [options.id] 用于移除,模型实体加载ID,加入到整体图层中 以便可以删除对应的图层 * * @param {Object} options.model model的样式,具有以下属性: * @param {String} options.model.url 模型路径 * @param {Number} [options.model.alpha] 模型透明度 * @param {Array} [options.model.silhouetteColor] 模型轮廓颜色[0~255,0~255,0~255,0~1] * @param {Number} [options.model.silhouetteSize] 模型轮廓宽度 * @param {Number} [options.model.minimumPixelSize] 模型最小刻度 * @param {Number} [options.model.maximumScale] 模型的最大比例尺大小,设置模型最大放大大小 * @param {Number} [options.model.heading=0.0] 以弧度为单位的航向分量 * @param {Number} [options.model.pitch=0.0] 以弧度为单位的螺距分量 * @param {Number} [options.model.roll=0.0] 以弧度为单位的滚动分量 */ addModel: function(points, options) { let _self = this; let viewer = this._viewer; //异步函数 return new Promise((resolve, reject) => { if (!Cesium.defined(points)) { throw new Cesium.DeveloperError("points is required."); } //坐标位置 let position; if (points instanceof Cesium.Cartesian3) { position = points; } else { position = Cesium.Cartesian3.fromDegrees(points[0], points[1], points[2] || 0); } // 初始化参数默认值 options = options || {}; options.id = options.id || setSessionid(); let model = options.model || {}; //透明度 model.alpha = Cesium.defaultValue(model.alpha, 1); //模型旋转 model.heading = Cesium.defaultValue(model.heading, 0.0); model.pitch = Cesium.defaultValue(model.pitch, 0.0); model.roll = Cesium.defaultValue(model.roll, 0.0); //弧度的航向分量。 var heading = Cesium.Math.toRadians(model.heading); //弧度的螺距分量。 var pitch = model.pitch; //滚动分量(以弧度为单位) var roll = model.roll; //HeadingPitchRoll旋转表示为航向,俯仰和滚动。围绕Z轴。节距是绕负y轴的旋转。滚动是关于正x轴。 var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); let entity = new Cesium.Entity({ id: options.id, //模型id position: position, // 模型位置 // orientation: Cesium.Transforms.headingPitchRollQuaternion(position, hpr), // 模型方向 model: { // 模型资源 uri: model.url, // 模型路径 incrementallyLoadTextures: true, //加载模型后纹理是否能够继续流入 colorBlendMode: Cesium.ColorBlendMode['HIGHLIGHT'], //经常使用的有三个HIGHLIGHT,REPLACE,MIX colorBlendAmount: 0.1, //这个属性必须是MIX混合属性才能生效,见colorBlendMode color: Cesium.Color.WHITE.withAlpha(model.alpha), //模型颜色,这里可以设置颜色的变化,包含透明度的颜色 imageBasedLightingFactor: new Cesium.Cartesian2(12.0, 13.0), runAnimations: true, //是否运行模型中的动画效果 show: true, // 模型是否可见 // 仅用于调试,显示魔仙绘制时的线框 debugWireframe: false, // 仅用于调试。显示模型绘制时的边界球。 debugShowBoundingVolume: false, heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, disableDepthTestDistance: Number.POSITIVE_INFINITY, }, }); // 模型最小刻度,不管缩放如何,模型的最小最小像素大小。 if (model.minimumPixelSize) { entity.model.minimumPixelSize = model.minimumPixelSize; } // 模型最大刻度,模型的最大比例尺大小。 minimumPixelSize的上限。 if (model.maximumScale) { entity.model.maximumScale = model.maximumScale; } // 模型轮廓颜色 if (model.silhouetteColor) { if (model.silhouetteColor instanceof Array) { entity.model.silhouetteColor = new Cesium.Color(model.silhouetteColor[0] / 255, model.silhouetteColor[1] / 255, model.silhouetteColor[2] / 255, model.silhouetteColor[3]); } else if (typeof(model.silhouetteColor) === 'string') { entity.model.silhouetteColor = new Cesium.Color.fromCssColorString(model.silhouetteColor); } } //模型轮廓宽度 model.silhouetteSize = Cesium.defaultValue(model.silhouetteSize, 1); _self._viewer.entities.add(entity); resolve(entity); }); }, /** * @description 根据坐标绘制点 * @param {Array/Cesium.Cartesian3} points 坐标位置[lng,lat,height]经度,以度为单位,纬度,以度为单位 * @param {Object} options * * @param {Object} [options.id] 用于移除 * * @param {Object} [options.point] 点的样式,具有以下属性: * @param {Number} [options.point.pixelSize=10] 指定点的大小,以像素为单位 * @param {Array} [options.point.color=[255,255,255,0]] 点位颜色,颜色数组,[0~255,0~255,0~255,0~1],[red 红色,green 绿色,blue 蓝色,alpha 透明度] * @param {String} [options.point.outlineColor=[255,255,255,0]] 指定点轮廓的颜色,,颜色数组,[0~255,0~255,0~255,0~1],[red 红色,green 绿色,blue 蓝色,alpha 透明, * @param {Number} [options.point.outlineWidth=0] 指定点轮廓的宽度 * * @param {Object} [options.label] label的样式,具有以下属性: * @param {Number} [options.label.text=""] 文字 * @param {String} [options.label.font="24px Helvetica"] 字体样式 * @param {String} [options.label.fillColor=[255,255,255,0]] 字体颜色 * @param {String} [options.label.outlineColor=[255,255,255,0]] 字体边框颜色 * @param {Number} [options.label.outlineWidth=1] 边框宽度 * @param {Number} [options.label.showBackground=false] 是否显示背景颜色 * @param {Number} [options.label.backgroundColor=[255,255,255,0]] 背景颜色 * @param {Number} [options.label.pixelOffset=0] 偏移量 * @param {Number} [options.label.scale=1] 尺寸 * @param {Number} [options.label.scaleByDistance] 相机范围 * @param {Number} [options.label.scaleByDistance.near=1.5e2] 相机范围的下界。 * @param {String} [options.label.scaleByDistance.nearValue=1] 相机范围下界的值。 * @param {String} [options.label.scaleByDistance.far=2400] 相机范围的上限。 * @param {Number} [options.label.scaleByDistance.farValue=0] 该值位于摄像机范围的上界。 */ generatePoint(points, options) { //异步函数 return new Promise((resolve, reject) => { let _self = this; if (!Cesium.defined(points)) { throw new Cesium.DeveloperError("points is required."); } options = options || {}; options.id = options.id || setSessionid(); let point = options.point || {}; //点的大小 point.pixelSize = Cesium.defaultValue(point.pixelSize, 10); //点位颜色 if (point.color instanceof Array) { point.color = new Cesium.Color(point.color[0] / 255, point.color[1] / 255, point.color[2] / 255, point.color[3]); } else if (typeof(point.color) === 'string') { point.color = new Cesium.Color.fromCssColorString(point.color); } else { point.color = new Cesium.Color.fromCssColorString("#FFF"); } //点位轮廓颜色 if (point.outlineColor instanceof Array) { point.outlineColor = new Cesium.Color(point.outlineColor[0] / 255, point.outlineColor[1] / 255, point.outlineColor[2] / 255, point.outlineColor[3]); } else if (typeof(point.outlineColor) === 'string') { point.outlineColor = new Cesium.Color.fromCssColorString(point.outlineColor); } else { point.outlineColor = new Cesium.Color.fromCssColorString("#FFF"); } //点位轮廓宽度 point.outlineWidth = Cesium.defaultValue(point.outlineWidth, 1); //获取指定坐标的地形高度。 let terrainAltitude = getHeigthByPointsMostDetailed(_self._viewer, [points]); terrainAltitude.then(function(updatedPositions) { let position = Cesium.Cartesian3.fromDegrees(points[0], points[1], updatedPositions[0].height) let entity = new Cesium.Entity({ id: options.id, position: position, point: { pixelSize: point.pixelSize, //点的大小 color: point.color, //点位颜色 outlineColor: point.outlineColor, //点位轮廓颜色 outlineWidth: point.outlineWidth, //点位轮廓宽度 heightReference: Cesium.HeightReference.NONE, //指定高度相对于什么的属性。CLAMP_TO_GROUND可使点贴地,地就是地形。NONE是绝对高程.RELATIVE_TO_GROUND是设置距离地形的相对高度。 // disableDepthTestDistance: Number.POSITIVE_INFINITY, //指定距离相机的距离,在这个距离上禁用深度测试。通过设置相机到圆要素的距离阈值来判断是否开启深度检测,这里设置为1000.0米正常,但是当相机距离超过阈值时,就会开启深度检测,圆还是会只显示一半。将阈值设置为无穷大时:Number.POSITIVE_INFINITY。虽然无论相机距离远近,圆都可以正常显示,但是没有圆的深度检测,不同要素之间的遮挡无法得到有效判断,有的在建筑物后的点会在建筑物前显示,造成视觉误差与干扰。 disableDepthTestDistance: updatedPositions[0].height, //指定距离相机的距离,在这个距离上禁用深度测试。通过设置相机到圆要素的距离阈值来判断是否开启深度检测,这里设置为1000.0米正常,但是当相机距离超过阈值时,就会开启深度检测,圆还是会只显示一半。将阈值设置为无穷大时:Number.POSITIVE_INFINITY。虽然无论相机距离远近,圆都可以正常显示,但是没有圆的深度检测,不同要素之间的遮挡无法得到有效判断,有的在建筑物后的点会在建筑物前显示,造成视觉误差与干扰。 } }); /* 判断是否需要绘制文字 */ if (options.label) { let label = options.label || {}; label.text = Cesium.defaultValue(label.text, ""); label.font = Cesium.defaultValue(label.font, "24px Helvetica"); //字体样式 //字体颜色 if (label.fillColor instanceof Array) { label.fillColor = new Cesium.Color(label.fillColor[0] / 255, label.fillColor[1] / 255, label.fillColor[2] / 255, label.fillColor[3]); } else if (typeof(label.fillColor) === 'string') { label.fillColor = new Cesium.Color.fromCssColorString(label.fillColor); } else { label.fillColor = new Cesium.Color.fromCssColorString("#FFFF00"); } //字体边框颜色 if (label.outlineColor instanceof Array) { label.outlineColor = new Cesium.Color(label.outlineColor[0] / 255, label.outlineColor[1] / 255, label.outlineColor[2] / 255, label.outlineColor[3]); } else if (typeof(label.outlineColor) === 'string') { label.outlineColor = new Cesium.Color.fromCssColorString(label.outlineColor); } else { label.outlineColor = new Cesium.Color.fromCssColorString("#FFF"); } //字体边框宽度 label.outlineWidth = Cesium.defaultValue(label.outlineWidth, 1); //是否显示背景颜色 label.showBackground = Cesium.defaultValue(label.showBackground, false); //背景颜色 if (label.backgroundColor instanceof Array) { label.backgroundColor = new Cesium.Color(label.backgroundColor[0] / 255, label.backgroundColor[1] / 255, label.backgroundColor[2] / 255, label.backgroundColor[3]); } else if (typeof(label.backgroundColor) === 'string') { label.backgroundColor = new Cesium.Color.fromCssColorString(label.backgroundColor); } else { label.backgroundColor = new Cesium.Color.fromCssColorString("#FFF"); } label.pixelOffset = Cesium.defaultValue(label.pixelOffset, 0); // label.pixelOffset.x = Cesium.defaultValue(label.pixelOffset.x, 0); // label.pixelOffset.y = Cesium.defaultValue(label.pixelOffset.y, 0); label.scale = Cesium.defaultValue(label.scale, 1); entity.label = { text: label.text, font: label.font, //字体样式 fillColor: label.fillColor, //字体颜色 outlineColor: label.outlineColor, //字体边框颜色 outlineWidth: label.outlineWidth, //边框宽度 style: Cesium.LabelStyle.FILL_AND_OUTLINE, //FILL不要轮廓 , OUTLINE只要轮廓,FILL_AND_OUTLINE轮廓加填充 verticalOrigin: Cesium.VerticalOrigin.BOTTOM, showBackground: label.showBackground, //是否显示背景颜色 backgroundColor: label.backgroundColor, // 背景颜色 backgroundPadding: new Cesium.Cartesian2(6, 6), //指定以像素为单位的水平和垂直背景填充padding disableDepthTestDistance: Number.POSITIVE_INFINITY, pixelOffset: new Cesium.Cartesian2(0, label.pixelOffset), //偏移量 scale: label.scale, //尺寸 } } _self._viewer.entities.add(entity); resolve(entity) }); }); }, /** * 根据GeoJson添加广告牌 * @param {String} geoJsonUrl geoJson文件路径 * @param {Object} options * @param {String} [options.id] 用于移除 * @param {Object} [options.billboard] 广告牌的样式,具有以下属性: * @param {Number} [options.billboard.imgUrl] 广告牌图片 * @param {Number} [options.billboard.imgWidth] 广告牌图片宽度 * @param {Number} [options.billboard.imgHeight] 广告牌图片高度 * @param {Number} [options.billboard.scale=1] 尺寸 * @param {Object} [options.billboard.scaleByDistance] 距离相机的距离缩放点。 * @param {Number} [options.billboard.scaleByDistance.near=0] 相机范围的下界。 * @param {String} [options.billboard.scaleByDistance.nearValue=0] 相机范围下界的值。 * @param {String} [options.billboard.scaleByDistance.far=1] 相机范围的上限。 * @param {Number} [options.billboard.scaleByDistance.farValue=0] 该值位于摄像机范围的上界。 * * @param {Object} [options.label] label的样式,具有以下属性: * @param {Number} [options.label.text=""] 文字 * @param {Number} [options.label.textField=""] 文字字段 * @param {String} [options.label.font="24px Helvetica"] 指定CSS字体的属性,字体大小及样式 * @param {String} [options.label.fillColor=[255,255,255,1]] 字体颜色 * @param {String} [options.label.outlineColor=[255,255,255,1]] 字体边框颜色 * @param {Number} [options.label.outlineWidth=1] 边框宽度 * @param {Number} [options.label.showBackground=false] 是否显示背景颜色 * @param {Number} [options.label.backgroundColor=[255,255,255,1]] 背景颜色 * @param {Number} [options.label.pixelOffset=0] 偏移量 * @param {Number} [options.label.scale=1] 尺寸 * @param {Object} [options.label.scaleByDistance] 距离相机的距离缩放点。 * @param {Number} [options.label.scaleByDistance.near=0] 相机范围的下界。 * @param {String} [options.label.scaleByDistance.nearValue=0] 相机范围下界的值。 * @param {String} [options.label.scaleByDistance.far=1] 相机范围的上限。 * @param {Number} [options.label.scaleByDistance.farValue=0] 该值位于摄像机范围的上界。 */ addBillboardByGeoJson: function(geoJsonUrl, options) { return new Promise((resolve, reject) => { let _self = this; let viewer = this._viewer; if (!Cesium.defined(geoJsonUrl)) { throw new Cesium.DeveloperError("geoJsonUrl is required."); } options = options || {}; options.id = options.id || setSessionid(); let billboard = options.billboard || {}; billboard.imgUrl = Cesium.defaultValue(billboard.imgUrl, 'jt3dSDK/imgs/point/point3.png'); billboard.scale = Cesium.defaultValue(billboard.scale, 1); billboard.pixelOffset = Cesium.defaultValue(billboard.pixelOffset, 0); // label.pixelOffset.x = Cesium.defaultValue(label.pixelOffset.x, 0); // label.pixelOffset.y = Cesium.defaultValue(label.pixelOffset.y, 0); let label = options.label || {}; label.text = Cesium.defaultValue(label.text, ""); label.textField = Cesium.defaultValue(label.textField, ""); label.font = Cesium.defaultValue(label.font, "24px Helvetica"); if (label.fillColor instanceof Array) { label.fillColor = new Cesium.Color(label.fillColor[0] / 255, label.fillColor[1] / 255, label.fillColor[2] / 255, label.fillColor[3]); } else if (typeof(label.fillColor) === 'string') { label.fillColor = new Cesium.Color.fromCssColorString(label.fillColor); } else { label.fillColor = new Cesium.Color.fromCssColorString("#ff0000"); } if (label.outlineColor instanceof Array) { label.outlineColor = new Cesium.Color(label.outlineColor[0] / 255, label.outlineColor[1] / 255, label.outlineColor[2] / 255, label.outlineColor[3]); } else if (typeof(label.outlineColor) === 'string') { label.outlineColor = new Cesium.Color.fromCssColorString(label.outlineColor); } else { label.outlineColor = new Cesium.Color.fromCssColorString("#FFFF00"); } label.outlineWidth = Cesium.defaultValue(label.outlineWidth, 1); //是否显示背景颜色 label.showBackground = Cesium.defaultValue(label.showBackground, false); //背景颜色 if (label.backgroundColor instanceof Array) { label.backgroundColor = new Cesium.Color(label.backgroundColor[0] / 255, label.backgroundColor[1] / 255, label.backgroundColor[2] / 255, label.backgroundColor[3]); } else if (typeof(label.backgroundColor) === 'string') { label.backgroundColor = new Cesium.Color.fromCssColorString(label.backgroundColor); } else { label.backgroundColor = new Cesium.Color.fromCssColorString("#FFFF00"); } label.pixelOffset = Cesium.defaultValue(label.pixelOffset, 0); // label.pixelOffset.x = Cesium.defaultValue(label.pixelOffset.x, 0); // label.pixelOffset.y = Cesium.defaultValue(label.pixelOffset.y, 0); label.scale = Cesium.defaultValue(label.scale, 1); const dataSource = new Cesium.GeoJsonDataSource(options.id); // 创建并取名 dataSource.load(geoJsonUrl, { clampToGround: true }).then(function(data) { viewer.dataSources.add(data); // 添加这个datasource const entities = data.entities.values; // 拿到所有实体 entities.forEach(entity => { entity.billboard = { image: billboard.imgUrl, horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平 verticalOrigin: Cesium.VerticalOrigin.BOTTOM, //垂直位置 scale: billboard.scale, //尺寸 pixelOffset: new Cesium.Cartesian2(0, billboard.pixelOffset), disableDepthTestDistance: Number.POSITIVE_INFINITY, }; let labelText = label.text; if (entity.properties[label.textField]) { labelText = entity.properties[label.textField]._value; } if (labelText === "") { labelText = (i + 1).toString(); } entity.label = { text: labelText.toString(), font: label.font, fillColor: label.fillColor, //填充颜色 outlineColor: label.outlineColor, //边框颜色 outlineWidth: label.outlineWidth, //边框宽度 style: Cesium.LabelStyle.FILL_AND_OUTLINE, //FILL不要轮廓 , OUTLINE只要轮廓,FILL_AND_OUTLINE轮廓加填充 verticalOrigin: Cesium.VerticalOrigin.BOTTOM, showBackground: label.showBackground, //指定标签后面背景的可见性 backgroundColor: label.backgroundColor, // 背景颜色 backgroundPadding: new Cesium.Cartesian2(6, 6), //指定以像素为单位的水平和垂直背景填充padding disableDepthTestDistance: Number.POSITIVE_INFINITY, pixelOffset: new Cesium.Cartesian2(0, label.pixelOffset), //偏移量 scale: label.scale, //尺寸 } if (label.scaleByDistance) { label.scaleByDistance.near = Cesium.defaultValue(label.scaleByDistance.near, 0); label.scaleByDistance.nearValue = Cesium.defaultValue(label.scaleByDistance.nearValue, 0); label.scaleByDistance.far = Cesium.defaultValue(label.scaleByDistance.far, 1); label.scaleByDistance.farValue = Cesium.defaultValue(label.scaleByDistance.farValue, 0); entity.label.scaleByDistance = new Cesium.NearFarScalar(label.scaleByDistance.near, label.scaleByDistance.nearValue, label.scaleByDistance.far, label.scaleByDistance.farValue) //按距离缩放,即距离大于180米时,图标不显示 Cesium.NearFarScalar(near, nearValue, far, farValue)相机范围的下界。相机范围下界的值。相机范围的上限。该值位于摄像机范围的上界。 } }) }) }); }, /** * 加载GLTF/GLB模型数据 * @param {Object} options 参数对象 * @param {Array/Cesium.Cartesian3} options.points 模型加载位置 Array[lng,lat,height]经度,以度为单位,纬度,以度为单位,高程 * @param {String} options.url 模型路径 * @param {String} [options.id=guid] 模型实体加载ID,加入到整体图层中 以便可以删除对应的图层 * @param {Number} [options.heading=0.0] 以弧度为单位的航向分量 * @param {Number} [options.pitch=0.0] 以弧度为单位的螺距分量 * @param {Number} [options.roll=0.0] 以弧度为单位的滚动分量 * @param {Number} [options.minimumPixelSize] 模型最小刻度 * @param {Number} [options.maximumScale] 模型的最大比例尺大小,设置模型最大放大大小 * @param {Array} [options.silhouetteColor] 模型轮廓颜色[0~255,0~255,0~255,0~1] * @param {Number} [options.alpha] 模型透明度 */ addGltf: function(options) { let _self = this; let viewer = this._viewer; //异步函数 return new Promise((resolve, reject) => { if (!Cesium.defined(options.points)) { resolve("options.points is required."); throw new Cesium.DeveloperError("options.points is required."); } if (!Cesium.defined(options.url)) { resolve("options.url is required."); throw new Cesium.DeveloperError("options.url is required."); } // 初始化参数默认值 options.id = options.id || setSessionid(); options.heading = Cesium.defaultValue(options.heading, 0.0); options.pitch = Cesium.defaultValue(options.pitch, 0.0); options.roll = Cesium.defaultValue(options.roll, 0.0); options.alpha = Cesium.defaultValue(options.alpha, 1); //模型加载位置 let position = undefined; if (options.points instanceof Cesium.Cartesian3) { position = options.points; } else { position = Cesium.Cartesian3.fromDegrees(options.points[0], options.points[1], options.points[2] || 0); } //弧度的航向分量。 var heading = Cesium.Math.toRadians(options.heading); //弧度的螺距分量。 var pitch = options.pitch; //滚动分量(以弧度为单位) var roll = options.roll; //HeadingPitchRoll旋转表示为航向,俯仰和滚动。围绕Z轴。节距是绕负y轴的旋转。滚动是关于正x轴。 var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); var modelGltf = viewer.entities.add({ id: options.id, //模型id position: position, // 模型位置 orientation: Cesium.Transforms.headingPitchRollQuaternion(position, hpr), // 模型方向 model: { // 模型资源 uri: options.url, // 模型路径 incrementallyLoadTextures: true, //加载模型后纹理是否能够继续流入 colorBlendMode: Cesium.ColorBlendMode['HIGHLIGHT'], //经常使用的有三个HIGHLIGHT,REPLACE,MIX colorBlendAmount: 0.1, //这个属性必须是MIX混合属性才能生效,见colorBlendMode color: Cesium.Color.WHITE.withAlpha(options.alpha), //模型颜色,这里可以设置颜色的变化,包含透明度的颜色 imageBasedLightingFactor: new Cesium.Cartesian2(12.0, 13.0), runAnimations: true, //是否运行模型中的动画效果 show: true, // 模型是否可见 // 仅用于调试,显示魔仙绘制时的线框 debugWireframe: false, // 仅用于调试。显示模型绘制时的边界球。 debugShowBoundingVolume: false, }, }); // 模型最小刻度,不管缩放如何,模型的最小最小像素大小。 if (options.minimumPixelSize) { modelGltf.model.minimumPixelSize = options.minimumPixelSize; } // 模型最大刻度,模型的最大比例尺大小。 minimumPixelSize的上限。 if (options.maximumScale) { modelGltf.model.maximumScale = options.maximumScale; } // 模型轮廓颜色 if (options.silhouetteColor) { if (options.silhouetteColor instanceof Array) { options.silhouetteColor = new Cesium.Color(options.silhouetteColor[0] / 255, options.silhouetteColor[1] / 255, options.silhouetteColor[2] / 255, options.silhouetteColor[3]); } else if (typeof(options.silhouetteColor) === 'string') { options.silhouetteColor = new Cesium.Color.fromCssColorString(options.silhouetteColor); } else { options.silhouetteColor = new Cesium.Color.fromCssColorString("#FFFF00"); } } window[options.id] = modelGltf; resolve(options.id); }); }, /** * 加载GLTF/GLB模型数据 * @param {Object} options 参数对象 * @param {Array/Cesium.Cartesian3} options.points 模型加载位置 Array[lng,lat,height]经度,以度为单位,纬度,以度为单位,高程 * @param {String} options.url 模型路径 * @param {String} [options.id=guid] 模型实体加载ID,加入到整体图层中 以便可以删除对应的图层 * @param {Number} [options.scale] 放大倍数 */ addModelFromGltf(points, options) { let _self = this; let viewer = this._viewer; //异步函数 return new Promise((resolve, reject) => { if (!Cesium.defined(options.points)) { resolve("options.points is required."); throw new Cesium.DeveloperError("options.points is required."); } if (!Cesium.defined(options.url)) { resolve("options.url is required."); throw new Cesium.DeveloperError("options.url is required."); } options.id = options.id || setSessionid(); options.scale = Cesium.defaultValue(options.scale, 1); //gltf数据加载位置 let position = undefined; if (options.points instanceof Cesium.Cartesian3) { position = options.points; } else { position = Cesium.Cartesian3.fromDegrees(options.points[0], options.points[1], options.points[2] || 0); } // options.heading = Cesium.defaultValue(options.heading, 0.0); // options.pitch = Cesium.defaultValue(options.pitch, 0.0); // options.roll = Cesium.defaultValue(options.roll, 0.0); // // 设置模型方向 // //弧度的航向分量。 // var heading = Cesium.Math.toRadians(options.heading); // //弧度的螺距分量。 // var pitch = options.pitch; // //滚动分量(以弧度为单位) // var roll = options.roll; // var hpRoll = new Cesium.HeadingPitchRoll(heading, pitch, roll); // // 生成一个函数,该函数从以提供的原点为中心的参考帧到提供的椭圆体的固定参考帧计算4x4变换矩阵。 // var fixedFrame = Cesium.Transforms.localFrameToFixedFrameGenerator('north', 'west'); const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(position); let model = viewer.scene.primitives.add( Cesium.Model.fromGltf({ show: true, //确定是否将显示模型基元 url: options.url, // 资源路径 modelMatrix: modelMatrix, // 模型矩阵 lightColor: new Cesium.Cartesian3(10.0, 10.0, 10.0), // scale: options.scale, // 放大倍数 // 仅用于调试,显示魔仙绘制时的线框 debugWireframe: false, // 仅用于调试。显示模型绘制时的边界球。 debugShowBoundingVolume: false, }) ) /** 模型旋转角度 */ model.readyPromise.then(function() { //延z轴旋转-90度,其它轴同理 var rotationX = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(0))); Cesium.Matrix4.multiply(model.modelMatrix, rotationX, model.modelMatrix); }) window[options.id] = model; resolve(options.id) }); }, }); export default PointObject;