Skip to content

Commit

Permalink
Support layer opacity for vector points
Browse files Browse the repository at this point in the history
  • Loading branch information
ahocevar committed Feb 3, 2015
1 parent b5a4687 commit 34c74ed
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
36 changes: 34 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,34 @@ goog.require('olcs.core.OlLayerPrimitive');
};


/**
* Synchronizes the vector layer rendering properties (currently only
* 'visible' and 'opacity') to the given Cesium primitives.
* @param {!ol.layer.Vector} olLayer
* @param {!Cesium.PrimitiveCollection} csPrimitives
* @api
*/
olcs.core.updateCesiumPrimitives = function(olLayer, csPrimitives) {
var visible = olLayer.getVisible();
if (goog.isDef(visible)) {
csPrimitives.show = visible;
}
//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);
}
};


/**
* Convert a 2D or 3D OpenLayers coordinate to Cesium.
* @param {ol.Coordinate} coordinate Ol3 coordinate.
Expand Down Expand Up @@ -789,16 +817,20 @@ goog.require('olcs.core.OlLayerPrimitive');
var position = olcs.core.ol4326CoordinateToCesiumCartesian(center);
var color;
var opacity = imageStyle.getOpacity();
if (goog.isDef(opacity)) {
color = new Cesium.Color(1.0, 1.0, 1.0, opacity);
if (!goog.isDef(opacity)) {
opacity = 1;
}
//FIXME Use Cesium.Color.fromAlpha after the next Cesium update
color = new Cesium.Color(1.0, 1.0, 1.0,
opacity * billboards.olLayerOpacity);
var bb = billboards.add({
// always update Cesium externs before adding a property
image: image,
color: color,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
position: position
});
bb.olStyleOpacity = opacity;
if (opt_newBillboardCallback) {
opt_newBillboardCallback(bb);
}
Expand Down
5 changes: 3 additions & 2 deletions src/vectorsynchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ olcs.VectorSynchronizer.prototype.createSingleCounterpart = function(olLayer) {
var csPrimitives = olcs.core.olVectorLayerToCesium(olLayer, view,
featurePrimitiveMap);

olLayer.on('change:visible', function(e) {
csPrimitives.show = olLayer.getVisible();
olLayer.on(['change:visible', 'change:opacity'], function(e) {
olcs.core.updateCesiumPrimitives(olLayer, csPrimitives);
});
olcs.core.updateCesiumPrimitives(olLayer, csPrimitives);

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

0 comments on commit 34c74ed

Please sign in to comment.