Skip to content

Commit 34c74ed

Browse files
committed
Support layer opacity for vector points
1 parent b5a4687 commit 34c74ed

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/core.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,34 @@ goog.require('olcs.core.OlLayerPrimitive');
412412
};
413413

414414

415+
/**
416+
* Synchronizes the vector layer rendering properties (currently only
417+
* 'visible' and 'opacity') to the given Cesium primitives.
418+
* @param {!ol.layer.Vector} olLayer
419+
* @param {!Cesium.PrimitiveCollection} csPrimitives
420+
* @api
421+
*/
422+
olcs.core.updateCesiumPrimitives = function(olLayer, csPrimitives) {
423+
var visible = olLayer.getVisible();
424+
if (goog.isDef(visible)) {
425+
csPrimitives.show = visible;
426+
}
427+
//FIXME Make this work for all geometry types, not just points
428+
var bbs = csPrimitives.context.billboards;
429+
var opacity = olLayer.getOpacity();
430+
if (!goog.isDef(opacity)) {
431+
opacity = 1;
432+
}
433+
bbs.olLayerOpacity = opacity;
434+
var i, bb;
435+
for (i = bbs.length - 1; i >= 0; --i) {
436+
bb = bbs.get(i);
437+
//FIXME Use Cesium.Color.fromAlpha after the next Cesium update
438+
bb.color = new Cesium.Color(1.0, 1.0, 1.0, bb.olStyleOpacity * opacity);
439+
}
440+
};
441+
442+
415443
/**
416444
* Convert a 2D or 3D OpenLayers coordinate to Cesium.
417445
* @param {ol.Coordinate} coordinate Ol3 coordinate.
@@ -789,16 +817,20 @@ goog.require('olcs.core.OlLayerPrimitive');
789817
var position = olcs.core.ol4326CoordinateToCesiumCartesian(center);
790818
var color;
791819
var opacity = imageStyle.getOpacity();
792-
if (goog.isDef(opacity)) {
793-
color = new Cesium.Color(1.0, 1.0, 1.0, opacity);
820+
if (!goog.isDef(opacity)) {
821+
opacity = 1;
794822
}
823+
//FIXME Use Cesium.Color.fromAlpha after the next Cesium update
824+
color = new Cesium.Color(1.0, 1.0, 1.0,
825+
opacity * billboards.olLayerOpacity);
795826
var bb = billboards.add({
796827
// always update Cesium externs before adding a property
797828
image: image,
798829
color: color,
799830
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
800831
position: position
801832
});
833+
bb.olStyleOpacity = opacity;
802834
if (opt_newBillboardCallback) {
803835
opt_newBillboardCallback(bb);
804836
}

src/vectorsynchronizer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ olcs.VectorSynchronizer.prototype.createSingleCounterpart = function(olLayer) {
7777
var csPrimitives = olcs.core.olVectorLayerToCesium(olLayer, view,
7878
featurePrimitiveMap);
7979

80-
olLayer.on('change:visible', function(e) {
81-
csPrimitives.show = olLayer.getVisible();
80+
olLayer.on(['change:visible', 'change:opacity'], function(e) {
81+
olcs.core.updateCesiumPrimitives(olLayer, csPrimitives);
8282
});
83+
olcs.core.updateCesiumPrimitives(olLayer, csPrimitives);
8384

8485
var onAddFeature = function(feature) {
8586
goog.asserts.assertInstanceof(olLayer, ol.layer.Vector);

0 commit comments

Comments
 (0)