1
Surpriseplus
2022-09-16 8d1a91c23df335b090e38b2edd15203aa3b03da9
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
461
462
463
464
465
466
467
468
469
470
471
472
var ids=[];
var DemoTileProvider = function DemoTileProvider() {
    this._quadtree = undefined;
    this._tilingScheme = new Cesium.GeographicTilingScheme();
    this._errorEvent = new Cesium.Event();
    this._levelZeroMaximumError = Cesium.QuadtreeTileProvider.computeDefaultLevelZeroMaximumGeometricError(
        this._tilingScheme);
    this.cartographicLimitRectangle = Cesium.Rectangle.clone(Cesium.Rectangle.MAX_VALUE);
};
Cesium.defineProperties(DemoTileProvider.prototype, {
    quadtree: {
        get: function() {
            return this._quadtree;
        },
        set: function(value) {
            this._quadtree = value;
        }
    },
    ready: {
        get: function() {
            return true;
        }
    },
    tilingScheme: {
        get: function() {
            return this._tilingScheme;
        }
    },
    errorEvent: {
        get: function() {
            return this._errorEvent;
        }
    }
});
var rectangleIntersectionScratch = new Cesium.Rectangle();
var cornerPositionsScratch = [new Cesium.Cartesian3(), new Cesium.Cartesian3(), new Cesium.Cartesian3(),
    new Cesium.Cartesian3()
];
DemoTileProvider.prototype.update = function(frameState) {
    this._quadtree.beginFrame(frameState);
};
DemoTileProvider.prototype.initialize = function(frameState) {
    this._quadtree.render(frameState);
};
DemoTileProvider.prototype.beginUpdate = function(frameState) {
 
};
DemoTileProvider.prototype.endUpdate = function(frameState) {
    this._quadtree.endFrame(frameState);
    for (var i=0;i<this._quadtree._tilesToRender.length;i++){
        if(this._quadtree._tilesToRender[i].data.geometryPrimitive)
            this._quadtree._tilesToRender[i].data.geometryPrimitive.update(frameState);
            
    }
     
};
 
DemoTileProvider.prototype.getLevelMaximumGeometricError = function(level) {
    return this._levelZeroMaximumError / (1 << level);
};
 
