-
Notifications
You must be signed in to change notification settings - Fork 2
/
test1.html
168 lines (153 loc) · 7.05 KB
/
test1.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>分层分户拾取Demo</title>
<script src="https://cesiumjs.org/Cesium/Build/CesiumUnminified/Cesium.js"></script>
<style>
@import url(https://cesiumjs.org/Cesium/Build/CesiumUnminified/Widgets/widgets.css);
html,body,#cesiumContainer{
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
</head>
<body>
<div id="cesiumContainer"></div>
</body>
<script>
var viewer = new Cesium.Viewer('cesiumContainer', {
terrainProvider: Cesium.createWorldTerrain()
});
var scene = viewer.scene;
var camera = scene.camera;
camera.setView({
destination : new Cesium.Cartesian3(1216394.1392207467, -4736348.59346919, 4081293.9160685353),
orientation : {
heading : 0.018509338875732695,
pitch : -0.09272999615872646
}
});
var center = new Cesium.Cartesian3(1216378.7274609583, -4736321.311000817, 4081334.9085783334);
var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
var hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(2.619728786416368, 0.0, 0.0));
var hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(0.0, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix);
var modelMatrix4=Cesium.Matrix4.multiplyByTranslation(modelMatrix, new Cesium.Cartesian3(-2.0, -1.0, 5.0), new Cesium.Matrix4());
var modelMatrix3=Cesium.Matrix4.multiplyByTranslation(modelMatrix, new Cesium.Cartesian3(-2.0, -1.0, -4.0), new Cesium.Matrix4());
var modelMatrix2=Cesium.Matrix4.multiplyByTranslation(modelMatrix, new Cesium.Cartesian3(-2.0, -1.0, -8.0), new Cesium.Matrix4());
var modelMatrix1=Cesium.Matrix4.multiplyByTranslation(modelMatrix, new Cesium.Cartesian3(-2.0, -1.0, -12.0), new Cesium.Matrix4());
var geometry4=Cesium.BoxGeometry.fromDimensions({
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
dimensions : new Cesium.Cartesian3(67.0, 36.0, 14.0)
});
var geometry3=Cesium.BoxGeometry.fromDimensions({
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
dimensions : new Cesium.Cartesian3(67.0, 36.0, 4.0)
});
var geometry2=Cesium.BoxGeometry.fromDimensions({
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
dimensions : new Cesium.Cartesian3(67.0, 36.0, 4.0)
});
var geometry1=Cesium.BoxGeometry.fromDimensions({
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
dimensions : new Cesium.Cartesian3(67.0, 36.0, 4.0)
});
var buildingHighlight4 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : geometry4,
modelMatrix : modelMatrix4,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromRandom().withAlpha(0.0)),
show : new Cesium.ShowGeometryInstanceAttribute(true)
},
id : 'volume'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));
var buildingHighlight3 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : geometry3,
modelMatrix : modelMatrix3,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromRandom().withAlpha(0.0)),
show : new Cesium.ShowGeometryInstanceAttribute(true)
},
id : 'volume'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));
var buildingHighlight2 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : geometry2,
modelMatrix : modelMatrix2,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromRandom().withAlpha(0.0)),
show : new Cesium.ShowGeometryInstanceAttribute(true)
},
id : 'volume'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));
var buildingHighlight1 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : geometry1,
modelMatrix : modelMatrix1,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromRandom().withAlpha(0.0)),
show : new Cesium.ShowGeometryInstanceAttribute(true)
},
id : 'volume'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));
var tileset = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(6074) });
scene.primitives.add(tileset);
var currentObjectId;
var currentPrimitive;
var currentColor;
var currentShow;
var attributes;
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
var position=scene.pickPosition(movement.endPosition);
//console.log(position);
var pickedObject = scene.pick(movement.endPosition);
if (Cesium.defined(pickedObject) && Cesium.defined(pickedObject.id)) {
console.log('aa');
if (pickedObject.id === currentObjectId) {
//return;
}
console.log('bb');
if (Cesium.defined(currentObjectId)) {
attributes = currentPrimitive.getGeometryInstanceAttributes(currentObjectId);
attributes.color = currentColor;
attributes.show = currentShow;
currentObjectId = undefined;
currentPrimitive = undefined;
currentColor = undefined;
currentShow = undefined;
}
}
if (Cesium.defined(pickedObject) && Cesium.defined(pickedObject.primitive) && Cesium.defined(pickedObject.id) && Cesium.defined(pickedObject.primitive.getGeometryInstanceAttributes)) {
currentObjectId = pickedObject.id;
currentPrimitive = pickedObject.primitive;
attributes = currentPrimitive.getGeometryInstanceAttributes(currentObjectId);
currentColor = attributes.color;
currentShow = attributes.show;
if (!scene.invertClassification) {
attributes.color = [255, 0, 255, 128];
}
attributes.show = [1];
} else if (Cesium.defined(currentObjectId)) {
attributes = currentPrimitive.getGeometryInstanceAttributes(currentObjectId);
attributes.color = currentColor;
attributes.show = currentShow;
currentObjectId = undefined;
currentPrimitive = undefined;
currentColor = undefined;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
</script>
</html>