123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- define(function () {
- /**
- * 状态值
- * @type {Boolean}
- * @default false
- * @private
- */
- var status = {
- initialized: false, //是否初始化
- };
- /**
- * 模块数据 用于数据存储和外部调用
- * @type {Object}
- * 数据存放
- */
- var modValue = {
- title: "模拟飞行",
- handler: null,
- pointArr: [],
- pointEntityArr: [],
- lineEntity: null,
- };
- /**
- *
- */
- function init() {
- if (!status.initialized) {
- subscribe();
- status.initialized = true;
- // map3DViewer.flightSimulation({
- // action: "add",
- // callback: callback
- // })
- }
- ONEMAP.C.publisher.publish({
- modName: 'tool3DFlightSimulation'
- }, 'tools:active');
- };
- /**
- * 注册监听事件
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(remove, 'tools:active');
- ONEMAP.C.publisher.subscribe(removeAndClear, 'cleanMap');
- ONEMAP.C.publisher.subscribe(removeEvent, 'change23D');
- };
- // 23D转换
- function removeEvent() {
- map3DViewer.flightSimulation({
- action: "remove"
- })
- $('#toolFlightSimulationPanel').remove();
- if ($(".tools-flightSimulation").hasClass('cur')) {
- $(".tools-flightSimulation").removeClass('cur');
- }
- }
- /**
- * 3D通视 加载/移除 注册事件
- */
- function remove(options) {
- if (options.modName != 'tool3DFlightSimulation') {
- // if (options.modName == 'cleanMap') {
- // clear();
- // }
- removeAndClear();
- $(".tools-flightSimulation").removeClass('cur');
- } else {
- if ($(".tools-flightSimulation").hasClass('cur')) {
- $(".tools-flightSimulation").removeClass('cur');
- removeAndClear();
- } else {
- $(".tools-flightSimulation").addClass('cur');
- addPopup();
- }
- }
- }
- /**
- * 移除 模拟飞行
- */
- function removeAndClear() {
- map3DViewer.flightSimulation({
- action: "remove"
- })
- clearDrawEntity();
- if (modValue.handler) {
- modValue.handler.destroy()
- modValue.handler = null;
- }
- $('#toolFlightSimulationPanel').remove();
- };
- function drawLine() {
- var arr = modValue.pointArr.join(",").split(",")
- if (!modValue.lineEntity) {
- modValue.lineEntity = map3DViewer.map.entities.add({
- polyline: {
- positions: Cesium.Cartesian3.fromDegreesArray(arr),
- width: 10.0,
- material: new Cesium.PolylineGlowMaterialProperty({
- color: Cesium.Color.CHARTREUSE.withAlpha(.5)
- }),
- clampToGround: true
- }
- });
- } else {
- modValue.lineEntity.polyline.positions.setValue(Cesium.Cartesian3.fromDegreesArray(arr))
- }
- }
- function drawPoint(point) {
- var entity = map3DViewer.map.entities.add({
- position: Cesium.Cartesian3.fromDegrees(point.lng, point.lat),
- point: {
- pixelSize: 10,
- heightReference: 2,
- color: Cesium.Color.RED,
- }
- });
- modValue.pointEntityArr.push(entity);
- }
- function clearDrawEntity() {
- modValue.pointArr = []
- if (modValue.lineEntity) {
- map3DViewer.map.entities.remove(modValue.lineEntity)
- modValue.lineEntity = null
- }
- if (modValue.pointEntityArr.length > 0) {
- for (var i = 0; i < modValue.pointEntityArr.length; i++) {
- map3DViewer.map.entities.remove(modValue.pointEntityArr[i])
- }
- modValue.pointEntityArr = [];
- }
- }
- // 添加 弹窗
- function addPopup() {
- var html = '<div id="toolFlightSimulationPanel" class="viewHeightPopup class3d">' +
- ' <iframe frameborder="0" class="cover-iframe"></iframe>' +
- ' <div class="cover-content">' +
- ' <div class="">' +
- ' <div class="popup-lt"></div>' +
- ' <div class="popup-lb"></div>' +
- ' <div class="popup-rt"></div>' +
- ' <div class="popup-rb"></div>' +
- ' <div class="popup-ct">' +
- ' <button type="button" class="close"></button>' +
- ' <h3>' + modValue.title + '</h3>' +
- ' </div>' +
- ' <div class="popup-cb">' +
- ' <div class="panel">' +
- ' <div class="first step able">' +
- ' <div class="number">' +
- ' <span>1</span>' +
- ' </div>' +
- ' <div class="right">' +
- ' <span>请在地图上绘制路径</span>' +
- ' <button class="first_start first_button_change">绘制</button>' +
- ' <button class="first_again">重新绘制</button>' +
- ' <button class="first_end">结束</button>' +
- ' </div>' +
- ' </div>' +
- ' <div class="second step">' +
- ' <div class="number">' +
- ' <span>2</span>' +
- ' </div>' +
- ' <div class="right">' +
- ' <div>参数设置:</div>' +
- ' <div>' +
- ' <label for="">飞行高度</label>' +
- // ' <input class="fly_height" onkeyup="if(!/^\d+(\.\d+)?$/.test(this.value)){this.value=\'\'}else{this.value=this.value}" type="text">米' +
- ' <input class="fly_height" onkeyup="ONEMAP.M.tool3DFlightSimulation.judgeNumber(this,this.value)" type="text">米' +
- ' </div>' +
- ' <div>' +
- ' <label for="">飞行速度</label>' +
- ' <input class="fly_speed" onkeyup="ONEMAP.M.tool3DFlightSimulation.judgeNumber(this,this.value)" type="text">米' +
- ' </div>' +
- ' <div>' +
- ' 初始视角:' +
- ' <input type="radio" name="view" value="one" id="" checked>第一视角' +
- ' <input type="radio" name="view" value="two" id="">第二视角' +
- ' <input type="radio" name="view" value="god" id="">第三视角' +
- ' </div> ' +
- ' <div>' +
- ' <button class="simulate_start second_button_change">开始模拟</button>' +
- ' <button class="simulate_restart">重新模拟</button>' +
- ' </div>' +
- ' </div>' +
- ' </div>' +
- ' <div class="third step">' +
- ' <div class="number">' +
- ' <span>3</span>' +
- ' </div>' +
- ' <div class="right">' +
- ' <div>' +
- ' 飞行控制' +
- ' <button class="fly_pause">暂停</button>' +
- ' <button class="fly_start third_button_change">开始</button>' +
- ' </div>' +
- ' <div>' +
- ' 初始视角:' +
- ' <input type="radio" name="view_change" value="one" id="" checked>第一视角' +
- ' <input type="radio" name="view_change" value="two" id="">第二视角' +
- ' <input type="radio" name="view_change" value="god" id="">第三视角' +
- ' </div>' +
- ' </div>' +
- ' </div>' +
- ' </div>' +
- ' </div>' +
- ' </div>' +
- ' </div>' +
- '</div>';
- $("body").append(html);
- $("#toolFlightSimulationPanel .popup-ct").dragmove($('#toolFlightSimulationPanel'));
- // 开始绘制/重新绘制
- $('#toolFlightSimulationPanel .first_start,#toolFlightSimulationPanel .first_again').click(function () {
- // 重新绘制时删除之前添加模拟飞行
- if ($(this).hasClass("first_again")) {
- map3DViewer.flightSimulation({
- action: "remove"
- })
- }
- $(this).siblings(".first_end").addClass("first_button_change")
- $(this).removeClass("first_button_change")
- // 重置第二步
- resetSecondParam()
- // 重置第三步
- resetThirdParam()
- // 清除已绘制的图形
- clearDrawEntity()
- modValue.handler = new Cesium.ScreenSpaceEventHandler(map3DViewer.map.scene.canvas);
- modValue.handler.setInputAction(function (click) {
- var pick1 = new Cesium.Cartesian2(click.position.x, click.position.y);
- var cartesian = map3DViewer.map.scene.globe.pick(map3DViewer.map.camera.getPickRay(pick1), map3DViewer.map.scene);
- if (cartesian) {
- var cartographic = map3DViewer.map.scene.globe.ellipsoid.cartesianToCartographic(cartesian);
- var lat = Cesium.Math.toDegrees(cartographic.latitude);
- var lng = Cesium.Math.toDegrees(cartographic.longitude);
- var alt = cartographic.height;
- var position = {
- lat: lat,
- lng: lng
- }
- modValue.pointArr.push([lng, lat])
- drawPoint(position);
- if (modValue.pointArr.length > 1) {
- drawLine();
- }
- }
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
- })
- // 结束绘制
- $('#toolFlightSimulationPanel .first_end').click(function () {
- if (!modValue.lineEntity) {
- clearDrawEntity()
- $(this).siblings(".first_start").addClass("first_button_change")
- $(this).removeClass("first_button_change")
- } else {
- $(this).siblings(".first_again").addClass("first_button_change")
- $(this).removeClass("first_button_change")
- if (modValue.handler) {
- modValue.handler.destroy()
- modValue.handler = null;
- }
- $('#toolFlightSimulationPanel .second').addClass("able")
- }
- })
- $('#toolFlightSimulationPanel .simulate_start,#toolFlightSimulationPanel .simulate_restart').click(function () {
- $(this).removeClass("second_button_change")
- if ($(this).hasClass("simulate_restart")) {
- $(this).addClass("second_button_change")
- map3DViewer.flightSimulation({
- action: "remove",
- })
- } else {
- $(this).siblings(".simulate_restart").addClass("second_button_change")
- }
- var height = Number($('#toolFlightSimulationPanel .fly_height').val())
- var speed = Number($('#toolFlightSimulationPanel .fly_speed').val())
- modValue.speed = speed
- var eye = $('#toolFlightSimulationPanel .second input[name="view"]:checked').val();
- // 使第三步的视角与初始化视角相同
- $('#toolFlightSimulationPanel .third input[value="' + eye + '"]').prop("checked", 'checked');
- //重置第三步
- resetThirdParam()
- $('#toolFlightSimulationPanel .third').addClass("able")
- $('#toolFlightSimulationPanel .third .third_button_change').removeClass("third_button_change")
- $('#toolFlightSimulationPanel .third .fly_pause').addClass("third_button_change")
- map3DViewer.flightSimulation({
- action: "add",
- eyeslook: eye,
- height: height,
- speed: speed,
- lineCoor: modValue.pointArr,
- lineColor: "#00ffcc",
- outlineColor: "#FFFFFF",
- modelUrl: "./data/airplane.glb",
- callback: function () {}
- })
- })
- // 模拟继续
- $('#toolFlightSimulationPanel .fly_start').click(function () {
- $('#toolFlightSimulationPanel .third .third_button_change').removeClass("third_button_change")
- $('#toolFlightSimulationPanel .third .fly_pause').addClass("third_button_change")
- map3DViewer.flightSimulation({
- action: "resetCondition",
- speed: modValue.speed
- })
- })
- // 模拟暂停
- $('#toolFlightSimulationPanel .fly_pause').click(function () {
- $('#toolFlightSimulationPanel .third .third_button_change').removeClass("third_button_change")
- $('#toolFlightSimulationPanel .third .fly_start').addClass("third_button_change")
- map3DViewer.flightSimulation({
- action: "resetCondition",
- speed: 0
- })
- })
- // 切换视角
- $('#toolFlightSimulationPanel .third input[name="view_change"]').click(function () {
- var eye = $(this).val();
- // one two god
- map3DViewer.flightSimulation({
- action: "changeView",
- eyeslook: eye
- })
- })
- // 关闭
- $('#toolFlightSimulationPanel .close').click(function () {
- removeAndClear()
- if ($(".tools-flightSimulation").hasClass('cur')) {
- $(".tools-flightSimulation").removeClass('cur');
- }
- })
- }
- // 重置第二步
- function resetSecondParam() {
- $('#toolFlightSimulationPanel .second').removeClass("able")
- $('#toolFlightSimulationPanel .second .second_button_change').removeClass("second_button_change")
- $('#toolFlightSimulationPanel .second .simulate_start').addClass("second_button_change")
- }
- // 重置第三步
- function resetThirdParam() {
- $('#toolFlightSimulationPanel .third').removeClass("able")
- $('#toolFlightSimulationPanel .third .third_button_change').removeClass("third_button_change")
- $('#toolFlightSimulationPanel .third .fly_start').addClass("third_button_change")
- }
- // 判断是否为非负实数
- function judgeNumber(docu, value) {
- if (isNaN(Number(value))) {
- docu.value = ""
- } else {
- if (/^\d+(\.\d+)?$/.test(value)) {
- docu.value = value
- }
- }
- }
- return ONEMAP.M.tool3DFlightSimulation = {
- init: init,
- judgeNumber: judgeNumber
- }
- })
|