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;i20) 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); }