DemoTileProvider.prototype.loadTile = function(frameState, tile) {
    var m_tile = function m_tile(json) {
        this._tile = tile;
        this._json = json;
        m_tile.prototype.draw = function draw() {
            var tile = this._tile;
            var json = this._json;
            var geometries = [];
            var billboards = new Cesium.BillboardCollection();//new Cesium.LabelCollection(); //new Cesium.PointPrimitiveCollection();//new Cesium.LabelCollection();
            //var positions = [];
            //var colorsTemp = [];
            //viewer.entities.removeAll();
            var entities=[];
            var count=0;
            for (var feature of json.features) {
                count++;
                if(count>20)
                    break;
                var coords = feature.geometry.coordinates;
                billboards.add({
                    position: Cesium.Cartesian3.fromDegrees(coords[0], coords[1], 200-tile._level*10),
                    //text: feature.properties.name,
                    //font: '10px sans-serif',
                    color: Cesium.Color.WHITE,
                    image: './js/plugin_video/video1.png'
                    //outlineColor: Cesium.Color.BLACK,
                    //outlineWidth: 1.0,
                    //style : Cesium.LabelStyle.FILL_AND_OUTLINE
                    
                });
                var entity = {
                    id:feature.id,
                    name: "点",
                    position: Cesium.Cartesian3.fromDegrees(coords[0], coords[1], 200-tile._level*10),
                    billboard: {
                        image: './js/plugin_video/video1.png',
                        
                    },
                    
                    click: function (entity) {//单击
                        //haoutil.alert('你单击了billboard:' + entity._name);
                        viewer.camera.flyTo({
                            destination : new Cesium.Cartesian3(entity._position._value.x, entity._position._value.y, entity._position._value.z+50)
                        });
                        if($("#video_toolbar").css('display')=='none'){
                            $("#video_toolbar").css('display','block');
                            
                        }
                    },
                    mouseover: function (entity1) {//移入
                    
                        mouseOverEntity(entity1)
                    },
                    mouseout: function (entity1) {//移出
                        
    
                        mouseOutEntity(entity1)
                    }
                }
                entities.push(entity);
                viewer.entities.add(entity);
               
            }
            //tile.data.geometryPrimitive = billboards;
            tile.data.entities = entities;
            tile.state = Cesium.QuadtreeTileLoadState.DONE;
            tile.renderable = true;
            
        };
    }
 
    if (tile.state === Cesium.QuadtreeTileLoadState.START) {
        tile.state = Cesium.QuadtreeTileLoadState.LOADING;
        tile.data = {
            geometryPrimitive: undefined,
            entities:[],
            freeResources:function(){
                if(this.geometryPrimitive&&this.geometryPrimitive.destory)
                {
                    this.geometryPrimitive.destory();
                    this.geometryPrimitive=undefined;
                }
                if(this.entities){
                    for(var entity of this.entities){
                        viewer.entities.remove(entity);
                    }
                    this.entities=[];
                }
                
            }
        };
        //viewer.entities.removeAll();
 
        if (tile._level < 14) {
            tile.state = Cesium.QuadtreeTileLoadState.DONE;
            tile.renderable = true;
            return;
        }
 
        var resource = new Cesium.Resource({
            url: 'http://localhost:8580/geoserver/gwc/service/wmts',
            queryParameters: {
                FORMAT: 'application/json;type=geojson',
                STYLE: '',
                REQUEST: 'GetTile',
                SERVICE: 'WMTS',
                VERSION: '1.0.0',
                LAYER: 'DOM:hzvideoPts',
                TILEMATRIX: 'EPSG:4326:' + tile._level,
                TILEMATRIXSET: 'EPSG:4326',
                TILECOL: tile._x,
                TILEROW: tile._y
            }
        });
        
        resource.fetchJson().then(function(results) {
            var tile = new m_tile(results);
            
            if(tile._json.features.length>0){
                tile.draw();   
               
                // var count=0;
                // for (var feature of tile._json.features) {
                //     for(var id of ids){
                //         if(feature.id != id){
                //             count++;
                //         }
                //     }
                    
                //     if(count==ids.length){
                //         count=0;
                //         ids.push(feature.id);
                //         var coords = feature.geometry.coordinates;
                    
                //         viewer.entities.add({
                //             name: "点",
                //             position: Cesium.Cartesian3.fromDegrees(coords[0], coords[1], 20),
                //             billboard: {
                //                 image: './js/plugin_video/video3.png'
                //             },
                //             click: function (entity) {//单击
                //                 //haoutil.alert('你单击了billboard:' + entity._name);
                //                 viewer.camera.flyTo({
                //                     destination : new Cesium.Cartesian3(entity._position._value.x, entity._position._value.y, entity._position._value.z)
                //                 });
                //                 if($("#video_toolbar").css('display')=='none'){
                //                     $("#video_toolbar").css('display','block');
                                    
                //                 }
                //             },
                //             mouseover: function (entity) {//移入
                            
                //                 mouseOverEntity(entity)
                //             },
                //             mouseout: function (entity) {//移出
                                
            
                //                 mouseOutEntity(entity)
                //             },
                //         });
                //     }
                        
                    
                // }
                
            }
            
                
        });
        var levelError = this.getLevelMaximumGeometricError(tile.level);
    }
};
 
