Skip to content

Commit

Permalink
Merge pull request #437 from oterral/teo_lineclamp
Browse files Browse the repository at this point in the history
Use GroundPrimitive for line
  • Loading branch information
gberaudo authored Feb 3, 2017
2 parents fc863aa + 5b99c1b commit 40ab703
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 19 additions & 1 deletion Cesium.externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,6 @@ Cesium.CircleOutlineGeometry = function(opt_opts) {};
*/
Cesium.ColorGeometryInstanceAttribute = function() {};


/**
* @param {!Cesium.Color} color
* @return {!Cesium.ColorGeometryInstanceAttribute}
Expand Down Expand Up @@ -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.<Cesium.Cartesian3>,
* width: (number|undefined),
* ellipsoid: (Cesium.Ellipsoid|undefined),
* granularity: (number|undefined),
* height: (number|undefined),
* extrudedHeight: (number|undefined),
* vertexFormat: number,
* cornerType: (number|undefined),
* }}
*/
Cesium.optionsCorridorGeometry;

/**
* @constructor
Expand Down
36 changes: 26 additions & 10 deletions src/featureconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 40ab703

Please sign in to comment.