Skip to content

Commit 7d0944b

Browse files
committed
Support layer opacity for vector points
1 parent b5a4687 commit 7d0944b

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/core.js

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

414414

415+
/**
416+
* Synchronizes the vector layer rendering properties (currently only
417+
* '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+
//FIXME Make this work for all geometry types, not just points
424+
var bbs = csPrimitives.context.billboards;
425+
var opacity = olLayer.getOpacity();
426+
if (!goog.isDef(opacity)) {
427+
opacity = 1;
428+
}
429+
bbs.olLayerOpacity = opacity;
430+
var i, bb;
431+
for (i = bbs.length - 1; i >= 0; --i) {
432+
bb = bbs.get(i);
433+
//FIXME Use Cesium.Color.fromAlpha after the next Cesium update
434+
bb.color = new Cesium.Color(1.0, 1.0, 1.0, bb.olStyleOpacity * opacity);
435+
}
436+
};
437+
438+
415439
/**
416440
* Convert a 2D or 3D OpenLayers coordinate to Cesium.
417441
* @param {ol.Coordinate} coordinate Ol3 coordinate.
@@ -789,16 +813,20 @@ goog.require('olcs.core.OlLayerPrimitive');
789813
var position = olcs.core.ol4326CoordinateToCesiumCartesian(center);
790814
var color;
791815
var opacity = imageStyle.getOpacity();
792-
if (goog.isDef(opacity)) {
793-
color = new Cesium.Color(1.0, 1.0, 1.0, opacity);
816+
if (!goog.isDef(opacity)) {
817+
opacity = 1;
794818
}
819+
//FIXME Use Cesium.Color.fromAlpha after the next Cesium update
820+
color = new Cesium.Color(1.0, 1.0, 1.0,
821+
opacity * billboards.olLayerOpacity);
795822
var bb = billboards.add({
796823
// always update Cesium externs before adding a property
797824
image: image,
798825
color: color,
799826
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
800827
position: position
801828
});
829+
bb.olStyleOpacity = opacity;
802830
if (opt_newBillboardCallback) {
803831
opt_newBillboardCallback(bb);
804832
}

src/vectorsynchronizer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ olcs.VectorSynchronizer.prototype.createSingleCounterpart = function(olLayer) {
8181
csPrimitives.show = olLayer.getVisible();
8282
});
8383

84+
olLayer.on('change:opacity', function(e) {
85+
olcs.core.updateCesiumPrimitives(olLayer, csPrimitives);
86+
});
87+
olcs.core.updateCesiumPrimitives(olLayer, csPrimitives);
88+
8489
var onAddFeature = function(feature) {
8590
goog.asserts.assertInstanceof(olLayer, ol.layer.Vector);
8691
var prim = csPrimitives.convert(olLayer, view, feature);

0 commit comments

Comments
 (0)