# cesium-鹰眼图
# 介绍
鹰眼图是GIS中一个基本的功能,鹰眼图,顾名思义,在鹰眼图上可以像从空中俯视一样查看地图框中所显示的地图在整个图中的位置。
# 实现思路
- 在原有的地图上新增一个viewer(地图)
- 让新增的地图和原地图联动视角
- 禁用小地图的操作
# 完整代码
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Use correct character set. -->
<meta charset="utf-8">
<!-- Tell IE to use the latest, best version. -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>Hello World!</title>
<script src="https://data.sunbt.ltd/lib/Cesium-1.89/Build/Cesium/Cesium.js"></script>
<style>
@import url(https://data.sunbt.ltd/lib/Cesium-1.89/Build/Cesium/Widgets/widgets.css);
html,
body,
#cesiumContainer {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
#eye {
position: absolute;
width: 20%;
height: 20%;
bottom: 0;
right: 0;
z-index: 999;
background: red;
border: solid blue 1px;
}
#show {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="cesiumContainer">
</div>
<div id="credit"></div>
<div id="eye"></div>
<script>
//Cesium token
let cesium_tk = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYWRlMmQ1Ni1iNGMxLTRhY2YtYmExYi1jNjYyNTUxNDhjYzgiLCJpZCI6MjMwODAsInNjb3BlcyI6WyJhc2wiLCJhc3IiLCJhc3ciLCJnYyIsInByIl0sImlhdCI6MTU4OTE4NzE1NH0.QrUVmI13wKIqFwmnsGSR6aMr8FEtbO7jsTA0mqnvbdM";
Cesium.Ion.defaultAccessToken = cesium_tk;
// 添加mapbox自定义地图实例
let layer = new Cesium.MapboxStyleImageryProvider({
url: 'https://api.mapbox.com/styles/v1',
username: 'sungang',
styleId: 'cky44gl8m0rwn15pqt8ovyhrs',
accessToken: 'pk.eyJ1Ijoic3VuZ2FuZyIsImEiOiJja2VqaW5rbWwwdWc2MnlwaGVrMnBhbnRuIn0.UlFQNpPyJjiYfETSNo5Zkg',
scaleFactor: true
});
let viewer = new Cesium.Viewer('cesiumContainer', {
imageryProvider: layer,
//geocoder: false,
homeButton: false,
sceneModePicker: false,
baseLayerPicker: false,
navigationHelpButton: false,
animation: false,
creditContainer: "credit",
timeline: false,
fullscreenButton: false,
vrButton: false
});
let viewer1 = new Cesium.Viewer('eye', {
imageryProvider: new Cesium.SingleTileImageryProvider({
url: '../../static/data/worldimage.jpg'
}),
geocoder: false,
homeButton: false,
sceneModePicker: false,
baseLayerPicker: false,
navigationHelpButton: false,
animation: false,
creditContainer: "credit",
timeline: false,
fullscreenButton: false,
vrButton: false
});
let control = viewer1.scene.screenSpaceCameraController;
// 旋转
control.enableRotate = false;
// 旋转
control.enableTranslate = false;
// 放大
control.enableZoom = false;
// 倾斜
control.enableTilt = false;
// 看向
control.enableLook = false;
//视角同步方法
let syncViewer = function() {
viewer1.camera.flyTo({
destination: viewer.camera.position,
orientation: {
heading: viewer.camera.heading,
pitch: viewer.camera.pitch,
roll: viewer.camera.roll
},
duration: 0.0
});
};
//使用回调方法联动视角
viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(0, 0),
label : {
text : new Cesium.CallbackProperty(function(){
syncViewer();
return "";
}, true)
}
});
</script>
</body>
</html>
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
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
效果如下:

# 小地图联动大地图
方式是类似的,代码如下:
// 修改小地图视角
let syncViewer = function() {
viewer1.camera.flyTo({
destination: viewer.camera.position,
orientation: {
heading: viewer.camera.heading,
pitch: viewer.camera.pitch,
roll: viewer.camera.roll
},
duration: 0.0
});
};
//修改大地图视角
let syncViewer1 = function() {
viewer.camera.flyTo({
destination: viewer1.camera.position,
orientation: {
heading: viewer1.camera.heading,
pitch: viewer1.camera.pitch,
roll: viewer1.camera.roll
},
duration: 0.0
});
};
// 大地图回调
viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(0, 0),
label : {
text : new Cesium.CallbackProperty(function(){
syncViewer();
return "";
}, true)
}
});
// 小地图回调
viewer1.entities.add({
position : Cesium.Cartesian3.fromDegrees(0, 0),
label : {
text : new Cesium.CallbackProperty(function(){
syncViewer1();
return "";
}, true)
}
});
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
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
← 2-3D切换 ol二三维联动(鹰眼图) →