From 9caf98e2ae39b6c033676c1fda8e9f847f91db86 Mon Sep 17 00:00:00 2001 From: gberaudo Date: Thu, 12 Feb 2015 13:48:58 +0100 Subject: [PATCH] Modify opacity after primitive was rendered --- cesium | 2 +- src/core.js | 46 +++++++++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/cesium b/cesium index bad8b17f7..9f5fa6a23 160000 --- a/cesium +++ b/cesium @@ -1 +1 @@ -Subproject commit bad8b17f7899233497e51eb674e430356e41f4c5 +Subproject commit 9f5fa6a2337b854caae08a8b45c9a5045d4b43c2 diff --git a/src/core.js b/src/core.js index 7aa4b4739..ee74e579d 100644 --- a/src/core.js +++ b/src/core.js @@ -420,18 +420,36 @@ goog.require('olcs.core.OlLayerPrimitive'); * @api */ olcs.core.updateCesiumPrimitives = function(olLayer, csPrimitives) { - //FIXME Make this work for all geometry types, not just points - var bbs = csPrimitives.context.billboards; var opacity = olLayer.getOpacity(); if (!goog.isDef(opacity)) { opacity = 1; } - bbs.olLayerOpacity = opacity; - var i, bb; - for (i = bbs.length - 1; i >= 0; --i) { - bb = bbs.get(i); - //FIXME Use Cesium.Color.fromAlpha after the next Cesium update - bb.color = new Cesium.Color(1.0, 1.0, 1.0, bb.olStyleOpacity * opacity); + csPrimitives.olLayerOpacity = opacity; + var i, bb, j, prim, geoms, geom, color; + for (i = csPrimitives.length - 1; i >= 0; --i) { + prim = csPrimitives.get(i); + if (prim instanceof Cesium.PrimitiveCollection) { + olcs.core.updateCesiumPrimitives(olLayer, prim); + } else { + if (!prim.ready) continue; + var attrs = prim.getGeometryInstanceAttributes("id"); + if (!attrs) continue; + color = attrs.color; + if (color) { + //FIXME This currently overrides style opacity with layer opacity + color[3] = Cesium.Color.floatToByte(opacity); + attrs.color = color; + } + } + } + if (csPrimitives instanceof olcs.core.OlLayerPrimitive) { + var bbs = csPrimitives.context.billboards; + bbs.olLayerOpacity = opacity; + for (i = bbs.length - 1; i >= 0; --i) { + bb = bbs.get(i); + //FIXME Use Cesium.Color.fromAlpha after the next Cesium update + bb.color = new Cesium.Color(1.0, 1.0, 1.0, bb.olStyleOpacity * opacity); + } } }; @@ -504,7 +522,8 @@ goog.require('olcs.core.OlLayerPrimitive'); geometry: geometry, attributes: { color: Cesium.ColorGeometryInstanceAttribute.fromColor(color) - } + }, + id: "id" }); }; @@ -526,7 +545,7 @@ goog.require('olcs.core.OlLayerPrimitive'); } var appearance = new Cesium.PerInstanceColorAppearance(options); - var instances = createInstance(geometry, color); + var instances = [createInstance(geometry, color)]; var primitive = new Cesium.Primitive({ // always update Cesium externs before adding a property @@ -714,9 +733,10 @@ goog.require('olcs.core.OlLayerPrimitive'); var outlinePrimitive = new Cesium.Primitive({ // always update Cesium externs before adding a property - geometryInstances: new Cesium.GeometryInstance({ - geometry: outlineGeometry - }), + geometryInstances: [new Cesium.GeometryInstance({ + geometry: outlineGeometry, + id: "id" + })], appearance: appearance });