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() {};
|
||||
|
||||
@@ -30,7 +30,7 @@ ol.geom.Geometry.prototype.getBounds = goog.abstractMethod;
|
||||
* Get 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
|
||||
* create one of the fixed type collections.
|
||||
* @constructor
|
||||
* @implements {ol.geom.Geometry}
|
||||
* @extends {ol.geom.Geometry}
|
||||
*/
|
||||
ol.geom.GeometryCollection = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.geom.Geometry>}
|
||||
*/
|
||||
@@ -31,6 +33,7 @@ ol.geom.GeometryCollection = function() {
|
||||
this.bounds = null;
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.GeometryCollection, ol.geom.Geometry);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,12 +10,14 @@ goog.require('ol.geom.GeometryType');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.geom.Geometry}
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {ol.geom.CoordinateArray} coordinates Coordinates array (e.g.
|
||||
* [[x0, y0], [x1, y1]]).
|
||||
*/
|
||||
ol.geom.LineString = function(coordinates) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
// assume the same dimension for all coordinates
|
||||
var dimension = coordinates[0].length,
|
||||
count = coordinates.length,
|
||||
@@ -43,6 +45,7 @@ ol.geom.LineString = function(coordinates) {
|
||||
this.bounds_ = null;
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.LineString, ol.geom.Geometry);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,11 +10,13 @@ goog.require('ol.geom.GeometryType');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.geom.Geometry}
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {ol.geom.Coordinate} coordinates Coordinates array (e.g. [x, y]).
|
||||
*/
|
||||
ol.geom.Point = function(coordinates) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @type {Float64Array}
|
||||
*/
|
||||
@@ -33,6 +35,7 @@ ol.geom.Point = function(coordinates) {
|
||||
this.bounds_ = null;
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.Point, ol.geom.Geometry);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,12 +11,14 @@ goog.require('ol.geom.LinearRing');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.geom.Geometry}
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {Array.<ol.geom.CoordinateArray>} coordinates Array of rings. First
|
||||
* is outer, any remaining are inner.
|
||||
*/
|
||||
ol.geom.Polygon = function(coordinates) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
var numRings = coordinates.length,
|
||||
dimension;
|
||||
|
||||
@@ -46,6 +48,7 @@ ol.geom.Polygon = function(coordinates) {
|
||||
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() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
expect(line).toBeA(ol.geom.LineString);
|
||||
expect(line).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
@@ -9,6 +9,7 @@ describe('ol.geom.MultiLineString', function() {
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
expect(multi).toBeA(ol.geom.MultiLineString);
|
||||
expect(multi).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
@@ -7,6 +7,7 @@ describe('ol.geom.MultiPoint', function() {
|
||||
it('creates a multi-point from an array', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
expect(multi).toBeA(ol.geom.MultiPoint);
|
||||
expect(multi).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
@@ -14,6 +14,7 @@ describe('ol.geom.MultiPolygon', function() {
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
expect(multi).toBeA(ol.geom.MultiPolygon);
|
||||
expect(multi).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
@@ -7,6 +7,7 @@ describe('ol.geom.Point', function() {
|
||||
it('creates a point from an array', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
expect(point).toBeA(ol.geom.Point);
|
||||
expect(point).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
@@ -11,6 +11,7 @@ describe('ol.geom.Polygon', function() {
|
||||
it('creates a polygon from an array', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
expect(poly).toBeA(ol.geom.Polygon);
|
||||
expect(poly).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user