Merge pull request #1358 from twpayne/vector-api-geometry-collection

[vector-api] Add ol.geom.GeometryCollection
This commit is contained in:
Tom Payne
2013-12-11 13:07:05 -08:00
28 changed files with 861 additions and 287 deletions

View File

@@ -1,13 +1,14 @@
// FIXME coordinate order
// FIXME reprojection
// FIXME GeometryCollection
goog.provide('ol.format.GeoJSON');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.object');
goog.require('ol.Feature');
goog.require('ol.format.JSON');
goog.require('ol.geom.GeometryCollection');
goog.require('ol.geom.LineString');
goog.require('ol.geom.MultiLineString');
goog.require('ol.geom.MultiPoint');
@@ -41,7 +42,7 @@ goog.inherits(ol.format.GeoJSON, ol.format.JSON);
/**
* @param {GeoJSONGeometry} object Object.
* @param {GeoJSONObject} object Object.
* @private
* @return {ol.geom.Geometry} Geometry.
*/
@@ -52,6 +53,19 @@ ol.format.GeoJSON.readGeometry_ = function(object) {
};
/**
* @param {GeoJSONGeometryCollection} object Object.
* @private
* @return {ol.geom.GeometryCollection} Geometry collection.
*/
ol.format.GeoJSON.readGeometryCollectionGeometry_ = function(object) {
goog.asserts.assert(object.type == 'GeometryCollection');
var geometries = goog.array.map(
object.geometries, ol.format.GeoJSON.readGeometry_);
return new ol.geom.GeometryCollection(geometries);
};
/**
* @param {GeoJSONGeometry} object Object.
* @private
@@ -121,7 +135,7 @@ ol.format.GeoJSON.readPolygonGeometry_ = function(object) {
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @private
* @return {GeoJSONGeometry} GeoJSON geometry.
* @return {GeoJSONObject} GeoJSON geometry.
*/
ol.format.GeoJSON.writeGeometry_ = function(geometry) {
var geometryWriter = ol.format.GeoJSON.GEOMETRY_WRITERS_[geometry.getType()];
@@ -130,6 +144,22 @@ ol.format.GeoJSON.writeGeometry_ = function(geometry) {
};
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @private
* @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
*/
ol.format.GeoJSON.writeGeometryCollectionGeometry_ = function(geometry) {
goog.asserts.assertInstanceof(geometry, ol.geom.GeometryCollection);
var geometries = goog.array.map(
geometry.getGeometriesArray(), ol.format.GeoJSON.writeGeometry_);
return /** @type {GeoJSONGeometryCollection} */ ({
'type': 'GeometryCollection',
'geometries': geometries
});
};
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @private
@@ -219,7 +249,7 @@ ol.format.GeoJSON.writePolygonGeometry_ = function(geometry) {
/**
* @const
* @private
* @type {Object.<string, function(GeoJSONGeometry): ol.geom.Geometry>}
* @type {Object.<string, function(GeoJSONObject): ol.geom.Geometry>}
*/
ol.format.GeoJSON.GEOMETRY_READERS_ = {
'Point': ol.format.GeoJSON.readPointGeometry_,
@@ -227,14 +257,15 @@ ol.format.GeoJSON.GEOMETRY_READERS_ = {
'Polygon': ol.format.GeoJSON.readPolygonGeometry_,
'MultiPoint': ol.format.GeoJSON.readMultiPointGeometry_,
'MultiLineString': ol.format.GeoJSON.readMultiLineStringGeometry_,
'MultiPolygon': ol.format.GeoJSON.readMultiPolygonGeometry_
'MultiPolygon': ol.format.GeoJSON.readMultiPolygonGeometry_,
'GeometryCollection': ol.format.GeoJSON.readGeometryCollectionGeometry_
};
/**
* @const
* @private
* @type {Object.<string, function(ol.geom.Geometry): GeoJSONGeometry>}
* @type {Object.<string, function(ol.geom.Geometry): GeoJSONObject>}
*/
ol.format.GeoJSON.GEOMETRY_WRITERS_ = {
'Point': ol.format.GeoJSON.writePointGeometry_,
@@ -242,7 +273,8 @@ ol.format.GeoJSON.GEOMETRY_WRITERS_ = {
'Polygon': ol.format.GeoJSON.writePolygonGeometry_,
'MultiPoint': ol.format.GeoJSON.writeMultiPointGeometry_,
'MultiLineString': ol.format.GeoJSON.writeMultiLineStringGeometry_,
'MultiPolygon': ol.format.GeoJSON.writeMultiPolygonGeometry_
'MultiPolygon': ol.format.GeoJSON.writeMultiPolygonGeometry_,
'GeometryCollection': ol.format.GeoJSON.writeGeometryCollectionGeometry_
};

View File

@@ -1,6 +1,3 @@
@exportSymbol ol.geom.Geometry
@exportProperty ol.geom.Geometry.prototype.getClosestPoint
@exportProperty ol.geom.Geometry.prototype.getExtent
@exportProperty ol.geom.Geometry.prototype.getLayout
@exportProperty ol.geom.Geometry.prototype.getSimplifiedGeometry
@exportProperty ol.geom.Geometry.prototype.transform
@exportProperty ol.geom.Geometry.prototype.getType

View File

@@ -1,14 +1,9 @@
// FIXME add GeometryCollection
goog.provide('ol.geom.Geometry');
goog.require('goog.asserts');
goog.require('goog.events.EventType');
goog.require('goog.functions');
goog.require('goog.object');
goog.require('ol.Observable');
goog.require('ol.extent');
goog.require('ol.geom.flat');
/**
@@ -21,7 +16,8 @@ ol.geom.GeometryType = {
POLYGON: 'Polygon',
MULTI_POINT: 'MultiPoint',
MULTI_LINE_STRING: 'MultiLineString',
MULTI_POLYGON: 'MultiPolygon'
MULTI_POLYGON: 'MultiPolygon',
GEOMETRY_COLLECTION: 'GeometryCollection'
};
@@ -45,24 +41,6 @@ ol.geom.Geometry = function() {
goog.base(this);
/**
* @protected
* @type {ol.geom.GeometryLayout}
*/
this.layout = ol.geom.GeometryLayout.XY;
/**
* @protected
* @type {number}
*/
this.stride = 2;
/**
* @protected
* @type {Array.<number>}
*/
this.flatCoordinates = null;
/**
* @protected
* @type {number}
@@ -82,27 +60,33 @@ ol.geom.Geometry = function() {
this.extentRevision = -1;
/**
* @private
* @protected
* @type {Object.<string, ol.geom.Geometry>}
*/
this.simplifiedGeometryCache_ = {};
this.simplifiedGeometryCache = {};
/**
* @private
* @protected
* @type {number}
*/
this.simplifiedGeometryMaxMinSquaredTolerance_ = 0;
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
/**
* @private
* @protected
* @type {number}
*/
this.simplifiedGeometryRevision_ = 0;
this.simplifiedGeometryRevision = 0;
};
goog.inherits(ol.geom.Geometry, ol.Observable);
/**
* @return {ol.geom.Geometry} Clone.
*/
ol.geom.Geometry.prototype.clone = goog.abstractMethod;
/**
* @param {number} x X.
* @param {number} y Y.
@@ -126,44 +110,6 @@ ol.geom.Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) {
};
/**
* @param {number} stride Stride.
* @private
* @return {ol.geom.GeometryLayout} layout Layout.
*/
ol.geom.Geometry.getLayoutForStride_ = function(stride) {
if (stride == 2) {
return ol.geom.GeometryLayout.XY;
} else if (stride == 3) {
return ol.geom.GeometryLayout.XYZ;
} else if (stride == 4) {
return ol.geom.GeometryLayout.XYZM;
} else {
throw new Error('unsupported stride: ' + stride);
}
};
/**
* @param {ol.geom.GeometryLayout} layout Layout.
* @private
* @return {number} Stride.
*/
ol.geom.Geometry.getStrideForLayout_ = function(layout) {
if (layout == ol.geom.GeometryLayout.XY) {
return 2;
} else if (layout == ol.geom.GeometryLayout.XYZ) {
return 3;
} else if (layout == ol.geom.GeometryLayout.XYM) {
return 3;
} else if (layout == ol.geom.GeometryLayout.XYZM) {
return 4;
} else {
throw new Error('unsupported layout: ' + layout);
}
};
/**
* @param {ol.Coordinate} coordinate Coordinate.
* @return {boolean} Contains coordinate.
@@ -194,31 +140,7 @@ ol.geom.Geometry.prototype.dispatchChangeEvent = function() {
* @param {ol.Extent=} opt_extent Extent.
* @return {ol.Extent} extent Extent.
*/
ol.geom.Geometry.prototype.getExtent = function(opt_extent) {
if (this.extentRevision != this.revision) {
this.extent = ol.extent.createOrUpdateFromFlatCoordinates(
this.flatCoordinates, this.stride, this.extent);
this.extentRevision = this.revision;
}
goog.asserts.assert(goog.isDef(this.extent));
return ol.extent.returnOrUpdate(this.extent, opt_extent);
};
/**
* @return {Array.<number>} Flat coordinates.
*/
ol.geom.Geometry.prototype.getFlatCoordinates = function() {
return this.flatCoordinates;
};
/**
* @return {ol.geom.GeometryLayout} Layout.
*/
ol.geom.Geometry.prototype.getLayout = function() {
return this.layout;
};
ol.geom.Geometry.prototype.getExtent = goog.abstractMethod;
/**
@@ -233,60 +155,7 @@ ol.geom.Geometry.prototype.getRevision = function() {
* @param {number} squaredTolerance Squared tolerance.
* @return {ol.geom.Geometry} Simplified geometry.
*/
ol.geom.Geometry.prototype.getSimplifiedGeometry = function(squaredTolerance) {
if (this.simplifiedGeometryRevision_ != this.revision) {
goog.object.clear(this.simplifiedGeometryCache_);
this.simplifiedGeometryMaxMinSquaredTolerance_ = 0;
this.simplifiedGeometryRevision_ = this.revision;
}
// If squaredTolerance is negative or if we know that simplification will not
// have any effect then just return this.
if (squaredTolerance < 0 ||
(this.simplifiedGeometryMaxMinSquaredTolerance_ !== 0 &&
squaredTolerance <= this.simplifiedGeometryMaxMinSquaredTolerance_)) {
return this;
}
var key = squaredTolerance.toString();
if (this.simplifiedGeometryCache_.hasOwnProperty(key)) {
return this.simplifiedGeometryCache_[key];
} else {
var simplifiedGeometry =
this.getSimplifiedGeometryInternal(squaredTolerance);
var simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
this.simplifiedGeometryCache_[key] = simplifiedGeometry;
return simplifiedGeometry;
} else {
// Simplification did not actually remove any coordinates. We now know
// that any calls to getSimplifiedGeometry with a squaredTolerance less
// than or equal to the current squaredTolerance will also not have any
// effect. This allows us to short circuit simplification (saving CPU
// cycles) and prevents the cache of simplified geometries from filling
// up with useless identical copies of this geometry (saving memory).
this.simplifiedGeometryMaxMinSquaredTolerance_ = squaredTolerance;
return this;
}
}
};
/**
* @param {number} squaredTolerance Squared tolerance.
* @return {ol.geom.Geometry} Simplified geometry.
* @protected
*/
ol.geom.Geometry.prototype.getSimplifiedGeometryInternal =
function(squaredTolerance) {
return this;
};
/**
* @return {number} Stride.
*/
ol.geom.Geometry.prototype.getStride = function() {
return this.stride;
};
ol.geom.Geometry.prototype.getSimplifiedGeometry = goog.abstractMethod;
/**
@@ -295,59 +164,10 @@ ol.geom.Geometry.prototype.getStride = function() {
ol.geom.Geometry.prototype.getType = goog.abstractMethod;
/**
* @param {ol.geom.GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @protected
*/
ol.geom.Geometry.prototype.setFlatCoordinatesInternal =
function(layout, flatCoordinates) {
this.stride = ol.geom.Geometry.getStrideForLayout_(layout);
this.layout = layout;
this.flatCoordinates = flatCoordinates;
};
/**
* @param {ol.geom.GeometryLayout|undefined} layout Layout.
* @param {Array} coordinates Coordinates.
* @param {number} nesting Nesting.
* @protected
*/
ol.geom.Geometry.prototype.setLayout =
function(layout, coordinates, nesting) {
/** @type {number} */
var stride;
if (goog.isDef(layout)) {
stride = ol.geom.Geometry.getStrideForLayout_(layout);
} else {
var i;
for (i = 0; i < nesting; ++i) {
if (coordinates.length === 0) {
this.layout = ol.geom.GeometryLayout.XY;
this.stride = 2;
return;
} else {
coordinates = /** @type {Array} */ (coordinates[0]);
}
}
stride = (/** @type {Array} */ (coordinates)).length;
layout = ol.geom.Geometry.getLayoutForStride_(stride);
}
this.layout = layout;
this.stride = stride;
};
/**
* @param {ol.TransformFunction} transformFn Transform.
*/
ol.geom.Geometry.prototype.transform = function(transformFn) {
if (!goog.isNull(this.flatCoordinates)) {
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
this.dispatchChangeEvent();
}
};
ol.geom.Geometry.prototype.transform = goog.abstractMethod;
/**
@@ -391,21 +211,3 @@ ol.geom.RawMultiLineString;
* @typedef {Array.<ol.geom.RawPolygon>}
*/
ol.geom.RawMultiPolygon;
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {goog.vec.Mat4.AnyType} transform Transform.
* @param {Array.<number>=} opt_dest Destination.
* @return {Array.<number>} Transformed flat coordinates.
*/
ol.geom.transformGeometry2D = function(geometry, transform, opt_dest) {
var flatCoordinates = geometry.getFlatCoordinates();
if (goog.isNull(flatCoordinates)) {
return null;
} else {
var stride = geometry.getStride();
return ol.geom.flat.transform2D(
flatCoordinates, stride, transform, opt_dest);
}
};

View File

@@ -0,0 +1,7 @@
@exportSymbol ol.geom.GeometryCollection
@exportProperty ol.geom.GeometryCollection.prototype.clone
@exportProperty ol.geom.GeometryCollection.prototype.getExtent
@exportProperty ol.geom.GeometryCollection.prototype.getGeometries
@exportProperty ol.geom.GeometryCollection.prototype.getSimplifiedGeometry
@exportProperty ol.geom.GeometryCollection.prototype.getType
@exportProperty ol.geom.GeometryCollection.prototype.setGeometries

View File

@@ -0,0 +1,204 @@
goog.provide('ol.geom.GeometryCollection');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.object');
goog.require('ol.extent');
goog.require('ol.geom.Geometry');
/**
* @constructor
* @extends {ol.geom.Geometry}
* @param {Array.<ol.geom.Geometry>=} opt_geometries Geometries.
*/
ol.geom.GeometryCollection = function(opt_geometries) {
goog.base(this);
/**
* @private
* @type {Array.<ol.geom.Geometry>}
*/
this.geometries_ = goog.isDef(opt_geometries) ? opt_geometries : null;
};
goog.inherits(ol.geom.GeometryCollection, ol.geom.Geometry);
/**
* @param {Array.<ol.geom.Geometry>} geometries Geometries.
* @private
* @return {Array.<ol.geom.Geometry>} Cloned geometries.
*/
ol.geom.GeometryCollection.cloneGeometries_ = function(geometries) {
var clonedGeometries = [];
var i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) {
clonedGeometries.push(geometries[i].clone());
}
return clonedGeometries;
};
/**
* @inheritDoc
*/
ol.geom.GeometryCollection.prototype.clone = function() {
var geometryCollection = new ol.geom.GeometryCollection(null);
geometryCollection.setGeometries(this.geometries_);
return geometryCollection;
};
/**
* @inheritDoc
*/
ol.geom.GeometryCollection.prototype.closestPointXY =
function(x, y, closestPoint, minSquaredDistance) {
if (minSquaredDistance <
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance;
}
var geometries = this.geometries_;
var i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) {
minSquaredDistance = geometries[i].closestPointXY(
x, y, closestPoint, minSquaredDistance);
}
return minSquaredDistance;
};
/**
* @inheritDoc
*/
ol.geom.GeometryCollection.prototype.containsXY = function(x, y) {
var geometries = this.geometries_;
var i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) {
if (geometries[i].containsXY(x, y)) {
return true;
}
}
return false;
};
/**
* @inheritDoc
*/
ol.geom.GeometryCollection.prototype.getExtent = function(opt_extent) {
if (this.extentRevision != this.revision) {
var extent = ol.extent.createOrUpdateEmpty(this.extent);
var geometries = this.geometries_;
var i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) {
ol.extent.extend(extent, geometries[i].getExtent());
}
this.extent = extent;
this.extentRevision = this.revision;
}
goog.asserts.assert(goog.isDef(this.extent));
return ol.extent.returnOrUpdate(this.extent, opt_extent);
};
/**
* @return {Array.<ol.geom.Geometry>} Geometries.
*/
ol.geom.GeometryCollection.prototype.getGeometries = function() {
return ol.geom.GeometryCollection.cloneGeometries_(this.geometries_);
};
/**
* @return {Array.<ol.geom.Geometry>} Geometries.
*/
ol.geom.GeometryCollection.prototype.getGeometriesArray = function() {
return this.geometries_;
};
/**
* @inheritDoc
*/
ol.geom.GeometryCollection.prototype.getSimplifiedGeometry =
function(squaredTolerance) {
if (this.simplifiedGeometryRevision != this.revision) {
goog.object.clear(this.simplifiedGeometryCache);
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
this.simplifiedGeometryRevision = this.revision;
}
if (squaredTolerance < 0 ||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
squaredTolerance < this.simplifiedGeometryMaxMinSquaredTolerance)) {
return this;
}
var key = squaredTolerance.toString();
if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
return this.simplifiedGeometryCache[key];
} else {
var simplifiedGeometries = [];
var geometries = this.geometries_;
var simplified = false;
var i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) {
var geometry = geometries[i];
var simplifiedGeometry = geometry.getSimplifiedGeometry(squaredTolerance);
simplifiedGeometries.push(simplifiedGeometry);
if (simplifiedGeometry !== geometry) {
simplified = true;
}
}
if (simplified) {
var simplifiedGeometryCollection = new ol.geom.GeometryCollection(null);
simplifiedGeometryCollection.setGeometriesArray(simplifiedGeometries);
this.simplifiedGeometryCache[key] = simplifiedGeometryCollection;
return simplifiedGeometryCollection;
} else {
this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
return this;
}
}
};
/**
* @inheritDoc
*/
ol.geom.GeometryCollection.prototype.getType = function() {
return ol.geom.GeometryType.GEOMETRY_COLLECTION;
};
/**
* @param {Array.<ol.geom.Geometry>} geometries Geometries.
*/
ol.geom.GeometryCollection.prototype.setGeometries = function(geometries) {
this.setGeometriesArray(
ol.geom.GeometryCollection.cloneGeometries_(geometries));
};
/**
* @param {Array.<ol.geom.Geometry>} geometries Geometries.
*/
ol.geom.GeometryCollection.prototype.setGeometriesArray = function(geometries) {
this.geometries_ = geometries;
this.dispatchChangeEvent();
};
/**
* @inheritDoc
*/
ol.geom.GeometryCollection.prototype.transform = function(transformFn) {
var geometries = this.geometries_;
var i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) {
geometries[i].transform(transformFn);
}
this.dispatchChangeEvent();
};

