Add ol.geom.MultiPoint

This commit is contained in:
Tom Payne
2013-11-09 15:50:15 +01:00
parent ec748f254e
commit 6d32756adf
3 changed files with 203 additions and 1 deletions

View File

@@ -1,4 +1,3 @@
// FIXME add MultiPoint
// FIXME add GeometryCollection
goog.provide('ol.geom.Geometry');
@@ -16,6 +15,7 @@ ol.geom.GeometryType = {
POINT: 'Point',
LINE_STRING: 'LineString',
POLYGON: 'Polygon',
MULTI_POINT: 'MultiPoint',
MULTI_LINE_STRING: 'MultiLineString',
MULTI_POLYGON: 'MultiPolygon'
};

46
src/ol/geom/multipoint.js Normal file
View File

@@ -0,0 +1,46 @@
goog.provide('ol.geom.MultiPoint');
goog.require('ol.geom.Geometry');
/**
* @constructor
* @extends {ol.geom.Geometry}
* @param {ol.geom.RawMultiPoint} coordinates Coordinates.
* @param {ol.geom.Layout=} opt_layout Layout.
*/
ol.geom.MultiPoint = function(coordinates, opt_layout) {
goog.base(this);
this.setCoordinates(coordinates, opt_layout);
};
goog.inherits(ol.geom.MultiPoint, ol.geom.Geometry);
/**
* @return {ol.geom.RawMultiPoint} Coordinates.
*/
ol.geom.MultiPoint.prototype.getCoordinates = function() {
return ol.geom.inflateCoordinates(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
};
/**
* @inheritDoc
*/
ol.geom.MultiPoint.prototype.getType = function() {
return ol.geom.GeometryType.MULTI_POINT;
};
/**
* @param {ol.geom.RawMultiPoint} coordinates Coordinates.
* @param {ol.geom.Layout=} opt_layout Layout.
*/
ol.geom.MultiPoint.prototype.setCoordinates =
function(coordinates, opt_layout) {
this.setLayout(opt_layout, coordinates, 1);
ol.geom.deflateCoordinates(this.flatCoordinates, 0, coordinates, this.stride);
this.dispatchChangeEvent();
};

View File

@@ -0,0 +1,156 @@
goog.provide('ol.test.geom.MultiPoint');
describe('ol.geom.MultiPoint', function() {
describe('construct empty', function() {
var multiPoint;
beforeEach(function() {
multiPoint = new ol.geom.MultiPoint([]);
});
it('defaults to layout XY', function() {
expect(multiPoint.getLayout()).to.be(ol.geom.Layout.XY);
});
it('has empty coordinates', function() {
expect(multiPoint.getCoordinates()).to.be.empty();
});
it('has an empty extent', function() {
expect(ol.extent.isEmpty(multiPoint.getExtent())).to.be(true);
});
it('has empty flat coordinates', function() {
expect(multiPoint.getFlatCoordinates()).to.be.empty();
});
it('has stride the expected stride', function() {
expect(multiPoint.getStride()).to.be(2);
});
});
describe('construct with 2D coordinates', function() {
var multiPoint;
beforeEach(function() {
multiPoint = new ol.geom.MultiPoint([[1, 2], [3, 4]]);
});
it('has the expected layout', function() {
expect(multiPoint.getLayout()).to.be(ol.geom.Layout.XY);
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2], [3, 4]]);
});
it('has the expected extent', function() {
expect(multiPoint.getExtent()).to.eql([1, 2, 3, 4]);
});
it('has the expected flat coordinates', function() {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4]);
});
it('has stride the expected stride', function() {
expect(multiPoint.getStride()).to.be(2);
});
});
describe('construct with 3D coordinates', function() {
var multiPoint;
beforeEach(function() {
multiPoint = new ol.geom.MultiPoint([[1, 2, 3], [4, 5, 6]]);
});
it('has the expected layout', function() {
expect(multiPoint.getLayout()).to.be(ol.geom.Layout.XYZ);
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
});
it('has the expected extent', function() {
expect(multiPoint.getExtent()).to.eql([1, 2, 4, 5]);
});
it('has the expected flat coordinates', function() {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6]);
});
it('has the expected stride', function() {
expect(multiPoint.getStride()).to.be(3);
});
});
describe('construct with 3D coordinates and layout XYM', function() {
var multiPoint;
beforeEach(function() {
multiPoint = new ol.geom.MultiPoint(
[[1, 2, 3], [4, 5, 6]], ol.geom.Layout.XYM);
});
it('has the expected layout', function() {
expect(multiPoint.getLayout()).to.be(ol.geom.Layout.XYM);
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
});
it('has the expected extent', function() {
expect(multiPoint.getExtent()).to.eql([1, 2, 4, 5]);
});
it('has the expected flat coordinates', function() {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6]);
});
it('has the expected stride', function() {
expect(multiPoint.getStride()).to.be(3);
});
});
describe('construct with 4D coordinates', function() {
var multiPoint;
beforeEach(function() {
multiPoint = new ol.geom.MultiPoint([[1, 2, 3, 4], [5, 6, 7, 8]]);
});
it('has the expected layout', function() {
expect(multiPoint.getLayout()).to.be(ol.geom.Layout.XYZM);
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2, 3, 4], [5, 6, 7, 8]]);
});
it('has the expected extent', function() {
expect(multiPoint.getExtent()).to.eql([1, 2, 5, 6]);
});
it('has the expected flat coordinates', function() {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6, 7, 8]);
});
it('has the expected stride', function() {
expect(multiPoint.getStride()).to.be(4);
});
});
});
goog.require('ol.extent');
goog.require('ol.geom.MultiPoint');