DemoTileProvider.prototype.computeTileVisibility = function(tile, frameState, occluders) {
    var distance = this.computeDistanceToTile(tile, frameState);
    tile._distance = distance;
 
    if (frameState.fog.enabled) {
        if (Cesium.Math.fog(distance, frameState.fog.density) >= 1.0) {
            // Tile is completely in fog so return that it is not visible.
            return Cesium.Visibility.NONE;
        }
    }
 
    var surfaceTile = tile.data;
    var tileBoundingRegion = surfaceTile.tileBoundingRegion;
 
    if (surfaceTile.boundingVolumeSourceTile === undefined) {
        // We have no idea where this tile is, so let's just call it partially visible.
        return Cesium.Visibility.PARTIAL;
    }
 
    var cullingVolume = frameState.cullingVolume;
    var boundingVolume = surfaceTile.orientedBoundingBox;
 
    if (!boundingVolume && surfaceTile.renderedMesh) {
        boundingVolume = surfaceTile.renderedMesh.boundingSphere3D;
    }
 
    // Check if the tile is outside the limit area in cartographic space
    surfaceTile.clippedByBoundaries = false;
    var clippedCartographicLimitRectangle = clipRectangleAntimeridian(tile.rectangle, this
        .cartographicLimitRectangle);
    var areaLimitIntersection = Cesium.Rectangle.simpleIntersection(clippedCartographicLimitRectangle, tile
        .rectangle, rectangleIntersectionScratch);
    if (!areaLimitIntersection) {
        return Visibility.NONE;
    }
    if (!Cesium.Rectangle.equals(areaLimitIntersection, tile.rectangle)) {
        surfaceTile.clippedByBoundaries = true;
    }
 
    if (frameState.mode !== Cesium.SceneMode.SCENE3D) {
        boundingVolume = boundingSphereScratch;
        BoundingSphere.fromRectangleWithHeights2D(tile.rectangle, frameState.mapProjection,
            tileBoundingRegion.minimumHeight, tileBoundingRegion.maximumHeight, boundingVolume);
        Cartesian3.fromElements(boundingVolume.center.z, boundingVolume.center.x, boundingVolume.center.y,
            boundingVolume.center);
 
        if (frameState.mode === SceneMode.MORPHING && surfaceTile.renderedMesh) {
            boundingVolume = BoundingSphere.union(surfaceTile.renderedMesh.boundingSphere3D, boundingVolume,
                boundingVolume);
        }
    }
 
    if (!boundingVolume) {
        return Cesium.Intersect.INTERSECTING;
    }
 
    var clippingPlanes = this._clippingPlanes;
    if (clippingPlanes && clippingPlanes.enabled) {
        var planeIntersection = clippingPlanes.computeIntersectionWithBoundingVolume(boundingVolume);
        tile.isClipped = (planeIntersection !== Intersect.INSIDE);
        if (planeIntersection === Cesium.Intersect.OUTSIDE) {
            return Cesium.Visibility.NONE;
        }
    }
 
    var intersection = cullingVolume.computeVisibility(boundingVolume);
    if (intersection === Cesium.Intersect.OUTSIDE) {
        return Cesium.Visibility.NONE;
    }
 
    var ortho3D = frameState.mode === Cesium.SceneMode.SCENE3D && frameState.camera
        .frustum instanceof Cesium.OrthographicFrustum;
    if (frameState.mode === Cesium.SceneMode.SCENE3D && !ortho3D && occluders) {
        var occludeePointInScaledSpace = surfaceTile.occludeePointInScaledSpace;
        if (!occludeePointInScaledSpace) {
            return intersection;
        }
 
        if (occluders.ellipsoid.isScaledSpacePointVisible(occludeePointInScaledSpace)) {
            return intersection;
        }
 
        return Cesium.Visibility.NONE;
    }
 
    return intersection;
};
DemoTileProvider.prototype.canRefine = function(tile, frameState, occluders) {
    if (tile.level < 19)
        return true;
    return false;
};
DemoTileProvider.prototype.showTileThisFrame = function(tile, context, frameState, commandList) {
 
    if (tile.data.geometryPrimitive) {
        //tile.data.geometryPrimitive.update(context, frameState, commandList);
    }
};
DemoTileProvider.prototype.computeDistanceToTile = function(tile, frameState) {
    // The distance should be:
    // 1. the actual distance to the tight-fitting bounding volume, or
    // 2. a distance that is equal to or greater than the actual distance to the tight-fitting bounding volume.
    //
    // When we don't know the min/max heights for a tile, but we do know the min/max of an ancestor tile, we can
    // build a tight-fitting bounding volume horizontally, but not vertically. The min/max heights from the
    // ancestor will likely form a volume that is much bigger than it needs to be. This means that the volume may
    // be deemed to be much closer to the camera than it really is, causing us to select tiles that are too detailed.
    // Loading too-detailed tiles is super expensive, so we don't want to do that. We don't know where the child
    // tile really lies within the parent range of heights, but we _do_ know the child tile can't be any closer than
    // the ancestor height surface (min or max) that is _farthest away_ from the camera. So if we compute distance
    // based that conservative metric, we may end up loading tiles that are not detailed enough, but that's much
    // better (faster) than loading tiles that are too detailed.
 
    var heightSource = updateTileBoundingRegion(tile, this.terrainProvider, frameState);
    var surfaceTile = tile.data;
    var tileBoundingRegion = surfaceTile.tileBoundingRegion;
 
    if (heightSource === undefined) {
        // Can't find any min/max heights anywhere? Ok, let's just say the
        // tile is really far away so we'll load and render it rather than
        // refining.
        return 9999999999.0;
    } else if (surfaceTile.boundingVolumeSourceTile !== heightSource) {
        // Heights are from a new source tile, so update the bounding volume.
        surfaceTile.boundingVolumeSourceTile = heightSource;
 
        var rectangle = tile.rectangle;
        if (rectangle && rectangle.width < Cesium.Math.PI_OVER_TWO + Cesium.Math.EPSILON5) {
            surfaceTile.orientedBoundingBox = Cesium.OrientedBoundingBox.fromRectangle(
                tile.rectangle,
                tileBoundingRegion.minimumHeight,
                tileBoundingRegion.maximumHeight,
                tile.tilingScheme.ellipsoid,
                surfaceTile.orientedBoundingBox);
 
            surfaceTile.occludeePointInScaledSpace = computeOccludeePoint(this, surfaceTile
                .orientedBoundingBox.center, tile.rectangle, tileBoundingRegion.maximumHeight,
                surfaceTile.occludeePointInScaledSpace);
        }
    }
 
    var min = tileBoundingRegion.minimumHeight;
    var max = tileBoundingRegion.maximumHeight;
 
    if (surfaceTile.boundingVolumeSourceTile !== tile) {
        var cameraHeight = frameState.camera.positionCartographic.height;
        var distanceToMin = Math.abs(cameraHeight - min);
        var distanceToMax = Math.abs(cameraHeight - max);
        if (distanceToMin > distanceToMax) {
            tileBoundingRegion.minimumHeight = min;
            tileBoundingRegion.maximumHeight = min;
        } else {
            tileBoundingRegion.minimumHeight = max;
            tileBoundingRegion.maximumHeight = max;
        }
    }
 
    var result = tileBoundingRegion.distanceToCamera(frameState);
 
    tileBoundingRegion.minimumHeight = min;
    tileBoundingRegion.maximumHeight = max;
 
    return result;
};
 
 
 
