diff --git a/examples/vectors.js b/examples/vectors.js index de6a70080..a852da759 100644 --- a/examples/vectors.js +++ b/examples/vectors.js @@ -3,7 +3,7 @@ var iconFeature = new ol.Feature({ }); var textFeature = new ol.Feature({ - geometry: new ol.geom.Point([1000000, 3000000, 50000]) + geometry: new ol.geom.Point([1000000, 3000000, 500000]) }); var cervinFeature = new ol.Feature({ @@ -34,7 +34,7 @@ var iconStyle = new ol.style.Style({ }) }); -var textStyle = new ol.style.Style({ +var textStyle = [new ol.style.Style({ text: new ol.style.Text({ text: 'Only text', textAlign: 'center', @@ -47,7 +47,16 @@ var textStyle = new ol.style.Style({ color: 'rgba(0, 0, 155, 0.3)' }) }) -}); +}), new ol.style.Style({ + geometry: new ol.geom.Circle([1000000, 3000000, 10000], 2e6), + stroke: new ol.style.Stroke({ + color: 'blue', + width: 2 + }), + fill:new ol.style.Fill({ + color: 'rgba(0, 0, 255, 0.2)' + }) +})] iconFeature.setStyle(iconStyle); diff --git a/src/featureconverter.js b/src/featureconverter.js index e30361958..a235749f8 100644 --- a/src/featureconverter.js +++ b/src/featureconverter.js @@ -835,7 +835,7 @@ olcs.FeatureConverter.prototype.olStyleToCesium = function(feature, style, outli * @param {!ol.Feature} feature * @param {ol.StyleFunction|undefined} fallbackStyleFunction * @param {number} resolution - * @return {ol.style.Style} null if no style is available + * @return {Array.} null if no style is available * @api */ olcs.FeatureConverter.prototype.computePlainStyle = function(layer, feature, fallbackStyleFunction, resolution) { @@ -866,7 +866,7 @@ olcs.FeatureConverter.prototype.computePlainStyle = function(layer, feature, fal // 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 Array.isArray(style) ? style[0] : style; + return Array.isArray(style) ? style : [style]; }; @@ -883,6 +883,14 @@ olcs.FeatureConverter.prototype.computePlainStyle = function(layer, feature, fal olcs.FeatureConverter.prototype.olFeatureToCesium = function(layer, feature, style, context, opt_geom) { let geom = opt_geom || feature.getGeometry(); const proj = context.projection; + + if (!opt_geom && style) { + const geomFuncRes = style.getGeometryFunction()(feature); + if (geomFuncRes instanceof ol.geom.Geometry) { + geom = geomFuncRes; + } + } + if (!geom) { // OpenLayers features may not have a geometry // See http://geojson.org/geojson-spec.html#feature-objects @@ -1001,13 +1009,31 @@ olcs.FeatureConverter.prototype.olVectorLayerToCesium = function(olLayer, olView } else { layerStyle = olLayer.getStyleFunction(); } - const style = this.computePlainStyle(olLayer, feature, layerStyle, + const styles = this.computePlainStyle(olLayer, feature, layerStyle, resolution); - if (!style) { + if (!styles.length) { // only 'render' features with a style continue; } - const primitives = this.olFeatureToCesium(olLayer, feature, style, context); + + /** + * @type {Cesium.Primitive|null} + */ + let primitives = null; + for (let i = 0; i < styles.length; i++) { + const prims = this.olFeatureToCesium(olLayer, feature, styles[i], context); + if (prims) { + if (!primitives) { + primitives = prims; + } else { + let i = 0, prim; + while ((prim = prims.get(i))) { + primitives.add(prim); + i++; + } + } + } + } if (!primitives) { continue; } @@ -1050,13 +1076,31 @@ olcs.FeatureConverter.prototype.convert = function(layer, view, feature, context } else { layerStyle = layer.getStyleFunction(); } - const style = this.computePlainStyle(layer, feature, layerStyle, resolution); - if (!style) { + const styles = this.computePlainStyle(layer, feature, layerStyle, resolution); + + if (!styles.length) { // only 'render' features with a style return null; } context.projection = proj; - return this.olFeatureToCesium(layer, feature, style, context); + + /** + * @type {Cesium.Primitive|null} + */ + let primitives = null; + for (let i = 0; i < styles.length; i++) { + const prims = this.olFeatureToCesium(layer, feature, styles[i], context); + if (!primitives) { + primitives = prims; + } else { + let i = 0, prim; + while ((prim = prims.get(i))) { + primitives.add(prim); + i++; + } + } + } + return primitives; };