View File

@@ -1,4 +1,5 @@
@exportSymbol ol.geom.LinearRing
@exportProperty ol.geom.LinearRing.prototype.clone
@exportProperty ol.geom.LinearRing.prototype.getArea
@exportProperty ol.geom.LinearRing.prototype.getCoordinates
@exportProperty ol.geom.LinearRing.prototype.getType

View File

@@ -1,7 +1,7 @@
goog.provide('ol.geom.LinearRing');
goog.require('ol.extent');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.SimpleGeometry');
goog.require('ol.geom.closest');
goog.require('ol.geom.flat');
goog.require('ol.geom.simplify');
@@ -10,7 +10,7 @@ goog.require('ol.geom.simplify');
/**
* @constructor
* @extends {ol.geom.Geometry}
* @extends {ol.geom.SimpleGeometry}
* @param {ol.geom.RawLinearRing} coordinates Coordinates.
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
*/
@@ -33,7 +33,17 @@ ol.geom.LinearRing = function(coordinates, opt_layout) {
this.setCoordinates(coordinates, opt_layout);
};
goog.inherits(ol.geom.LinearRing, ol.geom.Geometry);
goog.inherits(ol.geom.LinearRing, ol.geom.SimpleGeometry);
/**
* @inheritDoc
*/
ol.geom.LinearRing.prototype.clone = function() {
var linearRing = new ol.geom.LinearRing(null);
linearRing.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
return linearRing;
};
/**

View File

@@ -1,4 +1,5 @@
@exportSymbol ol.geom.LineString
@exportProperty ol.geom.LineString.prototype.clone
@exportProperty ol.geom.LineString.prototype.getCoordinates
@exportProperty ol.geom.LineString.prototype.getType
@exportProperty ol.geom.LineString.prototype.setCoordinates

View File

@@ -1,7 +1,7 @@
goog.provide('ol.geom.LineString');
goog.require('ol.extent');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.SimpleGeometry');
goog.require('ol.geom.closest');
goog.require('ol.geom.flat');
goog.require('ol.geom.simplify');
@@ -10,7 +10,7 @@ goog.require('ol.geom.simplify');
/**
* @constructor
* @extends {ol.geom.Geometry}
* @extends {ol.geom.SimpleGeometry}
* @param {ol.geom.RawLineString} coordinates Coordinates.
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
*/
@@ -33,7 +33,17 @@ ol.geom.LineString = function(coordinates, opt_layout) {
this.setCoordinates(coordinates, opt_layout);
};
goog.inherits(ol.geom.LineString, ol.geom.Geometry);
goog.inherits(ol.geom.LineString, ol.geom.SimpleGeometry);
/**
* @inheritDoc
*/
ol.geom.LineString.prototype.clone = function() {
var lineString = new ol.geom.LineString(null);
lineString.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
return lineString;
};
/**

View File

@@ -1,4 +1,5 @@
@exportSymbol ol.geom.MultiLineString
@exportProperty ol.geom.MultiLineString.prototype.clone
@exportProperty ol.geom.MultiLineString.prototype.getCoordinates
@exportProperty ol.geom.MultiLineString.prototype.getLineStrings
@exportProperty ol.geom.MultiLineString.prototype.getType

View File

@@ -1,8 +1,8 @@
goog.provide('ol.geom.MultiLineString');
goog.require('ol.extent');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.LineString');
goog.require('ol.geom.SimpleGeometry');
goog.require('ol.geom.closest');
goog.require('ol.geom.flat');
goog.require('ol.geom.simplify');
@@ -11,7 +11,7 @@ goog.require('ol.geom.simplify');
/**
* @constructor
* @extends {ol.geom.Geometry}
* @extends {ol.geom.SimpleGeometry}
* @param {ol.geom.RawMultiLineString} coordinates Coordinates.
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
*/
@@ -40,7 +40,18 @@ ol.geom.MultiLineString = function(coordinates, opt_layout) {
this.setCoordinates(coordinates, opt_layout);
};
goog.inherits(ol.geom.MultiLineString, ol.geom.Geometry);
goog.inherits(ol.geom.MultiLineString, ol.geom.SimpleGeometry);
/**
* @inheritDoc
*/
ol.geom.MultiLineString.prototype.clone = function() {
var multiLineString = new ol.geom.MultiLineString(null);
multiLineString.setFlatCoordinates(
this.layout, this.flatCoordinates.slice(), this.ends_.slice());
return multiLineString;
};
/**

View File

@@ -1,4 +1,5 @@
@exportSymbol ol.geom.MultiPoint
@exportProperty ol.geom.MultiPoint.prototype.clone
@exportProperty ol.geom.MultiPoint.prototype.getCoordinates
@exportProperty ol.geom.MultiPoint.prototype.getPoints
@exportProperty ol.geom.MultiPoint.prototype.getType

View File

@@ -1,15 +1,15 @@
goog.provide('ol.geom.MultiPoint');
goog.require('ol.extent');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.Point');
goog.require('ol.geom.SimpleGeometry');
goog.require('ol.geom.flat');
/**
* @constructor
* @extends {ol.geom.Geometry}
* @extends {ol.geom.SimpleGeometry}
* @param {ol.geom.RawMultiPoint} coordinates Coordinates.
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
*/
@@ -17,7 +17,17 @@ ol.geom.MultiPoint = function(coordinates, opt_layout) {
goog.base(this);
this.setCoordinates(coordinates, opt_layout);
};
goog.inherits(ol.geom.MultiPoint, ol.geom.Geometry);
goog.inherits(ol.geom.MultiPoint, ol.geom.SimpleGeometry);
/**
* @inheritDoc
*/
ol.geom.MultiPoint.prototype.clone = function() {
var multiPoint = new ol.geom.MultiPoint(null);
multiPoint.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
return multiPoint;
};
/**

View File

@@ -1,4 +1,5 @@
@exportSymbol ol.geom.MultiPolygon
@exportProperty ol.geom.MultiPolygon.prototype.clone
@exportProperty ol.geom.MultiPolygon.prototype.getArea
@exportProperty ol.geom.MultiPolygon.prototype.getCoordinates
@exportProperty ol.geom.MultiPolygon.prototype.getPolygons

View File

@@ -1,8 +1,8 @@
goog.provide('ol.geom.MultiPolygon');
goog.require('ol.extent');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.Polygon');
goog.require('ol.geom.SimpleGeometry');
goog.require('ol.geom.closest');
goog.require('ol.geom.flat');
goog.require('ol.geom.simplify');
@@ -11,7 +11,7 @@ goog.require('ol.geom.simplify');
/**
* @constructor
* @extends {ol.geom.Geometry}
* @extends {ol.geom.SimpleGeometry}
* @param {ol.geom.RawMultiPolygon} coordinates Coordinates.
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
*/
@@ -52,7 +52,18 @@ ol.geom.MultiPolygon = function(coordinates, opt_layout) {
this.setCoordinates(coordinates, opt_layout);
};
goog.inherits(ol.geom.MultiPolygon, ol.geom.Geometry);
goog.inherits(ol.geom.MultiPolygon, ol.geom.SimpleGeometry);
/**
* @inheritDoc
*/
ol.geom.MultiPolygon.prototype.clone = function() {
var multiPolygon = new ol.geom.MultiPolygon(null);
multiPolygon.setFlatCoordinates(
this.layout, this.flatCoordinates.slice(), this.endss_.slice());
return multiPolygon;
};
/**

View File

@@ -1,4 +1,5 @@
@exportSymbol ol.geom.Point
@exportProperty ol.geom.Point.prototype.clone
@exportProperty ol.geom.Point.prototype.getCoordinates
@exportProperty ol.geom.Point.prototype.getType
@exportProperty ol.geom.Point.prototype.setCoordinates

View File

@@ -2,14 +2,14 @@ goog.provide('ol.geom.Point');
goog.require('goog.asserts');
goog.require('ol.extent');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.SimpleGeometry');
goog.require('ol.geom.flat');
/**
* @constructor
* @extends {ol.geom.Geometry}
* @extends {ol.geom.SimpleGeometry}
* @param {ol.geom.RawPoint} coordinates Coordinates.
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
*/
@@ -17,7 +17,17 @@ ol.geom.Point = function(coordinates, opt_layout) {
goog.base(this);
this.setCoordinates(coordinates, opt_layout);
};
goog.inherits(ol.geom.Point, ol.geom.Geometry);
goog.inherits(ol.geom.Point, ol.geom.SimpleGeometry);
/**
* @inheritDoc
*/
ol.geom.Point.prototype.clone = function() {
var point = new ol.geom.Point(null);
point.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
return point;
};
/**

View File

@@ -1,4 +1,5 @@
@exportSymbol ol.geom.Polygon
@exportProperty ol.geom.Polygon.prototype.clone
@exportProperty ol.geom.Polygon.prototype.getArea
@exportProperty ol.geom.Polygon.prototype.getCoordinates
@exportProperty ol.geom.Polygon.prototype.getLinearRings

View File

@@ -1,8 +1,8 @@
goog.provide('ol.geom.Polygon');
goog.require('ol.extent');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.LinearRing');
goog.require('ol.geom.SimpleGeometry');
goog.require('ol.geom.closest');
goog.require('ol.geom.flat');
goog.require('ol.geom.simplify');
@@ -11,7 +11,7 @@ goog.require('ol.geom.simplify');
/**
* @constructor
* @extends {ol.geom.Geometry}
* @extends {ol.geom.SimpleGeometry}
* @param {ol.geom.RawPolygon} coordinates Coordinates.
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
*/
@@ -52,7 +52,18 @@ ol.geom.Polygon = function(coordinates, opt_layout) {
this.setCoordinates(coordinates, opt_layout);
};
goog.inherits(ol.geom.Polygon, ol.geom.Geometry);
goog.inherits(ol.geom.Polygon, ol.geom.SimpleGeometry);
/**
* @inheritDoc
*/
ol.geom.Polygon.prototype.clone = function() {
var polygon = new ol.geom.Polygon(null);
polygon.setFlatCoordinates(
this.layout, this.flatCoordinates.slice(), this.ends_.slice());
return polygon;
};
/**

View File

@@ -0,0 +1,5 @@
@exportSymbol ol.geom.SimpleGeometry
@exportProperty ol.geom.SimpleGeometry.prototype.getExtent
@exportProperty ol.geom.SimpleGeometry.prototype.getLayout
@exportProperty ol.geom.SimpleGeometry.prototype.getSimplifiedGeometry
@exportProperty ol.geom.SimpleGeometry.prototype.transform

View File

@@ -0,0 +1,247 @@
goog.provide('ol.geom.SimpleGeometry');
goog.require('goog.asserts');
goog.require('goog.functions');
goog.require('goog.object');
goog.require('ol.extent');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.flat');
/**
* @constructor
* @extends {ol.geom.Geometry}
*/
ol.geom.SimpleGeometry = function() {
goog.base(this);
/**
* @protected
* @type {ol.geom.GeometryLayout}
*/
this.layout = ol.geom.GeometryLayout.XY;
/**
* @protected
* @type {number}
*/
this.stride = 2;
/**
* @protected
* @type {Array.<number>}
*/
this.flatCoordinates = null;
};
goog.inherits(ol.geom.SimpleGeometry, ol.geom.Geometry);
/**
* @param {number} stride Stride.
* @private
* @return {ol.geom.GeometryLayout} layout Layout.
*/
ol.geom.SimpleGeometry.getLayoutForStride_ = function(stride) {
if (stride == 2) {
return ol.geom.GeometryLayout.XY;
} else if (stride == 3) {
return ol.geom.GeometryLayout.XYZ;
} else if (stride == 4) {
return ol.geom.GeometryLayout.XYZM;
} else {
throw new Error('unsupported stride: ' + stride);
}
};
/**
* @param {ol.geom.GeometryLayout} layout Layout.
* @private
* @return {number} Stride.
*/
ol.geom.SimpleGeometry.getStrideForLayout_ = function(layout) {
if (layout == ol.geom.GeometryLayout.XY) {
return 2;
} else if (layout == ol.geom.GeometryLayout.XYZ) {
return 3;
} else if (layout == ol.geom.GeometryLayout.XYM) {
return 3;
} else if (layout == ol.geom.GeometryLayout.XYZM) {
return 4;
} else {
throw new Error('unsupported layout: ' + layout);
}
};
/**
* @inheritDoc
*/
ol.geom.SimpleGeometry.prototype.containsXY = goog.functions.FALSE;
/**
* @inheritDoc
*/
ol.geom.SimpleGeometry.prototype.getExtent = function(opt_extent) {
if (this.extentRevision != this.revision) {
this.extent = ol.extent.createOrUpdateFromFlatCoordinates(
this.flatCoordinates, this.stride, this.extent);
this.extentRevision = this.revision;
}
goog.asserts.assert(goog.isDef(this.extent));
return ol.extent.returnOrUpdate(this.extent, opt_extent);
};
/**
* @return {Array.<number>} Flat coordinates.
*/
ol.geom.SimpleGeometry.prototype.getFlatCoordinates = function() {
return this.flatCoordinates;
};
/**
* @return {ol.geom.GeometryLayout} Layout.
*/
ol.geom.SimpleGeometry.prototype.getLayout = function() {
return this.layout;
};
/**
* @inheritDoc
*/
ol.geom.SimpleGeometry.prototype.getSimplifiedGeometry =
function(squaredTolerance) {
if (this.simplifiedGeometryRevision != this.revision) {
goog.object.clear(this.simplifiedGeometryCache);
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
this.simplifiedGeometryRevision = this.revision;
}
// If squaredTolerance is negative or if we know that simplification will not
// have any effect then just return this.
if (squaredTolerance < 0 ||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
squaredTolerance <= this.simplifiedGeometryMaxMinSquaredTolerance)) {
return this;
}
var key = squaredTolerance.toString();
if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
return this.simplifiedGeometryCache[key];
} else {
var simplifiedGeometry =
this.getSimplifiedGeometryInternal(squaredTolerance);
var simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
this.simplifiedGeometryCache[key] = simplifiedGeometry;
return simplifiedGeometry;
} else {
// Simplification did not actually remove any coordinates. We now know
// that any calls to getSimplifiedGeometry with a squaredTolerance less
// than or equal to the current squaredTolerance will also not have any
// effect. This allows us to short circuit simplification (saving CPU
// cycles) and prevents the cache of simplified geometries from filling
// up with useless identical copies of this geometry (saving memory).
this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
return this;
}
}
};
/**
* @param {number} squaredTolerance Squared tolerance.
* @return {ol.geom.SimpleGeometry} Simplified geometry.
* @protected
*/
ol.geom.SimpleGeometry.prototype.getSimplifiedGeometryInternal =
function(squaredTolerance) {
return this;
};
/**
* @return {number} Stride.
*/
ol.geom.SimpleGeometry.prototype.getStride = function() {
return this.stride;
};
/**
* @param {ol.geom.GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @protected
*/
ol.geom.SimpleGeometry.prototype.setFlatCoordinatesInternal =
function(layout, flatCoordinates) {
this.stride = ol.geom.SimpleGeometry.getStrideForLayout_(layout);
this.layout = layout;
this.flatCoordinates = flatCoordinates;
};
/**
* @param {ol.geom.GeometryLayout|undefined} layout Layout.
* @param {Array} coordinates Coordinates.
* @param {number} nesting Nesting.
* @protected
*/
ol.geom.SimpleGeometry.prototype.setLayout =
function(layout, coordinates, nesting) {
/** @type {number} */
var stride;
if (goog.isDef(layout)) {
stride = ol.geom.SimpleGeometry.getStrideForLayout_(layout);
} else {
var i;
for (i = 0; i < nesting; ++i) {
if (coordinates.length === 0) {
this.layout = ol.geom.GeometryLayout.XY;
this.stride = 2;
return;
} else {
coordinates = /** @type {Array} */ (coordinates[0]);
}
}
stride = (/** @type {Array} */ (coordinates)).length;
layout = ol.geom.SimpleGeometry.getLayoutForStride_(stride);
}
this.layout = layout;
this.stride = stride;
};
/**
* @inheritDoc
*/
ol.geom.SimpleGeometry.prototype.transform = function(transformFn) {
if (!goog.isNull(this.flatCoordinates)) {
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
this.dispatchChangeEvent();
}
};
/**
* @param {ol.geom.SimpleGeometry} simpleGeometry Simple geometry.
* @param {goog.vec.Mat4.AnyType} transform Transform.
* @param {Array.<number>=} opt_dest Destination.
* @return {Array.<number>} Transformed flat coordinates.
*/
ol.geom.transformSimpleGeometry2D =
function(simpleGeometry, transform, opt_dest) {
var flatCoordinates = simpleGeometry.getFlatCoordinates();
if (goog.isNull(flatCoordinates)) {
return null;
} else {
var stride = simpleGeometry.getStride();
return ol.geom.flat.transform2D(
flatCoordinates, stride, transform, opt_dest);
}
};

