Skip to content

Commit

Permalink
Handle change in style function API
Browse files Browse the repository at this point in the history
OL3 changed its style functions to allow returning a single style
instead of an array. This commit adapts OL3-Cesium code.

Closes: #300.
  • Loading branch information
gberaudo committed Dec 15, 2015
1 parent c3c8466 commit 211e089
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/featureconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,33 +783,41 @@ olcs.FeatureConverter.prototype.olStyleToCesium =
* Evaluates style function, blend arrays, get default style.
* @param {ol.layer.Vector|ol.layer.Image} layer
* @param {!ol.Feature} feature
* @param {ol.style.StyleFunction|undefined} fallbackStyle
* @param {ol.style.StyleFunction|undefined} fallbackStyleFunction
* @param {number} resolution
* @return {ol.style.Style} null if no style is available
* @api
*/
olcs.FeatureConverter.prototype.computePlainStyle =
function(layer, feature, fallbackStyle, resolution) {
var featureStyle = feature.getStyleFunction();
var style;
if (goog.isDef(featureStyle)) {
style = featureStyle.call(feature, resolution);
function(layer, feature, fallbackStyleFunction, resolution) {
/**
* @type {ol.FeatureStyleFunction|undefined}
*/
var featureStyleFunction = feature.getStyleFunction();

/**
* @type {ol.style.Style|Array.<ol.style.Style>}
*/
var style = null;

if (featureStyleFunction) {
style = featureStyleFunction.call(feature, resolution);
}
if (!goog.isDefAndNotNull(style) && goog.isDefAndNotNull(fallbackStyle)) {
style = fallbackStyle(feature, resolution);

if (!style && fallbackStyleFunction) {
style = fallbackStyleFunction(feature, resolution);
}

if (!goog.isDef(style)) {
if (!style) {
// The feature must not be displayed
return null;
}

goog.asserts.assert(Array.isArray(style));
// FIXME combine materials as in cesium-materials-pack?
// then this function must return a custom material
// More simply, could blend the colors like described in
// http://en.wikipedia.org/wiki/Alpha_compositing
return style[0];
return Array.isArray(style) ? style[0] : style;
};


Expand Down Expand Up @@ -935,6 +943,9 @@ olcs.FeatureConverter.prototype.olVectorLayerToCesium =
if (!goog.isDefAndNotNull(feature)) {
continue;
}
/**
* @type {ol.style.StyleFunction|undefined}
*/
var layerStyle;
if (olLayer instanceof ol.layer.Image) {
var imageSource = olLayer.getSource();
Expand Down Expand Up @@ -977,6 +988,9 @@ olcs.FeatureConverter.prototype.convert =
return null;
}

/**
* @type {ol.style.StyleFunction|undefined}
*/
var layerStyle;
if (layer instanceof ol.layer.Image) {
var imageSource = layer.getSource();
Expand Down

0 comments on commit 211e089

Please sign in to comment.