Allow instanceof checks for geometries
This commit is contained in:
@@ -7,7 +7,7 @@ goog.provide('ol.geom.GeometryType');
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @interface
|
* @constructor
|
||||||
*/
|
*/
|
||||||
ol.geom.Geometry = function() {};
|
ol.geom.Geometry = function() {};
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ ol.geom.Geometry.prototype.getBounds = goog.abstractMethod;
|
|||||||
* Get the geometry type.
|
* Get the geometry type.
|
||||||
* @return {ol.geom.GeometryType} The geometry type.
|
* @return {ol.geom.GeometryType} The geometry type.
|
||||||
*/
|
*/
|
||||||
ol.geom.Geometry.prototype.getType = function() {};
|
ol.geom.Geometry.prototype.getType = goog.abstractMethod;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ goog.require('ol.geom.GeometryType');
|
|||||||
* A collection of geometries. This constructor should not called. Instead
|
* A collection of geometries. This constructor should not called. Instead
|
||||||
* create one of the fixed type collections.
|
* create one of the fixed type collections.
|
||||||
* @constructor
|
* @constructor
|
||||||
* @implements {ol.geom.Geometry}
|
* @extends {ol.geom.Geometry}
|
||||||
*/
|
*/
|
||||||
ol.geom.GeometryCollection = function() {
|
ol.geom.GeometryCollection = function() {
|
||||||
|
|
||||||
|
goog.base(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Array.<ol.geom.Geometry>}
|
* @type {Array.<ol.geom.Geometry>}
|
||||||
*/
|
*/
|
||||||
@@ -31,6 +33,7 @@ ol.geom.GeometryCollection = function() {
|
|||||||
this.bounds = null;
|
this.bounds = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
goog.inherits(ol.geom.GeometryCollection, ol.geom.Geometry);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ goog.require('ol.geom.GeometryType');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @implements {ol.geom.Geometry}
|
* @extends {ol.geom.Geometry}
|
||||||
* @param {ol.geom.CoordinateArray} coordinates Coordinates array (e.g.
|
* @param {ol.geom.CoordinateArray} coordinates Coordinates array (e.g.
|
||||||
* [[x0, y0], [x1, y1]]).
|
* [[x0, y0], [x1, y1]]).
|
||||||
*/
|
*/
|
||||||
ol.geom.LineString = function(coordinates) {
|
ol.geom.LineString = function(coordinates) {
|
||||||
|
|
||||||
|
goog.base(this);
|
||||||
|
|
||||||
// assume the same dimension for all coordinates
|
// assume the same dimension for all coordinates
|
||||||
var dimension = coordinates[0].length,
|
var dimension = coordinates[0].length,
|
||||||
count = coordinates.length,
|
count = coordinates.length,
|
||||||
@@ -43,6 +45,7 @@ ol.geom.LineString = function(coordinates) {
|
|||||||
this.bounds_ = null;
|
this.bounds_ = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
goog.inherits(ol.geom.LineString, ol.geom.Geometry);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ goog.require('ol.geom.GeometryType');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @implements {ol.geom.Geometry}
|
* @extends {ol.geom.Geometry}
|
||||||
* @param {ol.geom.Coordinate} coordinates Coordinates array (e.g. [x, y]).
|
* @param {ol.geom.Coordinate} coordinates Coordinates array (e.g. [x, y]).
|
||||||
*/
|
*/
|
||||||
ol.geom.Point = function(coordinates) {
|
ol.geom.Point = function(coordinates) {
|
||||||
|
|
||||||
|
goog.base(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Float64Array}
|
* @type {Float64Array}
|
||||||
*/
|
*/
|
||||||
@@ -33,6 +35,7 @@ ol.geom.Point = function(coordinates) {
|
|||||||
this.bounds_ = null;
|
this.bounds_ = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
goog.inherits(ol.geom.Point, ol.geom.Geometry);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ goog.require('ol.geom.LinearRing');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @implements {ol.geom.Geometry}
|
* @extends {ol.geom.Geometry}
|
||||||
* @param {Array.<ol.geom.CoordinateArray>} coordinates Array of rings. First
|
* @param {Array.<ol.geom.CoordinateArray>} coordinates Array of rings. First
|
||||||
* is outer, any remaining are inner.
|
* is outer, any remaining are inner.
|
||||||
*/
|
*/
|
||||||
ol.geom.Polygon = function(coordinates) {
|
ol.geom.Polygon = function(coordinates) {
|
||||||
|
|
||||||
|
goog.base(this);
|
||||||
|
|
||||||
var numRings = coordinates.length,
|
var numRings = coordinates.length,
|
||||||
dimension;
|
dimension;
|
||||||
|
|
||||||
@@ -46,6 +48,7 @@ ol.geom.Polygon = function(coordinates) {
|
|||||||
this.bounds_ = null;
|
this.bounds_ = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
goog.inherits(ol.geom.Polygon, ol.geom.Geometry);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ describe('ol.geom.LineString', function() {
|
|||||||
it('creates a linestring from an array', function() {
|
it('creates a linestring from an array', function() {
|
||||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||||
expect(line).toBeA(ol.geom.LineString);
|
expect(line).toBeA(ol.geom.LineString);
|
||||||
|
expect(line).toBeA(ol.geom.Geometry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when given mismatched dimension', function() {
|
it('throws when given mismatched dimension', function() {
|
||||||
@@ -62,4 +63,5 @@ describe('ol.geom.LineString', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
goog.require('ol.geom.Geometry');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ describe('ol.geom.MultiLineString', function() {
|
|||||||
[[10, 20], [30, 40]],
|
[[10, 20], [30, 40]],
|
||||||
[[20, 30], [40, 50]]]);
|
[[20, 30], [40, 50]]]);
|
||||||
expect(multi).toBeA(ol.geom.MultiLineString);
|
expect(multi).toBeA(ol.geom.MultiLineString);
|
||||||
|
expect(multi).toBeA(ol.geom.Geometry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when given with insufficient dimensions', function() {
|
it('throws when given with insufficient dimensions', function() {
|
||||||
@@ -69,4 +70,5 @@ describe('ol.geom.MultiLineString', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
goog.require('ol.geom.Geometry');
|
||||||
goog.require('ol.geom.MultiLineString');
|
goog.require('ol.geom.MultiLineString');
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ describe('ol.geom.MultiPoint', function() {
|
|||||||
it('creates a multi-point from an array', function() {
|
it('creates a multi-point from an array', function() {
|
||||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||||
expect(multi).toBeA(ol.geom.MultiPoint);
|
expect(multi).toBeA(ol.geom.MultiPoint);
|
||||||
|
expect(multi).toBeA(ol.geom.Geometry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when given with insufficient dimensions', function() {
|
it('throws when given with insufficient dimensions', function() {
|
||||||
@@ -59,4 +60,5 @@ describe('ol.geom.MultiPoint', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
goog.require('ol.geom.Geometry');
|
||||||
goog.require('ol.geom.MultiPoint');
|
goog.require('ol.geom.MultiPoint');
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ describe('ol.geom.MultiPolygon', function() {
|
|||||||
[outer1, inner1a, inner1b],
|
[outer1, inner1a, inner1b],
|
||||||
[outer2]]);
|
[outer2]]);
|
||||||
expect(multi).toBeA(ol.geom.MultiPolygon);
|
expect(multi).toBeA(ol.geom.MultiPolygon);
|
||||||
|
expect(multi).toBeA(ol.geom.Geometry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when given with insufficient dimensions', function() {
|
it('throws when given with insufficient dimensions', function() {
|
||||||
@@ -72,4 +73,5 @@ describe('ol.geom.MultiPolygon', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
goog.require('ol.geom.Geometry');
|
||||||
goog.require('ol.geom.MultiPolygon');
|
goog.require('ol.geom.MultiPolygon');
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ describe('ol.geom.Point', function() {
|
|||||||
it('creates a point from an array', function() {
|
it('creates a point from an array', function() {
|
||||||
var point = new ol.geom.Point([10, 20]);
|
var point = new ol.geom.Point([10, 20]);
|
||||||
expect(point).toBeA(ol.geom.Point);
|
expect(point).toBeA(ol.geom.Point);
|
||||||
|
expect(point).toBeA(ol.geom.Geometry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when given with insufficient dimensions', function() {
|
it('throws when given with insufficient dimensions', function() {
|
||||||
@@ -60,4 +61,5 @@ describe('ol.geom.Point', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
goog.require('ol.geom.Geometry');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ describe('ol.geom.Polygon', function() {
|
|||||||
it('creates a polygon from an array', function() {
|
it('creates a polygon from an array', function() {
|
||||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||||
expect(poly).toBeA(ol.geom.Polygon);
|
expect(poly).toBeA(ol.geom.Polygon);
|
||||||
|
expect(poly).toBeA(ol.geom.Geometry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when given mismatched dimension', function() {
|
it('throws when given mismatched dimension', function() {
|
||||||
@@ -64,4 +65,5 @@ describe('ol.geom.Polygon', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
goog.require('ol.geom.Geometry');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
|
|||||||
Reference in New Issue
Block a user