View File

@@ -113,7 +113,7 @@ ol.render.canvas.Immediate.prototype.drawImages_ = function(geometry) {
goog.asserts.assert(goog.isDef(state.anchorY));
goog.asserts.assert(goog.isDef(state.height));
goog.asserts.assert(goog.isDef(state.width));
var pixelCoordinates = ol.geom.transformGeometry2D(
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
geometry, this.transform_, this.pixelCoordinates_);
var i, ii;
for (i = 0, ii = pixelCoordinates.length; i < ii; i += 2) {
@@ -144,7 +144,7 @@ ol.render.canvas.Immediate.prototype.drawText_ = function(geometry) {
return;
}
this.setFillStrokeStyles_();
var pixelCoordinates = ol.geom.transformGeometry2D(
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
geometry, this.transform_, this.pixelCoordinates_);
var i, ii;
for (i = 0, ii = pixelCoordinates.length; i < ii; i += 2) {
@@ -220,6 +220,23 @@ ol.render.canvas.Immediate.prototype.drawFeature = function(feature, style) {
};
/**
* @inheritDoc
*/
ol.render.canvas.Immediate.prototype.drawGeometryCollectionGeometry =
function(geometryCollectionGeometry, data) {
var geometries = geometryCollectionGeometry.getGeometriesArray();
var i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) {
var geometry = geometries[i];
var geometryRenderer =
ol.render.canvas.Immediate.GEOMETRY_RENDERES_[geometry.getType()];
goog.asserts.assert(goog.isDef(geometryRenderer));
geometryRenderer.call(this, geometry, data);
}
};
/**
* @inheritDoc
*/
@@ -251,7 +268,7 @@ ol.render.canvas.Immediate.prototype.drawLineStringGeometry =
}
this.setFillStrokeStyles_();
var context = this.context_;
var pixelCoordinates = ol.geom.transformGeometry2D(
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
lineStringGeometry, this.transform_, this.pixelCoordinates_);
context.beginPath();
this.moveToLineTo_(pixelCoordinates, 0, pixelCoordinates.length, false);
@@ -271,7 +288,7 @@ ol.render.canvas.Immediate.prototype.drawMultiLineStringGeometry =
}
this.setFillStrokeStyles_();
var context = this.context_;
var pixelCoordinates = ol.geom.transformGeometry2D(
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
multiLineStringGeometry, this.transform_, this.pixelCoordinates_);
context.beginPath();
var ends = multiLineStringGeometry.getEnds();
@@ -298,7 +315,7 @@ ol.render.canvas.Immediate.prototype.drawPolygonGeometry =
}
this.setFillStrokeStyles_();
var context = this.context_;
var pixelCoordinates = ol.geom.transformGeometry2D(
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
polygonGeometry, this.transform_, this.pixelCoordinates_);
var ends = polygonGeometry.getEnds();
context.beginPath();
@@ -327,7 +344,7 @@ ol.render.canvas.Immediate.prototype.drawMultiPolygonGeometry =
}
this.setFillStrokeStyles_();
var context = this.context_;
var pixelCoordinates = ol.geom.transformGeometry2D(
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
multiPolygonGeometry, this.transform_, this.pixelCoordinates_);
var endss = multiPolygonGeometry.getEndss();
var offset = 0;
@@ -478,5 +495,7 @@ ol.render.canvas.Immediate.GEOMETRY_RENDERES_ = {
'MultiPoint': ol.render.canvas.Immediate.prototype.drawMultiPointGeometry,
'MultiLineString':
ol.render.canvas.Immediate.prototype.drawMultiLineStringGeometry,
'MultiPolygon': ol.render.canvas.Immediate.prototype.drawMultiPolygonGeometry
'MultiPolygon': ol.render.canvas.Immediate.prototype.drawMultiPolygonGeometry,
'GeometryCollection':
ol.render.canvas.Immediate.prototype.drawGeometryCollectionGeometry
};

