Cesium 通过点击获取经纬度及绘制点线面


Cesium 通过点击获取经纬度及绘制点线面

一、前言

在Cesium三维地球应用中,通过鼠标点击获取经纬度坐标是一个基础且重要的功能。本文将详细介绍如何使用Cesium的点击事件来获取经纬度,并在此基础上实现点击绘制点、线、面等几何元素的功能。

二、环境准备

在开始之前,请确保你已经按照之前的教程搭建了Cesium + Vite项目环境:

  • Cesium:^1.128.0
  • vite-plugin-cesium:^1.2.23
  • Vue3:^3.5.13
  • Node.js:v22.13.0 或更高版本
  • pnpm:10.5.0 或更高版本
  • turf.js:^6.5.0 或更高版本(用于地理空间分析)

安装turf.js:

1
pnpm add @turf/turf

三、基础点击事件获取经纬度

1. 创建点击事件处理器

Cesium提供了ScreenSpaceEventHandler类来处理屏幕空间事件,我们可以使用它来监听鼠标点击操作。

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
// 创建点击事件处理器
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);

// 监听左键点击事件
handler.setInputAction(function (event) {
// 获取点击位置的笛卡尔坐标
const cartesian = viewer.camera.pickEllipsoid(
event.position,
viewer.scene.globe.ellipsoid,
);

if (Cesium.defined(cartesian)) {
// 将笛卡尔坐标转换为地理坐标(弧度制)
const cartographic = Cesium.Cartographic.fromCartesian(cartesian);

// 将弧度转换为度数
const longitude = Cesium.Math.toDegrees(cartographic.longitude);
const latitude = Cesium.Math.toDegrees(cartographic.latitude);
const height = cartographic.height;

console.log(
`经度: ${longitude.toFixed(6)}, 纬度: ${latitude.toFixed(6)}, 高度: ${height.toFixed(2)}`,
);
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

2. 坐标转换原理

Cesium中的坐标转换过程如下:

  1. 屏幕坐标:鼠标点击的屏幕像素位置
  2. 笛卡尔坐标:通过pickEllipsoid()方法将屏幕坐标转换为三维笛卡尔坐标
  3. 地理坐标:通过Cartographic.fromCartesian()将笛卡尔坐标转换为地理坐标(弧度制)
  4. 经纬度:通过Math.toDegrees()将弧度转换为度数

四、点击绘制点

基础点绘制

在获取点击位置后,可以在该位置绘制一个点:

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
let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);

handler.setInputAction(function (event) {
const cartesian = viewer.camera.pickEllipsoid(
event.position,
viewer.scene.globe.ellipsoid,
);

if (Cesium.defined(cartesian)) {
const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
const longitude = Cesium.Math.toDegrees(cartographic.longitude);
const latitude = Cesium.Math.toDegrees(cartographic.latitude);

// 在点击位置绘制点
viewer.entities.add({
position: cartesian,
point: {
pixelSize: 10,
color: Cesium.Color.RED,
outlineColor: Cesium.Color.WHITE,
outlineWidth: 2,
},
label: {
text: `经度: ${longitude.toFixed(4)}\n纬度: ${latitude.toFixed(4)}`,
font: "12pt sans-serif",
fillColor: Cesium.Color.WHITE,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 2,
pixelOffset: new Cesium.Cartesian2(0, -20),
verticalOrigin: Cesium.VerticalOrigin.TOP,
},
});
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

五、点击绘制线

连续点击绘制线

实现连续点击绘制线的功能,需要记录点击的点:

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
let points = [];
let currentLine = null;

handler.setInputAction(function (event) {
const cartesian = viewer.camera.pickEllipsoid(
event.position,
viewer.scene.globe.ellipsoid,
);

if (Cesium.defined(cartesian)) {
points.push(cartesian);

// 绘制点标记
viewer.entities.add({
position: cartesian,
point: {
pixelSize: 8,
color: Cesium.Color.RED,
},
});

// 如果有两个或更多点,绘制线
if (points.length >= 2) {
if (currentLine) {
viewer.entities.remove(currentLine);
}

currentLine = viewer.entities.add({
polyline: {
positions: points,
width: 3,
material: Cesium.Color.BLUE,
clampToGround: true,
},
});
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

// 右键点击结束绘制
handler.setInputAction(function () {
points = [];
currentLine = null;
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);

六、点击绘制面

连续点击绘制多边形

实现连续点击绘制多边形的功能:

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
let polygonPoints = [];
let currentPolygon = null;

handler.setInputAction(function (event) {
const cartesian = viewer.camera.pickEllipsoid(
event.position,
viewer.scene.globe.ellipsoid,
);

if (Cesium.defined(cartesian)) {
polygonPoints.push(cartesian);

// 绘制点标记
viewer.entities.add({
position: cartesian,
point: {
pixelSize: 8,
color: Cesium.Color.RED,
},
});

// 如果有三个或更多点,绘制多边形
if (polygonPoints.length >= 3) {
if (currentPolygon) {
viewer.entities.remove(currentPolygon);
}

currentPolygon = viewer.entities.add({
polygon: {
hierarchy: polygonPoints,
material: Cesium.Color.GREEN.withAlpha(0.5),
outline: true,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 2,
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
},
});
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

// 右键点击结束绘制
handler.setInputAction(function () {
polygonPoints = [];
currentPolygon = null;
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);

自动闭合多边形

实现点击自动闭合多边形的功能:

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
let polygonPoints = [];
let currentPolygon = null;

handler.setInputAction(function(event) {
const cartesian = viewer.camera.pickEllipsoid(event.position, viewer.scene.globe.ellipsoid);

if (Cesium.defined(cartesian)) {
polygonPoints.push(cartesian);

viewer.entities.add({
position: cartesian,
point: {
pixelSize: 8,
color: Cesium.Color.RED
}
});

if (polygonPoints.length >= 3) {
if (currentPolygon) {
viewer.entities.remove(currentPolygon);
}

currentPolygon = viewer.entities.add({
polygon: {
hierarchy: new Cesium.PolygonHierarchy(polygonPoints),
material: Cesium.Color.BLUE.withAlpha(0.4),
outline: true,
outlineColor: Cesium.Color.WHITE,
outlineWidth: 3,
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
}
});
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

// 双击结束绘制并自动闭合
handler.setInputAction(function() {
if (polygonPoints.length >= 3) {
// 自动闭合多边形
if (currentPolygon) {
viewer.entities.remove(currentPolygon);
}

currentPolygon = viewer.entities.add({
polygon: {
hierarchy: new Cesium.PolygonHierarchy(polygonPoints),
material: Cesium.Color.BLUE.withAlpha(0.4),
outline: true,
outlineColor: Cesium.Color.WHITE,
outlineWidth: 3,
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
});
}
}
polygonPoints = [];
currentPolygon = null;
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);

七、使用Turf.js测量距离和面积

Turf.js是一个强大的地理空间分析库,可以与Cesium完美配合使用,实现距离测量、面积计算等功能。

1. 安装和引入Turf.js

1
2
# 安装turf.js
pnpm add @turf/turf
1
2
// 在Vue组件中引入turf.js
import * as turf from "@turf/turf";

2. 测量距离

使用turf.js的distance方法计算两点之间的距离:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 将Cesium的笛卡尔坐标转换为经纬度数组
function cartesianToLngLat(cartesian) {
const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
return [
Cesium.Math.toDegrees(cartographic.longitude),
Cesium.Math.toDegrees(cartographic.latitude),
];
}

// 计算两点之间的距离
function calculateDistance(point1, point2) {
const coords1 = cartesianToLngLat(point1);
const coords2 = cartesianToLngLat(point2);

// 使用turf.js计算距离(单位:千米)
const distance = turf.distance(turf.point(coords1), turf.point(coords2), {
units: "kilometers",
});

return distance;
}

3. 测量面积

使用turf.js的area方法计算多边形的面积:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 计算多边形的面积
function calculateArea(polygonPoints) {
// 将Cesium坐标转换为GeoJSON格式
const coords = polygonPoints.map((point) => {
const cartographic = Cesium.Cartographic.fromCartesian(point);
return [
Cesium.Math.toDegrees(cartographic.longitude),
Cesium.Math.toDegrees(cartographic.latitude),
];
});

// 闭合多边形
const closedCoords = [...coords, coords[0]];

// 创建turf.js的多边形
const polygon = turf.polygon([closedCoords]);

// 计算面积(单位:平方米)
const area = turf.area(polygon);

return area;
}

4. Turf.js常用功能

除了距离和面积测量,turf.js还提供了丰富的地理空间分析功能:

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
// 计算两点间的距离
const distance = turf.distance(
turf.point([116.3974, 39.9093]),
turf.point([121.4737, 31.2304]),
{ units: "kilometers" },
);

// 计算多边形面积
const polygon = turf.polygon([
[
[116.3974, 39.9093],
[121.4737, 31.2304],
[113.2644, 23.1291],
[116.3974, 39.9093],
],
]);
const area = turf.area(polygon);

// 计算线的长度
const line = turf.lineString([
[116.3974, 39.9093],
[121.4737, 31.2304],
]);
const length = turf.length(line, { units: "kilometers" });

// 计算多边形的中心点
const centroid = turf.centroid(polygon);

// 计算缓冲区
const buffer = turf.buffer(point, 10, { units: "kilometers" });

八、完整Vue组件示例

以下是一个完整的Vue组件示例,展示了如何在Vue3 + Vite + Cesium项目中实现点击绘制和测量功能:

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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
<template>
<div class="cesium-container">
<div class="cesium-map" id="cesiumMap"></div>
<div class="toolbar">
<button
@click="setDrawMode('none')"
:class="{ active: drawMode === 'none' }"
>
浏览模式
</button>
<button
@click="setDrawMode('point')"
:class="{ active: drawMode === 'point' }"
>
绘制点
</button>
<button
@click="setDrawMode('line')"
:class="{ active: drawMode === 'line' }"
>
绘制线
</button>
<button
@click="setDrawMode('polygon')"
:class="{ active: drawMode === 'polygon' }"
>
绘制面
</button>
<button @click="clearDrawings">清除绘制</button>
</div>
<div class="info-panel" v-if="currentPosition">
<div>经度: {{ currentPosition.longitude.toFixed(6) }}</div>
<div>纬度: {{ currentPosition.latitude.toFixed(6) }}</div>
<div>高度: {{ currentPosition.height.toFixed(2) }}m</div>
</div>
</div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import {
Viewer,
ScreenSpaceEventHandler,
ScreenSpaceEventType,
Cartesian3,
Cartesian2,
Cartographic,
Color,
Math,
defined,
PolygonHierarchy,
HeightReference,
LabelStyle,
HorizontalOrigin,
VerticalOrigin,
} from "cesium";
import * as turf from "@turf/turf";

let viewer = null;
let handler = null;

const drawMode = ref("none");
const confirmedPoints = ref([]); // 已经左键点击确认的点
const currentPosition = ref(null);

// 临时绘制相关(鼠标移动时的预览)
let tempShapeEntity = null;
let tempLabelEntity = null;

onMounted(() => {
viewer = new Viewer("cesiumMap", {
geocoder: false,
homeButton: false,
sceneModePicker: false,
baseLayerPicker: false,
navigationHelpButton: false,
animation: false,
timeline: false,
fullscreenButton: false,
vrButton: false,
infoBox: false,
selectionIndicator: false,
});

handler = new ScreenSpaceEventHandler(viewer.scene.canvas);

// 1. 左键点击:确认一个点
handler.setInputAction((event) => {
if (drawMode.value === "none") return;

const cartesian = viewer.camera.pickEllipsoid(
event.position,
viewer.scene.globe.ellipsoid,
);

if (defined(cartesian)) {
const cartographic = Cartographic.fromCartesian(cartesian);
const longitude = Math.toDegrees(cartographic.longitude);
const latitude = Math.toDegrees(cartographic.latitude);
const height = cartographic.height;

currentPosition.value = { longitude, latitude, height };

// 绘制一个永久的红色顶点标记
viewer.entities.add({
position: cartesian,
point: {
pixelSize: 8,
color: Color.RED,
outlineColor: Color.WHITE,
outlineWidth: 2,
},
});

handlePointConfirmed(cartesian, longitude, latitude);
}
}, ScreenSpaceEventType.LEFT_CLICK);

// 2. 鼠标移动:更新预览
handler.setInputAction((event) => {
if (
drawMode.value === "none" ||
drawMode.value === "point" ||
confirmedPoints.value.length === 0
) {
return;
}

const cartesian = viewer.camera.pickEllipsoid(
event.endPosition,
viewer.scene.globe.ellipsoid,
);

if (defined(cartesian)) {
updatePreview([...confirmedPoints.value, cartesian]);
}
}, ScreenSpaceEventType.MOUSE_MOVE);

// 3. 右键点击:完成绘制,创建永久实体
handler.setInputAction(() => {
if (drawMode.value !== "none" && confirmedPoints.value.length > 0) {
finishDrawing();
}
}, ScreenSpaceEventType.RIGHT_CLICK);
});

onUnmounted(() => {
if (handler) handler.destroy();
if (viewer) viewer.destroy();
});

// 坐标转换:Cesium Cartesian3 数组 -> Turf [lng, lat] 数组
function cartesiansToTurfCoords(cartesians) {
return cartesians.map((c) => {
const carto = Cartographic.fromCartesian(c);
return [Math.toDegrees(carto.longitude), Math.toDegrees(carto.latitude)];
});
}

// 计算测量结果并返回标签文本和中心点
function calculateMeasurement(positions) {
if (positions.length < 2) return null;

const coords = cartesiansToTurfCoords(positions);
let labelText = "";
let centerCoords = null;

if (drawMode.value === "line") {
const line = turf.lineString(coords);
const lengthM = turf.length(line) * 1000; // 转换为米

if (lengthM < 1000) {
labelText = `距离: ${lengthM.toFixed(2)} 米`;
} else {
labelText = `距离: ${(lengthM / 1000).toFixed(2)} 公里`;
}

centerCoords = turf.center(line).geometry.coordinates;
} else if (drawMode.value === "polygon" && positions.length >= 3) {
// Turf要求多边形首尾闭合
const closedCoords = [...coords, coords[0]];
const polygon = turf.polygon([closedCoords]);
const areaSqm = turf.area(polygon);

if (areaSqm < 10000) {
labelText = `面积: ${areaSqm.toFixed(2)} ㎡`;
} else if (areaSqm < 1000000) {
labelText = `面积: ${(areaSqm / 10000).toFixed(2)} 公顷`;
} else {
labelText = `面积: ${(areaSqm / 1000000).toFixed(2)} km²`;
}

centerCoords = turf.center(polygon).geometry.coordinates;
}

if (labelText && centerCoords) {
return {
text: labelText,
center: Cartesian3.fromDegrees(centerCoords[0], centerCoords[1]),
};
}

return null;
}

// 创建标签实体
function createLabel(position, text) {
return viewer.entities.add({
position: position,
label: {
text: text,
font: "bold 14pt sans-serif",
fillColor: Color.BLACK,
outlineColor: Color.WHITE,
outlineWidth: 3,
style: LabelStyle.FILL_AND_OUTLINE,
pixelOffset: new Cartesian2(0, 0),
horizontalOrigin: HorizontalOrigin.CENTER,
verticalOrigin: VerticalOrigin.CENTER,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
},
});
}

// 更新临时预览(图形+标签)
function updatePreview(positions) {
// 清除旧的临时预览
if (tempShapeEntity) {
viewer.entities.remove(tempShapeEntity);
tempShapeEntity = null;
}
if (tempLabelEntity) {
viewer.entities.remove(tempLabelEntity);
tempLabelEntity = null;
}

if (positions.length < 2) return;

// 创建临时图形
if (drawMode.value === "line") {
tempShapeEntity = viewer.entities.add({
polyline: {
positions: positions,
width: 3,
material: Color.BLUE,
clampToGround: true,
},
});
} else if (drawMode.value === "polygon") {
if (positions.length >= 3) {
tempShapeEntity = viewer.entities.add({
polygon: {
hierarchy: new PolygonHierarchy(positions),
material: Color.GREEN.withAlpha(0.5),
outline: true,
outlineColor: Color.BLACK,
outlineWidth: 2,
heightReference: HeightReference.CLAMP_TO_GROUND,
},
});
} else {
// 不够3个点时先显示线
tempShapeEntity = viewer.entities.add({
polyline: {
positions: positions,
width: 3,
material: Color.BLUE,
clampToGround: true,
},
});
}
}

// 创建临时标签
const measurement = calculateMeasurement(positions);
if (measurement) {
tempLabelEntity = createLabel(measurement.center, measurement.text);
}
}

// 处理点确认
function handlePointConfirmed(cartesian, longitude, latitude) {
if (drawMode.value === "point") {
// 点直接创建永久实体
viewer.entities.add({
position: cartesian,
point: {
pixelSize: 12,
color: Color.RED,
outlineColor: Color.WHITE,
outlineWidth: 2,
},
label: {
text: `经度: ${longitude.toFixed(4)}\n纬度: ${latitude.toFixed(4)}`,
font: "12pt sans-serif",
fillColor: Color.WHITE,
outlineColor: Color.BLACK,
outlineWidth: 2,
pixelOffset: new Cartesian2(0, -20),
disableDepthTestDistance: Number.POSITIVE_INFINITY,
},
});
} else {
// 线和面:添加到确认点数组
confirmedPoints.value.push(cartesian);

// 点击后立即更新预览
if (confirmedPoints.value.length >= 2) {
updatePreview(confirmedPoints.value);
}
}
}

// 完成绘制:将临时实体转为永久实体
function finishDrawing() {
// 1. 清除临时预览
if (tempShapeEntity) {
viewer.entities.remove(tempShapeEntity);
tempShapeEntity = null;
}
if (tempLabelEntity) {
viewer.entities.remove(tempLabelEntity);
tempLabelEntity = null;
}

// 2. 创建永久的图形和标签
const positions = confirmedPoints.value;

if (drawMode.value === "line" && positions.length >= 2) {
// 创建永久的线
viewer.entities.add({
polyline: {
positions: positions,
width: 3,
material: Color.BLUE,
clampToGround: true,
},
});

// 创建永久的距离标签
const measurement = calculateMeasurement(positions);
if (measurement) {
createLabel(measurement.center, measurement.text);
}
} else if (drawMode.value === "polygon" && positions.length >= 3) {
// 创建永久的面
viewer.entities.add({
polygon: {
hierarchy: new PolygonHierarchy(positions),
material: Color.GREEN.withAlpha(0.5),
outline: true,
outlineColor: Color.BLACK,
outlineWidth: 2,
heightReference: HeightReference.CLAMP_TO_GROUND,
},
});

// 创建永久的面积标签
const measurement = calculateMeasurement(positions);
if (measurement) {
createLabel(measurement.center, measurement.text);
}
}

// 3. 重置状态
confirmedPoints.value = [];
}

// 设置绘制模式
function setDrawMode(mode) {
// 如果正在绘制中,先完成当前绘制
if (drawMode.value !== "none" && confirmedPoints.value.length > 0) {
finishDrawing();
}

// 清除所有临时预览
if (tempShapeEntity) {
viewer.entities.remove(tempShapeEntity);
tempShapeEntity = null;
}
if (tempLabelEntity) {
viewer.entities.remove(tempLabelEntity);
tempLabelEntity = null;
}

drawMode.value = mode;
confirmedPoints.value = [];
}

// 清除所有绘制
function clearDrawings() {
viewer.entities.removeAll();
confirmedPoints.value = [];
tempShapeEntity = null;
tempLabelEntity = null;
currentPosition.value = null;
}
</script>

<style scoped>
.cesium-container {
position: relative;
width: 100%;
height: 100vh;
}

.cesium-map {
width: 100%;
height: 100%;
}

.toolbar {
position: absolute;
top: 20px;
left: 20px;
z-index: 1000;
display: flex;
gap: 10px;
padding: 10px;
background: rgba(255, 255, 255, 0.9);
border-radius: 4px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.toolbar button {
padding: 8px 16px;
border: 1px solid #ddd;
background: white;
cursor: pointer;
border-radius: 4px;
transition: all 0.3s;
}

.toolbar button:hover {
background: #f0f0f0;
}

.toolbar button.active {
background: #007bff;
color: white;
border-color: #007bff;
}

.info-panel {
position: absolute;
bottom: 20px;
right: 20px;
z-index: 1000;
padding: 15px;
background: rgba(255, 255, 255, 0.95);
border-radius: 4px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
min-width: 200px;
}

.info-panel div {
margin: 5px 0;
font-size: 14px;
}
</style>

点击绘制和测量


文章作者: 栖桐听雨声
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 栖桐听雨声 !
  目录