From 6ef2184c8352e7cd86ce49cae413dc1e1e5b7a78 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Mon, 21 Jan 2013 17:46:41 -0700 Subject: [PATCH] Geometry type enumeration --- src/ol/geom/geometry.js | 21 +++++++++++++++++++++ src/ol/geom/linestring.js | 9 +++++++++ src/ol/geom/multilinestring.js | 9 +++++++++ src/ol/geom/multipoint.js | 8 ++++++++ src/ol/geom/multipolygon.js | 9 +++++++++ src/ol/geom/point.js | 9 +++++++++ src/ol/geom/polygon.js | 9 +++++++++ 7 files changed, 74 insertions(+) diff --git a/src/ol/geom/geometry.js b/src/ol/geom/geometry.js index 238c9bca51..3b3834d704 100644 --- a/src/ol/geom/geometry.js +++ b/src/ol/geom/geometry.js @@ -2,6 +2,7 @@ goog.require('ol.Extent'); goog.provide('ol.geom.Coordinate'); goog.provide('ol.geom.CoordinateArray'); goog.provide('ol.geom.Geometry'); +goog.provide('ol.geom.GeometryType'); @@ -25,6 +26,13 @@ ol.geom.Geometry.prototype.dimension; ol.geom.Geometry.prototype.getBounds = goog.abstractMethod; +/** + * Get the geometry type. + * @return {ol.geom.GeometryType} The geometry type. + */ +ol.geom.Geometry.prototype.getType = function() {}; + + /** * @typedef {Array.} */ @@ -35,3 +43,16 @@ ol.geom.Coordinate; * @typedef {Array.} */ ol.geom.CoordinateArray; + + +/** + * @enum {string} + */ +ol.geom.GeometryType = { + POINT: 'point', + LINESTRING: 'linestring', + POLYGON: 'polygon', + MULTIPOINT: 'multipoint', + MULTILINESTRING: 'multilinestring', + MULTIPOLYGON: 'multipolygon' +}; diff --git a/src/ol/geom/linestring.js b/src/ol/geom/linestring.js index a1a5f83f43..256df191a8 100644 --- a/src/ol/geom/linestring.js +++ b/src/ol/geom/linestring.js @@ -5,6 +5,7 @@ goog.require('goog.vec.Float64Array'); goog.require('ol.Extent'); goog.require('ol.geom.CoordinateArray'); goog.require('ol.geom.Geometry'); +goog.require('ol.geom.GeometryType'); @@ -71,3 +72,11 @@ ol.geom.LineString.prototype.getBounds = function() { } return this.bounds_; }; + + +/** + * @inheritDoc + */ +ol.geom.LineString.prototype.getType = function() { + return ol.geom.GeometryType.LINESTRING; +}; diff --git a/src/ol/geom/multilinestring.js b/src/ol/geom/multilinestring.js index 36567eb7eb..c9def94fbe 100644 --- a/src/ol/geom/multilinestring.js +++ b/src/ol/geom/multilinestring.js @@ -3,6 +3,7 @@ goog.provide('ol.geom.MultiLineString'); goog.require('goog.asserts'); goog.require('ol.geom.CoordinateArray'); goog.require('ol.geom.GeometryCollection'); +goog.require('ol.geom.GeometryType'); goog.require('ol.geom.LineString'); @@ -39,3 +40,11 @@ ol.geom.MultiLineString = function(coordinates) { }; goog.inherits(ol.geom.MultiLineString, ol.geom.GeometryCollection); + + +/** + * @inheritDoc + */ +ol.geom.MultiLineString.prototype.getType = function() { + return ol.geom.GeometryType.MULTILINESTRING; +}; diff --git a/src/ol/geom/multipoint.js b/src/ol/geom/multipoint.js index 4fa8174e3b..bfefe0c957 100644 --- a/src/ol/geom/multipoint.js +++ b/src/ol/geom/multipoint.js @@ -39,3 +39,11 @@ ol.geom.MultiPoint = function(coordinates) { }; goog.inherits(ol.geom.MultiPoint, ol.geom.GeometryCollection); + + +/** + * @inheritDoc + */ +ol.geom.MultiPoint.prototype.getType = function() { + return ol.geom.GeometryType.MULTIPOINT; +}; diff --git a/src/ol/geom/multipolygon.js b/src/ol/geom/multipolygon.js index 8049493784..dcc0ec89c3 100644 --- a/src/ol/geom/multipolygon.js +++ b/src/ol/geom/multipolygon.js @@ -3,6 +3,7 @@ goog.provide('ol.geom.MultiPolygon'); goog.require('goog.asserts'); goog.require('ol.geom.CoordinateArray'); goog.require('ol.geom.GeometryCollection'); +goog.require('ol.geom.GeometryType'); goog.require('ol.geom.Polygon'); @@ -40,3 +41,11 @@ ol.geom.MultiPolygon = function(coordinates) { }; goog.inherits(ol.geom.MultiPolygon, ol.geom.GeometryCollection); + + +/** + * @inheritDoc + */ +ol.geom.MultiPolygon.prototype.getType = function() { + return ol.geom.GeometryType.MULTIPOLYGON; +}; diff --git a/src/ol/geom/point.js b/src/ol/geom/point.js index 03f644106d..b2c13f00f2 100644 --- a/src/ol/geom/point.js +++ b/src/ol/geom/point.js @@ -5,6 +5,7 @@ goog.require('goog.vec.Float64Array'); goog.require('ol.Extent'); goog.require('ol.geom.Coordinate'); goog.require('ol.geom.Geometry'); +goog.require('ol.geom.GeometryType'); @@ -46,3 +47,11 @@ ol.geom.Point.prototype.getBounds = function() { } return this.bounds_; }; + + +/** + * @inheritDoc + */ +ol.geom.Point.prototype.getType = function() { + return ol.geom.GeometryType.POINT; +}; diff --git a/src/ol/geom/polygon.js b/src/ol/geom/polygon.js index 90a9b07c88..30ddd5f5be 100644 --- a/src/ol/geom/polygon.js +++ b/src/ol/geom/polygon.js @@ -5,6 +5,7 @@ goog.require('goog.vec.Float64Array'); goog.require('ol.Extent'); goog.require('ol.geom.CoordinateArray'); goog.require('ol.geom.Geometry'); +goog.require('ol.geom.GeometryType'); goog.require('ol.geom.LinearRing'); @@ -54,3 +55,11 @@ ol.geom.Polygon = function(coordinates) { ol.geom.Polygon.prototype.getBounds = function() { return this.rings[0].getBounds(); }; + + +/** + * @inheritDoc + */ +ol.geom.Polygon.prototype.getType = function() { + return ol.geom.GeometryType.POLYGON; +};