Cesium Overriding Methods ('-' * 25) Just setting up a simple Cesium viewer.
A Pen by Michael Lodge-Paolini on CodePen.
Cesium Overriding Methods ('-' * 25) Just setting up a simple Cesium viewer.
A Pen by Michael Lodge-Paolini on CodePen.
| <div id="cesiumContainer" class="fullScreen"><div> |
| //https://groups.google.com/forum/#!topic/cesium-dev/_9lVzDBZ--c | |
| var testInstanceId = 'FindME'; | |
| var viewer = new Cesium.Viewer('cesiumContainer', {}); | |
| var primitives = viewer.scene.primitives; | |
| //Override primitive collection | |
| primitives.contains = function(searchFor) { | |
| //custom find code | |
| for (var i = 0; i < this._primitives.length; i++) { | |
| if (this._primitives[i].geometryInstances.id === searchFor) { | |
| return true; | |
| } | |
| } | |
| //custom find did not find anything so check original contains | |
| return Cesium.PrimitiveCollection.prototype.contains.call(this, searchFor); | |
| }; | |
| var primTest = new Cesium.Primitive({ | |
| geometryInstances: new Cesium.GeometryInstance({ | |
| id: testInstanceId, | |
| geometry: Cesium.BoxGeometry.fromDimensions({ | |
| vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT, | |
| dimensions: new Cesium.Cartesian3(400000.0, 300000.0, 500000.0) | |
| }), | |
| modelMatrix: Cesium.Matrix4.multiplyByTranslation( | |
| Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(-105.0, 45.0)), | |
| new Cesium.Cartesian3(0.0, 0.0, 250000), new Cesium.Matrix4()), | |
| attributes: { | |
| color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED.withAlpha(0.5)) | |
| } | |
| }), | |
| appearance: new Cesium.PerInstanceColorAppearance({ | |
| closed: true | |
| }) | |
| }); | |
| primitives.add(new Cesium.Primitive({ | |
| geometryInstances: new Cesium.GeometryInstance({ | |
| geometry: new Cesium.RectangleGeometry({ | |
| rectangle: Cesium.Rectangle.fromDegrees(-100.0, 30.0, -93.0, 37.0), | |
| height: 100000, | |
| vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT | |
| }), | |
| attributes: { | |
| color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.BLUE) | |
| } | |
| }), | |
| appearance: new Cesium.PerInstanceColorAppearance() | |
| })); | |
| primitives.add(primTest); | |
| var found = primitives.contains(testInstanceId); | |
| console.log('Found by InstanceId: ' + found); | |
| found = primitives.contains('notThere'); | |
| console.log('Found by InstanceId: ' + found); | |
| found = primitives.contains(primTest); | |
| console.log('Found by Primitive: ' + found); |
| .fullScreen { | |
| display: block; | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| border: none; | |
| width: 100%; | |
| height: 100%; | |
| } |