///////////////////////////////////////////////////////////////////////////
|
// Copyright © 2019 zhongsong. All Rights Reserved.
|
// 模块描述:显示坐标
|
///////////////////////////////////////////////////////////////////////////
|
define([
|
'dojo/_base/declare',
|
'dojo/_base/lang',
|
'dojo/_base/array',
|
'dojo/_base/html',
|
'dojo/topic',
|
'jimu/BaseWidget',
|
'jimu/utils',
|
'jimu/css!libs/zTree_v3/css/zTreeStyle/zTreeStyle.css',
|
'libs/zTree_v3/js/jquery.ztree.all'
|
],
|
function (declare,
|
lang,
|
array,
|
html,
|
topic,
|
BaseWidget,
|
aspect,
|
string,
|
utils
|
) {
|
return declare([BaseWidget], {
|
baseClass: 'jimu-widget-modelDiagram',
|
name: 'modelDiagram',
|
layers: {},
|
startup: function () {
|
var that = this;
|
// 暴露在外的接口
|
// that.beginModelDiagram();
|
// that.beginCesium();
|
|
$('.seemodo').click(() => {
|
that.seemodo();
|
})
|
|
$('.closemodo').click(() => {
|
that.closeModo();
|
})
|
$('.beginPlay').click(() => {
|
that.beginPlay();
|
})
|
$('.stopPlay').click(() => {
|
that.stopPlay();
|
})
|
$('.closesmodelDiagram').click(() => {
|
console.log(3423)
|
$('.jimu-widget-modelDiagram').hide();
|
if (that.openEntity) {
|
that.map.entities.removeAll();
|
}
|
})
|
|
},
|
beginCesium: function (a = 116.058987, b = 28.973468, g = 1000) {
|
var viewer = this.map
|
, that = this
|
, url = "./images/gltf/Cesium_Man.glb";
|
// var startPosition = new Cesium.Cartesian3(
|
// 116.058987,
|
// 28.973468,
|
// 1000
|
// );
|
// var endPosition = new Cesium.Cartesian3(
|
// 116.158987,
|
// 29.073468,
|
// 1000
|
// );
|
// var position = Cesium.Cartesian3.fromDegrees(116.058987, 28.973468);
|
//动态 //缺少viewer.timeline时间轴
|
//Make sure viewer is at the desired time.
|
//Make sure viewer is at the desired time.
|
// var start = Cesium.JulianDate.fromDate(new Date(2018, 11, 12, 15));
|
// var totalSeconds = 10;
|
// var stop = Cesium.JulianDate.addSeconds(
|
// start,
|
// totalSeconds,
|
// new Cesium.JulianDate()
|
// );
|
// viewer.clock.startTime = start.clone();
|
// viewer.clock.stopTime = stop.clone();
|
// viewer.clock.currentTime = start.clone();
|
// viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
|
// // console.log(viewer.timeline,111)
|
// viewer.timeline.zoomTo = function (startTime, stopTime) {
|
// //>>includeStart('debug', pragmas.debug);
|
// if (!defined(startTime)) {
|
// throw new DeveloperError("startTime is required.");
|
// }
|
// if (!defined(stopTime)) {
|
// throw new DeveloperError("stopTime is required");
|
// }
|
// if (JulianDate.lessThanOrEquals(stopTime, startTime)) {
|
// throw new DeveloperError("Start time must come before end time.");
|
// }
|
// //>>includeEnd('debug');
|
|
// this._startJulian = startTime;
|
// this._endJulian = stopTime;
|
// this._timeBarSecondsSpan = JulianDate.secondsDifference(stopTime, startTime);
|
|
// // If clock is not unbounded, clamp timeline range to clock.
|
// if (this._clock && this._clock.clockRange !== ClockRange$1.UNBOUNDED) {
|
// var clockStart = this._clock.startTime;
|
// var clockEnd = this._clock.stopTime;
|
// var clockSpan = JulianDate.secondsDifference(clockEnd, clockStart);
|
// var startOffset = JulianDate.secondsDifference(
|
// clockStart,
|
// this._startJulian
|
// );
|
// var endOffset = JulianDate.secondsDifference(clockEnd, this._endJulian);
|
|
// if (this._timeBarSecondsSpan >= clockSpan) {
|
// // if new duration longer than clock range duration, clamp to full range.
|
// this._timeBarSecondsSpan = clockSpan;
|
// this._startJulian = this._clock.startTime;
|
// this._endJulian = this._clock.stopTime;
|
// } else if (startOffset > 0) {
|
// // if timeline start is before clock start, shift right
|
// this._endJulian = JulianDate.addSeconds(
|
// this._endJulian,
|
// startOffset,
|
// new JulianDate()
|
// );
|
// this._startJulian = clockStart;
|
// this._timeBarSecondsSpan = JulianDate.secondsDifference(
|
// this._endJulian,
|
// this._startJulian
|
// );
|
// } else if (endOffset < 0) {
|
// // if timeline end is after clock end, shift left
|
// this._startJulian = JulianDate.addSeconds(
|
// this._startJulian,
|
// endOffset,
|
// new JulianDate()
|
// );
|
// this._endJulian = clockEnd;
|
// this._timeBarSecondsSpan = JulianDate.secondsDifference(
|
// this._endJulian,
|
// this._startJulian
|
// );
|
// }
|
// }
|
|
// this._makeTics();
|
|
// var evt = document.createEvent("Event");
|
// evt.initEvent("setzoom", true, true);
|
// evt.startJulian = this._startJulian;
|
// evt.endJulian = this._endJulian;
|
// evt.epochJulian = this._epochJulian;
|
// evt.totalSpan = this._timeBarSecondsSpan;
|
// evt.mainTicSpan = this._mainTicSpan;
|
// this._topDiv.dispatchEvent(evt);
|
// }
|
// viewer.timeline.zoomTo(start, stop);
|
|
// // Create a path for our vehicle by lerping between two positions.
|
// var position = new Cesium.SampledPositionProperty();
|
// var startPosition = Cesium.Cartesian3.fromDegrees(116.058987, 28.973468, 1000);
|
// var endPosition = Cesium.Cartesian3.fromDegrees(116.158987, 29.073468, 1000);
|
// // var startPosition = new Cesium.Cartesian3(
|
// // -2379556.799372864,
|
// // -4665528.205030263,
|
// // 3628013.106599678
|
// // );
|
// // var endPosition = new Cesium.Cartesian3(
|
// // -2379603.7074103747,
|
// // -4665623.48990283,
|
// // 3627860.82704567
|
// // );
|
// // A velocity vector property will give us the entity's speed and direction at any given time.
|
// var velocityVectorProperty = new Cesium.VelocityVectorProperty(
|
// position,
|
// false
|
// );
|
// var velocityVector = new Cesium.Cartesian3();
|
// // Store the wheel's rotation over time in a SampledProperty.
|
// var wheelAngleProperty = new Cesium.SampledProperty(Number);
|
// var wheelAngle = 0;
|
|
// var numberOfSamples = 100;
|
// for (var i = 0; i <= numberOfSamples; ++i) {
|
// var factor = i / numberOfSamples;
|
// var time = Cesium.JulianDate.addSeconds(
|
// start,
|
// factor * totalSeconds,
|
// new Cesium.JulianDate()
|
// );
|
|
// // Lerp using a non-linear factor so that the vehicle accelerates.
|
// var locationFactor = Math.pow(factor, 2);
|
// var location = Cesium.Cartesian3.lerp(
|
// startPosition,
|
// endPosition,
|
// locationFactor,
|
// new Cesium.Cartesian3()
|
// );
|
// position.addSample(time, location);
|
// // Rotate the wheels based on how fast the vehicle is moving at each timestep.
|
// velocityVectorProperty.getValue(time, velocityVector);
|
// var metersPerSecond = Cesium.Cartesian3.magnitude(velocityVector);
|
// var wheelRadius = 0.52; //in meters.
|
// var circumference = Math.PI * wheelRadius * 2;
|
// var rotationsPerSecond = metersPerSecond / circumference;
|
|
// wheelAngle +=
|
// ((Math.PI * 2 * totalSeconds) / numberOfSamples) *
|
// rotationsPerSecond;
|
// wheelAngleProperty.addSample(time, wheelAngle);
|
// }
|
|
// function updateSpeedLabel(time, result) {
|
// velocityVectorProperty.getValue(time, velocityVector);
|
// var metersPerSecond = Cesium.Cartesian3.magnitude(velocityVector);
|
// var kmPerHour = Math.round(metersPerSecond * 3.6);
|
|
// return kmPerHour + " km/hr";
|
// }
|
|
// var rotationProperty = new Cesium.CallbackProperty(function (
|
// time,
|
// result
|
// ) {
|
// return Cesium.Quaternion.fromAxisAngle(
|
// Cesium.Cartesian3.UNIT_X,
|
// wheelAngleProperty.getValue(time),
|
// result
|
// );
|
// },
|
// false);
|
|
// var wheelTransformation = new Cesium.NodeTransformationProperty({
|
// rotation: rotationProperty,
|
// });
|
|
// var nodeTransformations = {
|
// Wheels: wheelTransformation,
|
// Wheels_mid: wheelTransformation,
|
// Wheels_rear: wheelTransformation,
|
// };
|
|
// // Add our vehicle model.
|
// var vehicleEntity = viewer.entities.add({
|
// position: position,
|
// orientation: new Cesium.VelocityOrientationProperty(position), // Automatically set the vehicle's orientation to the direction it's facing.
|
// model: {
|
// uri: url,
|
// runAnimations: false,
|
// nodeTransformations: nodeTransformations,
|
// },
|
// label: {
|
// text: new Cesium.CallbackProperty(updateSpeedLabel, false),
|
// font: "20px sans-serif",
|
// showBackground: true,
|
// distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
// 0.0,
|
// 100.0
|
// ),
|
// eyeOffset: new Cesium.Cartesian3(0, 3.5, 0),
|
// },
|
// });
|
|
// viewer.trackedEntity = vehicleEntity;
|
// vehicleEntity.viewFrom = new Cesium.Cartesian3(-10.0, 7.0, 4.0);
|
|
//静态
|
// var position = Cesium.Cartesian3.fromDegrees(116.058987, 28.973468, 1000);
|
var position = Cesium.Cartesian3.fromDegrees(a, b, g);
|
viewer.trackedEntity = viewer.entities.add({//viewer.trackedEntity跟随
|
name: url,
|
position: position,
|
model: {
|
uri: url,
|
},
|
});
|
that.entityPeople = viewer.trackedEntity;
|
|
// var viewModel = {// 以下是工具栏
|
// blackAndWhiteShow: false,
|
// blackAndWhiteGradations: 5.0,
|
// brightnessShow: false,
|
// brightnessValue: 0.5,
|
// nightVisionShow: false,
|
// silhouette: false,
|
// };
|
|
// Cesium.knockout.track(viewModel);
|
// var toolbar = document.getElementById("toolbarcesium");
|
// Cesium.knockout.applyBindings(viewModel, toolbar);
|
// for (var name in viewModel) {
|
// if (viewModel.hasOwnProperty(name)) {
|
// Cesium.knockout
|
// .getObservable(viewModel, name)
|
// .subscribe(updatePostProcess);
|
// }
|
// }
|
|
// if (
|
// !Cesium.PostProcessStageLibrary.isSilhouetteSupported(viewer.scene)
|
// ) {
|
// window.alert(
|
// "This browser does not support the silhouette post process."
|
// );
|
// }
|
|
// var stages = viewer.scene.postProcessStages;
|
// var silhouette = stages.add(
|
// Cesium.PostProcessStageLibrary.createSilhouetteStage()
|
// );
|
// var blackAndWhite = stages.add(
|
// Cesium.PostProcessStageLibrary.createBlackAndWhiteStage()
|
// );
|
// var brightness = stages.add(
|
// Cesium.PostProcessStageLibrary.createBrightnessStage()
|
// );
|
// var nightVision = stages.add(
|
// Cesium.PostProcessStageLibrary.createNightVisionStage()
|
// );
|
|
// function updatePostProcess() {
|
// silhouette.enabled = Boolean(viewModel.silhouette);
|
// silhouette.uniforms.color = Cesium.Color.YELLOW;
|
// blackAndWhite.enabled = Boolean(viewModel.blackAndWhiteShow);
|
// blackAndWhite.uniforms.gradations = Number(
|
// viewModel.blackAndWhiteGradations
|
// );
|
// brightness.enabled = Boolean(viewModel.brightnessShow);
|
// brightness.uniforms.brightness = Number(viewModel.brightnessValue);
|
// nightVision.enabled = Boolean(viewModel.nightVisionShow);
|
// }
|
// updatePostProcess();
|
|
},
|
entityPeople: '',
|
seeEntity: true,
|
openEntity: false,
|
time: '',
|
beginPlay: function () {
|
var postion = [116.058987, 28.973468, 1000]
|
, a = 116.058987
|
, b = 28.973468
|
, g = 1000;
|
this.time = setInterval(() => {
|
|
if (this.openEntity) {
|
// this.map.entities.remove(this.entityPeople)//删除entity
|
// this.map.entities.remove(this.map.trackedEntity)//删除entity
|
this.map.entities.removeAll();
|
} else {
|
a += 0.01;
|
b += 0.01;
|
// g += 0.01;
|
this.beginCesium(a, b);
|
}
|
this.openEntity = !this.openEntity;
|
console.log(this.openEntity)
|
}, 1000);
|
},
|
stopPlay: function () {
|
this.map.entities.removeAll();
|
clearInterval(this.time);
|
},
|
seemodo: function () {
|
var that = this;
|
if (that.seeEntity) {
|
this.map.trackedEntity = that.entityPeople;//目标视野跟踪
|
} else {
|
this.map.trackedEntity = '';
|
}
|
that.seeEntity = !that.seeEntity;
|
console.log(that.seeEntity)
|
// console.log('seedom')
|
// this.map.entities.remove(this.entityPeople)//删除entity
|
},
|
closeModo: function () {
|
if (this.openEntity) {
|
// this.map.entities.remove(this.entityPeople)//删除entity
|
// this.map.entities.remove(this.map.trackedEntity)//删除entity
|
this.map.entities.removeAll();
|
} else {
|
var a = $('#modelDiagramjdu').val() == '' ? 116.058987 : +$('#modelDiagramjdu').val();
|
var b = $('#modelDiagramwdu').val() == '' ? 28.973468 : +$('#modelDiagramwdu').val();
|
var g = $('#modelDiagramgdu').val() == '' ? 1000 : +$('#modelDiagramgdu').val();
|
// console.log([a, b, g])
|
this.beginCesium(a, b, g);
|
}
|
this.openEntity = !this.openEntity;
|
console.log(this.openEntity)
|
// var that = this;
|
// if (that.seeEntity) {
|
// this.map.trackedEntity = that.entityPeople;//目标视野跟踪
|
// } else {
|
// this.map.trackedEntity = '';
|
// }
|
// viewer.entities.remove(that.entityPeople)//删除entity
|
|
// viewer.entities.removeById(id)//根据id删除entity
|
|
// viewer.entities.removeAll()//清空所有entity
|
|
// viewer.entities.getById(id)// 获取enetity
|
|
// viewer.entities.contains(entity)// 是否包含
|
// viewer.entities.removeById('')
|
},
|
beginModelDiagram: function () {
|
var that = this
|
, viewer = that.map
|
, scene = viewer.scene;
|
// scene.globe.show = false;
|
viewer.shouldAnimate = true;
|
var collect = new Cesium.InstanceLayer(scene._context)
|
, url = "./images/gltf/walk.gltf"
|
, gltf = viewer.entities.add({
|
name: "gltf",
|
position: new Cesium.Cartesian3.fromDegrees(115.783206 - 0.002034006, 28.810602 - 0.005072179, 800),
|
model: {
|
uri: url
|
}
|
});
|
viewer.zoomTo(gltf);
|
$("#modelDiagramSelOpt").change(function () {
|
var value = $(this).val();
|
if (value === "1") {
|
collect.removeInstance(url, [collect._instances._array[0]._array[0].id]);
|
viewer.entities._show = true;
|
} else {
|
viewer.entities._show = false;
|
collect.add(url,
|
{
|
position: new Cesium.Cartesian3.fromDegrees(115.783206 - 0.002034006, 28.810602 - 0.005072179, 1000)
|
});
|
|
}
|
})
|
},
|
onClose: function () {
|
//面板关闭的时候触发 (when this panel is closed trigger)
|
},
|
|
onMinimize: function () {
|
this.resize();
|
},
|
|
onMaximize: function () {
|
this.resize();
|
},
|
|
resize: function () {
|
|
},
|
|
|
destroy: function () {
|
//销毁的时候触发
|
//todo
|
//do something before this func
|
this.inherited(arguments);
|
}
|
|
});
|
});
|