Remove old ol.geom
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
@exportSymbol ol.geom.GeometryType
|
||||
@exportProperty ol.geom.GeometryType.POINT
|
||||
@exportProperty ol.geom.GeometryType.LINEAR_RING
|
||||
@exportProperty ol.geom.GeometryType.LINE_STRING
|
||||
@exportProperty ol.geom.GeometryType.POLYGON
|
||||
@exportProperty ol.geom.GeometryType.MULTI_POINT
|
||||
@exportProperty ol.geom.GeometryType.MULTI_LINE_STRING
|
||||
@exportProperty ol.geom.GeometryType.MULTI_POLYGON
|
||||
@exportProperty ol.geom.GeometryType.GEOMETRY_COLLECTION
|
||||
|
||||
@exportSymbol ol.geom.Geometry
|
||||
|
||||
@exportSymbol ol.geom.Point
|
||||
@exportProperty ol.geom.Point.prototype.getCoordinates
|
||||
|
||||
@exportSymbol ol.geom.LineString
|
||||
@exportProperty ol.geom.LineString.prototype.getCoordinates
|
||||
|
||||
@exportSymbol ol.geom.Polygon
|
||||
@exportProperty ol.geom.Polygon.prototype.getCoordinates
|
||||
|
||||
@exportSymbol ol.geom.MultiPoint
|
||||
@exportProperty ol.geom.MultiPoint.prototype.getCoordinates
|
||||
|
||||
@exportSymbol ol.geom.MultiLineString
|
||||
@exportProperty ol.geom.MultiLineString.prototype.getCoordinates
|
||||
|
||||
@exportSymbol ol.geom.MultiPolygon
|
||||
@exportProperty ol.geom.MultiPolygon.prototype.getCoordinates
|
||||
@@ -1,3 +0,0 @@
|
||||
/**
|
||||
* @namespace ol.geom
|
||||
*/
|
||||
@@ -1,96 +0,0 @@
|
||||
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 {Array.<ol.geom.Geometry>}
|
||||
* @protected
|
||||
*/
|
||||
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 bounds = ol.extent.createEmpty();
|
||||
var components = this.components;
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
ol.extent.extend(bounds, components[i].getBounds());
|
||||
}
|
||||
this.bounds = bounds;
|
||||
}
|
||||
return this.bounds;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<ol.geom.Geometry>} Components.
|
||||
*/
|
||||
ol.geom.AbstractCollection.prototype.getComponents = function() {
|
||||
return this.components;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
|
||||
/**
|
||||
* Listener for component change events.
|
||||
* @param {goog.events.Event} evt Change event.
|
||||
* @protected
|
||||
*/
|
||||
ol.geom.AbstractCollection.prototype.handleComponentChange = function(evt) {
|
||||
this.bounds = null;
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.AbstractCollection.prototype.transform = function(transform) {
|
||||
var components = this.components;
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
components[i].transform(transform);
|
||||
}
|
||||
this.bounds = null;
|
||||
};
|
||||
@@ -1,82 +0,0 @@
|
||||
goog.provide('ol.geom.Geometry');
|
||||
goog.provide('ol.geom.GeometryType');
|
||||
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Observable');
|
||||
goog.require('ol.TransformFunction');
|
||||
|
||||
|
||||
/**
|
||||
* Geometry types.
|
||||
*
|
||||
* @enum {string}
|
||||
* @todo stability stable
|
||||
*/
|
||||
ol.geom.GeometryType = {
|
||||
POINT: 'Point',
|
||||
LINE_STRING: 'LineString',
|
||||
LINEAR_RING: 'LinearRing',
|
||||
POLYGON: 'Polygon',
|
||||
MULTI_POINT: 'MultiPoint',
|
||||
MULTI_LINE_STRING: 'MultiLineString',
|
||||
MULTI_POLYGON: 'MultiPolygon',
|
||||
GEOMETRY_COLLECTION: 'GeometryCollection'
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Observable}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.Geometry = function() {
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.geom.Geometry, ol.Observable);
|
||||
|
||||
|
||||
/**
|
||||
* Create a clone of this geometry.
|
||||
* @return {ol.geom.Geometry} The cloned geometry.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.clone = function() {
|
||||
return new this.constructor(goog.object.unsafeClone(this.getCoordinates()));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 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 geometry type.
|
||||
* @return {ol.geom.GeometryType} The geometry type.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getType = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* Transform a geometry in place.
|
||||
* @param {ol.TransformFunction} transform Transform function.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.transform = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* Dispatch a generic event with type "change."
|
||||
*/
|
||||
ol.geom.Geometry.prototype.dispatchChangeEvent = function() {
|
||||
this.dispatchEvent(goog.events.EventType.CHANGE);
|
||||
};
|
||||
@@ -1,57 +0,0 @@
|
||||
goog.provide('ol.geom.GeometryCollection');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
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.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.GeometryCollection = function(geometries) {
|
||||
goog.base(this);
|
||||
|
||||
for (var i = geometries.length - 1; i >= 0; --i) {
|
||||
goog.events.listen(geometries[i], goog.events.EventType.CHANGE,
|
||||
this.handleComponentChange, false, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.geom.Geometry>}
|
||||
* @protected
|
||||
*/
|
||||
this.components = geometries;
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.GeometryCollection, ol.geom.AbstractCollection);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.GeometryCollection.prototype.clone = function() {
|
||||
var numComponents = this.components.length;
|
||||
var components = new Array(numComponents);
|
||||
for (var i = 0; i < numComponents; ++i) {
|
||||
components[i] = this.components[i].clone();
|
||||
}
|
||||
return new ol.geom.GeometryCollection(components);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.GeometryCollection.prototype.getType = function() {
|
||||
return ol.geom.GeometryType.GEOMETRYCOLLECTION;
|
||||
};
|
||||
@@ -1,100 +0,0 @@
|
||||
goog.provide('ol.geom.LinearRing');
|
||||
|
||||
goog.require('ol.CoordinateArray');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LineString');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.LineString}
|
||||
* @param {ol.CoordinateArray} coordinates Vertex array (e.g.
|
||||
* `[[x0, y0], [x1, y1]]`).
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.LinearRing = function(coordinates) {
|
||||
goog.base(this, coordinates);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a vertex array representing a linear ring is in clockwise
|
||||
* order.
|
||||
*
|
||||
* This method comes from Green's Theorem and was mentioned in an answer to a
|
||||
* a Stack Overflow question (http://tinyurl.com/clockwise-method).
|
||||
*
|
||||
* Note that calculating the cross product for each pair of edges could be
|
||||
* avoided by first finding the lowest, rightmost vertex. See OGR's
|
||||
* implementation for an example of this.
|
||||
* https://github.com/OSGeo/gdal/blob/trunk/gdal/ogr/ogrlinearring.cpp
|
||||
*
|
||||
* @param {ol.CoordinateArray} coordinates Linear ring coordinates.
|
||||
* @return {boolean} The coordinates are in clockwise order.
|
||||
*/
|
||||
ol.geom.LinearRing.isClockwise = function(coordinates) {
|
||||
var length = coordinates.length;
|
||||
var edge = 0;
|
||||
|
||||
var last = coordinates[length - 1];
|
||||
var x1 = last[0];
|
||||
var y1 = last[1];
|
||||
|
||||
var x2, y2, coord;
|
||||
for (var i = 0; i < length; ++i) {
|
||||
coord = coordinates[i];
|
||||
x2 = coord[0];
|
||||
y2 = coord[1];
|
||||
edge += (x2 - x1) * (y2 + y1);
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
return edge > 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.LinearRing.prototype.getType = function() {
|
||||
return ol.geom.GeometryType.LINEARRING;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check whether a given coordinate is inside this ring. Note that this is a
|
||||
* fast and simple check - points on an edge or vertex of the ring are either
|
||||
* classified inside or outside.
|
||||
*
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @return {boolean} Whether the coordinate is inside the ring.
|
||||
*/
|
||||
ol.geom.LinearRing.prototype.containsCoordinate = function(coordinate) {
|
||||
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||
var x = coordinate[0], y = coordinate[1];
|
||||
var vertices = this.getCoordinates();
|
||||
var inside = false;
|
||||
var xi, yi, xj, yj, intersect;
|
||||
var numVertices = vertices.length;
|
||||
for (var i = 0, j = numVertices - 1; i < numVertices; j = i++) {
|
||||
xi = vertices[i][0];
|
||||
yi = vertices[i][1];
|
||||
xj = vertices[j][0];
|
||||
yj = vertices[j][1];
|
||||
intersect = ((yi > y) != (yj > y)) &&
|
||||
(x < (xj - xi) * (y - yi) / (yj - yi) + xi);
|
||||
if (intersect) {
|
||||
inside = !inside;
|
||||
}
|
||||
}
|
||||
return inside;
|
||||
};
|
||||
@@ -1,134 +0,0 @@
|
||||
goog.provide('ol.geom.LineString');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.CoordinateArray');
|
||||
goog.require('ol.coordinate');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {ol.CoordinateArray} coordinates Array of coordinates (e.g.
|
||||
* `[[x0, y0], [x1, y1]]`).
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.LineString = function(coordinates) {
|
||||
goog.base(this);
|
||||
goog.asserts.assert(goog.isArray(coordinates[0]));
|
||||
|
||||
/**
|
||||
* Array of coordinates.
|
||||
* @type {ol.CoordinateArray}
|
||||
* @private
|
||||
*/
|
||||
this.coordinates_ = coordinates;
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
var coordinates = this.getCoordinates();
|
||||
goog.asserts.assert(coordinates.length > index);
|
||||
return coordinates[index][dim];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return {ol.CoordinateArray} Coordinates array.
|
||||
*/
|
||||
ol.geom.LineString.prototype.getCoordinates = function() {
|
||||
return this.coordinates_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the count of vertices in this linestring.
|
||||
* @return {number} The vertex count.
|
||||
*/
|
||||
ol.geom.LineString.prototype.getCount = function() {
|
||||
return this.getCoordinates().length;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.LineString.prototype.getBounds = function() {
|
||||
if (goog.isNull(this.bounds_)) {
|
||||
var coordinates = this.getCoordinates();
|
||||
var extent = ol.extent.createEmpty();
|
||||
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
ol.extent.extendCoordinate(extent, coordinates[i]);
|
||||
}
|
||||
this.bounds_ = extent;
|
||||
}
|
||||
return this.bounds_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.LineString.prototype.getType = function() {
|
||||
return ol.geom.GeometryType.LINE_STRING;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the distance from a coordinate to this linestring.
|
||||
*
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @return {number} Distance from the coordinate to this linestring.
|
||||
*/
|
||||
ol.geom.LineString.prototype.distanceFromCoordinate = function(coordinate) {
|
||||
var coordinates = this.getCoordinates();
|
||||
var dist2 = Infinity;
|
||||
for (var i = 0, j = 1, len = coordinates.length; j < len; i = j++) {
|
||||
dist2 = Math.min(dist2, ol.coordinate.squaredDistanceToSegment(coordinate,
|
||||
[coordinates[i], coordinates[j]]));
|
||||
}
|
||||
return Math.sqrt(dist2);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Update the linestring coordinates.
|
||||
* @param {ol.CoordinateArray} coordinates Coordinates array.
|
||||
*/
|
||||
ol.geom.LineString.prototype.setCoordinates = function(coordinates) {
|
||||
this.bounds_ = null;
|
||||
this.coordinates_ = coordinates;
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.LineString.prototype.transform = function(transform) {
|
||||
var coordinates = this.getCoordinates();
|
||||
var coord;
|
||||
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
coord = coordinates[i];
|
||||
transform(coord, coord, coord.length);
|
||||
}
|
||||
this.setCoordinates(coordinates); // for invalidating bounds
|
||||
};
|
||||
@@ -1,81 +0,0 @@
|
||||
goog.provide('ol.geom.MultiLineString');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.CoordinateArray');
|
||||
goog.require('ol.geom.AbstractCollection');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LineString');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.AbstractCollection}
|
||||
* @param {Array.<ol.CoordinateArray>} coordinates Coordinates array.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.MultiLineString = function(coordinates) {
|
||||
goog.base(this);
|
||||
goog.asserts.assert(goog.isArray(coordinates[0][0]));
|
||||
|
||||
var numParts = coordinates.length;
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.geom.LineString>}
|
||||
* @protected
|
||||
*/
|
||||
this.components = new Array(numParts);
|
||||
for (var i = 0; i < numParts; ++i) {
|
||||
var component = new ol.geom.LineString(coordinates[i]);
|
||||
this.components[i] = component;
|
||||
goog.events.listen(component, goog.events.EventType.CHANGE,
|
||||
this.handleComponentChange, false, this);
|
||||
}
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.MultiLineString, ol.geom.AbstractCollection);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.getType = function() {
|
||||
return ol.geom.GeometryType.MULTILINESTRING;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the distance from a coordinate to this multilinestring. This is
|
||||
* the closest distance of the coordinate to one of this multilinestring's
|
||||
* components.<
|
||||
*
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @return {number} Distance from the coordinate to this multilinestring.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.distanceFromCoordinate =
|
||||
function(coordinate) {
|
||||
var distance = Infinity;
|
||||
for (var i = 0, ii = this.components.length; i < ii; ++i) {
|
||||
distance = Math.min(distance,
|
||||
this.components[i].distanceFromCoordinate(coordinate));
|
||||
}
|
||||
return distance;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a multi-linestring geometry from an array of linestring geometries.
|
||||
*
|
||||
* @param {Array.<ol.geom.LineString>} geometries Array of geometries.
|
||||
* @return {ol.geom.MultiLineString} A new geometry.
|
||||
*/
|
||||
ol.geom.MultiLineString.fromParts = function(geometries) {
|
||||
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);
|
||||
};
|
||||
@@ -1,62 +0,0 @@
|
||||
goog.provide('ol.geom.MultiPoint');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.CoordinateArray');
|
||||
goog.require('ol.geom.AbstractCollection');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.Point');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.AbstractCollection}
|
||||
* @param {ol.CoordinateArray} coordinates Coordinates array.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.MultiPoint = function(coordinates) {
|
||||
goog.base(this);
|
||||
goog.asserts.assert(goog.isArray(coordinates[0]));
|
||||
|
||||
var numParts = coordinates.length;
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.geom.Point>}
|
||||
* @protected
|
||||
*/
|
||||
this.components = new Array(numParts);
|
||||
for (var i = 0; i < numParts; ++i) {
|
||||
var component = new ol.geom.Point(coordinates[i]);
|
||||
this.components[i] = component;
|
||||
goog.events.listen(component, goog.events.EventType.CHANGE,
|
||||
this.handleComponentChange, false, this);
|
||||
}
|
||||
|
||||
};
|
||||
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.
|
||||
* @return {ol.geom.MultiPoint} A new geometry.
|
||||
*/
|
||||
ol.geom.MultiPoint.fromParts = function(geometries) {
|
||||
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);
|
||||
};
|
||||
@@ -1,81 +0,0 @@
|
||||
goog.provide('ol.geom.MultiPolygon');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.CoordinateArray');
|
||||
goog.require('ol.geom.AbstractCollection');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.Polygon');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.AbstractCollection}
|
||||
* @param {Array.<Array.<ol.CoordinateArray>>} coordinates Coordinates
|
||||
* array.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.MultiPolygon = function(coordinates) {
|
||||
goog.base(this);
|
||||
goog.asserts.assert(goog.isArray(coordinates[0][0][0]));
|
||||
|
||||
var numParts = coordinates.length;
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.geom.Polygon>}
|
||||
* @protected
|
||||
*/
|
||||
this.components = new Array(numParts);
|
||||
for (var i = 0; i < numParts; ++i) {
|
||||
var component = new ol.geom.Polygon(coordinates[i]);
|
||||
this.components[i] = component;
|
||||
goog.events.listen(component, goog.events.EventType.CHANGE,
|
||||
this.handleComponentChange, false, this);
|
||||
}
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.MultiPolygon, ol.geom.AbstractCollection);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.getType = function() {
|
||||
return ol.geom.GeometryType.MULTIPOLYGON;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check whether a given coordinate is inside this multipolygon.
|
||||
*
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @return {boolean} Whether the coordinate is inside the multipolygon.
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.containsCoordinate = function(coordinate) {
|
||||
var containsCoordinate = false;
|
||||
for (var i = 0, ii = this.components.length; i < ii; ++i) {
|
||||
if (this.components[i].containsCoordinate(coordinate)) {
|
||||
containsCoordinate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return containsCoordinate;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a multi-polygon geometry from an array of polygon geometries.
|
||||
*
|
||||
* @param {Array.<ol.geom.Polygon>} geometries Array of geometries.
|
||||
* @return {ol.geom.MultiPolygon} A new geometry.
|
||||
*/
|
||||
ol.geom.MultiPolygon.fromParts = function(geometries) {
|
||||
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);
|
||||
};
|
||||
@@ -1,93 +0,0 @@
|
||||
goog.provide('ol.geom.Point');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {ol.Coordinate} coordinates Coordinate values (e.g. `[x, y]`).
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.Point = function(coordinates) {
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* Point coordinate values.
|
||||
* @type {ol.Coordinate}
|
||||
* @private
|
||||
*/
|
||||
this.coordinates_ = coordinates;
|
||||
|
||||
/**
|
||||
* @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.getCoordinates()[dim];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.Point.prototype.getBounds = function() {
|
||||
if (goog.isNull(this.bounds_)) {
|
||||
var x = this.get(0),
|
||||
y = this.get(1);
|
||||
this.bounds_ = [x, y, x, y];
|
||||
}
|
||||
return this.bounds_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return {ol.Coordinate} Coordinates array.
|
||||
*/
|
||||
ol.geom.Point.prototype.getCoordinates = function() {
|
||||
return this.coordinates_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.Point.prototype.getType = function() {
|
||||
return ol.geom.GeometryType.POINT;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Update the point coordinates.
|
||||
* @param {ol.Coordinate} coordinates Coordinates array.
|
||||
*/
|
||||
ol.geom.Point.prototype.setCoordinates = function(coordinates) {
|
||||
this.bounds_ = null;
|
||||
this.coordinates_ = coordinates;
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.Point.prototype.transform = function(transform) {
|
||||
var coordinates = this.getCoordinates();
|
||||
transform(coordinates, coordinates, coordinates.length);
|
||||
this.setCoordinates(coordinates); // for invalidating bounds
|
||||
};
|
||||
@@ -1,198 +0,0 @@
|
||||
goog.provide('ol.geom.Polygon');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.CoordinateArray');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a polygon from an array of vertex arrays. Coordinates for the
|
||||
* exterior ring will be forced to clockwise order. Coordinates for any
|
||||
* interior rings will be forced to counter-clockwise order. In cases where
|
||||
* the opposite winding order occurs in the passed vertex arrays, they will
|
||||
* be modified in place.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {Array.<ol.CoordinateArray>} coordinates Array of rings. First
|
||||
* is outer, any remaining are inner.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.Polygon = function(coordinates) {
|
||||
goog.base(this);
|
||||
goog.asserts.assert(goog.isArray(coordinates[0][0]));
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Coordinate}
|
||||
*/
|
||||
this.labelPoint_ = null;
|
||||
|
||||
var numRings = coordinates.length;
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.geom.LinearRing>}
|
||||
* @private
|
||||
*/
|
||||
this.rings_ = new Array(numRings);
|
||||
var ringCoords, ring;
|
||||
for (var i = 0; i < numRings; ++i) {
|
||||
ringCoords = coordinates[i];
|
||||
if (i === 0) {
|
||||
// force exterior ring to be clockwise
|
||||
if (!ol.geom.LinearRing.isClockwise(ringCoords)) {
|
||||
ringCoords.reverse();
|
||||
}
|
||||
} else {
|
||||
// force interior rings to be counter-clockwise
|
||||
if (ol.geom.LinearRing.isClockwise(ringCoords)) {
|
||||
ringCoords.reverse();
|
||||
}
|
||||
}
|
||||
ring = new ol.geom.LinearRing(ringCoords);
|
||||
goog.events.listen(ring, goog.events.EventType.CHANGE,
|
||||
this.handleRingChange_, false, this);
|
||||
this.rings_[i] = ring;
|
||||
}
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.Polygon, ol.geom.Geometry);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.Polygon.prototype.getBounds = function() {
|
||||
return this.rings_[0].getBounds();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<ol.CoordinateArray>} Coordinates array.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get polygon rings.
|
||||
* @return {Array.<ol.geom.LinearRing>} Array of rings. The first ring is the
|
||||
* exterior and any additional rings are interior.
|
||||
*/
|
||||
ol.geom.Polygon.prototype.getRings = function() {
|
||||
return this.rings_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Listener for ring change events.
|
||||
* @param {goog.events.Event} evt Change event.
|
||||
* @private
|
||||
*/
|
||||
ol.geom.Polygon.prototype.handleRingChange_ = function(evt) {
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check whether a given coordinate is inside this polygon. Note that this is a
|
||||
* fast and simple check - points on an edge or vertex of the polygon or one of
|
||||
* its inner rings are either classified inside or outside.
|
||||
*
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @return {boolean} Whether the coordinate is inside the polygon.
|
||||
*/
|
||||
ol.geom.Polygon.prototype.containsCoordinate = function(coordinate) {
|
||||
var rings = this.rings_;
|
||||
/** @type {boolean} */
|
||||
var containsCoordinate;
|
||||
for (var i = 0, ii = rings.length; i < ii; ++i) {
|
||||
containsCoordinate = rings[i].containsCoordinate(coordinate);
|
||||
// if inner ring (i > 0) contains coordinate, polygon does not contain it
|
||||
if (i > 0) {
|
||||
containsCoordinate = !containsCoordinate;
|
||||
}
|
||||
if (!containsCoordinate) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return containsCoordinate;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Calculates a point that is guaranteed to lie in the interior of the polygon.
|
||||
* Inspired by JTS's com.vividsolutions.jts.geom.Geometry#getInteriorPoint.
|
||||
* @return {ol.Coordinate} A point which is in the interior of the polygon.
|
||||
*/
|
||||
ol.geom.Polygon.prototype.getInteriorPoint = function() {
|
||||
if (goog.isNull(this.labelPoint_)) {
|
||||
var center = ol.extent.getCenter(this.getBounds()),
|
||||
resultY = center[1],
|
||||
vertices = this.rings_[0].getCoordinates(),
|
||||
intersections = [],
|
||||
maxLength = 0,
|
||||
i, vertex1, vertex2, x, segmentLength, resultX;
|
||||
|
||||
// Calculate intersections with the horizontal bounding box center line
|
||||
for (i = vertices.length - 1; i >= 1; --i) {
|
||||
vertex1 = vertices[i];
|
||||
vertex2 = vertices[i - 1];
|
||||
if ((vertex1[1] >= resultY && vertex2[1] <= resultY) ||
|
||||
(vertex1[1] <= resultY && vertex2[1] >= resultY)) {
|
||||
x = (resultY - vertex1[1]) / (vertex2[1] - vertex1[1]) *
|
||||
(vertex2[0] - vertex1[0]) + vertex1[0];
|
||||
intersections.push(x);
|
||||
}
|
||||
}
|
||||
|
||||
// Find the longest segment of the horizontal bounding box center line that
|
||||
// has its center point inside the polygon
|
||||
intersections.sort();
|
||||
for (i = intersections.length - 1; i >= 1; --i) {
|
||||
segmentLength = Math.abs(intersections[i] - intersections[i - 1]);
|
||||
if (segmentLength > maxLength) {
|
||||
x = (intersections[i] + intersections[i - 1]) / 2;
|
||||
if (this.containsCoordinate([x, resultY])) {
|
||||
maxLength = segmentLength;
|
||||
resultX = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.labelPoint_ = [resultX, resultY];
|
||||
}
|
||||
|
||||
return this.labelPoint_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.Polygon.prototype.transform = function(transform) {
|
||||
var rings = this.rings_;
|
||||
for (var i = 0, ii = rings.length; i < ii; ++i) {
|
||||
rings[i].transform(transform);
|
||||
}
|
||||
};
|
||||
@@ -1,31 +0,0 @@
|
||||
goog.provide('ol.test.geom.Geometry');
|
||||
|
||||
describe('ol.geom.Geometry', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new geometry', function() {
|
||||
var geom = new ol.geom.Geometry();
|
||||
expect(geom).to.be.a(ol.geom.Geometry);
|
||||
expect(geom).to.be.a(ol.Observable);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clone()', function() {
|
||||
it('clones a geometry', function() {
|
||||
var line = new ol.geom.LineString([[0, 0], [1, 1]]);
|
||||
var clone = line.clone();
|
||||
expect(clone.getCoordinates().length).to.be(2);
|
||||
expect(clone.getCoordinates()[0]).to.eql(line.getCoordinates()[0]);
|
||||
expect(clone.getCoordinates()[0]).to.not.be(line.getCoordinates()[0]);
|
||||
var coordinates = clone.getCoordinates();
|
||||
coordinates[0] = [2, 2];
|
||||
clone.setCoordinates(coordinates);
|
||||
expect(clone.getCoordinates()[0]).to.not.eql(line.getCoordinates()[0]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Observable');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LineString');
|
||||
@@ -1,78 +0,0 @@
|
||||
goog.provide('ol.test.geom.GeometryCollection');
|
||||
|
||||
describe('ol.geom.GeometryCollection', function() {
|
||||
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
|
||||
inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||
inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
|
||||
it('creates a geometry collection from an array of geometries', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||
expect(multi).to.be.a(ol.geom.GeometryCollection);
|
||||
expect(multi).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of geometries', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(3);
|
||||
expect(components[0]).to.be.a(ol.geom.Point);
|
||||
expect(components[1]).to.be.a(ol.geom.LineString);
|
||||
expect(components[2]).to.be.a(ol.geom.Polygon);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#clone()', function() {
|
||||
|
||||
it('has a working clone method', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||
var clone = multi.clone();
|
||||
expect(clone).to.not.be(multi);
|
||||
var components = clone.getComponents();
|
||||
expect(components[0].getCoordinates()).to.eql([10, 20]);
|
||||
expect(components[1].getCoordinates()).to.eql([[10, 20], [30, 40]]);
|
||||
expect(components[2].getCoordinates()).to.eql([outer, inner1, inner2]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var point = new ol.geom.Point([10, 2]);
|
||||
var line = new ol.geom.LineString([[1, 20], [30, 40]]);
|
||||
var multi = new ol.geom.GeometryCollection([point, line]);
|
||||
var bounds = multi.getBounds();
|
||||
expect(bounds[0]).to.be(1);
|
||||
expect(bounds[2]).to.be(30);
|
||||
expect(bounds[1]).to.be(2);
|
||||
expect(bounds[3]).to.be(40);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryCollection');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
@@ -1,125 +0,0 @@
|
||||
goog.provide('ol.test.geom.LinearRing');
|
||||
|
||||
describe('ol.geom.LinearRing', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a ring from an array', function() {
|
||||
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
|
||||
expect(ring).to.be.a(ol.geom.LinearRing);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates()', function() {
|
||||
|
||||
it('is an array', function() {
|
||||
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
|
||||
expect(ring.getCoordinates()).to.eql([[10, 20], [30, 40]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#containsCoordinate()', function() {
|
||||
|
||||
it('knows when a point coordinate is inside a ring', function() {
|
||||
/**
|
||||
* The ring:
|
||||
* edge 3
|
||||
* (5, 10) __________ (15, 10)
|
||||
* / /
|
||||
* edge 4 / / edge 2
|
||||
* / /
|
||||
* (0, 0) /_________/ (10, 0)
|
||||
* edge 1
|
||||
*/
|
||||
var ring = new ol.geom.LinearRing(
|
||||
[[0, 0], [10, 0], [15, 10], [5, 10]]);
|
||||
|
||||
// contains: 1 (touches - not implemented), true (within), false (outside)
|
||||
var cases = [{
|
||||
point: [5, 5], contains: true
|
||||
}, {
|
||||
point: [20, 20], contains: false
|
||||
}, {
|
||||
point: [15, 15], contains: false
|
||||
}/*, {
|
||||
point: [0, 0], contains: 1 // lower left corner
|
||||
}, {
|
||||
point: [10, 0], contains: 1 // lower right corner
|
||||
}, {
|
||||
point: [15, 10], contains: 1 // upper right corner
|
||||
}, {
|
||||
point: [5, 10], contains: 1 // upper left corner
|
||||
}, {
|
||||
point: [5, 0], contains: 1 // on edge 1
|
||||
}*/, {
|
||||
point: [5, -0.1], contains: false // below edge 1
|
||||
}, {
|
||||
point: [5, 0.1], contains: true // above edge 1
|
||||
}/*, {
|
||||
point: [12.5, 5], contains: 1 // on edge 2
|
||||
}*/, {
|
||||
point: [12.4, 5], contains: true // left of edge 2
|
||||
}, {
|
||||
point: [12.6, 5], contains: false // right of edge 2
|
||||
}/*, {
|
||||
point: [10, 10], contains: 1 // on edge 3
|
||||
}*/, {
|
||||
point: [10, 9.9], contains: true // below edge 3
|
||||
}, {
|
||||
point: [10, 10.1], contains: false // above edge 3
|
||||
}/*, {
|
||||
point: [2.5, 5], contains: 1 // on edge 4
|
||||
}*/, {
|
||||
point: [2.4, 5], contains: false // left of edge 4
|
||||
}, {
|
||||
point: [2.6, 5], contains: true // right of edge 4
|
||||
}];
|
||||
|
||||
var c;
|
||||
for (var i = 0, ii = cases.length; i < ii; ++i) {
|
||||
c = cases[i];
|
||||
expect(ring.containsCoordinate(c.point)).to.be(c.contains);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.geom.LinearRing.isClockwise()', function() {
|
||||
|
||||
var isClockwise = ol.geom.LinearRing.isClockwise;
|
||||
|
||||
it('returns true for clockwise coordinates', function() {
|
||||
var coordinates = [
|
||||
[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]
|
||||
];
|
||||
expect(isClockwise(coordinates)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false for counter-clockwise coordinates', function() {
|
||||
var coordinates = [
|
||||
[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]
|
||||
];
|
||||
expect(isClockwise(coordinates)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true for mostly clockwise, self-intersecting ring', function() {
|
||||
var coordinates = [
|
||||
[0, 0], [0, 1], [1.5, 1], [1.5, 1.5], [1, 1.5], [1, 0], [0, 0]
|
||||
];
|
||||
expect(isClockwise(coordinates)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false for mostly counter-clockwise, intersecting', function() {
|
||||
var coordinates = [
|
||||
[0, 0], [1, 0], [1, 1.5], [1.5, 1.5], [1.5, 1], [0, 1], [0, 0]
|
||||
];
|
||||
expect(isClockwise(coordinates)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.geom.LinearRing');
|
||||
@@ -1,101 +0,0 @@
|
||||
goog.provide('ol.test.geom.LineString');
|
||||
|
||||
describe('ol.geom.LineString', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a linestring from an array', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
expect(line).to.be.a(ol.geom.LineString);
|
||||
expect(line).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [20, 30], [30, 40]]);
|
||||
var bounds = line.getBounds();
|
||||
expect(bounds[0]).to.be(10);
|
||||
expect(bounds[2]).to.be(30);
|
||||
expect(bounds[1]).to.be(20);
|
||||
expect(bounds[3]).to.be(40);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
expect(line.getCoordinates()).to.eql([[10, 20], [30, 40]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setCoordinates()', function() {
|
||||
|
||||
it('updates the coordinates', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
line.setCoordinates([[30, 40], [50, 60]]);
|
||||
expect(line.getCoordinates()).to.eql([[30, 40], [50, 60]]);
|
||||
});
|
||||
|
||||
it('invalidates bounds', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
line.setCoordinates([[30, 40], [50, 60]]);
|
||||
expect(line.getBounds()).to.eql([30, 40, 50, 60]);
|
||||
});
|
||||
|
||||
it('triggers a change event', function(done) {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
expect(line.getBounds()).to.eql([10, 20, 30, 40]);
|
||||
goog.events.listen(line, 'change', function(evt) {
|
||||
expect(evt.target).to.equal(line);
|
||||
expect(evt.target.getBounds()).to.eql([30, 40, 50, 60]);
|
||||
expect(evt.target.getCoordinates()).to.eql([[30, 40], [50, 60]]);
|
||||
done();
|
||||
});
|
||||
line.setCoordinates([[30, 40], [50, 60]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#transform()', function() {
|
||||
|
||||
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||
var inverse = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
|
||||
|
||||
it('forward transforms a linestring in place', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [20, 30], [30, 40]]);
|
||||
line.transform(forward);
|
||||
expect(line.get(0, 0)).to.roughlyEqual(1113195, 1);
|
||||
expect(line.get(0, 1)).to.roughlyEqual(2273031, 1);
|
||||
expect(line.get(1, 0)).to.roughlyEqual(2226390, 1);
|
||||
expect(line.get(1, 1)).to.roughlyEqual(3503550, 1);
|
||||
expect(line.get(2, 0)).to.roughlyEqual(3339585, 1);
|
||||
expect(line.get(2, 1)).to.roughlyEqual(4865942, 1);
|
||||
});
|
||||
|
||||
it('inverse transforms a linestring in place', function() {
|
||||
var line = new ol.geom.LineString([
|
||||
[1113195, 2273031], [2226390, 3503550], [3339585, 4865942]
|
||||
]);
|
||||
line.transform(inverse);
|
||||
expect(line.get(0, 0)).to.roughlyEqual(10, 0.001);
|
||||
expect(line.get(0, 1)).to.roughlyEqual(20, 0.001);
|
||||
expect(line.get(1, 0)).to.roughlyEqual(20, 0.001);
|
||||
expect(line.get(1, 1)).to.roughlyEqual(30, 0.001);
|
||||
expect(line.get(2, 0)).to.roughlyEqual(30, 0.001);
|
||||
expect(line.get(2, 1)).to.roughlyEqual(40, 0.001);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.proj');
|
||||
@@ -1,65 +0,0 @@
|
||||
goog.provide('ol.test.geom.MultiLineString');
|
||||
|
||||
describe('ol.geom.MultiLineString', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a multi-linestring from an array', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
expect(multi).to.be.a(ol.geom.MultiLineString);
|
||||
expect(multi).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of linestrings', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(2);
|
||||
expect(components[0]).to.be.a(ol.geom.LineString);
|
||||
expect(components[1]).to.be.a(ol.geom.LineString);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
var bounds = multi.getBounds();
|
||||
expect(bounds[0]).to.be(10);
|
||||
expect(bounds[2]).to.be(40);
|
||||
expect(bounds[1]).to.be(20);
|
||||
expect(bounds[3]).to.be(50);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var coordinates = [
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]
|
||||
];
|
||||
var multi = new ol.geom.MultiLineString(coordinates);
|
||||
expect(multi.getCoordinates()).to.eql(coordinates);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
@@ -1,86 +0,0 @@
|
||||
goog.provide('ol.test.geom.MultiPoint');
|
||||
|
||||
describe('ol.geom.MultiPoint', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a multi-point from an array', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
expect(multi).to.be.a(ol.geom.MultiPoint);
|
||||
expect(multi).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of points', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(2);
|
||||
expect(components[0]).to.be.a(ol.geom.Point);
|
||||
expect(components[1]).to.be.a(ol.geom.Point);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
var bounds = multi.getBounds();
|
||||
expect(bounds[0]).to.be(10);
|
||||
expect(bounds[2]).to.be(30);
|
||||
expect(bounds[1]).to.be(20);
|
||||
expect(bounds[3]).to.be(40);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
expect(multi.getCoordinates()).to.eql([[10, 20], [30, 40]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#transform', function() {
|
||||
|
||||
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||
var inverse = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
|
||||
|
||||
it('forward transforms a multi-point', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
multi.transform(forward);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components[0].get(0)).to.roughlyEqual(1113195, 1);
|
||||
expect(components[0].get(1)).to.roughlyEqual(2273031, 1);
|
||||
expect(components[1].get(0)).to.roughlyEqual(3339584, 1);
|
||||
expect(components[1].get(1)).to.roughlyEqual(4865942, 1);
|
||||
});
|
||||
|
||||
it('inverse transforms a multi-point', function() {
|
||||
var multi = new ol.geom.MultiPoint(
|
||||
[[1113195, 2273031], [3339584, 4865942]]);
|
||||
multi.transform(inverse);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components[0].get(0)).to.roughlyEqual(10, 0.001);
|
||||
expect(components[0].get(1)).to.roughlyEqual(20, 0.001);
|
||||
expect(components[1].get(0)).to.roughlyEqual(30, 0.001);
|
||||
expect(components[1].get(1)).to.roughlyEqual(40, 0.001);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.proj');
|
||||
@@ -1,118 +0,0 @@
|
||||
goog.provide('ol.test.geom.MultiPolygon');
|
||||
|
||||
describe('ol.geom.MultiPolygon', function() {
|
||||
|
||||
var outer1 = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
|
||||
inner1a = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||
inner1b = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]],
|
||||
outer2 = [[10, 10], [20, 0], [20, 50], [10, 50], [10, 10]];
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a multi-linestring from an array', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
expect(multi).to.be.a(ol.geom.MultiPolygon);
|
||||
expect(multi).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
it('throws when given with insufficient dimensions', function() {
|
||||
expect(function() {
|
||||
var multi = new ol.geom.MultiPolygon([1]);
|
||||
multi = multi; // suppress gjslint warning about unused variable
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of polygons', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(2);
|
||||
expect(components[0]).to.be.a(ol.geom.Polygon);
|
||||
expect(components[1]).to.be.a(ol.geom.Polygon);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
var bounds = multi.getBounds();
|
||||
expect(bounds[0]).to.be(0);
|
||||
expect(bounds[2]).to.be(20);
|
||||
expect(bounds[1]).to.be(0);
|
||||
expect(bounds[3]).to.be(50);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var coordinates = [
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]
|
||||
];
|
||||
var multi = new ol.geom.MultiPolygon(coordinates);
|
||||
expect(multi.getCoordinates()).to.eql(coordinates);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('change event', function() {
|
||||
|
||||
var outer, inner;
|
||||
beforeEach(function() {
|
||||
outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
|
||||
inner = [[2, 2], [2, 8], [8, 8], [8, 2], [2, 2]];
|
||||
});
|
||||
|
||||
it('is fired when outer ring is modified', function(done) {
|
||||
var multi = new ol.geom.MultiPolygon([[outer, inner], [outer, inner]]);
|
||||
var components = multi.getComponents();
|
||||
goog.events.listen(multi, 'change', function(evt) {
|
||||
expect(evt.target).to.be(multi);
|
||||
expect(evt.target.getBounds()).to.eql([0, 0, 11, 10]);
|
||||
done();
|
||||
});
|
||||
|
||||
var outerOne = components[0].getRings()[0];
|
||||
var outerCoords = outerOne.getCoordinates();
|
||||
outerCoords[1][0] = 11;
|
||||
outerOne.setCoordinates(outerCoords);
|
||||
});
|
||||
|
||||
it('is fired when inner ring is modified', function(done) {
|
||||
var multi = new ol.geom.MultiPolygon([[outer, inner], [outer, inner]]);
|
||||
var components = multi.getComponents();
|
||||
goog.events.listen(multi, 'change', function(evt) {
|
||||
expect(evt.target).to.be(multi);
|
||||
expect(evt.target.getBounds()).to.eql([0, 0, 10, 10]);
|
||||
done();
|
||||
});
|
||||
|
||||
var innerTwo = components[1].getRings()[1];
|
||||
var innerCoords = innerTwo.getCoordinates();
|
||||
innerCoords[1][0] = 3;
|
||||
innerTwo.setCoordinates(innerCoords);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Polygon');
|
||||
@@ -1,91 +0,0 @@
|
||||
goog.provide('ol.test.geom.Point');
|
||||
|
||||
describe('ol.geom.Point', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a point from an array', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
expect(point).to.be.a(ol.geom.Point);
|
||||
expect(point).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
var bounds = point.getBounds();
|
||||
expect(bounds[0]).to.be(10);
|
||||
expect(bounds[2]).to.be(10);
|
||||
expect(bounds[1]).to.be(20);
|
||||
expect(bounds[3]).to.be(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates()', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
expect(point.getCoordinates()).to.eql([10, 20]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setCoordinates()', function() {
|
||||
|
||||
it('updates the coordinates', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
point.setCoordinates([30, 40]);
|
||||
expect(point.getCoordinates()).to.eql([30, 40]);
|
||||
});
|
||||
|
||||
it('invalidates bounds', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
point.setCoordinates([30, 40]);
|
||||
expect(point.getBounds()).to.eql([30, 40, 30, 40]);
|
||||
});
|
||||
|
||||
it('triggers a change event', function(done) {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
expect(point.getBounds()).to.eql([10, 20, 10, 20]);
|
||||
goog.events.listen(point, 'change', function(evt) {
|
||||
expect(evt.target).to.equal(point);
|
||||
expect(evt.target.getBounds()).to.eql([30, 40, 30, 40]);
|
||||
expect(evt.target.getCoordinates()).to.eql([30, 40]);
|
||||
done();
|
||||
});
|
||||
point.setCoordinates([30, 40]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#transform()', function() {
|
||||
|
||||
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||
var inverse = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
|
||||
|
||||
it('forward transforms a point in place', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
point.transform(forward);
|
||||
expect(point.get(0)).to.roughlyEqual(1113195, 1);
|
||||
expect(point.get(1)).to.roughlyEqual(2273031, 1);
|
||||
});
|
||||
|
||||
it('inverse transforms a point in place', function() {
|
||||
var point = new ol.geom.Point([1113195, 2273031]);
|
||||
point.transform(inverse);
|
||||
expect(point.get(0)).to.roughlyEqual(10, 0.001);
|
||||
expect(point.get(1)).to.roughlyEqual(20, 0.001);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.proj');
|
||||
@@ -1,179 +0,0 @@
|
||||
goog.provide('ol.test.geom.Polygon');
|
||||
|
||||
describe('ol.geom.Polygon', function() {
|
||||
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
|
||||
inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||
inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a polygon from an array', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
expect(poly).to.be.a(ol.geom.Polygon);
|
||||
expect(poly).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getRings()', function() {
|
||||
|
||||
it('returns an array of LinearRing', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var rings = poly.getRings();
|
||||
expect(rings.length).to.be(3);
|
||||
expect(rings[0]).to.be.a(ol.geom.LinearRing);
|
||||
expect(rings[1]).to.be.a(ol.geom.LinearRing);
|
||||
expect(rings[2]).to.be.a(ol.geom.LinearRing);
|
||||
});
|
||||
|
||||
var isClockwise = ol.geom.LinearRing.isClockwise;
|
||||
|
||||
it('forces exterior ring to be clockwise', function() {
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
|
||||
expect(isClockwise(outer)).to.be(false);
|
||||
|
||||
var poly = new ol.geom.Polygon([outer]);
|
||||
var ring = poly.getRings()[0];
|
||||
expect(isClockwise(ring.getCoordinates())).to.be(true);
|
||||
});
|
||||
|
||||
it('forces interior ring to be counter-clockwise', function() {
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
|
||||
var inner = [[2, 2], [2, 8], [8, 8], [8, 2], [2, 2]];
|
||||
expect(isClockwise(inner)).to.be(true);
|
||||
|
||||
var poly = new ol.geom.Polygon([outer, inner]);
|
||||
var ring = poly.getRings()[1];
|
||||
expect(isClockwise(ring.getCoordinates())).to.be(false);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var bounds = poly.getBounds();
|
||||
expect(bounds[0]).to.be(0);
|
||||
expect(bounds[2]).to.be(10);
|
||||
expect(bounds[1]).to.be(0);
|
||||
expect(bounds[3]).to.be(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates()', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
expect(poly.getCoordinates()).to.eql([outer, inner1, inner2]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#transform()', function() {
|
||||
|
||||
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||
var inverse = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
|
||||
|
||||
var gg, sm;
|
||||
beforeEach(function() {
|
||||
gg = [
|
||||
[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]],
|
||||
[[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||
[[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]]
|
||||
];
|
||||
|
||||
sm = [[
|
||||
[0, 0], [0, 1118890], [1113195, 1118890], [1113195, 0], [0, 0]
|
||||
], [
|
||||
[111319, 111325], [222639, 111325], [222639, 222684],
|
||||
[111319, 222684], [111319, 111325]
|
||||
], [
|
||||
[890556, 893464], [1001875, 893464], [1001875, 1006021],
|
||||
[890556, 1006021], [890556, 893464]
|
||||
]];
|
||||
|
||||
});
|
||||
|
||||
it('forward transforms a polygon in place', function() {
|
||||
|
||||
var poly = new ol.geom.Polygon(gg);
|
||||
poly.transform(forward);
|
||||
var coordinates = poly.getCoordinates();
|
||||
var ring;
|
||||
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
var ring = coordinates[i];
|
||||
for (var j = 0, jj = ring.length; j < jj; ++j) {
|
||||
expect(ring[j][0]).to.roughlyEqual(sm[i][j][0], 1);
|
||||
expect(ring[j][1]).to.roughlyEqual(sm[i][j][1], 1);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
it('inverse transforms a polygon in place', function() {
|
||||
|
||||
var poly = new ol.geom.Polygon(sm);
|
||||
poly.transform(inverse);
|
||||
var coordinates = poly.getCoordinates();
|
||||
var ring;
|
||||
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
var ring = coordinates[i];
|
||||
for (var j = 0, jj = ring.length; j < jj; ++j) {
|
||||
expect(ring[j][0]).to.roughlyEqual(gg[i][j][0], 0.001);
|
||||
expect(ring[j][1]).to.roughlyEqual(gg[i][j][1], 0.001);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('change event', function() {
|
||||
|
||||
var outer, inner;
|
||||
beforeEach(function() {
|
||||
outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
|
||||
inner = [[2, 2], [2, 8], [8, 8], [8, 2], [2, 2]];
|
||||
});
|
||||
|
||||
it('is fired when outer ring is modified', function(done) {
|
||||
var poly = new ol.geom.Polygon([outer, inner]);
|
||||
var rings = poly.getRings();
|
||||
goog.events.listen(poly, 'change', function(evt) {
|
||||
expect(evt.target).to.be(poly);
|
||||
expect(evt.target.getBounds()).to.eql([0, 0, 11, 10]);
|
||||
done();
|
||||
});
|
||||
|
||||
var outerCoords = rings[0].getCoordinates();
|
||||
outerCoords[1][0] = 11;
|
||||
rings[0].setCoordinates(outerCoords);
|
||||
});
|
||||
|
||||
it('is fired when inner ring is modified', function(done) {
|
||||
var poly = new ol.geom.Polygon([outer, inner]);
|
||||
var rings = poly.getRings();
|
||||
goog.events.listen(poly, 'change', function(evt) {
|
||||
expect(evt.target).to.be(poly);
|
||||
expect(evt.target.getBounds()).to.eql([0, 0, 10, 10]);
|
||||
done();
|
||||
});
|
||||
|
||||
var innerCoords = rings[1].getCoordinates();
|
||||
innerCoords[1][0] = 3;
|
||||
rings[1].setCoordinates(innerCoords);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.proj');
|
||||
Reference in New Issue
Block a user