|
@@ -1,745 +1,777 @@
|
|
|
export default {
|
|
|
- /**
|
|
|
- * 添加自定义数据源
|
|
|
- * @param viewer
|
|
|
- * @param dsIds
|
|
|
- */
|
|
|
- addCustomLayer(viewer, dsIds) {
|
|
|
- dsIds = Array.isArray(dsIds) ? dsIds : [dsIds]
|
|
|
- dsIds.forEach(id => {
|
|
|
- let source = viewer.dataSources.getByName(id);
|
|
|
- if (source.length == 0) {
|
|
|
- viewer.dataSources.add(new Cesium.CustomDataSource(id))
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- /**
|
|
|
- * 根据id获取数据源
|
|
|
- * @param viewer
|
|
|
- * @param id
|
|
|
- */
|
|
|
- getCustomLayer(viewer, id) {
|
|
|
- let source = viewer.dataSources.getByName(id);
|
|
|
- return source.length > 0 ? source[0] : null
|
|
|
- },
|
|
|
- /**
|
|
|
- * 通过id获取DataSource里面的实体
|
|
|
- * @param {*} ds
|
|
|
- * @param {*} id
|
|
|
- * @returns
|
|
|
- */
|
|
|
- getEntityByIdDS(ds, id) {
|
|
|
- const entities = ds.entities || [];
|
|
|
- return entities.getById(id);
|
|
|
- },
|
|
|
- /**
|
|
|
- * 移除自定义数据源
|
|
|
- * @param viewer
|
|
|
- * @param dsIds
|
|
|
- */
|
|
|
- removeCustomLayer(viewer, dsIds) {
|
|
|
- dsIds = Array.isArray(dsIds) ? dsIds : [dsIds]
|
|
|
- dsIds.forEach(id => {
|
|
|
- let source = viewer.dataSources.getByName(id);
|
|
|
- source.forEach(sou => {
|
|
|
- viewer.dataSources.remove(sou, true)
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- /**
|
|
|
- * 根据id删除指定数据源的实体
|
|
|
- * @param viewer
|
|
|
- * @param dsId
|
|
|
- * @param ids
|
|
|
- */
|
|
|
- removeCustomLayerEntitysById(viewer, dsId, ids) {
|
|
|
- ids = Array.isArray(ids) ? ids : [ids];
|
|
|
- let source = viewer.dataSources.getByName(dsId);
|
|
|
- source.forEach(sou => {
|
|
|
- ids.forEach(id => {
|
|
|
- sou.entities.removeById(id);
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- /**
|
|
|
- * 添加自定义数据源的点
|
|
|
- * @param viewer
|
|
|
- * @param dsId
|
|
|
- * @param points
|
|
|
- */
|
|
|
- addCustomPoints(viewer, dsId, points) {
|
|
|
- if (!Array.isArray(points)) {
|
|
|
- points = [points]
|
|
|
- }
|
|
|
- let source = viewer.dataSources.getByName(dsId);
|
|
|
+ /**
|
|
|
+ * 添加自定义数据源
|
|
|
+ * @param viewer
|
|
|
+ * @param dsIds
|
|
|
+ */
|
|
|
+ addCustomLayer(viewer, dsIds) {
|
|
|
+ dsIds = Array.isArray(dsIds) ? dsIds : [dsIds]
|
|
|
+ dsIds.forEach(id => {
|
|
|
+ let source = viewer.dataSources.getByName(id);
|
|
|
+ if (source.length == 0) {
|
|
|
+ viewer.dataSources.add(new Cesium.CustomDataSource(id))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 根据id获取数据源
|
|
|
+ * @param viewer
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ getCustomLayer(viewer, id) {
|
|
|
+ let source = viewer.dataSources.getByName(id);
|
|
|
+ return source.length > 0 ? source[0] : null
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 通过id获取DataSource里面的实体
|
|
|
+ * @param {*} ds
|
|
|
+ * @param {*} id
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+ getEntityByIdDS(ds, id) {
|
|
|
+ const entities = ds.entities || [];
|
|
|
+ return entities.getById(id);
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 移除自定义数据源
|
|
|
+ * @param viewer
|
|
|
+ * @param dsIds
|
|
|
+ */
|
|
|
+ removeCustomLayer(viewer, dsIds) {
|
|
|
+ dsIds = Array.isArray(dsIds) ? dsIds : [dsIds]
|
|
|
+ dsIds.forEach(id => {
|
|
|
+ let source = viewer.dataSources.getByName(id);
|
|
|
+ source.forEach(sou => {
|
|
|
+ viewer.dataSources.remove(sou, true)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 根据id删除指定数据源的实体
|
|
|
+ * @param viewer
|
|
|
+ * @param dsId
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
+ removeCustomLayerEntitysById(viewer, dsId, ids) {
|
|
|
+ ids = Array.isArray(ids) ? ids : [ids];
|
|
|
+ let source = viewer.dataSources.getByName(dsId);
|
|
|
+ source.forEach(sou => {
|
|
|
+ ids.forEach(id => {
|
|
|
+ sou.entities.removeById(id);
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 添加自定义数据源的点
|
|
|
+ * @param viewer
|
|
|
+ * @param dsId
|
|
|
+ * @param points
|
|
|
+ */
|
|
|
+ addCustomPoints(viewer, dsId, points) {
|
|
|
+ if (!Array.isArray(points)) {
|
|
|
+ points = [points]
|
|
|
+ }
|
|
|
+ let source = viewer.dataSources.getByName(dsId);
|
|
|
|
|
|
|
|
|
+ if (source.length > 0) {
|
|
|
+ source = source[0];
|
|
|
+ points.forEach(point => {
|
|
|
+ // 如果层数据里面有该id的实体,则不在新增
|
|
|
+ if (source.entities.getById(point.id)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ source.entities.add({
|
|
|
+ position: Cesium.Cartesian3.fromDegrees(point.lon, point.lat),
|
|
|
+ id: point.id,
|
|
|
+ name: point.name,
|
|
|
+ point: {
|
|
|
+ show: true,
|
|
|
+ color: point.color ? point.color : Cesium.Color.SKYBLUE,
|
|
|
+ pixelSize: point.size ? point.size : 5,
|
|
|
+ outlineColor: point.outlineColor ? point.outlineColor : null,
|
|
|
+ outlineWidth: point.outlineWidth ? point.outlineWidth : 1,
|
|
|
+ zIndex: point.zIndex ? point.zIndex : 1
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 添加自定义数据源的点
|
|
|
+ * @param viewer
|
|
|
+ * @param dsId
|
|
|
+ * @param points
|
|
|
+ */
|
|
|
+ addCustomLines(viewer, dsId, lines) {
|
|
|
+ if (!Array.isArray(lines)) {
|
|
|
+ lines = [lines]
|
|
|
+ }
|
|
|
+ let source = viewer.dataSources.getByName(dsId);
|
|
|
|
|
|
- if (source.length > 0) {
|
|
|
- source = source[0];
|
|
|
- points.forEach(point => {
|
|
|
- // 如果层数据里面有该id的实体,则不在新增
|
|
|
- if (source.entities.getById(point.id)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- source.entities.add({
|
|
|
- position: Cesium.Cartesian3.fromDegrees(point.lon, point.lat),
|
|
|
- id: point.id,
|
|
|
- name: point.name,
|
|
|
- point: {
|
|
|
- show: true,
|
|
|
- color: point.color ? point.color : Cesium.Color.SKYBLUE,
|
|
|
- pixelSize: point.size ? point.size : 5,
|
|
|
- outlineColor: point.outlineColor ? point.outlineColor : null,
|
|
|
- outlineWidth: point.outlineWidth ? point.outlineWidth : 1,
|
|
|
- zIndex: point.zIndex ? point.zIndex : 1
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- /**
|
|
|
- * 添加自定义数据源的矩形
|
|
|
- * @param viewer
|
|
|
- * @param dsId
|
|
|
- * @param rectangles
|
|
|
- */
|
|
|
- addCustomRectangles(viewer, dsId, rectangles) {
|
|
|
- let source = viewer.dataSources.getByName(dsId);
|
|
|
- if (source.length > 0) {
|
|
|
- source = source[0];
|
|
|
- rectangles.forEach(rectangle => {
|
|
|
- if (rectangle.coordinates.length === 4) {
|
|
|
- let coords = Cesium.Rectangle.fromDegreesArray(Cesium.Cartesian3.fromDegreesArray(rectangle.coordinates));
|
|
|
- // rectangle.coordinates.forEach(item => {
|
|
|
- // coords.push(Cesium.Rectangle.fromDegrees(Cesium.Cartesian3.fromDegrees()))
|
|
|
- // })
|
|
|
- source.entities.add({
|
|
|
- id: rectangle.id,
|
|
|
- name: rectangle.name,
|
|
|
- rectangle: {
|
|
|
- show: true,
|
|
|
- height: rectangles.height ? rectangles.height : 0,
|
|
|
- coordinates: coords,
|
|
|
- material: Cesium.Color.SKYBLUE,
|
|
|
- zIndex: rectangle.zIndex ? rectangle.zIndex : 1
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- /**
|
|
|
- * 添加自定义数据源的多边形
|
|
|
- * @param viewer
|
|
|
- * @param dsId
|
|
|
- * @param polygons
|
|
|
- */
|
|
|
+ if (source.length > 0) {
|
|
|
+ source = source[0];
|
|
|
+ lines.forEach(line => {
|
|
|
+ // 如果层数据里面有该id的实体,则不在新增
|
|
|
+ if (source.entities.getById(line.id)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ source.entities.add({
|
|
|
+ id: line.id,
|
|
|
+ name: line.name,
|
|
|
+ polyline: {
|
|
|
+ positions: Cesium.Cartesian3.fromDegreesArray(line.points),
|
|
|
+ width: line.material ? 10 : 5,
|
|
|
+ material: line.material ? line.material : Cesium.Color.RED,
|
|
|
+ clampToGround: true,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 添加自定义数据源的矩形
|
|
|
+ * @param viewer
|
|
|
+ * @param dsId
|
|
|
+ * @param rectangles
|
|
|
+ */
|
|
|
+ addCustomRectangles(viewer, dsId, rectangles) {
|
|
|
+ let source = viewer.dataSources.getByName(dsId);
|
|
|
+ if (source.length > 0) {
|
|
|
+ source = source[0];
|
|
|
+ rectangles.forEach(rectangle => {
|
|
|
+ if (rectangle.coordinates.length === 4) {
|
|
|
+ let coords = Cesium.Rectangle.fromDegreesArray(Cesium.Cartesian3.fromDegreesArray(rectangle.coordinates));
|
|
|
+ // rectangle.coordinates.forEach(item => {
|
|
|
+ // coords.push(Cesium.Rectangle.fromDegrees(Cesium.Cartesian3.fromDegrees()))
|
|
|
+ // })
|
|
|
+ source.entities.add({
|
|
|
+ id: rectangle.id,
|
|
|
+ name: rectangle.name,
|
|
|
+ rectangle: {
|
|
|
+ show: true,
|
|
|
+ height: rectangles.height ? rectangles.height : 0,
|
|
|
+ coordinates: coords,
|
|
|
+ material: Cesium.Color.SKYBLUE,
|
|
|
+ zIndex: rectangle.zIndex ? rectangle.zIndex : 1
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
- addCustomPolygons(viewer, dsId, polygons) {
|
|
|
- polygons = Array.isArray(polygons) ? polygons : [polygons];
|
|
|
- let source = viewer.dataSources.getByName(dsId);
|
|
|
- if (source.length > 0) {
|
|
|
- source = source[0];
|
|
|
- polygons.forEach(polygon => {
|
|
|
- // 如果层数据里面有该id的实体,则不在新增
|
|
|
- if (source.entities.getById(polygon.id)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- source.entities.add({
|
|
|
- id: polygon.id,
|
|
|
- name: polygon.name,
|
|
|
- polygon: {
|
|
|
- show: true,
|
|
|
- height: polygon.height ? polygon.height : 0,
|
|
|
- arcType: polygon.isRhumb ? Cesium.ArcType.RHUMB : Cesium.ArcType.GEODESIC,
|
|
|
- hierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(polygon.polygon)),
|
|
|
- material: polygon.material ? polygon.material : Cesium.Color.SKYBLUE,
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- /**
|
|
|
- * 添加自定义数据源的实体
|
|
|
- * @param viewer
|
|
|
- * @param dsId
|
|
|
- * @param entities
|
|
|
- */
|
|
|
- addEntitiesToLayer(viewer, dsId, entities) {
|
|
|
- entities = Array.isArray(entities) ? entities : [entities];
|
|
|
- let dataSouce = viewer.dataSources.getByName(dsId);
|
|
|
- if (dataSouce.length > 0) {
|
|
|
- entities.forEach(entitie => {
|
|
|
- dataSouce[0].entities.add(entitie)
|
|
|
- })
|
|
|
- } else {
|
|
|
- console.log("未找到id为" + dsId + "的数据源")
|
|
|
- }
|
|
|
- },
|
|
|
- /**
|
|
|
- * 控制指定数据源显示
|
|
|
- * @param viewer
|
|
|
- * @param dsIds
|
|
|
- * @param isshow
|
|
|
- */
|
|
|
- controlLayer(viewer, dsIds, isshow) {
|
|
|
- dsIds = Array.isArray(dsIds) ? dsIds : [dsIds]
|
|
|
- dsIds.forEach(id => {
|
|
|
- let source = viewer.dataSources.getByName(id);
|
|
|
- source.forEach(sou => {
|
|
|
- sou.show = isshow
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- /**
|
|
|
- * 控制所有数据源显示
|
|
|
- * @param viewer
|
|
|
- * @param isshow
|
|
|
- */
|
|
|
- controlAllLayer(viewer, isshow) {
|
|
|
- let dataSources = viewer.dataSources;
|
|
|
- for (let i = 0; i < dataSources.length; i++) {
|
|
|
- dataSources.get(i).show = isshow;
|
|
|
- }
|
|
|
- // viewer.entities.show = false
|
|
|
- },
|
|
|
- /**
|
|
|
- * 相机飞行指定点视角
|
|
|
- * @param viewer
|
|
|
- * @param lon
|
|
|
- * @param lat
|
|
|
- * @param height
|
|
|
- */
|
|
|
- flyToTargetPoint(viewer, lon, lat, height) {
|
|
|
- viewer.camera.flyTo({
|
|
|
- destination: Cesium.Cartesian3.fromDegrees(lon, lat, height),
|
|
|
- orientation: {
|
|
|
- pitch: Cesium.Math.toRadians(-88)
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- /**
|
|
|
- * 相机飞行指定点视角
|
|
|
- * @param viewer
|
|
|
- * @param points
|
|
|
- * @param height
|
|
|
- */
|
|
|
- flyToTargetPolygon(viewer, points, height) {
|
|
|
- // debugger
|
|
|
- let rec = Cesium.Rectangle.fromCartesianArray(Cesium.Cartesian3.fromDegreesArray(points));
|
|
|
- // let boundingSphere = Cesium.BoundingSphere.fromRectangle3D(rec);
|
|
|
- let boundingSphere = Cesium.BoundingSphere.fromRectangle3D(rec);
|
|
|
- // let matr = new Cesium.Matrix4.fromCamera(viewer.camera)
|
|
|
- let offset = new Cesium.HeadingPitchRange(0, -90, height)
|
|
|
- // viewer.camera.viewBoundingSphere(boundingSphere, offset)//直接跳转
|
|
|
- viewer.camera.flyToBoundingSphere(boundingSphere, {
|
|
|
- offset: offset
|
|
|
- })
|
|
|
- },
|
|
|
- /**
|
|
|
- * 添加地面站模型
|
|
|
- * @param viewer
|
|
|
- * @param dsId
|
|
|
- * @param models
|
|
|
- */
|
|
|
- addModels(viewer, dsId, models) {
|
|
|
- if (!Array.isArray(models)) {
|
|
|
- models = [models]
|
|
|
- }
|
|
|
- let source = viewer.dataSources.getByName(dsId);
|
|
|
- if (source.length > 0) {
|
|
|
- source = source[0];
|
|
|
- source.entities.removeAll();
|
|
|
- const heading = Cesium.Math.toRadians(135);
|
|
|
- const pitch = 0;
|
|
|
- const roll = 0;
|
|
|
- const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
|
|
|
- models.forEach(model => {
|
|
|
- let position = Cesium.Cartesian3.fromDegrees(model.lon, model.lat, model.height);
|
|
|
- const orientation = Cesium.Transforms.headingPitchRollQuaternion(
|
|
|
- position,
|
|
|
- hpr
|
|
|
- );
|
|
|
- source.entities.add({
|
|
|
- id: model.id,
|
|
|
- name: model.name,
|
|
|
- position: position,
|
|
|
- orientation: orientation,
|
|
|
- data: model,
|
|
|
- model: {
|
|
|
- show: true,
|
|
|
- uri: model.url,
|
|
|
- scale: model.scale ? model.scale : 1,
|
|
|
- minimumPixelSize: model.min ? model.min : 50,
|
|
|
- maximumScale: model.max ? model.max : undefined
|
|
|
- },
|
|
|
- label: {
|
|
|
- text: model.name,
|
|
|
- font: '12px SimHei ',
|
|
|
- Width: 100,
|
|
|
- height: 20,
|
|
|
- style: Cesium.LabelStyle.FILL,
|
|
|
- fillColor: Cesium.Color.WHITE,
|
|
|
- backgroundColor: new Cesium.Color(226, 48, 48, 0.57),
|
|
|
- // backgroundColor: Cesium.Color.RED.withAlpha(0.5),
|
|
|
- showBackground: true,
|
|
|
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
|
|
|
- verticalOrigin: Cesium.VerticalOrigin.TOP,
|
|
|
- },
|
|
|
- // show: true
|
|
|
- });
|
|
|
- })
|
|
|
- }
|
|
|
- // viewer.trackedEntity = entity;
|
|
|
- },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 添加自定义数据源的多边形
|
|
|
+ * @param viewer
|
|
|
+ * @param dsId
|
|
|
+ * @param polygons
|
|
|
+ */
|
|
|
|
|
|
- /**
|
|
|
- * 获取实体某时间的位置信息
|
|
|
- * @param {*} entity
|
|
|
- * @param {*} time
|
|
|
- * @returns
|
|
|
- */
|
|
|
- getEntityPos: function (entity, time) {
|
|
|
- if (entity.position.getValue(time)) {
|
|
|
- let cartographic = Cesium.Cartographic.fromCartesian(entity.position.getValue(time));
|
|
|
- return {
|
|
|
- lon: Cesium.Math.toDegrees(cartographic.longitude),
|
|
|
- lat: Cesium.Math.toDegrees(cartographic.latitude),
|
|
|
- alt: cartographic.height,
|
|
|
- }
|
|
|
- } else {
|
|
|
- return {
|
|
|
- lon: 0,
|
|
|
- lat: 0,
|
|
|
- alt: 0,
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
+ addCustomPolygons(viewer, dsId, polygons) {
|
|
|
+ polygons = Array.isArray(polygons) ? polygons : [polygons];
|
|
|
+ let source = viewer.dataSources.getByName(dsId);
|
|
|
+ if (source.length > 0) {
|
|
|
+ source = source[0];
|
|
|
+ polygons.forEach(polygon => {
|
|
|
+ // 如果层数据里面有该id的实体,则不在新增
|
|
|
+ if (source.entities.getById(polygon.id)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ source.entities.add({
|
|
|
+ id: polygon.id,
|
|
|
+ name: polygon.name,
|
|
|
+ polygon: {
|
|
|
+ show: true,
|
|
|
+ height: polygon.height ? polygon.height : 0,
|
|
|
+ arcType: polygon.isRhumb ? Cesium.ArcType.RHUMB : Cesium.ArcType.GEODESIC,
|
|
|
+ hierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(polygon.polygon)),
|
|
|
+ material: polygon.material ? polygon.material : Cesium.Color.SKYBLUE,
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 添加自定义数据源的实体
|
|
|
+ * @param viewer
|
|
|
+ * @param dsId
|
|
|
+ * @param entities
|
|
|
+ */
|
|
|
+ addEntitiesToLayer(viewer, dsId, entities) {
|
|
|
+ entities = Array.isArray(entities) ? entities : [entities];
|
|
|
+ let dataSouce = viewer.dataSources.getByName(dsId);
|
|
|
+ if (dataSouce.length > 0) {
|
|
|
+ entities.forEach(entitie => {
|
|
|
+ dataSouce[0].entities.add(entitie)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ console.log("未找到id为" + dsId + "的数据源")
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 控制指定数据源显示
|
|
|
+ * @param viewer
|
|
|
+ * @param dsIds
|
|
|
+ * @param isshow
|
|
|
+ */
|
|
|
+ controlLayer(viewer, dsIds, isshow) {
|
|
|
+ dsIds = Array.isArray(dsIds) ? dsIds : [dsIds]
|
|
|
+ dsIds.forEach(id => {
|
|
|
+ let source = viewer.dataSources.getByName(id);
|
|
|
+ source.forEach(sou => {
|
|
|
+ sou.show = isshow
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 控制所有数据源显示
|
|
|
+ * @param viewer
|
|
|
+ * @param isshow
|
|
|
+ */
|
|
|
+ controlAllLayer(viewer, isshow) {
|
|
|
+ let dataSources = viewer.dataSources;
|
|
|
+ for (let i = 0; i < dataSources.length; i++) {
|
|
|
+ dataSources.get(i).show = isshow;
|
|
|
+ }
|
|
|
+ // viewer.entities.show = false
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 相机飞行指定点视角
|
|
|
+ * @param viewer
|
|
|
+ * @param lon
|
|
|
+ * @param lat
|
|
|
+ * @param height
|
|
|
+ */
|
|
|
+ flyToTargetPoint(viewer, lon, lat, height) {
|
|
|
+ viewer.camera.flyTo({
|
|
|
+ destination: Cesium.Cartesian3.fromDegrees(lon, lat, height),
|
|
|
+ orientation: {
|
|
|
+ pitch: Cesium.Math.toRadians(-88)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 相机飞行指定点视角
|
|
|
+ * @param viewer
|
|
|
+ * @param points
|
|
|
+ * @param height
|
|
|
+ */
|
|
|
+ flyToTargetPolygon(viewer, points, height) {
|
|
|
+ // debugger
|
|
|
+ let rec = Cesium.Rectangle.fromCartesianArray(Cesium.Cartesian3.fromDegreesArray(points));
|
|
|
+ // let boundingSphere = Cesium.BoundingSphere.fromRectangle3D(rec);
|
|
|
+ let boundingSphere = Cesium.BoundingSphere.fromRectangle3D(rec);
|
|
|
+ // let matr = new Cesium.Matrix4.fromCamera(viewer.camera)
|
|
|
+ let offset = new Cesium.HeadingPitchRange(0, -90, height)
|
|
|
+ // viewer.camera.viewBoundingSphere(boundingSphere, offset)//直接跳转
|
|
|
+ viewer.camera.flyToBoundingSphere(boundingSphere, {
|
|
|
+ offset: offset
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 添加地面站模型
|
|
|
+ * @param viewer
|
|
|
+ * @param dsId
|
|
|
+ * @param models
|
|
|
+ */
|
|
|
+ addModels(viewer, dsId, models) {
|
|
|
+ if (!Array.isArray(models)) {
|
|
|
+ models = [models]
|
|
|
+ }
|
|
|
+ let source = viewer.dataSources.getByName(dsId);
|
|
|
+ if (source.length > 0) {
|
|
|
+ source = source[0];
|
|
|
+ source.entities.removeAll();
|
|
|
+ const heading = Cesium.Math.toRadians(135);
|
|
|
+ const pitch = 0;
|
|
|
+ const roll = 0;
|
|
|
+ const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
|
|
|
+ models.forEach(model => {
|
|
|
+ let position = Cesium.Cartesian3.fromDegrees(model.lon, model.lat, model.height);
|
|
|
+ const orientation = Cesium.Transforms.headingPitchRollQuaternion(
|
|
|
+ position,
|
|
|
+ hpr
|
|
|
+ );
|
|
|
+ source.entities.add({
|
|
|
+ id: model.id,
|
|
|
+ name: model.name,
|
|
|
+ position: position,
|
|
|
+ orientation: orientation,
|
|
|
+ data: model,
|
|
|
+ model: {
|
|
|
+ show: true,
|
|
|
+ uri: model.url,
|
|
|
+ scale: model.scale ? model.scale : 1,
|
|
|
+ minimumPixelSize: model.min ? model.min : 50,
|
|
|
+ maximumScale: model.max ? model.max : undefined
|
|
|
+ },
|
|
|
+ label: {
|
|
|
+ text: model.name,
|
|
|
+ font: '12px SimHei ',
|
|
|
+ Width: 100,
|
|
|
+ height: 20,
|
|
|
+ style: Cesium.LabelStyle.FILL,
|
|
|
+ fillColor: Cesium.Color.WHITE,
|
|
|
+ backgroundColor: new Cesium.Color(226, 48, 48, 0.57),
|
|
|
+ // backgroundColor: Cesium.Color.RED.withAlpha(0.5),
|
|
|
+ showBackground: true,
|
|
|
+ horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
|
|
|
+ verticalOrigin: Cesium.VerticalOrigin.TOP,
|
|
|
+ },
|
|
|
+ // show: true
|
|
|
+ });
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // viewer.trackedEntity = entity;
|
|
|
+ },
|
|
|
|
|
|
- // 将字符串时间转为中间带T的字符串时间
|
|
|
- strTimeToCesiumStrTime(strTime) {
|
|
|
- if (typeof strTime === 'string') {
|
|
|
- return strTime.replace(' ', 'T') + 'Z';
|
|
|
- }
|
|
|
- },
|
|
|
+ /**
|
|
|
+ * 获取实体某时间的位置信息
|
|
|
+ * @param {*} entity
|
|
|
+ * @param {*} time
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+ getEntityPos: function (entity, time) {
|
|
|
+ if (entity.position.getValue(time)) {
|
|
|
+ let cartographic = Cesium.Cartographic.fromCartesian(entity.position.getValue(time));
|
|
|
+ return {
|
|
|
+ lon: Cesium.Math.toDegrees(cartographic.longitude),
|
|
|
+ lat: Cesium.Math.toDegrees(cartographic.latitude),
|
|
|
+ alt: cartographic.height,
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return {
|
|
|
+ lon: 0,
|
|
|
+ lat: 0,
|
|
|
+ alt: 0,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 添加卫星轨道
|
|
|
- * @param {cesium viewer} viewer
|
|
|
- * @param {
|
|
|
- * startTime:'yyyy-MM-dd hh-mm-ss',
|
|
|
- * endTime:'yyyy-MM-dd hh-mm-ss',
|
|
|
- * satelliteCode:'xxx',
|
|
|
- * gdColor:[r,g,b,a], //可选
|
|
|
- * ephList:[time,lon,lat,height,...]} gdList
|
|
|
- * @param {'./xxx.gltf'} modelUrl //可选
|
|
|
- */
|
|
|
- createCZML(viewer, czmlId, startTime, endTime, gdList, modelUrl = '/models/wx.gltf') {
|
|
|
- startTime = this.strTimeToCesiumStrTime(startTime);
|
|
|
- endTime = this.strTimeToCesiumStrTime(endTime);
|
|
|
- const leadTime = 2800;
|
|
|
- const trailTime = 2800;
|
|
|
- const clock = {
|
|
|
- currentTime: startTime,
|
|
|
- interval: startTime + "/" + endTime,
|
|
|
- rang: "LOOP_STOP",
|
|
|
- step: "SYSTEM_CLOCK_MULTIPLIER",
|
|
|
- multiplier: 1,
|
|
|
- };
|
|
|
- let czml = [{
|
|
|
- availability: clock.interval,
|
|
|
- id: "document",
|
|
|
- version: "1.0",
|
|
|
- description: "CZML Document",
|
|
|
- clock: clock,
|
|
|
- }];
|
|
|
- gdList.forEach(gd => {
|
|
|
- const gdColor = gd.gdColor;
|
|
|
- let lineObj = {
|
|
|
- id: gd.satelliteCode,
|
|
|
- description: gd.trackType,
|
|
|
- availability: clock.interval,
|
|
|
- model: {
|
|
|
- gltf: modelUrl,
|
|
|
- scale: 1.0,
|
|
|
- minimumPixelSize: 55,
|
|
|
- },
|
|
|
- position: {
|
|
|
- epoch: startTime,
|
|
|
- interpolationAlgorithm: "LAGRANGE",
|
|
|
- // cartesian: item.data,
|
|
|
- cartographicDegrees: gd.ephList,
|
|
|
- interpolationDegree: 5,
|
|
|
- // referenceFrame: "INERTIAL",
|
|
|
- },
|
|
|
- label: {
|
|
|
- show: true,
|
|
|
- text: gd.satelliteCode,
|
|
|
- horizontalOrigin: "LEFT",
|
|
|
- pixelOffset: {
|
|
|
- cartesian2: [12, 0],
|
|
|
- },
|
|
|
- fillColor: {
|
|
|
- rgba: [1, 253, 60, 255],
|
|
|
- },
|
|
|
- font: "13pt Lucida Console",
|
|
|
- outlineColor: {
|
|
|
- rgba: [0, 0, 0, 255],
|
|
|
- },
|
|
|
- outlineWidth: 3,
|
|
|
- },
|
|
|
- path: {
|
|
|
- show: [{
|
|
|
- interval: clock.interval,
|
|
|
- boolean: true,
|
|
|
- },],
|
|
|
- width: 2,
|
|
|
- leadTime: leadTime,
|
|
|
- trailTime: trailTime,
|
|
|
- resolution: 120,
|
|
|
- material: {
|
|
|
- solidColor: {
|
|
|
- color: {
|
|
|
- rgba: gdColor ? gdColor : [0, 255, 255, 30],
|
|
|
- // rgba: [0, 255, 255, 255],
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- };
|
|
|
- czml.push(lineObj);
|
|
|
- });
|
|
|
- const czmlDS = viewer.dataSources.getByName(czmlId)
|
|
|
- if (czmlDS.length > 0) {
|
|
|
- czmlDS[0].load(czml).then(() => {
|
|
|
- window.trackShow = true;
|
|
|
- });
|
|
|
- } else {
|
|
|
- viewer.dataSources.add(new Cesium.CzmlDataSource(czmlId)).then(czmlSource => {
|
|
|
- czmlSource.load(czml).then(() => {
|
|
|
- window.trackShow = true;
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
+ // 将字符串时间转为中间带T的字符串时间
|
|
|
+ strTimeToCesiumStrTime(strTime) {
|
|
|
+ if (typeof strTime === 'string') {
|
|
|
+ return strTime.replace(' ', 'T') + 'Z';
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 绘制投影
|
|
|
- * @param {*} viewer
|
|
|
- * @param {*} type
|
|
|
- * @param {*} satellite
|
|
|
- * @param {*} show
|
|
|
- * @param {*} data
|
|
|
- * @returns
|
|
|
- */
|
|
|
- drawProjection(viewer, type, satellite, show, data) { // 场景,卫星实体,视场角
|
|
|
- // debugger
|
|
|
- //圆锥clockNow===2;
|
|
|
- // let clockNow = 1;
|
|
|
- // if (type == 2) clockNow = 90;
|
|
|
- let currentTime = viewer.clock.currentTime;
|
|
|
- let position = this.getEntityPos(satellite, currentTime);
|
|
|
- let alt = null;
|
|
|
- let directions = [];
|
|
|
- if (type == 2) {
|
|
|
- alt = position.alt * 10 + position.alt * 10;
|
|
|
- const clockList = [60, 120, 240, 300];
|
|
|
- clockList.forEach(clockItem => {
|
|
|
- let clock = Cesium.Math.toRadians(clockItem);
|
|
|
- let cone = Cesium.Math.toRadians(data.far);
|
|
|
- directions.push(new Cesium.Spherical(clock, cone));
|
|
|
- });
|
|
|
- } else if (type == 1) { //锥形
|
|
|
- alt = position.alt * 2.5;
|
|
|
- for (let i = 0; i < 360; ++i) {
|
|
|
- let clock = Cesium.Math.toRadians(i); // 弧度
|
|
|
- if (clock >= Cesium.Math.toRadians(360)) break;
|
|
|
- let cone = Cesium.Math.toRadians(data.far);
|
|
|
- directions.push(new Cesium.Spherical(clock, cone));
|
|
|
- }
|
|
|
- } else if (type == 3) { //矩形
|
|
|
- alt = position.alt * 2.5;
|
|
|
- // const fourPoints = [45, 135, 225, 315]
|
|
|
- const fourPoints = [60, 120, 240, 300]
|
|
|
- fourPoints.forEach(item => {
|
|
|
- let clock = Cesium.Math.toRadians(item); // 弧度
|
|
|
- let cone = Cesium.Math.toRadians(data.far);
|
|
|
- directions.push(new Cesium.Spherical(clock, cone));
|
|
|
- });
|
|
|
- }
|
|
|
- let customSensor = new CesiumSensors.CustomSensorVolume();
|
|
|
- viewer.scene.preRender.addEventListener((scene, time) => {
|
|
|
- if (satellite.computeModelMatrix(time)) {
|
|
|
- let modelMatrix = satellite.computeModelMatrix(time);
|
|
|
- if (typeof (modelMatrix) == 'object') {
|
|
|
- Cesium.Matrix4.multiply(modelMatrix, Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(-180))), modelMatrix)
|
|
|
- customSensor.modelMatrix = modelMatrix
|
|
|
- }
|
|
|
- let posData = this.setPos(viewer, satellite, 5);
|
|
|
- satellite.orientation = posData.sys;
|
|
|
- }
|
|
|
- })
|
|
|
- if (customSensor.id) customSensor.id = data.id;
|
|
|
- customSensor.radius = alt;
|
|
|
- customSensor.directions = directions;
|
|
|
- customSensor.intersectionWidth = 3;
|
|
|
- customSensor.intersectionColor = new Cesium.Color(51 / 255, 255 / 255, 255 / 255, 1);
|
|
|
- customSensor.lateralSurfaceMaterial.uniforms.color = new Cesium.Color(51 / 255, 255 / 255, 255 / 255, 0.2);
|
|
|
- let entity = viewer.scene.primitives.add(customSensor);
|
|
|
- entity.show = show;
|
|
|
- return entity
|
|
|
- },
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param {*} viewer
|
|
|
- * @param {*} entity
|
|
|
- * @param {*} step
|
|
|
- * @returns
|
|
|
- */
|
|
|
- setPos(viewer, entity, step) {
|
|
|
- let computeLine = function (position, startTime, step) {
|
|
|
- let property = new Cesium.SampledPositionProperty();
|
|
|
- position.forEach((item, index) => {
|
|
|
- let time = Cesium.JulianDate.addSeconds(
|
|
|
- startTime,
|
|
|
- index * step,
|
|
|
- new Cesium.JulianDate()
|
|
|
- );
|
|
|
- property.addSample(time, item);
|
|
|
- });
|
|
|
- let time2 = Cesium.JulianDate.addSeconds(
|
|
|
- startTime,
|
|
|
- step / position.length,
|
|
|
- new Cesium.JulianDate()
|
|
|
- );
|
|
|
- let pos = Cesium.HeadingPitchRoll.fromQuaternion(new Cesium.VelocityOrientationProperty(property).getValue(time2))
|
|
|
- return {
|
|
|
- sys: new Cesium.VelocityOrientationProperty(property).getValue(time2),
|
|
|
- olj: {
|
|
|
- // heading: pos.heading,
|
|
|
- // pitch: pos.pitch,
|
|
|
- // roll: pos.roll
|
|
|
- heading: Cesium.Math.toDegrees(pos.heading),
|
|
|
- pitch: Cesium.Math.toDegrees(pos.pitch),
|
|
|
- roll: Cesium.Math.toDegrees(pos.roll)
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- let tiem1 = viewer.clock.currentTime;
|
|
|
- let time2 = Cesium.JulianDate.addSeconds(
|
|
|
- viewer.clock.currentTime,
|
|
|
- 5,
|
|
|
- new Cesium.JulianDate()
|
|
|
- );
|
|
|
- let position = [entity.position.getValue(tiem1), entity.position.getValue(time2)];
|
|
|
- return computeLine(position, tiem1, step);
|
|
|
- },
|
|
|
+ /**
|
|
|
+ * 添加卫星轨道
|
|
|
+ * @param {cesium viewer} viewer
|
|
|
+ * @param {
|
|
|
+ * startTime:'yyyy-MM-dd hh-mm-ss',
|
|
|
+ * endTime:'yyyy-MM-dd hh-mm-ss',
|
|
|
+ * satelliteCode:'xxx',
|
|
|
+ * gdColor:[r,g,b,a], //可选
|
|
|
+ * ephList:[time,lon,lat,height,...]} gdList
|
|
|
+ * @param {'./xxx.gltf'} modelUrl //可选
|
|
|
+ */
|
|
|
+ createCZML(viewer, czmlId, startTime, endTime, gdList, modelUrl = '/models/wx.gltf') {
|
|
|
+ startTime = this.strTimeToCesiumStrTime(startTime);
|
|
|
+ endTime = this.strTimeToCesiumStrTime(endTime);
|
|
|
+ const leadTime = 2800;
|
|
|
+ const trailTime = 2800;
|
|
|
+ const clock = {
|
|
|
+ currentTime: startTime,
|
|
|
+ interval: startTime + "/" + endTime,
|
|
|
+ rang: "LOOP_STOP",
|
|
|
+ step: "SYSTEM_CLOCK_MULTIPLIER",
|
|
|
+ multiplier: 1,
|
|
|
+ };
|
|
|
+ let czml = [{
|
|
|
+ availability: clock.interval,
|
|
|
+ id: "document",
|
|
|
+ version: "1.0",
|
|
|
+ description: "CZML Document",
|
|
|
+ clock: clock,
|
|
|
+ }];
|
|
|
+ gdList.forEach(gd => {
|
|
|
+ const gdColor = gd.gdColor;
|
|
|
+ let lineObj = {
|
|
|
+ id: gd.satelliteCode,
|
|
|
+ description: gd.trackType,
|
|
|
+ availability: clock.interval,
|
|
|
+ model: {
|
|
|
+ gltf: modelUrl,
|
|
|
+ scale: 1.0,
|
|
|
+ minimumPixelSize: 55,
|
|
|
+ },
|
|
|
+ position: {
|
|
|
+ epoch: startTime,
|
|
|
+ interpolationAlgorithm: "LAGRANGE",
|
|
|
+ // cartesian: item.data,
|
|
|
+ cartographicDegrees: gd.ephList,
|
|
|
+ interpolationDegree: 5,
|
|
|
+ // referenceFrame: "INERTIAL",
|
|
|
+ },
|
|
|
+ label: {
|
|
|
+ show: true,
|
|
|
+ text: gd.satelliteCode,
|
|
|
+ horizontalOrigin: "LEFT",
|
|
|
+ pixelOffset: {
|
|
|
+ cartesian2: [12, 0],
|
|
|
+ },
|
|
|
+ fillColor: {
|
|
|
+ rgba: [1, 253, 60, 255],
|
|
|
+ },
|
|
|
+ font: "13pt Lucida Console",
|
|
|
+ outlineColor: {
|
|
|
+ rgba: [0, 0, 0, 255],
|
|
|
+ },
|
|
|
+ outlineWidth: 3,
|
|
|
+ },
|
|
|
+ path: {
|
|
|
+ show: [{
|
|
|
+ interval: clock.interval,
|
|
|
+ boolean: true,
|
|
|
+ },],
|
|
|
+ width: 2,
|
|
|
+ leadTime: leadTime,
|
|
|
+ trailTime: trailTime,
|
|
|
+ resolution: 120,
|
|
|
+ material: {
|
|
|
+ solidColor: {
|
|
|
+ color: {
|
|
|
+ rgba: gdColor ? gdColor : [0, 255, 255, 30],
|
|
|
+ // rgba: [0, 255, 255, 255],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ };
|
|
|
+ czml.push(lineObj);
|
|
|
+ });
|
|
|
+ const czmlDS = viewer.dataSources.getByName(czmlId)
|
|
|
+ if (czmlDS.length > 0) {
|
|
|
+ czmlDS[0].load(czml).then(() => {
|
|
|
+ window.trackShow = true;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ viewer.dataSources.add(new Cesium.CzmlDataSource(czmlId)).then(czmlSource => {
|
|
|
+ czmlSource.load(czml).then(() => {
|
|
|
+ window.trackShow = true;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * utc时间转换为北京时间
|
|
|
- * @param {*} viewer
|
|
|
- * @param {*} isutc
|
|
|
- */
|
|
|
- formatterDateToUTC8: function(viewer, isutc) {
|
|
|
- const correct = function(tar) {
|
|
|
- if (tar < 10) tar = '0' + tar;
|
|
|
- return tar
|
|
|
- }
|
|
|
- viewer.animation.viewModel.dateFormatter = localeDateTimeFormatter;
|
|
|
- viewer.animation.viewModel.timeFormatter = localeTimeFormatter;
|
|
|
- viewer.timeline.makeLabel = localeDateTimeFormatter;
|
|
|
+ /**
|
|
|
+ * 绘制投影
|
|
|
+ * @param {*} viewer
|
|
|
+ * @param {*} type
|
|
|
+ * @param {*} satellite
|
|
|
+ * @param {*} show
|
|
|
+ * @param {*} data
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+ drawProjection(viewer, type, satellite, show, data) { // 场景,卫星实体,视场角
|
|
|
+ // debugger
|
|
|
+ //圆锥clockNow===2;
|
|
|
+ // let clockNow = 1;
|
|
|
+ // if (type == 2) clockNow = 90;
|
|
|
+ let currentTime = viewer.clock.currentTime;
|
|
|
+ let position = this.getEntityPos(satellite, currentTime);
|
|
|
+ let alt = null;
|
|
|
+ let directions = [];
|
|
|
+ if (type == 2) {
|
|
|
+ alt = position.alt * 10 + position.alt * 10;
|
|
|
+ const clockList = [60, 120, 240, 300];
|
|
|
+ clockList.forEach(clockItem => {
|
|
|
+ let clock = Cesium.Math.toRadians(clockItem);
|
|
|
+ let cone = Cesium.Math.toRadians(data.far);
|
|
|
+ directions.push(new Cesium.Spherical(clock, cone));
|
|
|
+ });
|
|
|
+ } else if (type == 1) { //锥形
|
|
|
+ alt = position.alt * 2.5;
|
|
|
+ for (let i = 0; i < 360; ++i) {
|
|
|
+ let clock = Cesium.Math.toRadians(i); // 弧度
|
|
|
+ if (clock >= Cesium.Math.toRadians(360)) break;
|
|
|
+ let cone = Cesium.Math.toRadians(data.far);
|
|
|
+ directions.push(new Cesium.Spherical(clock, cone));
|
|
|
+ }
|
|
|
+ } else if (type == 3) { //矩形
|
|
|
+ alt = position.alt * 2.5;
|
|
|
+ // const fourPoints = [45, 135, 225, 315]
|
|
|
+ const fourPoints = [60, 120, 240, 300]
|
|
|
+ fourPoints.forEach(item => {
|
|
|
+ let clock = Cesium.Math.toRadians(item); // 弧度
|
|
|
+ let cone = Cesium.Math.toRadians(data.far);
|
|
|
+ directions.push(new Cesium.Spherical(clock, cone));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ let customSensor = new CesiumSensors.CustomSensorVolume();
|
|
|
+ viewer.scene.preRender.addEventListener((scene, time) => {
|
|
|
+ if (satellite.computeModelMatrix(time)) {
|
|
|
+ let modelMatrix = satellite.computeModelMatrix(time);
|
|
|
+ if (typeof (modelMatrix) == 'object') {
|
|
|
+ Cesium.Matrix4.multiply(modelMatrix, Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(-180))), modelMatrix)
|
|
|
+ customSensor.modelMatrix = modelMatrix
|
|
|
+ }
|
|
|
+ let posData = this.setPos(viewer, satellite, 5);
|
|
|
+ satellite.orientation = posData.sys;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (customSensor.id) customSensor.id = data.id;
|
|
|
+ customSensor.radius = alt;
|
|
|
+ customSensor.directions = directions;
|
|
|
+ customSensor.intersectionWidth = 3;
|
|
|
+ customSensor.intersectionColor = new Cesium.Color(51 / 255, 255 / 255, 255 / 255, 1);
|
|
|
+ customSensor.lateralSurfaceMaterial.uniforms.color = new Cesium.Color(51 / 255, 255 / 255, 255 / 255, 0.2);
|
|
|
+ let entity = viewer.scene.primitives.add(customSensor);
|
|
|
+ entity.show = show;
|
|
|
+ return entity
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param {*} viewer
|
|
|
+ * @param {*} entity
|
|
|
+ * @param {*} step
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+ setPos(viewer, entity, step) {
|
|
|
+ let computeLine = function (position, startTime, step) {
|
|
|
+ let property = new Cesium.SampledPositionProperty();
|
|
|
+ position.forEach((item, index) => {
|
|
|
+ let time = Cesium.JulianDate.addSeconds(
|
|
|
+ startTime,
|
|
|
+ index * step,
|
|
|
+ new Cesium.JulianDate()
|
|
|
+ );
|
|
|
+ property.addSample(time, item);
|
|
|
+ });
|
|
|
+ let time2 = Cesium.JulianDate.addSeconds(
|
|
|
+ startTime,
|
|
|
+ step / position.length,
|
|
|
+ new Cesium.JulianDate()
|
|
|
+ );
|
|
|
+ let pos = Cesium.HeadingPitchRoll.fromQuaternion(new Cesium.VelocityOrientationProperty(property).getValue(time2))
|
|
|
+ return {
|
|
|
+ sys: new Cesium.VelocityOrientationProperty(property).getValue(time2),
|
|
|
+ olj: {
|
|
|
+ // heading: pos.heading,
|
|
|
+ // pitch: pos.pitch,
|
|
|
+ // roll: pos.roll
|
|
|
+ heading: Cesium.Math.toDegrees(pos.heading),
|
|
|
+ pitch: Cesium.Math.toDegrees(pos.pitch),
|
|
|
+ roll: Cesium.Math.toDegrees(pos.roll)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ let tiem1 = viewer.clock.currentTime;
|
|
|
+ let time2 = Cesium.JulianDate.addSeconds(
|
|
|
+ viewer.clock.currentTime,
|
|
|
+ 5,
|
|
|
+ new Cesium.JulianDate()
|
|
|
+ );
|
|
|
+ let position = [entity.position.getValue(tiem1), entity.position.getValue(time2)];
|
|
|
+ return computeLine(position, tiem1, step);
|
|
|
+ },
|
|
|
|
|
|
- function localeDateTimeFormatter(datetime, viewModel, ignoredate) {
|
|
|
- let julianDT = new Cesium.JulianDate();
|
|
|
- Cesium.JulianDate.addHours(datetime, isutc ? 8 : 0, julianDT);
|
|
|
- let gregorianDT = Cesium.JulianDate.toGregorianDate(julianDT);
|
|
|
+ /**
|
|
|
+ * utc时间转换为北京时间
|
|
|
+ * @param {*} viewer
|
|
|
+ * @param {*} isutc
|
|
|
+ */
|
|
|
+ formatterDateToUTC8: function (viewer, isutc) {
|
|
|
+ const correct = function (tar) {
|
|
|
+ if (tar < 10) tar = '0' + tar;
|
|
|
+ return tar
|
|
|
+ }
|
|
|
+ viewer.animation.viewModel.dateFormatter = localeDateTimeFormatter;
|
|
|
+ viewer.animation.viewModel.timeFormatter = localeTimeFormatter;
|
|
|
+ viewer.timeline.makeLabel = localeDateTimeFormatter;
|
|
|
|
|
|
- let objDT;
|
|
|
- if (ignoredate) {
|
|
|
- objDT = "";
|
|
|
- } else {
|
|
|
- objDT = gregorianDT.year + "年" + gregorianDT.month + "月" + gregorianDT.day + "日";
|
|
|
- if (viewModel || gregorianDT.hour + gregorianDT.minute === 0) {
|
|
|
- return objDT;
|
|
|
- }
|
|
|
- }
|
|
|
- return objDT + correct(gregorianDT.hour) + ":" + correct(gregorianDT.minute) + ":" + correct(gregorianDT.second);
|
|
|
- }
|
|
|
+ function localeDateTimeFormatter(datetime, viewModel, ignoredate) {
|
|
|
+ let julianDT = new Cesium.JulianDate();
|
|
|
+ Cesium.JulianDate.addHours(datetime, isutc ? 8 : 0, julianDT);
|
|
|
+ let gregorianDT = Cesium.JulianDate.toGregorianDate(julianDT);
|
|
|
|
|
|
- function localeTimeFormatter(time, viewModel) {
|
|
|
- return localeDateTimeFormatter(time, viewModel, true);
|
|
|
- }
|
|
|
+ let objDT;
|
|
|
+ if (ignoredate) {
|
|
|
+ objDT = "";
|
|
|
+ } else {
|
|
|
+ objDT = gregorianDT.year + "年" + gregorianDT.month + "月" + gregorianDT.day + "日";
|
|
|
+ if (viewModel || gregorianDT.hour + gregorianDT.minute === 0) {
|
|
|
+ return objDT;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return objDT + correct(gregorianDT.hour) + ":" + correct(gregorianDT.minute) + ":" + correct(gregorianDT.second);
|
|
|
+ }
|
|
|
|
|
|
- },
|
|
|
+ function localeTimeFormatter(time, viewModel) {
|
|
|
+ return localeDateTimeFormatter(time, viewModel, true);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 流动材质
|
|
|
- */
|
|
|
- polylineMaterial: function() {
|
|
|
- function PolylineTrailLinkMaterialProperty(color, duration) {
|
|
|
- this._definitionChanged = new Cesium.Event();
|
|
|
- this._color = undefined;
|
|
|
- this._colorSubscription = undefined;
|
|
|
- this.color = color;
|
|
|
- this.duration = duration;
|
|
|
- this._time = (new Date()).getTime();
|
|
|
- }
|
|
|
+ },
|
|
|
|
|
|
- Object.defineProperties(PolylineTrailLinkMaterialProperty.prototype, {
|
|
|
- isConstant: {
|
|
|
- get: function() {
|
|
|
- return false;
|
|
|
- }
|
|
|
- },
|
|
|
- definitionChanged: {
|
|
|
- get: function() {
|
|
|
- return this._definitionChanged;
|
|
|
- }
|
|
|
- },
|
|
|
- color: Cesium.createPropertyDescriptor('color')
|
|
|
- });
|
|
|
- PolylineTrailLinkMaterialProperty.prototype.getType = function(time) {
|
|
|
- return 'PolylineTrailLink';
|
|
|
- }
|
|
|
- PolylineTrailLinkMaterialProperty.prototype.getValue = function(time, result) {
|
|
|
- if (!Cesium.defined(result)) {
|
|
|
- result = {};
|
|
|
- }
|
|
|
- result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
|
|
|
- result.image = Cesium.Material.PolylineTrailLinkImage;
|
|
|
- result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration;
|
|
|
- return result;
|
|
|
- }
|
|
|
- PolylineTrailLinkMaterialProperty.prototype.equals = function(other) {
|
|
|
- return this === other || (other instanceof PolylineTrailLinkMaterialProperty && Property.equals(this._color, other._color))
|
|
|
- };
|
|
|
- Cesium.PolylineTrailLinkMaterialProperty = PolylineTrailLinkMaterialProperty;
|
|
|
- Cesium.Material.PolylineTrailLinkType = 'PolylineTrailLink';
|
|
|
- Cesium.Material.PolylineTrailLinkImage = "img/colors1.png"; //图片
|
|
|
- Cesium.Material.PolylineTrailLinkSource =
|
|
|
- "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
|
|
|
- {\n\
|
|
|
- czm_material material = czm_getDefaultMaterial(materialInput);\n\
|
|
|
- vec2 st = materialInput.st;\n\
|
|
|
- vec4 colorImage = texture2D(image, vec2(fract(st.s - time), st.t));\n\
|
|
|
- material.alpha = colorImage.a * color.a;\n\
|
|
|
- material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
|
|
|
- return material;\n\
|
|
|
- }";
|
|
|
- Cesium.Material._materialCache.addMaterial(Cesium.Material.PolylineTrailLinkType, {
|
|
|
- fabric: {
|
|
|
- type: Cesium.Material.PolylineTrailLinkType,
|
|
|
- uniforms: {
|
|
|
- color: Cesium.Color.RED,
|
|
|
- image: Cesium.Material.PolylineTrailLinkImage,
|
|
|
- time: 0
|
|
|
- },
|
|
|
- source: Cesium.Material.PolylineTrailLinkSource
|
|
|
- },
|
|
|
- translucent: function(material) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- })
|
|
|
+ /**
|
|
|
+ * 流动材质
|
|
|
+ */
|
|
|
+ polylineMaterial: function () {
|
|
|
+ function PolylineTrailLinkMaterialProperty(color, duration) {
|
|
|
+ this._definitionChanged = new Cesium.Event();
|
|
|
+ this._color = undefined;
|
|
|
+ this._colorSubscription = undefined;
|
|
|
+ this.color = color;
|
|
|
+ this.duration = duration;
|
|
|
+ this._time = (new Date()).getTime();
|
|
|
+ }
|
|
|
|
|
|
- function PolylineTrailLinkMaterialProperty2(color, duration) {
|
|
|
- this._definitionChanged = new Cesium.Event();
|
|
|
- this._color = undefined;
|
|
|
- this._colorSubscription = undefined;
|
|
|
- this.color = color;
|
|
|
- this.duration = duration;
|
|
|
- this._time = (new Date()).getTime();
|
|
|
- }
|
|
|
+ Object.defineProperties(PolylineTrailLinkMaterialProperty.prototype, {
|
|
|
+ isConstant: {
|
|
|
+ get: function () {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ definitionChanged: {
|
|
|
+ get: function () {
|
|
|
+ return this._definitionChanged;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ color: Cesium.createPropertyDescriptor('color')
|
|
|
+ });
|
|
|
+ PolylineTrailLinkMaterialProperty.prototype.getType = function (time) {
|
|
|
+ return 'PolylineTrailLink';
|
|
|
+ }
|
|
|
+ PolylineTrailLinkMaterialProperty.prototype.getValue = function (time, result) {
|
|
|
+ if (!Cesium.defined(result)) {
|
|
|
+ result = {};
|
|
|
+ }
|
|
|
+ result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
|
|
|
+ result.image = Cesium.Material.PolylineTrailLinkImage;
|
|
|
+ result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ PolylineTrailLinkMaterialProperty.prototype.equals = function (other) {
|
|
|
+ return this === other || (other instanceof PolylineTrailLinkMaterialProperty && Property.equals(this._color, other._color))
|
|
|
+ };
|
|
|
+ Cesium.PolylineTrailLinkMaterialProperty = PolylineTrailLinkMaterialProperty;
|
|
|
+ Cesium.Material.PolylineTrailLinkType = 'PolylineTrailLink';
|
|
|
+ Cesium.Material.PolylineTrailLinkImage = "img/colors1.png"; //图片
|
|
|
+ Cesium.Material.PolylineTrailLinkSource =
|
|
|
+ "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
|
|
|
+ {\n\
|
|
|
+ czm_material material = czm_getDefaultMaterial(materialInput);\n\
|
|
|
+ vec2 st = materialInput.st;\n\
|
|
|
+ vec4 colorImage = texture2D(image, vec2(fract(st.s - time), st.t));\n\
|
|
|
+ material.alpha = colorImage.a * color.a;\n\
|
|
|
+ material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
|
|
|
+ return material;\n\
|
|
|
+ }";
|
|
|
+ Cesium.Material._materialCache.addMaterial(Cesium.Material.PolylineTrailLinkType, {
|
|
|
+ fabric: {
|
|
|
+ type: Cesium.Material.PolylineTrailLinkType,
|
|
|
+ uniforms: {
|
|
|
+ color: Cesium.Color.RED,
|
|
|
+ image: Cesium.Material.PolylineTrailLinkImage,
|
|
|
+ time: 0
|
|
|
+ },
|
|
|
+ source: Cesium.Material.PolylineTrailLinkSource
|
|
|
+ },
|
|
|
+ translucent: function (material) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
- Object.defineProperties(PolylineTrailLinkMaterialProperty2.prototype, {
|
|
|
- isConstant: {
|
|
|
- get: function() {
|
|
|
- return false;
|
|
|
- }
|
|
|
- },
|
|
|
- definitionChanged: {
|
|
|
- get: function() {
|
|
|
- return this._definitionChanged;
|
|
|
- }
|
|
|
- },
|
|
|
- color: Cesium.createPropertyDescriptor('color')
|
|
|
- });
|
|
|
- PolylineTrailLinkMaterialProperty2.prototype.getType = function(time) {
|
|
|
- return 'PolylineTrailLink';
|
|
|
- }
|
|
|
- PolylineTrailLinkMaterialProperty2.prototype.getValue = function(time, result) {
|
|
|
- if (!Cesium.defined(result)) {
|
|
|
- result = {};
|
|
|
- }
|
|
|
- result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
|
|
|
- result.image = "img/colors2.png";
|
|
|
- result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration;
|
|
|
- return result;
|
|
|
- }
|
|
|
- PolylineTrailLinkMaterialProperty2.prototype.equals = function(other) {
|
|
|
- return this === other || (other instanceof PolylineTrailLinkMaterialProperty2 && Property.equals(this._color, other._color))
|
|
|
- };
|
|
|
- Cesium.PolylineTrailLinkMaterialProperty2 = PolylineTrailLinkMaterialProperty2;
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 线条连接两个实体
|
|
|
- * @param {*} options
|
|
|
- * @returns
|
|
|
- */
|
|
|
- addLineBetweenTwoEntity(options) {
|
|
|
- const { viewer, dsId, lineId, satellite, station, times, lineColor, direction } = options;
|
|
|
- const inDirection = direction || 'SC'
|
|
|
- let TimeInterval = null;
|
|
|
- if (times) {
|
|
|
- TimeInterval = new Cesium.TimeIntervalCollection();
|
|
|
- times.forEach(time => {
|
|
|
- TimeInterval.addInterval(
|
|
|
- new Cesium.TimeInterval({
|
|
|
- start: time.start,
|
|
|
- stop: time.stop
|
|
|
- })
|
|
|
- )
|
|
|
- })
|
|
|
- }
|
|
|
- // const material = new Cesium.PolylineTrailLinkMaterialProperty(Cesium.Color.RED, 700);
|
|
|
- const materialCK = new Cesium.PolylineTrailLinkMaterialProperty(Cesium.Color.RED, 700);
|
|
|
- const materialSC = new Cesium.PolylineTrailLinkMaterialProperty2(Cesium.Color.GREEN, 700);
|
|
|
- const source = viewer.dataSources.getByName(dsId)[0];
|
|
|
- const lineEntity = source.entities.add({
|
|
|
- availability: TimeInterval,
|
|
|
- id: lineId,
|
|
|
- polyline: {
|
|
|
- positions: new Cesium.CallbackProperty(time => {
|
|
|
- let positions = []
|
|
|
- inDirection == 'SC' && (positions = [satellite.position.getValue(time), station.position.getValue(time)])
|
|
|
- inDirection == 'CK' && (positions = [station.position.getValue(time), satellite.position.getValue(time)])
|
|
|
- // return [satellite.position.getValue(time), station.position.getValue(time)];
|
|
|
- return positions;
|
|
|
- }, false),
|
|
|
- with: 100,
|
|
|
- // material: lineColor ? lineColor : material,
|
|
|
- material: inDirection == 'CK' ? materialCK : materialSC,
|
|
|
- }
|
|
|
- })
|
|
|
- return lineEntity;
|
|
|
- },
|
|
|
- /**
|
|
|
- * 投影是否可见
|
|
|
- * @param {*} viewer
|
|
|
- * @param {*} proPrimitive
|
|
|
- * @param {*} taskTime
|
|
|
- */
|
|
|
- projectionVisible(viewer, proPrimitive, taskTime) {
|
|
|
- let st = Cesium.JulianDate.fromIso8601(this.strTimeToCesiumStrTime(taskTime.startTime))
|
|
|
- let et = Cesium.JulianDate.fromIso8601(this.strTimeToCesiumStrTime(taskTime.endTime))
|
|
|
- viewer.scene.preUpdate.addEventListener(function(scene, time) {
|
|
|
- if (Cesium.JulianDate.lessThan(time, et)) {
|
|
|
- proPrimitive.show = (Cesium.JulianDate.greaterThanOrEquals(time, st))
|
|
|
- } else {
|
|
|
- proPrimitive.show = false
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
-}
|
|
|
+ function PolylineTrailLinkMaterialProperty2(color, duration) {
|
|
|
+ this._definitionChanged = new Cesium.Event();
|
|
|
+ this._color = undefined;
|
|
|
+ this._colorSubscription = undefined;
|
|
|
+ this.color = color;
|
|
|
+ this.duration = duration;
|
|
|
+ this._time = (new Date()).getTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ Object.defineProperties(PolylineTrailLinkMaterialProperty2.prototype, {
|
|
|
+ isConstant: {
|
|
|
+ get: function () {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ definitionChanged: {
|
|
|
+ get: function () {
|
|
|
+ return this._definitionChanged;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ color: Cesium.createPropertyDescriptor('color')
|
|
|
+ });
|
|
|
+ PolylineTrailLinkMaterialProperty2.prototype.getType = function (time) {
|
|
|
+ return 'PolylineTrailLink';
|
|
|
+ }
|
|
|
+ PolylineTrailLinkMaterialProperty2.prototype.getValue = function (time, result) {
|
|
|
+ if (!Cesium.defined(result)) {
|
|
|
+ result = {};
|
|
|
+ }
|
|
|
+ result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
|
|
|
+ result.image = "img/colors2.png";
|
|
|
+ result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ PolylineTrailLinkMaterialProperty2.prototype.equals = function (other) {
|
|
|
+ return this === other || (other instanceof PolylineTrailLinkMaterialProperty2 && Property.equals(this._color, other._color))
|
|
|
+ };
|
|
|
+ Cesium.PolylineTrailLinkMaterialProperty2 = PolylineTrailLinkMaterialProperty2;
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 线条连接两个实体
|
|
|
+ * @param {*} options
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+ addLineBetweenTwoEntity(options) {
|
|
|
+ const {viewer, dsId, lineId, satellite, station, times, lineColor, direction} = options;
|
|
|
+ const inDirection = direction || 'SC'
|
|
|
+ let TimeInterval = null;
|
|
|
+ if (times) {
|
|
|
+ TimeInterval = new Cesium.TimeIntervalCollection();
|
|
|
+ times.forEach(time => {
|
|
|
+ TimeInterval.addInterval(
|
|
|
+ new Cesium.TimeInterval({
|
|
|
+ start: time.start,
|
|
|
+ stop: time.stop
|
|
|
+ })
|
|
|
+ )
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // const material = new Cesium.PolylineTrailLinkMaterialProperty(Cesium.Color.RED, 700);
|
|
|
+ const materialCK = new Cesium.PolylineTrailLinkMaterialProperty(Cesium.Color.RED, 700);
|
|
|
+ const materialSC = new Cesium.PolylineTrailLinkMaterialProperty2(Cesium.Color.GREEN, 700);
|
|
|
+ const source = viewer.dataSources.getByName(dsId)[0];
|
|
|
+ const lineEntity = source.entities.add({
|
|
|
+ availability: TimeInterval,
|
|
|
+ id: lineId,
|
|
|
+ polyline: {
|
|
|
+ positions: new Cesium.CallbackProperty(time => {
|
|
|
+ let positions = []
|
|
|
+ inDirection == 'SC' && (positions = [satellite.position.getValue(time), station.position.getValue(time)])
|
|
|
+ inDirection == 'CK' && (positions = [station.position.getValue(time), satellite.position.getValue(time)])
|
|
|
+ // return [satellite.position.getValue(time), station.position.getValue(time)];
|
|
|
+ return positions;
|
|
|
+ }, false),
|
|
|
+ with: 100,
|
|
|
+ // material: lineColor ? lineColor : material,
|
|
|
+ material: inDirection == 'CK' ? materialCK : materialSC,
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return lineEntity;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 投影是否可见
|
|
|
+ * @param {*} viewer
|
|
|
+ * @param {*} proPrimitive
|
|
|
+ * @param {*} taskTime
|
|
|
+ */
|
|
|
+ projectionVisible(viewer, proPrimitive, taskTime) {
|
|
|
+ let st = Cesium.JulianDate.fromIso8601(this.strTimeToCesiumStrTime(taskTime.startTime))
|
|
|
+ let et = Cesium.JulianDate.fromIso8601(this.strTimeToCesiumStrTime(taskTime.endTime))
|
|
|
+ viewer.scene.preUpdate.addEventListener(function (scene, time) {
|
|
|
+ if (Cesium.JulianDate.lessThan(time, et)) {
|
|
|
+ proPrimitive.show = (Cesium.JulianDate.greaterThanOrEquals(time, st))
|
|
|
+ } else {
|
|
|
+ proPrimitive.show = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+}
|