wangzhibo
2021-09-06 2efb5d2a02ce47a9fd6f1cec138496aba72f0815
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
"use script"; //开发环境建议开启严格模式
 
//对应widget.js中MyWidget实例化后的对象
var thisWidget;
 
//当前页面业务
function initWidgetView(_thisWidget) {
  thisWidget = _thisWidget;
 
  $("#btnFlyStop").click(function (event) {
    thisWidget.toRoamLine();
  });
 
  $("#btnSelChars").click(function (event) {
    thisWidget.showHeightChars();
  });
 
  var attr = thisWidget.getAttr();
  var followedX = attr.camera.followedX ?? 200;
  var followedZ = attr.camera.followedZ ?? 50;
  var offsetZ = attr.camera.offsetZ || 0;
  var offsetY = attr.camera.offsetY || 0;
  var offsetX = attr.camera.offsetX || 0;
 
  //改变视角模式
  $("#followedX").val(followedX);
  $("#followedZ").val(followedZ);
  $("#offsetZ").val(offsetZ);
  $("#offsetY").val(offsetY);
  $("#offsetX").val(offsetX);
 
  $("#cameraType").attr("data-value", attr.camera.type);
  $("#cameraType").select(); //绑定样式
  $("#cameraType").change(function () {
    $("#tr_followedX").hide();
    $("#tr_followedZ").hide();
    $("#tr_offsetZ").hide();
    $("#tr_offsetY").hide();
    $("#tr_offsetX").hide();
 
    var attrVal = $(this).attr("data-value");
    switch (attrVal) {
      default:
        break;
      case "gs": //
        $("#tr_followedX").show();
        break;
      case "dy": //锁定第一视角
        $("#tr_followedX").show();
        $("#tr_followedZ").show();
        $("#tr_offsetZ").show();
        $("#tr_offsetY").show();
        $("#tr_offsetX").show();
 
        $("#followedX").val(followedX);
        $("#followedZ").val(followedZ);
        $("#offsetZ").val(offsetZ);
        $("#offsetY").val(offsetY);
        $("#offsetX").val(offsetX);
 
        break;
      case "sd": //锁定上帝视角
        $("#tr_followedZ").show();
 
        var sdZ = Number($("#followedZ").val());
        $("#followedZ").val(sdZ);
        break;
    }
    updateCameraSetting();
  });
  $("#cameraType").change();
 
  //第一视角
  $("#followedX").change(function () {
    updateCameraSetting();
  });
  $("#followedZ").change(function () {
    updateCameraSetting();
  });
  $("#offsetY").change(function () {
    updateCameraSetting();
  });
  $("#offsetZ").change(function () {
    updateCameraSetting();
  });
  $("#offsetX").change(function () {
    updateCameraSetting();
  });
}
 
//改变视角模式
function updateCameraSetting() {
  var cameraType = $("#cameraType").attr("data-value");
  var followedX = Number($("#followedX").val());
  var followedZ = Number($("#followedZ").val());
  var offsetZ = Number($("#offsetZ").val());
  var offsetY = Number($("#offsetY").val());
  var offsetX = Number($("#offsetX").val());
 
  thisWidget.setCameraOptions({
    type: cameraType,
    radius: cameraType == "gs" ? followedX : 0,
    followedX: followedX,
    followedZ: followedZ,
    offsetZ: offsetZ,
    offsetY: offsetY,
    offsetX: offsetX,
  });
}
 
//显示基本信息,名称、总长、总时间
var _alltime = 100;
function showAllInfo(params) {
  _alltime = params.alltime;
 
  $("#td_name").html(params.name);
  $("#td_alltimes").html(haoutil.str.formatTime(params.alltime));
  $("#td_alllength").html(haoutil.str.formatLength(params.alllen));
}
 
//显示实时坐标和时间
function showRealTimeInfo(params) {
  var val = Math.ceil((params.time * 100) / _alltime);
  if (val < 1) {
    val = 1;
  }
  if (val > 100) {
    val = 100;
  }
 
  $(".progress-bar")
    .css("width", val + "%")
    .attr("aria-valuenow", val)
    .html(val + "%");
 
  $("#td_jd").html(params.lng);
  $("#td_wd").html(params.lat);
  $("#td_gd").html(haoutil.str.formatLength(params.alt));
 
  $("#td_times").html(haoutil.str.formatTime(params.time));
  $("#td_length").html(haoutil.str.formatLength(params.len));
 
  if (params.hbgd) {
    $("#td_dmhb").html(haoutil.str.formatLength(params.hbgd));
  } else {
    $("#td_dmhb").html("未知");
  }
 
  if (params.ldgd) {
    $("#td_ldgd").html(haoutil.str.formatLength(params.ldgd));
  } else {
    $("#td_ldgd").html("未知");
  }
}
 
//下拉框
(function ($) {
  //下拉菜单默认参数
  var defaluts = {
    select: "mp_select",
    select_text: "mp_select_text",
    select_ul: "mp_select_ul",
  };
 
  $.fn.extend({
    // 下拉菜单
    // 下拉菜单
    select: function (options) {
      var opts = $.extend({}, defaluts, options);
      return this.each(function () {
        var that = $(this);
        //模拟下拉列表
        if (that.data("value") !== undefined && that.data("value") !== "") {
          that.val(that.data("value"));
        }
        var _html = [];
        _html.push('<div class="' + that.attr("class") + '">');
        _html.push('<div class="' + opts.select_text + '">' + that.find(":selected").text() + "</div>");
        _html.push('<ul class="' + opts.select_ul + '">');
        that.children("option").each(function () {
          var option = $(this);
          if (that.data("value") == option.val()) {
            _html.push('<li data-value="' + option.val() + '" >' + option.text() + "</li>");
          } else {
            _html.push('<li data-value="' + option.val() + '">' + option.text() + "</li>");
          }
        });
        _html.push("</ul>");
        _html.push("</div>");
        var select = $(_html.join(""));
        var select_text = select.find("." + opts.select_text);
        var select_ul = select.find("." + opts.select_ul);
        that.after(select);
        that.hide();
 
        that.change(function () {
          var val = that.attr("data-value");
          that.children("option").each(function () {
            var option = $(this);
            if (val == option.val()) {
              select_text.text(option.text());
            }
          });
        });
 
        //下拉列表操作
        select.click(function (event) {
          $(this).toggleClass("mp_selected");
          $(this)
            .find("." + opts.select_ul)
            .slideToggle()
            .end()
            .siblings("div." + opts.select)
            .find("." + opts.select_ul)
            .slideUp();
          event.stopPropagation();
        });
        $("body").click(function () {
          select_ul.slideUp();
        });
        select_ul.on("click", "li", function () {
          var li = $(this);
          var val = li.addClass("selecton").siblings("li").removeClass("selecton").end().data("value").toString();
          if (val !== that.attr("data-value")) {
            select_text.text(li.text());
            that.attr("data-value", val);
            that.attr("data-text", li.text());
            that.change();
          }
        });
      });
    },
  });
})(window.jQuery);