From b2a93dcda7bf2b91eadf73dfd43114dc9ce1020e Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 30 Nov 2013 19:28:00 +0100 Subject: [PATCH] Add ol.geom.LinearRing --- src/ol/geom/geometry.js | 1 + src/ol/geom/linearring.exports | 4 +++ src/ol/geom/linearring.js | 48 ++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 src/ol/geom/linearring.exports create mode 100644 src/ol/geom/linearring.js diff --git a/src/ol/geom/geometry.js b/src/ol/geom/geometry.js index bed5760b08..334d43c701 100644 --- a/src/ol/geom/geometry.js +++ b/src/ol/geom/geometry.js @@ -16,6 +16,7 @@ goog.require('ol.geom.flat'); ol.geom.Type = { POINT: 'Point', LINE_STRING: 'LineString', + LINEAR_RING: 'LinearRing', POLYGON: 'Polygon', MULTI_POINT: 'MultiPoint', MULTI_LINE_STRING: 'MultiLineString', diff --git a/src/ol/geom/linearring.exports b/src/ol/geom/linearring.exports new file mode 100644 index 0000000000..59792c22b9 --- /dev/null +++ b/src/ol/geom/linearring.exports @@ -0,0 +1,4 @@ +@exportSymbol ol.geom.LinearRing +@exportProperty ol.geom.LinearRing.prototype.getCoordinates +@exportProperty ol.geom.LinearRing.prototype.getType +@exportProperty ol.geom.LinearRing.prototype.setCoordinates diff --git a/src/ol/geom/linearring.js b/src/ol/geom/linearring.js new file mode 100644 index 0000000000..555c91d516 --- /dev/null +++ b/src/ol/geom/linearring.js @@ -0,0 +1,48 @@ +goog.provide('ol.geom.LinearRing'); + +goog.require('ol.geom.Geometry'); +goog.require('ol.geom.flat'); + + + +/** + * @constructor + * @extends {ol.geom.Geometry} + * @param {ol.geom.RawLinearRing} coordinates Coordinates. + * @param {ol.geom.Layout=} opt_layout Layout. + */ +ol.geom.LinearRing = function(coordinates, opt_layout) { + goog.base(this); + this.setCoordinates(coordinates, opt_layout); +}; +goog.inherits(ol.geom.LinearRing, ol.geom.Geometry); + + +/** + * @return {ol.geom.RawLinearRing} Coordinates. + */ +ol.geom.LinearRing.prototype.getCoordinates = function() { + return ol.geom.flat.inflateCoordinates( + this.flatCoordinates, 0, this.flatCoordinates.length, this.stride); +}; + + +/** + * @inheritDoc + */ +ol.geom.LinearRing.prototype.getType = function() { + return ol.geom.Type.LINEAR_RING; +}; + + +/** + * @param {ol.geom.RawLinearRing} coordinates Coordinates. + * @param {ol.geom.Layout=} opt_layout Layout. + */ +ol.geom.LinearRing.prototype.setCoordinates = + function(coordinates, opt_layout) { + this.setLayout(opt_layout, coordinates, 1); + ol.geom.flat.deflateCoordinates( + this.flatCoordinates, 0, coordinates, this.stride); + this.dispatchChangeEvent(); +};