View File

@@ -330,6 +330,13 @@ ol.render.canvas.Replay.prototype.reverseHitDetectionInstructions_ =
ol.render.canvas.Replay.prototype.drawFeature = goog.abstractMethod;
/**
* @inheritDoc
*/
ol.render.canvas.Replay.prototype.drawGeometryCollectionGeometry =
goog.abstractMethod;
/**
* @inheritDoc
*/

View File

@@ -1,3 +1,5 @@
// FIXME remove trailing "Geometry" in method names
goog.provide('ol.render.IRender');
@@ -17,6 +19,16 @@ ol.render.IRender.prototype.drawFeature = function(feature, style) {
};
/**
* @param {ol.geom.GeometryCollection} geometryCollectionGeometry Geometry
* collection.
* @param {Object} data Opaque data object.
*/
ol.render.IRender.prototype.drawGeometryCollectionGeometry =
function(geometryCollectionGeometry, data) {
};
/**
* @param {ol.geom.Point} pointGeometry Point geometry.
* @param {Object} data Opaque data object.

View File

@@ -1,6 +1,7 @@
goog.provide('ol.renderer.vector');
goog.require('goog.asserts');
goog.require('ol.geom.GeometryCollection');
goog.require('ol.geom.LineString');
goog.require('ol.geom.MultiLineString');
goog.require('ol.geom.MultiPoint');
@@ -28,6 +29,29 @@ ol.renderer.vector.renderFeature = function(
};
/**
* @param {ol.render.IReplayGroup} replayGroup Replay group.
* @param {ol.geom.Geometry} geometry Geometry.
* @param {ol.style.Style} style Style.
* @param {Object} data Opaque data object.
* @private
*/
ol.renderer.vector.renderGeometryCollectionGeometry_ =
function(replayGroup, geometry, style, data) {
goog.asserts.assertInstanceof(geometry, ol.geom.GeometryCollection);
var geometryCollectionGeometry = /** @type {ol.geom.GeometryCollection} */ (
geometry);
var geometries = geometryCollectionGeometry.getGeometriesArray();
var i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) {
var geometryRenderer =
ol.renderer.vector.GEOMETRY_RENDERERS_[geometries[i].getType()];
goog.asserts.assert(goog.isDef(geometryRenderer));
geometryRenderer(replayGroup, geometries[i], style, data);
}
};
/**
* @param {ol.render.IReplayGroup} replayGroup Replay group.
* @param {ol.geom.Geometry} geometry Geometry.
@@ -167,5 +191,6 @@ ol.renderer.vector.GEOMETRY_RENDERERS_ = {
'Polygon': ol.renderer.vector.renderPolygonGeometry_,
'MultiPoint': ol.renderer.vector.renderMultiPointGeometry_,
'MultiLineString': ol.renderer.vector.renderMultiLineStringGeometry_,
'MultiPolygon': ol.renderer.vector.renderMultiPolygonGeometry_
'MultiPolygon': ol.renderer.vector.renderMultiPolygonGeometry_,
'GeometryCollection': ol.renderer.vector.renderGeometryCollectionGeometry_
};