wangrong
2025-09-23 40634ebaf5863a599bba8ca2c0575ca079fb8e15
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
function initTable() {
  $("#showEditor").hide()
  $("#show").change(function () {
    let val = $(this).is(":checked")
    thisLayer.show = val
  })
 
  // 亮度
  $("#brightness")
    .slider({
      min: 0,
      max: 3,
      step: 0.01,
      value: 1
    })
    .on("change", (e) => {
      //修改步长
      if (e && e.value) {
        setLayerOptions("brightness", e.value.newValue)
      }
    })
  // 对比度
  $("#contrast")
    .slider({
      min: 0,
      max: 3,
      step: 0.01,
      value: 1
    })
    .on("change", (e) => {
      //修改步长
      if (e && e.value) {
        setLayerOptions("contrast", e.value.newValue)
      }
    })
  // 色彩
  $("#hue")
    .slider({
      min: 0,
      max: 3,
      step: 0.01,
      value: 0.1
    })
    .on("change", (e) => {
      //修改步长
      if (e && e.value) {
        setLayerOptions("hue", e.value.newValue)
      }
    })
  // 饱和度
  $("#saturation")
    .slider({
      min: 0,
      max: 3,
      step: 0.01,
      value: 1
    })
    .on("change", (e) => {
      //修改步长
      if (e && e.value) {
        setLayerOptions("saturation", e.value.newValue)
      }
    })
  // 饱和度
  $("#gamma")
    .slider({
      min: 0,
      max: 3,
      step: 0.01,
      value: 0.2
    })
    .on("change", (e) => {
      //修改步长
      if (e && e.value) {
        setLayerOptions("gamma", e.value.newValue)
      }
    })
  // 透明度
  $("#opacity")
    .slider({
      min: 0,
      max: 1,
      step: 0.01,
      value: 1
    })
    .on("change", (e) => {
      //修改步长
      if (e && e.value) {
        setLayerOptions("opacity", e.value.newValue)
      }
    })
 
  const layers = map.getLayers()
  for (let i = layers.length - 1; i >= 0; i--) {
    const layer = layers[i]
    if (layer.isPrivate) {
      continue
    }
 
    tileLayerList.push({
      key: layer,
      name: `${layer.type} - ${layer.name || "未命名"}`,
      isTile: layer.isTile
    })
  }
 
  selectedFirst()
  addTable()
 
  if (tileLayerList.lenght) {
    $("#showEditor").show()
  }
 
  // 添加新的图层,数组中也添加数据
  map.on(mars3d.EventType.addLayer, function (event) {
    const layer = event.layer
    thisLayer = event.layer
    if (layer.isPrivate || layer.name === "POI查询") {
      return
    }
 
    tileLayerList.push({
      key: layer,
      name: `${layer.type} - ${layer.name || "未命名"}`,
      isTile: layer.isTile
    })
 
    selectedFirst()
    addTable()
  })
 
  // 删除图层
  map.on(mars3d.EventType.removeLayer, function (event) {
    const layerId = event.layer
 
    const idx = tileLayerList.findIndex((item) => item.key === layerId)
    tileLayerList.splice(idx, 1)
 
    addTable()
 
    if (thisLayer === layerId) {
      thisLayer = null
    }
    $("#layerName").html("") // 隐藏编辑面板
    $("#showEditor").hide()
  })
}
 
function selectedFirst() {
  setTimeout(() => {
    // 选中第一个
    if (tileLayerList.length === 1) {
      const layer = tileLayerList[0]
 
      if (!layer.isTile) {
        return
      }
 
      $("#layerName").html(layer.name) // 获取到的对应图层的信息
      $("#showEditor").show()
      thisLayer = map.getLayerById(layer.key.id)
      $("#show").attr("checked", thisLayer)
    }
  }, 50)
}
 
function setLayerOptions(attribute, val) {
  if (thisLayer) {
    thisLayer[attribute] = val
  }
}
 
// 表格添加一行记录 item - 数据
function addTable() {
  // 增加tr和td表格
  let tbody = document.getElementById("tbPoly")
  tbody.innerHTML = ``
 
  tileLayerList.forEach((item) => {
    let tr = document.createElement("tr")
    tr.innerHTML = `
            <tr>
              <td>${item.name}</td>
              <td>
                <a class="flyTo" href="javascript:void(0)" title="飞行定位"><i class="fa fa-send-o"></i></a>&nbsp;&nbsp;
                <a class="remove" href="javascript:void(0)" title="删除区域"><i class="fa fa-trash"></i></a>
              </td>
            </tr>`
    tbody.appendChild(tr)
 
    //绑定单击事件 定位
    tr.querySelector(".flyTo").addEventListener("click", function (e) {
      const layer = map.getLayerById(item.key.uuid)
      if (layer) {
        layer.flyTo()
      }
    })
 
    // 删除压平数据和压平线
    tr.querySelector(".remove").addEventListener("click", function (e) {
      const layer = map.getLayerById(item.key.uuid)
      if (layer) {
        layer.remove(true)
        // formState.layerName = "" // 隐藏编辑面板
      }
    })
  })
}