Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GroundPrimitive for line #437

Merged
merged 1 commit into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the positions are 3D (just test the first one), could you disregard the CLAMP_TO_GROUND height reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean if the coordinates is x,y,z. we deactivate the clampToGround?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

@oterral oterral Feb 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do this for polygons why doing it for lines ? and that doesn't make sense if the user specify clampToGround he expects the data are clamped to ground whatever the z value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I checked the KML documentation and they do like you propose: https://developers.google.com/kml/documentation/altitudemode. So OK to merge. However, please update the README.md.

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