function updateTileBoundingRegion(tile, terrainProvider, frameState) {
    var surfaceTile = tile.data;
    if (surfaceTile === undefined) {
        surfaceTile = tile.data = new Cesium.GlobeSurfaceTile();
    }
 
    if (surfaceTile.tileBoundingRegion === undefined) {
        surfaceTile.tileBoundingRegion = new Cesium.TileBoundingRegion({
            computeBoundingVolumes: false,
            rectangle: tile.rectangle,
            ellipsoid: tile.tilingScheme.ellipsoid,
            minimumHeight: 0,
            maximumHeight: 0
        });
    }
    return tile;
}
 
function clipRectangleAntimeridian(tileRectangle, cartographicLimitRectangle) {
    if (cartographicLimitRectangle.west < cartographicLimitRectangle.east) {
        return cartographicLimitRectangle;
    }
    var splitRectangle = Rectangle.clone(cartographicLimitRectangle, splitCartographicLimitRectangleScratch);
    var tileCenter = Rectangle.center(tileRectangle, rectangleCenterScratch);
    if (tileCenter.longitude > 0.0) {
        splitRectangle.east = CesiumMath.PI;
    } else {
        splitRectangle.west = -CesiumMath.PI;
    }
    return splitRectangle;
}
 
function computeOccludeePoint(tileProvider, center, rectangle, height, result) {
    var ellipsoidalOccluder = tileProvider.quadtree._occluders.ellipsoid;
    var ellipsoid = ellipsoidalOccluder.ellipsoid;
 
    var cornerPositions = cornerPositionsScratch;
    Cesium.Cartesian3.fromRadians(rectangle.west, rectangle.south, height, ellipsoid, cornerPositions[0]);
    Cesium.Cartesian3.fromRadians(rectangle.east, rectangle.south, height, ellipsoid, cornerPositions[1]);
    Cesium.Cartesian3.fromRadians(rectangle.west, rectangle.north, height, ellipsoid, cornerPositions[2]);
    Cesium.Cartesian3.fromRadians(rectangle.east, rectangle.north, height, ellipsoid, cornerPositions[3]);
 
    return ellipsoidalOccluder.computeHorizonCullingPoint(center, cornerPositions, result);
}
DemoTileProvider.prototype.isDestroyed = function() {
 
    return false;
}
DemoTileProvider.prototype.destroy = function() {
 
    return Cesium.destroyObject(this);
};
DemoTileProvider.prototype.updateForPick = function(frameState) {
    // Add the tile pick commands from the tiles drawn last frame.
    var drawCommands = this._drawCommands;
    for (var i = 0, length = this._usedDrawCommands; i < length; ++i) {
        frameState.commandList.push(drawCommands[i]);
    }
};
 
function mouseOverEntity(entity) {
    entity._billboard._image._value='./js/plugin_video/video2.png';
    //var newclr = color.getValue().withAlpha(alpha);
    //color.setValue(newclr);
}
 
function mouseOutEntity(entity) {
    entity._billboard._image._value='./js/plugin_video/video1.png';
    //var newclr = color.getValue().withAlpha(alpha);
    //color.setValue(newclr);
}