Vector work #218

Merged
merged 207 commits into from Mar 12, 2013
Select commit
Jump to file
+6,860 −39
View
2 base.json
@@ -39,7 +39,9 @@
"disambiguate-properties": true,
"externs": [
+ "//json.js",
"externs/bingmaps.js",
+ "externs/geojson.js",
"externs/proj4js.js",
"externs/tilejson.js"
],
View
2 build/ol-simple.json
@@ -13,7 +13,9 @@
"id": "ol-simple",
"externs": [
+ "//json.js",
"externs/bingmaps.js",
+ "externs/geojson.js",
"externs/proj4js.js",
"externs/tilejson.js"
],
View
2 build/ol-whitespace.json
@@ -14,7 +14,9 @@
"disambiguate-properties": false,
"externs": [
+ "//json.js",
"externs/bingmaps.js",
+ "externs/geojson.js",
"externs/proj4js.js",
"externs/tilejson.js"
],
View
2 build/ol.json
@@ -13,8 +13,10 @@
"css-output-file": "build/ol.css",
"externs": [
+ "//json.js",
"build/src/external/externs/types.js",
"externs/bingmaps.js",
+ "externs/geojson.js",
"externs/proj4js.js",
"externs/tilejson.js"
],
View
52 examples/style-rules.html
@@ -0,0 +1,52 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="chrome=1">
+ <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
+ <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" type="text/css">
+ <link rel="stylesheet" href="examples.css" type="text/css">
+ <link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" type="text/css">
+ <title>Style with rules example</title>
+ </head>
+ <body>
+
+ <div class="navbar navbar-inverse navbar-fixed-top">
+ <div class="navbar-inner">
+ <div class="container">
+ <a class="brand" href="example-list.html">OpenLayers 3 Examples</a>
+ <ul class="nav pull-right">
+ <li><a href="https://github.com/openlayers/ol3"><i class="icon-github"></i></a></li>
+ <li><a href="https://twitter.com/openlayers"><i class="icon-twitter"></i></a></li>
+ </ul>
+ </div>
+ </div>
+ </div>
+
+ <div class="container-fluid">
+
+ <div class="row-fluid">
+ <div class="span12">
+ <div id="map" class="map"></div>
+ </div>
+ </div>
+
+ <div class="row-fluid">
+
+ <div class="span4">
+ <h4 id="title">Style with rules example</h4>
+ <p id="shortdesc">Draws features with rule based styles.</p>
+ <div id="docs">
+ <p>See the <a href="style-rules.js" target="_blank">style-rules.js source</a> to see how this is done.</p>
+ </div>
+ <div id="tags">vector, geojson, style</div>
+ </div>
+
+ </div>
+
+ </div>
+
+ <script src="loader.js?id=style-rules" type="text/javascript"></script>
+
+ </body>
+</html>
View
136 examples/style-rules.js
@@ -0,0 +1,136 @@
+goog.require('ol.Collection');
+goog.require('ol.Coordinate');
+goog.require('ol.Expression');
+goog.require('ol.Feature');
+goog.require('ol.Map');
+goog.require('ol.RendererHint');
+goog.require('ol.View2D');
+goog.require('ol.control.defaults');
+goog.require('ol.filter.Filter');
+goog.require('ol.geom.LineString');
+goog.require('ol.layer.Vector');
+goog.require('ol.parser.GeoJSON');
+goog.require('ol.projection');
+goog.require('ol.source.Vector');
+goog.require('ol.style.Line');
+goog.require('ol.style.Rule');
+goog.require('ol.style.Style');
+
+
+var style = new ol.style.Style({rules: [
+ new ol.style.Rule({
+ filter: new ol.filter.Filter(function(feature) {
+ return feature.get('where') == 'outer';
+ }),
+ symbolizers: [
+ new ol.style.Line({
+ strokeColor: new ol.Expression('color'),
+ strokeWidth: 4,
+ opacity: 1
+ })
+ ]
+ }),
+ new ol.style.Rule({
+ filter: new ol.filter.Filter(function(feature) {
+ return feature.get('where') == 'inner';
+ }),
+ symbolizers: [
+ new ol.style.Line({
+ strokeColor: '#013',
+ strokeWidth: 4,
+ opacity: 1
+ }),
+ new ol.style.Line({
+ strokeColor: new ol.Expression('color'),
+ strokeWidth: 2,
+ opacity: 1
+ })
+ ]
+ })
+]});
+
+var vector = new ol.layer.Vector({
+ style: style,
+ source: new ol.source.Vector({
+ projection: ol.projection.get('EPSG:3857')
+ })
+});
+
+vector.parseFeatures({
+ 'type': 'FeatureCollection',
+ 'features': [{
+ 'type': 'Feature',
+ 'properties': {
+ 'color': '#BADA55',
+ 'where': 'inner'
+ },
+ 'geometry': {
+ 'type': 'LineString',
+ 'coordinates': [[-10000000, -10000000], [10000000, 10000000]]
+ }
+ }, {
+ 'type': 'Feature',
+ 'properties': {
+ 'color': '#BADA55',
+ 'where': 'inner'
+ },
+ 'geometry': {
+ 'type': 'LineString',
+ 'coordinates': [[-10000000, 10000000], [10000000, -10000000]]
+ }
+ }, {
+ 'type': 'Feature',
+ 'properties': {
+ 'color': '#013',
+ 'where': 'outer'
+ },
+ 'geometry': {
+ 'type': 'LineString',
+ 'coordinates': [[-10000000, -10000000], [-10000000, 10000000]]
+ }
+ }, {
+ 'type': 'Feature',
+ 'properties': {
+ 'color': '#013',
+ 'where': 'outer'
+ },
+ 'geometry': {
+ 'type': 'LineString',
+ 'coordinates': [[-10000000, 10000000], [10000000, 10000000]]
+ }
+ }, {
+ 'type': 'Feature',
+ 'properties': {
+ 'color': '#013',
+ 'where': 'outer'
+ },
+ 'geometry': {
+ 'type': 'LineString',
+ 'coordinates': [[10000000, 10000000], [10000000, -10000000]]
+ }
+ }, {
+ 'type': 'Feature',
+ 'properties': {
+ 'color': '#013',
+ 'where': 'outer'
+ },
+ 'geometry': {
+ 'type': 'LineString',
+ 'coordinates': [[10000000, -10000000], [-10000000, -10000000]]
+ }
+ }]
+}, new ol.parser.GeoJSON(), ol.projection.get('EPSG:3857'));
+
+
+var map = new ol.Map({
+ layers: [vector],
+ controls: ol.control.defaults({
+ attribution: false
+ }),
+ renderer: ol.RendererHint.CANVAS,
+ target: 'map',
+ view: new ol.View2D({
+ center: new ol.Coordinate(0, 0),
+ zoom: 1
+ })
+});
View
52 examples/vector-layer.html
@@ -0,0 +1,52 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="chrome=1">
+ <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
+ <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" type="text/css">
+ <link rel="stylesheet" href="examples.css" type="text/css">
+ <link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" type="text/css">
+ <title>Vector layer example</title>
+ </head>
+ <body>
+
+ <div class="navbar navbar-inverse navbar-fixed-top">
+ <div class="navbar-inner">
+ <div class="container">
+ <a class="brand" href="example-list.html">OpenLayers 3 Examples</a>
+ <ul class="nav pull-right">
+ <li><a href="https://github.com/openlayers/ol3"><i class="icon-github"></i></a></li>
+ <li><a href="https://twitter.com/openlayers"><i class="icon-twitter"></i></a></li>
+ </ul>
+ </div>
+ </div>
+ </div>
+
+ <div class="container-fluid">
+
+ <div class="row-fluid">
+ <div class="span12">
+ <div id="map" class="map"></div>
+ </div>
+ </div>
+
+ <div class="row-fluid">
+
+ <div class="span4">
+ <h4 id="title">Vector layer example</h4>
+ <p id="shortdesc">Example of a vector layer.</p>
+ <div id="docs">
+ <p>See the <a href="vector-layer.js" target="_blank">vector-layer.js source</a> to see how this is done.</p>
+ </div>
+ <div id="tags">vector, geojson, style</div>
+ </div>
+
+ </div>
+
+ </div>
+
+ <script src="loader.js?id=vector-layer" type="text/javascript"></script>
+
+ </body>
+</html>
View
71 examples/vector-layer.js
@@ -0,0 +1,71 @@
+goog.require('ol.Collection');
+goog.require('ol.Coordinate');
+goog.require('ol.Feature');
+goog.require('ol.Map');
+goog.require('ol.RendererHint');
+goog.require('ol.View2D');
+goog.require('ol.geom.LineString');
+goog.require('ol.geom.Point');
+goog.require('ol.layer.TileLayer');
+goog.require('ol.layer.Vector');
+goog.require('ol.parser.GeoJSON');
+goog.require('ol.projection');
+goog.require('ol.source.MapQuestOpenAerial');
+goog.require('ol.source.Vector');
+goog.require('ol.style.Polygon');
+goog.require('ol.style.Rule');
+goog.require('ol.style.Style');
+
+
+var map;
+
+var raster = new ol.layer.TileLayer({
+ source: new ol.source.MapQuestOpenAerial()
+});
+
+var vector = new ol.layer.Vector({
+ source: new ol.source.Vector({
+ projection: ol.projection.get('EPSG:4326')
+ }),
+ style: new ol.style.Style({rules: [
+ new ol.style.Rule({
+ symbolizers: [
+ new ol.style.Polygon({
+ strokeStyle: '#696969',
+ strokeWidth: 1,
+ opacity: 1.5
+ })
+ ]
+ })
+ ]})
+});
+
+var geojson = new ol.parser.GeoJSON();
+var url = '../test/spec/ol/parser/geojson/countries.json';
+var xhr = new XMLHttpRequest();
+xhr.open('GET', url, true);
+
+
+/**
+ * onload handler for the XHR request.
+ */
+xhr.onload = function() {
+ if (xhr.status == 200) {
+ // this is silly to have to tell the layer the destination projection
+ var projection = map.getView().getProjection();
@twpayne
twpayne added a note Mar 11, 2013

map is used before it is defined here.

@ahocevar
OpenLayers member
@ahocevar
OpenLayers member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ vector.parseFeatures(xhr.responseText, geojson, projection);
+ } else {
+ throw new Error('Data loading failed: ' + xhr.status);
+ }
+};
+xhr.send();
+
+map = new ol.Map({
+ layers: new ol.Collection([raster, vector]),
+ renderer: ol.RendererHint.CANVAS,
+ target: 'map',
+ view: new ol.View2D({
+ center: new ol.Coordinate(0, 0),
+ zoom: 1
+ })
+});
View
60 externs/geojson.js
@@ -10,51 +10,70 @@
/**
* @constructor
*/
-var GeoJSONCRS = function() {};
+var GeoJSONObject = function() {};
/**
* @type {string}
*/
-GeoJSONCRS.prototype.type;
+GeoJSONObject.prototype.type;
/**
- * @type {!Object.<string, *>}
+ * @type {!GeoJSONCRS|undefined}
*/
-GeoJSONCRS.prototype.properties;
+GeoJSONObject.prototype.crs;
/**
* @constructor
+ * @extends {GeoJSONObject}
*/
-var GeoJSONGeometry = function() {};
+var GeoJSONCRS = function() {};
/**
- * @type {string}
+ * @type {!Object.<string, *>}
+ */
+GeoJSONCRS.prototype.properties;
+
+
+
+/**
+ * @constructor
+ * @extends {GeoJSONObject}
*/
-GeoJSONGeometry.prototype.type;
+var GeoJSONGeometry = function() {};
/**
- * @type {!Array.<number>|!Array.<!Array.<number>>}
+ * @type {!Array.<number>|!Array.<!Array.<number>>|
+ * !Array.<!Array.<!Array.<number>>>}
*/
GeoJSONGeometry.prototype.coordinates;
/**
* @constructor
+ * @extends {GeoJSONObject}
*/
-var GeoJSONFeature = function() {};
+var GeoJSONGeometryCollection = function() {};
/**
- * @type {string}
+ * @type {!Array.<GeoJSONGeometry>}
+ */
+GeoJSONGeometryCollection.prototype.geometries;
+
+
+
+/**
+ * @constructor
+ * @extends {GeoJSONObject}
*/
-GeoJSONFeature.prototype.type;
+var GeoJSONFeature = function() {};
/**
@@ -72,17 +91,12 @@ GeoJSONFeature.prototype.properties;
/**
* @constructor
+ * @extends {GeoJSONObject}
*/
var GeoJSONFeatureCollection = function() {};
/**
- * @type {string}
- */
-GeoJSONFeatureCollection.prototype.type;
-
-
-/**
* @type {!Array.<GeoJSONFeature>}
*/
GeoJSONFeatureCollection.prototype.features;
@@ -92,15 +106,3 @@ GeoJSONFeatureCollection.prototype.features;
* @type {!Array.<number>|undefined}
*/
GeoJSONFeatureCollection.prototype.bbox;
-
-
-/**
- * @type {!GeoJSONCRS|undefined}
- */
-GeoJSONFeatureCollection.prototype.crs;
-
-
-/**
- * @type {!Object.<string, *>}
- */
-GeoJSONFeatureCollection.prototype.properties;
View
38 src/objectliterals.exports
@@ -120,6 +120,11 @@
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.resolutions Array.<number>|undefined
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.url string|undefined
+@exportObjectLiteral ol.source.SourceOptions
+@exportObjectLiteralProperty ol.source.SourceOptions.attributions Array.<ol.Attribution>|undefined
+@exportObjectLiteralProperty ol.source.SourceOptions.extent ol.Extent|undefined
+@exportObjectLiteralProperty ol.source.SourceOptions.projection ol.Projection|undefined
+
@exportObjectLiteral ol.source.StamenOptions
@exportObjectLiteralProperty ol.source.StamenOptions.layer string
@exportObjectLiteralProperty ol.source.StamenOptions.minZoom number|undefined
@@ -150,6 +155,39 @@
@exportObjectLiteralProperty ol.source.TiledWMSOptions.url string|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.urls Array.<string>|undefined
+@exportObjectLiteral ol.style.IconOptions
+@exportObjectLiteralProperty ol.style.IconOptions.url string|ol.Expression
+@exportObjectLiteralProperty ol.style.IconOptions.width number|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.IconOptions.height number|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.IconOptions.opacity number|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.IconOptions.rotation number|ol.Expression|undefined
+
+@exportObjectLiteral ol.style.LineOptions
+@exportObjectLiteralProperty ol.style.LineOptions.strokeColor string|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.LineOptions.strokeWidth number|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.LineOptions.opacity number|ol.Expression|undefined
+
+@exportObjectLiteral ol.style.PolygonOptions
+@exportObjectLiteralProperty ol.style.PolygonOptions.fillColor string|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.PolygonOptions.strokeColor string|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.PolygonOptions.strokeWidth number|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.PolygonOptions.opacity number|ol.Expression|undefined
+
+@exportObjectLiteral ol.style.RuleOptions
+@exportObjectLiteralProperty ol.style.RuleOptions.filter ol.filter.Filter|undefined
+@exportObjectLiteralProperty ol.style.RuleOptions.symbolizers Array.<ol.style.Symbolizer>|undefined
+
+@exportObjectLiteral ol.style.ShapeOptions
+@exportObjectLiteralProperty ol.style.ShapeOptions.type ol.style.ShapeType|undefined
+@exportObjectLiteralProperty ol.style.ShapeOptions.size number|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.ShapeOptions.fillColor string|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.ShapeOptions.strokeColor string|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.ShapeOptions.strokeWidth number|ol.Expression|undefined
+@exportObjectLiteralProperty ol.style.ShapeOptions.opacity number|ol.Expression|undefined
+
+@exportObjectLiteral ol.style.StyleOptions
+@exportObjectLiteralProperty ol.style.StyleOptions.rules Array.<ol.style.Rule>
+
@exportObjectLiteral ol.source.WMTSOptions
@exportObjectLiteralProperty ol.source.WMTSOptions.attributions Array.<ol.Attribution>|undefined
@exportObjectLiteralProperty ol.source.WMTSOptions.crossOrigin string|null|undefined
View
70 src/ol/expression.js
@@ -0,0 +1,70 @@
+goog.provide('ol.Expression');
+goog.provide('ol.ExpressionLiteral');
+
+
+
+/**
+ * @constructor
+ * @param {string} source Expression to be evaluated.
+ */
+ol.Expression = function(source) {
+
+ /**
+ * @type {string}
+ * @private
+ */
+ this.source_ = source;
+
+};
+
+
+/**
+ * Evaluate the expression and return the result.
+ *
+ * @param {Object=} opt_thisArg Object to use as this when evaluating the
+ * expression. If not provided, the global object will be used.
+ * @param {Object=} opt_scope Evaluation scope. All properties of this object
+ * will be available as variables when evaluating the expression. If not
+ * provided, the global object will be used.
+ * @return {*} Result of the expression.
+ */
+ol.Expression.prototype.evaluate = function(opt_thisArg, opt_scope) {
+ var thisArg = goog.isDef(opt_thisArg) ? opt_thisArg : goog.global,
+ scope = goog.isDef(opt_scope) ? opt_scope : goog.global,
+ names = [],
+ values = [];
+
+ for (var name in scope) {
+ names.push(name);
+ values.push(scope[name]);
+ }
+
+ var evaluator = new Function(names.join(','), 'return ' + this.source_);
+ return evaluator.apply(thisArg, values);
+};
+
+
+
+/**
+ * @constructor
+ * @extends {ol.Expression}
+ * @param {*} value Literal value.
+ */
+ol.ExpressionLiteral = function(value) {
+
+ /**
+ * @type {*}
+ * @private
+ */
+ this.value_ = value;
+
+};
+goog.inherits(ol.ExpressionLiteral, ol.Expression);
+
+
+/**
+ * @inheritDoc
+ */
+ol.ExpressionLiteral.prototype.evaluate = function(opt_thisArg, opt_scope) {
+ return this.value_;
+};
View
7 src/ol/feature.exports
@@ -0,0 +1,7 @@
+@exportSymbol ol.Feature
+@exportProperty ol.Feature.prototype.get
+@exportProperty ol.Feature.prototype.getAttributes
+@exportProperty ol.Feature.prototype.getGeometry
+@exportProperty ol.Feature.prototype.set
+@exportProperty ol.Feature.prototype.setGeometry
+@exportProperty ol.Feature.prototype.setSymbolizers
View
112 src/ol/feature.js
@@ -0,0 +1,112 @@
+goog.provide('ol.Feature');
+
+goog.require('ol.Object');
+goog.require('ol.geom.Geometry');
+
+
+
+/**
+ * @constructor
+ * @extends {ol.Object}
+ * @param {Object=} opt_values Attributes.
+ */
+ol.Feature = function(opt_values) {
+
+ goog.base(this, opt_values);
+
+ /**
+ * @type {string|undefined}
+ * @private
+ */
+ this.geometryName_;
+
+ /**
+ * @type {Array.<ol.style.Symbolizer>}
+ * @private
+ */
+ this.symbolizers_ = null;
+
+};
+goog.inherits(ol.Feature, ol.Object);
+
+
+/**
+ * @return {Object} Attributes object.
+ */
+ol.Feature.prototype.getAttributes = function() {
+ var keys = this.getKeys(),
+ len = keys.length,
+ attributes = {},
+ i, key;
+ for (i = 0; i < len; ++ i) {
+ key = keys[i];
+ attributes[key] = this.get(key);
+ }
+ return attributes;
+};
+
+
+/**
+ * @return {ol.geom.Geometry} The geometry (or null if none).
+ */
+ol.Feature.prototype.getGeometry = function() {
+ return goog.isDef(this.geometryName_) ?
+ /** @type {ol.geom.Geometry} */ (this.get(this.geometryName_)) :
+ null;
+};
+
+
+/**
+ * @return {Array.<ol.style.SymbolizerLiteral>} Symbolizer literals.
+ */
+ol.Feature.prototype.getSymbolizerLiterals = function() {
+ var symbolizerLiterals = null;
+ if (!goog.isNull(this.symbolizers_)) {
+ var numSymbolizers = this.symbolizers_.length;
+ symbolizerLiterals = new Array(numSymbolizers);
+ for (var i = 0; i < numSymbolizers; ++i) {
+ symbolizerLiterals[i] = this.symbolizers_[i].createLiteral(this);
+ }
+ }
+ return symbolizerLiterals;
+};
+
+
+/**
+ * @inheritDoc
+ * @param {string} key Key.
+ * @param {*} value Value.
+ */
+ol.Feature.prototype.set = function(key, value) {
+ if (!goog.isDef(this.geometryName_) && (value instanceof ol.geom.Geometry)) {
+ this.geometryName_ = key;
+ }
+ goog.base(this, 'set', key, value);
+};
+
+
+/**
+ * @param {ol.geom.Geometry} geometry The geometry.
+ */
+ol.Feature.prototype.setGeometry = function(geometry) {
+ if (!goog.isDef(this.geometryName_)) {
+ this.geometryName_ = ol.Feature.DEFAULT_GEOMETRY;
+ }
+ this.set(this.geometryName_, geometry);
+};
+
+
+/**
+ * @param {Array.<ol.style.Symbolizer>} symbolizers Symbolizers for this
+ * features. If set, these take precedence over layer style.
+ */
+ol.Feature.prototype.setSymbolizers = function(symbolizers) {
+ this.symbolizers_ = symbolizers;
+};
+
+
+/**
+ * @const
+ * @type {string}
+ */
+ol.Feature.DEFAULT_GEOMETRY = 'geometry';
View
39 src/ol/filter/extentfilter.js
@@ -0,0 +1,39 @@
+goog.provide('ol.filter.Extent');
+
+goog.require('ol.Extent');
+goog.require('ol.filter.Filter');
+
+
+
+/**
+ * @constructor
+ * @extends {ol.filter.Filter}
+ * @param {ol.Extent} extent The extent.
+ */
+ol.filter.Extent = function(extent) {
+ goog.base(this);
+
+ /**
+ * @type {ol.Extent}
+ * @private
+ */
+ this.extent_ = extent;
+
+};
+goog.inherits(ol.filter.Extent, ol.filter.Filter);
+
+
+/**
+ * @return {ol.Extent} The filter extent.
+ */
+ol.filter.Extent.prototype.getExtent = function() {
+ return this.extent_;
+};
+
+
+/**
+ * @inheritDoc
+ */
+ol.filter.Extent.prototype.applies = function(feature) {
+ return feature.getGeometry().getBounds().intersects(this.extent_);
+};
View
7 src/ol/filter/filter.exports
@@ -0,0 +1,7 @@
+@exportSymbol ol.filter.Filter
+@exportSymbol ol.filter.Geometry
+@exportSymbol ol.filter.Logical
+
+@exportSymbol ol.filter.LogicalOperator
+@exportProperty ol.filter.LogicalOperator.AND
+@exportProperty ol.filter.LogicalOperator.OR
View
24 src/ol/filter/filter.js
@@ -0,0 +1,24 @@
+goog.provide('ol.filter.Filter');
+
+goog.require('ol.Feature');
+
+
+
+/**
+ * @constructor
+ * @param {function(this:ol.filter.Filter, ol.Feature)=} opt_filterFunction
+ * Filter function. Should return true if the passed feature passes the
+ * filter, false otherwise.
+ */
+ol.filter.Filter = function(opt_filterFunction) {
+ if (goog.isDef(opt_filterFunction)) {
+ this.applies = opt_filterFunction;
+ }
+};
+
+
+/**
+ * @param {ol.Feature} feature Feature to evaluate the filter against.
+ * @return {boolean} The provided feature passes this filter.
+ */
+ol.filter.Filter.prototype.applies = goog.abstractMethod;
View
42 src/ol/filter/geometryfilter.js
@@ -0,0 +1,42 @@
+goog.provide('ol.filter.Geometry');
+goog.provide('ol.filter.GeometryType');
+
+goog.require('ol.filter.Filter');
+goog.require('ol.geom.GeometryType');
+
+
+
+/**
+ * @constructor
+ * @extends {ol.filter.Filter}
+ * @param {ol.geom.GeometryType} type The geometry type.
+ */
+ol.filter.Geometry = function(type) {
+ goog.base(this);
+
+ /**
+ * @type {ol.geom.GeometryType}
+ * @private
+ */
+ this.type_ = type;
+
+};
+goog.inherits(ol.filter.Geometry, ol.filter.Filter);
+
+
+/**
+ * @inheritDoc
+ */
+ol.filter.Geometry.prototype.applies = function(feature) {
+ var geometry = feature.getGeometry();
+ return goog.isNull(geometry) ? false : geometry.getType() === this.type_;
+};
+
+
+/**
+ * @return {ol.geom.GeometryType} The geometry type.
+ */
+ol.filter.Geometry.prototype.getType = function() {
+ return this.type_;
+};
+
View
63 src/ol/filter/logicalfilter.js
@@ -0,0 +1,63 @@
+goog.provide('ol.filter.Logical');
+goog.provide('ol.filter.LogicalOperator');
+
+goog.require('ol.filter.Filter');
+
+
+
+/**
+ * @constructor
+ * @extends {ol.filter.Filter}
+ * @param {Array.<ol.filter.Filter>} filters Filters to and-combine.
+ * @param {!ol.filter.LogicalOperator} operator Operator.
+ */
+ol.filter.Logical = function(filters, operator) {
+ goog.base(this);
+
+ /**
+ * @type {Array.<ol.filter.Filter>}
+ * @private
+ */
+ this.filters_ = filters;
+
+ /**
+ * @type {!ol.filter.LogicalOperator}
+ */
+ this.operator = operator;
+
+};
+goog.inherits(ol.filter.Logical, ol.filter.Filter);
+
+
+/**
+ * @inheritDoc
+ */
+ol.filter.Logical.prototype.applies = function(feature) {
+ var filters = this.filters_,
+ i = 0, ii = filters.length,
+ operator = this.operator,
+ start = operator(true, false),
+ result = start;
+ while (result === start && i < ii) {
+ result = operator(result, filters[i].applies(feature));
+ ++i;
+ }
+ return result;
+};
+
+
+/**
+ * @return {Array.<ol.filter.Filter>} The filter's filters.
+ */
+ol.filter.Logical.prototype.getFilters = function() {
+ return this.filters_;
+};
+
+
+/**
+ * @enum {!Function}
+ */
+ol.filter.LogicalOperator = {
+ AND: /** @return {boolean} result. */ function(a, b) { return a && b; },
+ OR: /** @return {boolean} result. */ function(a, b) { return a || b; }
+};
View
79 src/ol/geom/abstractcollection.js
@@ -0,0 +1,79 @@
+goog.provide('ol.geom.AbstractCollection');
+
+goog.require('ol.Extent');
+goog.require('ol.geom.Geometry');
+
+
+
+/**
+ * A collection of geometries. This constructor is not to be used directly.
+ *
+ * @constructor
+ * @extends {ol.geom.Geometry}
+ */
+ol.geom.AbstractCollection = function() {
+ goog.base(this);
+
+ /**
+ * @type {number}
+ */
+ this.dimension;
+
+ /**
+ * @type {Array.<ol.geom.Geometry>}
+ */
+ this.components = null;
+
+ /**
+ * @type {ol.Extent}
+ * @protected
+ */
+ this.bounds = null;
+
+};
+goog.inherits(ol.geom.AbstractCollection, ol.geom.Geometry);
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.AbstractCollection.prototype.getBounds = function() {
+ if (goog.isNull(this.bounds)) {
+ var minX,
+ minY = minX = Number.POSITIVE_INFINITY,
+ maxX,
+ maxY = maxX = Number.NEGATIVE_INFINITY,
+ components = this.components,
+ len = components.length,
+ bounds, i;
+
+ for (i = 0; i < len; ++i) {
+ bounds = components[i].getBounds();
+ minX = Math.min(bounds.minX, minX);
+ minY = Math.min(bounds.minY, minY);
+ maxX = Math.max(bounds.maxX, maxX);
+ maxY = Math.max(bounds.maxY, maxY);
+ }
+ this.bounds = new ol.Extent(minX, minY, maxX, maxY);
+ }
+ return this.bounds;
+};
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.AbstractCollection.prototype.getCoordinates = function() {
+ var count = this.components.length;
+ var coordinates = new Array(count);
+ for (var i = 0; i < count; ++i) {
+ coordinates[i] = this.components[i].getCoordinates();
+ }
+ return coordinates;
+};
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.AbstractCollection.prototype.getType = goog.abstractMethod;
View
14 src/ol/geom/base.js
@@ -0,0 +1,14 @@
+goog.provide('ol.geom.Vertex');
+goog.provide('ol.geom.VertexArray');
+
+
+/**
+ * @typedef {Array.<number>}
+ */
+ol.geom.Vertex;
+
+
+/**
+ * @typedef {Array.<ol.geom.Vertex>}
+ */
+ol.geom.VertexArray;
View
1 src/ol/geom/expression.exports
@@ -0,0 +1 @@
+@exportSymbol ol.Expression
View
6 src/ol/geom/geometry.exports
@@ -0,0 +1,6 @@
+@exportSymbol ol.geom.Point
+@exportSymbol ol.geom.LineString
+@exportSymbol ol.geom.Polygon
+@exportSymbol ol.geom.MultiPoint
+@exportSymbol ol.geom.MultiLineString
+@exportSymbol ol.geom.MultiPolygon
View
71 src/ol/geom/geometry.js
@@ -0,0 +1,71 @@
+goog.provide('ol.geom.Geometry');
+goog.provide('ol.geom.GeometryType');
+
+goog.require('ol.Extent');
+goog.require('ol.geom.SharedVertices');
+
+
+
+/**
+ * @constructor
+ */
+ol.geom.Geometry = function() {
+
+ /**
+ * @type {ol.geom.SharedVertices}
+ * @protected
+ */
+ this.vertices = null;
+
+};
+
+
+/**
+ * The dimension of this geometry (2 or 3).
+ * @type {number}
+ */
+ol.geom.Geometry.prototype.dimension;
+
+
+/**
+ * Get the rectangular 2D envelope for this geoemtry.
+ * @return {ol.Extent} The bounding rectangular envelope.
+ */
+ol.geom.Geometry.prototype.getBounds = goog.abstractMethod;
+
+
+/**
+ * @return {Array} The GeoJSON style coordinates array for the geometry.
+ */
+ol.geom.Geometry.prototype.getCoordinates = goog.abstractMethod;
+
+
+/**
+ * Get the shared vertices for this geometry.
+ * @return {ol.geom.SharedVertices} The shared vertices.
+ */
+ol.geom.Geometry.prototype.getSharedVertices = function() {
+ return this.vertices;
+};
+
+
+/**
+ * Get the geometry type.
+ * @return {ol.geom.GeometryType} The geometry type.
+ */
+ol.geom.Geometry.prototype.getType = goog.abstractMethod;
+
+
+/**
+ * @enum {string}
+ */
+ol.geom.GeometryType = {
+ POINT: 'point',
+ LINESTRING: 'linestring',
+ LINEARRING: 'linearring',
+ POLYGON: 'polygon',
+ MULTIPOINT: 'multipoint',
+ MULTILINESTRING: 'multilinestring',
+ MULTIPOLYGON: 'multipolygon',
+ GEOMETRYCOLLECTION: 'geometrycollection'
+};
View
48 src/ol/geom/geometrycollection.js
@@ -0,0 +1,48 @@
+goog.provide('ol.geom.GeometryCollection');
+
+goog.require('ol.geom.AbstractCollection');
+goog.require('ol.geom.Geometry');
+goog.require('ol.geom.GeometryType');
+
+
+
+/**
+ * A mixed collection of geometries. Used one of the fixed type multi-part
+ * constructors for collections of the same type.
+ *
+ * @constructor
+ * @extends {ol.geom.AbstractCollection}
+ * @param {Array.<ol.geom.Geometry>} geometries Array of geometries.
+ */
+ol.geom.GeometryCollection = function(geometries) {
+ goog.base(this);
+
+ /**
+ * @type {Array.<ol.geom.Geometry>}
+ */
+ this.components = geometries;
+
+ var dimension = 0;
+ for (var i = 0, ii = geometries.length; i < ii; ++i) {
+ if (goog.isDef(dimension)) {
+ dimension = geometries[i].dimension;
+ } else {
+ goog.asserts.assert(dimension == geometries[i].dimension);
+ }
+ }
+
+ /**
+ * @type {number}
+ */
+ this.dimension = dimension;
+
+};
+goog.inherits(ol.geom.GeometryCollection, ol.geom.AbstractCollection);
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.GeometryCollection.prototype.getType = function() {
+ return ol.geom.GeometryType.GEOMETRYCOLLECTION;
+};
View
35 src/ol/geom/linearring.js
@@ -0,0 +1,35 @@
+goog.provide('ol.geom.LinearRing');
+
+goog.require('ol.geom.GeometryType');
+goog.require('ol.geom.LineString');
+goog.require('ol.geom.SharedVertices');
+goog.require('ol.geom.VertexArray');
+
+
+
+/**
+ * @constructor
+ * @extends {ol.geom.LineString}
+ * @param {ol.geom.VertexArray} coordinates Vertex array (e.g.
+ * [[x0, y0], [x1, y1]]).
+ * @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
+ */
+ol.geom.LinearRing = function(coordinates, opt_shared) {
+ goog.base(this, coordinates, opt_shared);
+
+ /**
+ * We're intentionally not enforcing that rings be closed right now. This
+ * will allow proper rendering of data from tiled vector sources that leave
+ * open rings.
+ */
+
+};
+goog.inherits(ol.geom.LinearRing, ol.geom.LineString);
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.LinearRing.prototype.getType = function() {
+ return ol.geom.GeometryType.LINEARRING;
+};
View
149 src/ol/geom/linestring.js
@@ -0,0 +1,149 @@
+goog.provide('ol.geom.LineString');
+
+goog.require('goog.asserts');
+goog.require('ol.Extent');
+goog.require('ol.geom.Geometry');
+goog.require('ol.geom.GeometryType');
+goog.require('ol.geom.SharedVertices');
+goog.require('ol.geom.VertexArray');
+
+
+
+/**
+ * @constructor
+ * @extends {ol.geom.Geometry}
+ * @param {ol.geom.VertexArray} coordinates Vertex array (e.g.
+ * [[x0, y0], [x1, y1]]).
+ * @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
+ */
+ol.geom.LineString = function(coordinates, opt_shared) {
+ goog.base(this);
+ goog.asserts.assert(goog.isArray(coordinates[0]));
+
+ var vertices = opt_shared,
+ dimension;
+
+ if (!goog.isDef(vertices)) {
+ dimension = coordinates[0].length;
+ vertices = new ol.geom.SharedVertices({dimension: dimension});
+ }
+
+ /**
+ * @type {ol.geom.SharedVertices}
+ */
+ this.vertices = vertices;
+
+ /**
+ * @type {number}
+ * @private
+ */
+ this.sharedId_ = vertices.add(coordinates);
+
+ /**
+ * @type {number}
+ */
+ this.dimension = vertices.getDimension();
+ goog.asserts.assert(this.dimension >= 2);
+
+ /**
+ * @type {ol.Extent}
+ * @private
+ */
+ this.bounds_ = null;
+
+};
+goog.inherits(ol.geom.LineString, ol.geom.Geometry);
+
+
+/**
+ * Get a vertex coordinate value for the given dimension.
+ * @param {number} index Vertex index.
+ * @param {number} dim Coordinate dimension.
+ * @return {number} The vertex coordinate value.
+ */
+ol.geom.LineString.prototype.get = function(index, dim) {
+ return this.vertices.get(this.sharedId_, index, dim);
+};
+
+
+/**
+ * @inheritDoc
+ * @return {ol.geom.VertexArray} Coordinates array.
+ */
+ol.geom.LineString.prototype.getCoordinates = function() {
+ var count = this.getCount();
+ var coordinates = new Array(count);
+ var vertex;
+ for (var i = 0; i < count; ++i) {
+ vertex = new Array(this.dimension);
+ for (var j = 0; j < this.dimension; ++j) {
+ vertex[j] = this.get(i, j);
+ }
+ coordinates[i] = vertex;
+ }
+ return coordinates;
+};
+
+
+/**
+ * Get the count of vertices in this linestring.
+ * @return {number} The vertex count.
+ */
+ol.geom.LineString.prototype.getCount = function() {
+ return this.vertices.getCount(this.sharedId_);
+};
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.LineString.prototype.getBounds = function() {
+ if (goog.isNull(this.bounds_)) {
+ var dimension = this.dimension,
+ vertices = this.vertices,
+ id = this.sharedId_,
+ count = vertices.getCount(id),
+ start = vertices.getStart(id),
+ end = start + (count * dimension),
+ coordinates = vertices.coordinates,
+ minX, maxX,
+ minY, maxY,
+ x, y, i;
+
+ minX = maxX = coordinates[start];
+ minY = maxY = coordinates[start + 1];
+ for (i = start + dimension; i < end; i += dimension) {
+ x = coordinates[i];
+ y = coordinates[i + 1];
+ if (x < minX) {
+ minX = x;
+ } else if (x > maxX) {
+ maxX = x;
+ }
+ if (y < minY) {
+ minY = y;
+ } else if (y > maxY) {
+ maxY = y;
+ }
+ }
+ this.bounds_ = new ol.Extent(minX, minY, maxX, maxY);
+ }
+ return this.bounds_;
+};
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.LineString.prototype.getType = function() {
+ return ol.geom.GeometryType.LINESTRING;
+};
+
+
+/**
+ * Get the identifier used to mark this line in the shared vertices structure.
+ * @return {number} The identifier.
+ */
+ol.geom.LineString.prototype.getSharedId = function() {
+ return this.sharedId_;
+};
View
72 src/ol/geom/multilinestring.js
@@ -0,0 +1,72 @@
+goog.provide('ol.geom.MultiLineString');
+
+goog.require('goog.asserts');
+goog.require('ol.geom.AbstractCollection');
+goog.require('ol.geom.GeometryType');
+goog.require('ol.geom.LineString');
+goog.require('ol.geom.SharedVertices');
+goog.require('ol.geom.VertexArray');
+
+
+
+/**
+ * @constructor
+ * @extends {ol.geom.AbstractCollection}
+ * @param {Array.<ol.geom.VertexArray>} coordinates Coordinates array.
+ * @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
+ */
+ol.geom.MultiLineString = function(coordinates, opt_shared) {
+ goog.base(this);
+ goog.asserts.assert(goog.isArray(coordinates[0][0]));
+
+ var vertices = opt_shared,
+ dimension;
+
+ if (!goog.isDef(vertices)) {
+ // try to get dimension from first vertex in first line
+ dimension = coordinates[0][0].length;
+ vertices = new ol.geom.SharedVertices({dimension: dimension});
+ }
+
+ var numParts = coordinates.length;
+
+ /**
+ * @type {Array.<ol.geom.LineString>}
+ */
+ this.components = new Array(numParts);
+ for (var i = 0; i < numParts; ++i) {
+ this.components[i] = new ol.geom.LineString(coordinates[i], vertices);
+ }
+
+ /**
+ * @type {number}
+ */
+ this.dimension = vertices.getDimension();
+
+};
+goog.inherits(ol.geom.MultiLineString, ol.geom.AbstractCollection);
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.MultiLineString.prototype.getType = function() {
+ return ol.geom.GeometryType.MULTILINESTRING;
+};
+
+
+/**
+ * Create a multi-linestring geometry from an array of linestring geometries.
+ *
+ * @param {Array.<ol.geom.LineString>} geometries Array of geometries.
+ * @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
+ * @return {ol.geom.MultiLineString} A new geometry.
+ */
+ol.geom.MultiLineString.fromParts = function(geometries, opt_shared) {
+ var count = geometries.length;
+ var coordinates = new Array(count);
+ for (var i = 0; i < count; ++i) {
+ coordinates[i] = geometries[i].getCoordinates();
+ }
+ return new ol.geom.MultiLineString(coordinates, opt_shared);
+};
View
77 src/ol/geom/multipoint.js
@@ -0,0 +1,77 @@
+goog.provide('ol.geom.MultiPoint');
+
+goog.require('goog.asserts');
+goog.require('ol.geom.AbstractCollection');
+goog.require('ol.geom.GeometryType');
+goog.require('ol.geom.Point');
+goog.require('ol.geom.SharedVertices');
+goog.require('ol.geom.VertexArray');
+
+
+
+/**
+ * @constructor
+ * @extends {ol.geom.AbstractCollection}
+ * @param {ol.geom.VertexArray} coordinates Coordinates array.
+ * @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
+ */
+ol.geom.MultiPoint = function(coordinates, opt_shared) {
+ goog.base(this);
+ goog.asserts.assert(goog.isArray(coordinates[0]));
+
+ var vertices = opt_shared,
+ dimension;
+
+ if (!goog.isDef(vertices)) {
+ // try to get dimension from first vertex
+ dimension = coordinates[0].length;
+ vertices = new ol.geom.SharedVertices({dimension: dimension});
+ }
+
+ /**
+ * @type {ol.geom.SharedVertices}
+ */
+ this.vertices = vertices;
+
+ var numParts = coordinates.length;
+
+ /**
+ * @type {Array.<ol.geom.Point>}
+ */
+ this.components = new Array(numParts);
+ for (var i = 0; i < numParts; ++i) {
+ this.components[i] = new ol.geom.Point(coordinates[i], vertices);
+ }
+
+ /**
+ * @type {number}
+ */
+ this.dimension = vertices.getDimension();
+
+};
+goog.inherits(ol.geom.MultiPoint, ol.geom.AbstractCollection);
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.MultiPoint.prototype.getType = function() {
+ return ol.geom.GeometryType.MULTIPOINT;
+};
+
+
+/**
+ * Create a multi-point geometry from an array of point geometries.
+ *
+ * @param {Array.<ol.geom.Point>} geometries Array of geometries.
+ * @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
+ * @return {ol.geom.MultiPoint} A new geometry.
+ */
+ol.geom.MultiPoint.fromParts = function(geometries, opt_shared) {
+ var count = geometries.length;
+ var coordinates = new Array(count);
+ for (var i = 0; i < count; ++i) {
+ coordinates[i] = geometries[i].getCoordinates();
+ }
+ return new ol.geom.MultiPoint(coordinates, opt_shared);
+};
View
73 src/ol/geom/multipolygon.js
@@ -0,0 +1,73 @@
+goog.provide('ol.geom.MultiPolygon');
+
+goog.require('goog.asserts');
+goog.require('ol.geom.AbstractCollection');
+goog.require('ol.geom.GeometryType');
+goog.require('ol.geom.Polygon');
+goog.require('ol.geom.SharedVertices');
+goog.require('ol.geom.VertexArray');
+
+
+
+/**
+ * @constructor
+ * @extends {ol.geom.AbstractCollection}
+ * @param {Array.<Array.<ol.geom.VertexArray>>} coordinates Coordinates
+ * array.
+ * @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
+ */
+ol.geom.MultiPolygon = function(coordinates, opt_shared) {
+ goog.base(this);
+ goog.asserts.assert(goog.isArray(coordinates[0][0][0]));
+
+ var vertices = opt_shared,
+ dimension;
+
+ if (!goog.isDef(vertices)) {
+ // try to get dimension from first vertex in first ring of the first poly
+ dimension = coordinates[0][0][0].length;
+ vertices = new ol.geom.SharedVertices({dimension: dimension});
+ }
+
+ var numParts = coordinates.length;
+
+ /**
+ * @type {Array.<ol.geom.Polygon>}
+ */
+ this.components = new Array(numParts);
+ for (var i = 0; i < numParts; ++i) {
+ this.components[i] = new ol.geom.Polygon(coordinates[i], vertices);
+ }
+
+ /**
+ * @type {number}
+ */
+ this.dimension = vertices.getDimension();
+
+};
+goog.inherits(ol.geom.MultiPolygon, ol.geom.AbstractCollection);
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.MultiPolygon.prototype.getType = function() {
+ return ol.geom.GeometryType.MULTIPOLYGON;
+};
+
+
+/**
+ * Create a multi-polygon geometry from an array of polygon geometries.
+ *
+ * @param {Array.<ol.geom.Polygon>} geometries Array of geometries.
+ * @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
+ * @return {ol.geom.MultiPolygon} A new geometry.
+ */
+ol.geom.MultiPolygon.fromParts = function(geometries, opt_shared) {
+ var count = geometries.length;
+ var coordinates = new Array(count);
+ for (var i = 0; i < count; ++i) {
+ coordinates[i] = geometries[i].getCoordinates();
+ }
+ return new ol.geom.MultiPolygon(coordinates, opt_shared);
+};
View
105 src/ol/geom/point.js
@@ -0,0 +1,105 @@
+goog.provide('ol.geom.Point');
+
+goog.require('goog.asserts');
+goog.require('ol.Extent');
+goog.require('ol.geom.Geometry');
+goog.require('ol.geom.GeometryType');
+goog.require('ol.geom.SharedVertices');
+goog.require('ol.geom.Vertex');
+
+
+
+/**
+ * @constructor
+ * @extends {ol.geom.Geometry}
+ * @param {ol.geom.Vertex} coordinates Coordinates array (e.g. [x, y]).
+ * @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
+ */
+ol.geom.Point = function(coordinates, opt_shared) {
+ goog.base(this);
+
+ var vertices = opt_shared,
+ dimension;
+
+ if (!goog.isDef(vertices)) {
+ dimension = coordinates.length;
+ vertices = new ol.geom.SharedVertices({dimension: dimension});
+ }
+
+ /**
+ * @type {ol.geom.SharedVertices}
+ */
+ this.vertices = vertices;
+
+ /**
+ * @type {number}
+ * @private
+ */
+ this.sharedId_ = vertices.add([coordinates]);
+
+ /**
+ * @type {number}
+ */
+ this.dimension = vertices.getDimension();
+ goog.asserts.assert(this.dimension >= 2);
+
+ /**
+ * @type {ol.Extent}
+ * @private
+ */
+ this.bounds_ = null;
+
+};
+goog.inherits(ol.geom.Point, ol.geom.Geometry);
+
+
+/**
+ * @param {number} dim Coordinate dimension.
+ * @return {number} The coordinate value.
+ */
+ol.geom.Point.prototype.get = function(dim) {
+ return this.vertices.get(this.sharedId_, 0, dim);
+};
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.Point.prototype.getBounds = function() {
+ if (goog.isNull(this.bounds_)) {
+ var x = this.get(0),
+ y = this.get(1);
+ this.bounds_ = new ol.Extent(x, y, x, y);
+ }
+ return this.bounds_;
+};
+
+
+/**
+ * @inheritDoc
+ * @return {ol.geom.Vertex} Coordinates array.
+ */
+ol.geom.Point.prototype.getCoordinates = function() {
+ var coordinates = new Array(this.dimension);
+ for (var i = 0; i < this.dimension; ++i) {
+ coordinates[i] = this.get(i);
+ }
+ return coordinates;
+};
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.Point.prototype.getType = function() {
+ return ol.geom.GeometryType.POINT;
+};
+
+
+/**
+ * Get the identifier used to mark this point in the shared vertices structure.
+ * @return {number} The identifier.
+ */
+ol.geom.Point.prototype.getSharedId = function() {
+ return this.sharedId_;
+};
View
90 src/ol/geom/polygon.js
@@ -0,0 +1,90 @@
+goog.provide('ol.geom.Polygon');
+
+goog.require('goog.asserts');
+goog.require('ol.Extent');
+goog.require('ol.geom.Geometry');
+goog.require('ol.geom.GeometryType');
+goog.require('ol.geom.LinearRing');
+goog.require('ol.geom.SharedVertices');
+goog.require('ol.geom.VertexArray');
+
+
+
+/**
+ * @constructor
+ * @extends {ol.geom.Geometry}
+ * @param {Array.<ol.geom.VertexArray>} coordinates Array of rings. First
+ * is outer, any remaining are inner.
+ * @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
+ */
+ol.geom.Polygon = function(coordinates, opt_shared) {
+ goog.base(this);
+ goog.asserts.assert(goog.isArray(coordinates[0][0]));
+
+ var vertices = opt_shared,
+ dimension;
+
+ if (!goog.isDef(vertices)) {
+ // try to get dimension from first vertex in first ring
+ dimension = coordinates[0][0].length;
+ vertices = new ol.geom.SharedVertices({dimension: dimension});
+ }
+
+ /**
+ * @type {ol.geom.SharedVertices}
+ */
+ this.vertices = vertices;
+
+ var numRings = coordinates.length;
+
+ /**
+ * @type {Array.<ol.geom.LinearRing>}
+ */
+ this.rings = new Array(numRings);
+ for (var i = 0; i < numRings; ++i) {
+ this.rings[i] = new ol.geom.LinearRing(coordinates[i], vertices);
+ }
+
+ /**
+ * @type {number}
+ */
+ this.dimension = vertices.getDimension();
+ goog.asserts.assert(this.dimension >= 2);
+
+ /**
+ * @type {ol.Extent}
+ * @private
+ */
+ this.bounds_ = null;
+
+};
+goog.inherits(ol.geom.Polygon, ol.geom.Geometry);
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.Polygon.prototype.getBounds = function() {
+ return this.rings[0].getBounds();
+};
+
+
+/**
+ * @return {Array.<ol.geom.VertexArray>} Coordinates array.
+ */
+ol.geom.Polygon.prototype.getCoordinates = function() {
+ var count = this.rings.length;
+ var coordinates = new Array(count);
+ for (var i = 0; i < count; ++i) {
+ coordinates[i] = this.rings[i].getCoordinates();
+ }
+ return coordinates;
+};
+
+
+/**
+ * @inheritDoc
+ */
+ol.geom.Polygon.prototype.getType = function() {
+ return ol.geom.GeometryType.POLYGON;
+};
View
163 src/ol/geom/sharedvertices.js
@@ -0,0 +1,163 @@
+goog.provide('ol.geom.SharedVertices');
+
+goog.require('goog.asserts');
+goog.require('ol.geom.Vertex');
+goog.require('ol.geom.VertexArray');
+
+
+/**
+ * @typedef {{dimension: (number),
+ * offset: (ol.geom.Vertex|undefined)}}
+ */
+ol.geom.SharedVerticesOptions;
+
+
+
+/**