From 5b99c1b2f561e4dd034867dffd82254766955c1d Mon Sep 17 00:00:00 2001 From: oterral Date: Thu, 2 Feb 2017 13:29:13 +0100 Subject: [PATCH] Use GroundPrimitive for line --- CHANGES.md | 5 +++++ Cesium.externs.js | 20 +++++++++++++++++++- src/featureconverter.js | 36 ++++++++++++++++++++++++++---------- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bda0fda9d..cfd14f042 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,10 @@ # Changelog +# v 1.24 + +* Changes + * Clamp line to the ground using Corridor geometry (experimental feature). + # v 1.23 - 2016-01-04 * Changes diff --git a/Cesium.externs.js b/Cesium.externs.js index d071bbcad..2be1a310b 100644 --- a/Cesium.externs.js +++ b/Cesium.externs.js @@ -1273,7 +1273,6 @@ Cesium.CircleOutlineGeometry = function(opt_opts) {}; */ Cesium.ColorGeometryInstanceAttribute = function() {}; - /** * @param {!Cesium.Color} color * @return {!Cesium.ColorGeometryInstanceAttribute} @@ -1508,7 +1507,26 @@ Cesium.optionsRectangleGeometry; */ Cesium.RectangleGeometry = function(opt_opts) {}; +/** + * @constructor + * @param {Cesium.optionsCorridorGeometry} opt_opts + * @extends {Cesium.Geometry} + */ +Cesium.CorridorGeometry = function(opt_opts) {}; +/** + * @typedef {{ + * positions: !Array., + * width: (number|undefined), + * ellipsoid: (Cesium.Ellipsoid|undefined), + * granularity: (number|undefined), + * height: (number|undefined), + * extrudedHeight: (number|undefined), + * vertexFormat: number, + * cornerType: (number|undefined), + * }} + */ +Cesium.optionsCorridorGeometry; /** * @constructor diff --git a/src/featureconverter.js b/src/featureconverter.js index 584ebb900..fd7417f2b 100644 --- a/src/featureconverter.js +++ b/src/featureconverter.js @@ -350,21 +350,37 @@ olcs.FeatureConverter.prototype.olLineStringGeometryToCesium = function(layer, f material: this.olStyleToCesium(feature, olStyle, true) }); - // Handle both color and width - var outlineGeometry = new Cesium.PolylineGeometry({ + var geometryOptions = { // always update Cesium externs before adding a property positions: positions, width: this.extractLineWidthFromOlStyle(olStyle), vertexFormat: appearance.vertexFormat - }); + }; + + var outlinePrimitive; + var heightReference = this.getHeightReference(layer, feature, olGeometry); + + if (heightReference == Cesium.HeightReference.CLAMP_TO_GROUND) { + var color = this.extractColorFromOlStyle(olStyle, true); + outlinePrimitive = new Cesium.GroundPrimitive({ + // always update Cesium externs before adding a property + geometryInstances: new Cesium.GeometryInstance({ + geometry: new Cesium.CorridorGeometry(geometryOptions), + attributes : { + color : Cesium.ColorGeometryInstanceAttribute.fromColor(color) + } + }) + }); + } else { + outlinePrimitive = new Cesium.Primitive({ + // always update Cesium externs before adding a property + geometryInstances: new Cesium.GeometryInstance({ + geometry: new Cesium.PolylineGeometry(geometryOptions) + }), + appearance: appearance + }); + } - var outlinePrimitive = new Cesium.Primitive({ - // always update Cesium externs before adding a property - geometryInstances: new Cesium.GeometryInstance({ - geometry: outlineGeometry - }), - appearance: appearance - }); this.setReferenceForPicking(layer, feature, outlinePrimitive); return this.addTextStyle(layer, feature, olGeometry, olStyle,