Merge remote-tracking branch 'origin/master' into mocha
Conflicts: test/jasmine-extensions.js
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
goog.provide('ol.test.Expression');
|
||||
|
||||
describe('ol.Expression', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates an expression', function() {
|
||||
var exp = new ol.Expression('foo');
|
||||
expect(exp).toBeA(ol.Expression);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
|
||||
it('evaluates and returns the result', function() {
|
||||
// test cases here with unique values only (lack of messages in expect)
|
||||
var cases = [{
|
||||
source: '42', result: 42
|
||||
}, {
|
||||
source: '10 + 10', result: 20
|
||||
}, {
|
||||
source: '"a" + "b"', result: 'ab'
|
||||
}, {
|
||||
source: 'Math.floor(Math.PI)', result: 3
|
||||
}, {
|
||||
source: 'ol', result: ol
|
||||
}, {
|
||||
source: 'this', result: goog.global
|
||||
}];
|
||||
|
||||
var c, exp;
|
||||
for (var i = 0, ii = cases.length; i < ii; ++i) {
|
||||
c = cases[i];
|
||||
exp = new ol.Expression(c.source);
|
||||
expect(exp.evaluate()).toBe(c.result);
|
||||
}
|
||||
});
|
||||
|
||||
it('accepts an optional this argument', function() {
|
||||
function Thing() {
|
||||
this.works = true;
|
||||
};
|
||||
|
||||
var exp = new ol.Expression('this.works ? "yes" : "no"');
|
||||
expect(exp.evaluate(new Thing())).toBe('yes');
|
||||
expect(exp.evaluate({})).toBe('no');
|
||||
});
|
||||
|
||||
it('accepts an optional scope argument', function() {
|
||||
var exp;
|
||||
var scope = {
|
||||
greeting: 'hello world',
|
||||
punctuation: '!',
|
||||
pick: function(array, index) {
|
||||
return array[index];
|
||||
}
|
||||
};
|
||||
|
||||
// access two members in the scope
|
||||
exp = new ol.Expression('greeting + punctuation');
|
||||
expect(exp.evaluate({}, scope)).toBe('hello world!');
|
||||
|
||||
// call a function in the scope
|
||||
exp = new ol.Expression(
|
||||
'pick([10, 42, "chicken"], 2) + Math.floor(Math.PI)');
|
||||
expect(exp.evaluate({}, scope)).toBe('chicken3');
|
||||
|
||||
});
|
||||
|
||||
it('throws on error', function() {
|
||||
var exp = new ol.Expression('@*)$(&');
|
||||
expect(function() {exp.evaluate()}).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Expression');
|
||||
@@ -0,0 +1,201 @@
|
||||
goog.provide('ol.test.Feature');
|
||||
|
||||
describe('ol.Feature', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a new feature', function() {
|
||||
var feature = new ol.Feature();
|
||||
expect(feature).toBeA(ol.Feature);
|
||||
});
|
||||
|
||||
it('takes attribute values', function() {
|
||||
var feature = new ol.Feature({
|
||||
foo: 'bar'
|
||||
});
|
||||
expect(feature.get('foo')).toBe('bar');
|
||||
});
|
||||
|
||||
it('will set the default geometry', function() {
|
||||
var feature = new ol.Feature({
|
||||
loc: new ol.geom.Point([10, 20]),
|
||||
foo: 'bar'
|
||||
});
|
||||
var geometry = feature.getGeometry();
|
||||
expect(geometry).toBeA(ol.geom.Point);
|
||||
expect(feature.get('loc')).toBe(geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#get()', function() {
|
||||
|
||||
it('returns values set at construction', function() {
|
||||
var feature = new ol.Feature({
|
||||
a: 'first',
|
||||
b: 'second'
|
||||
});
|
||||
expect(feature.get('a')).toBe('first');
|
||||
expect(feature.get('b')).toBe('second');
|
||||
});
|
||||
|
||||
it('returns undefined for unset attributes', function() {
|
||||
var feature = new ol.Feature();
|
||||
expect(feature.get('a')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns values set by set', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.set('a', 'b');
|
||||
expect(feature.get('a')).toBe('b');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getAttributes()', function() {
|
||||
|
||||
it('returns an object with all attributes', function() {
|
||||
var point = new ol.geom.Point([15, 30]);
|
||||
var feature = new ol.Feature({
|
||||
foo: 'bar',
|
||||
ten: 10,
|
||||
loc: point
|
||||
});
|
||||
|
||||
var attributes = feature.getAttributes();
|
||||
|
||||
var keys = goog.object.getKeys(attributes);
|
||||
expect(keys.sort()).toEqual(['foo', 'loc', 'ten']);
|
||||
|
||||
expect(attributes.foo).toBe('bar');
|
||||
expect(attributes.loc).toBe(point);
|
||||
expect(attributes.ten).toBe(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#getGeometry()', function() {
|
||||
|
||||
var point = new ol.geom.Point([15, 30]);
|
||||
|
||||
it('returns null for no geometry', function() {
|
||||
var feature = new ol.Feature();
|
||||
expect(feature.getGeometry()).toBeNull();
|
||||
});
|
||||
|
||||
it('gets the geometry set at construction', function() {
|
||||
var feature = new ol.Feature({
|
||||
geom: point
|
||||
});
|
||||
expect(feature.getGeometry()).toBe(point);
|
||||
});
|
||||
|
||||
it('gets any geometry set by setGeometry', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.getGeometry()).toBe(point);
|
||||
|
||||
var point2 = new ol.geom.Point([1, 2]);
|
||||
feature.setGeometry(point2);
|
||||
expect(feature.getGeometry()).toBe(point2);
|
||||
});
|
||||
|
||||
it('gets the first geometry set by set', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.set('foo', point);
|
||||
expect(feature.getGeometry()).toBe(point);
|
||||
|
||||
feature.set('bar', new ol.geom.Point([1, 2]));
|
||||
expect(feature.getGeometry()).toBe(point);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#set()', function() {
|
||||
|
||||
it('sets values', function() {
|
||||
var feature = new ol.Feature({
|
||||
a: 'first',
|
||||
b: 'second'
|
||||
});
|
||||
feature.set('a', 'new');
|
||||
expect(feature.get('a')).toBe('new');
|
||||
});
|
||||
|
||||
it('can be used to set the geometry', function() {
|
||||
var point = new ol.geom.Point([3, 4]);
|
||||
var feature = new ol.Feature({
|
||||
loc: new ol.geom.Point([1, 2])
|
||||
});
|
||||
feature.set('loc', point);
|
||||
expect(feature.get('loc')).toBe(point);
|
||||
expect(feature.getGeometry()).toBe(point);
|
||||
});
|
||||
|
||||
it('can be used to set attributes with arbitrary names', function() {
|
||||
|
||||
var feature = new ol.Feature();
|
||||
|
||||
feature.set('toString', 'string');
|
||||
expect(feature.get('toString')).toBe('string');
|
||||
expect(typeof feature.toString).toBe('function');
|
||||
|
||||
feature.set('getGeometry', 'x');
|
||||
expect(feature.get('getGeometry')).toBe('x');
|
||||
|
||||
feature.set('geom', new ol.geom.Point([1, 2]));
|
||||
expect(feature.getGeometry()).toBeA(ol.geom.Point);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setGeometry()', function() {
|
||||
|
||||
var point = new ol.geom.Point([15, 30]);
|
||||
|
||||
it('sets the default geometry', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.get(ol.Feature.DEFAULT_GEOMETRY)).toBe(point);
|
||||
});
|
||||
|
||||
it('replaces previous default geometry', function() {
|
||||
var feature = new ol.Feature({
|
||||
geom: point
|
||||
});
|
||||
expect(feature.getGeometry()).toBe(point);
|
||||
|
||||
var point2 = new ol.geom.Point([1, 2]);
|
||||
feature.setGeometry(point2);
|
||||
expect(feature.getGeometry()).toBe(point2);
|
||||
});
|
||||
|
||||
it('gets any geometry set by setGeometry', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.getGeometry()).toBe(point);
|
||||
|
||||
var point2 = new ol.geom.Point([1, 2]);
|
||||
feature.setGeometry(point2);
|
||||
expect(feature.getGeometry()).toBe(point2);
|
||||
});
|
||||
|
||||
it('gets the first geometry set by set', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.set('foo', point);
|
||||
expect(feature.getGeometry()).toBe(point);
|
||||
|
||||
feature.set('bar', new ol.geom.Point([1, 2]));
|
||||
expect(feature.getGeometry()).toBe(point);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.Point');
|
||||
@@ -0,0 +1,37 @@
|
||||
goog.provide('ol.test.filter.Extent');
|
||||
|
||||
|
||||
describe('ol.filter.Extent', function() {
|
||||
|
||||
var extent, filter;
|
||||
|
||||
beforeEach(function() {
|
||||
extent = new ol.Extent(0, 0, 45, 90);
|
||||
filter = new ol.filter.Extent(extent);
|
||||
});
|
||||
|
||||
describe('#getExtent()', function() {
|
||||
|
||||
it('returns the configured extent', function() {
|
||||
expect(filter.getExtent()).toBe(extent);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
|
||||
it('returns true if a feature intersects, false if not', function() {
|
||||
expect(filter.applies(new ol.Feature({g: new ol.geom.Point([44, 89])})))
|
||||
.toBe(true);
|
||||
expect(filter.applies(new ol.Feature({g: new ol.geom.Point([46, 91])})))
|
||||
.toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.filter.Extent');
|
||||
goog.require('ol.geom.Point');
|
||||
@@ -0,0 +1,51 @@
|
||||
goog.provide('ol.test.filter.Geometry');
|
||||
|
||||
|
||||
describe('ol.filter.Geometry', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new filter', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.POINT);
|
||||
expect(filter).toBeA(ol.filter.Geometry);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getType()', function() {
|
||||
|
||||
it('works for point', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.POINT);
|
||||
expect(filter.getType()).toBe(ol.filter.GeometryType.POINT);
|
||||
});
|
||||
|
||||
it('works for linestring', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.LINESTRING);
|
||||
expect(filter.getType()).toBe(ol.filter.GeometryType.LINESTRING);
|
||||
});
|
||||
|
||||
it('works for polygon', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.POLYGON);
|
||||
expect(filter.getType()).toBe(ol.filter.GeometryType.POLYGON);
|
||||
});
|
||||
|
||||
it('works for multi-point', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.MULTIPOINT);
|
||||
expect(filter.getType()).toBe(ol.filter.GeometryType.MULTIPOINT);
|
||||
});
|
||||
|
||||
it('works for multi-linestring', function() {
|
||||
var filter = new ol.filter.Geometry(
|
||||
ol.filter.GeometryType.MULTILINESTRING);
|
||||
expect(filter.getType()).toBe(ol.filter.GeometryType.MULTILINESTRING);
|
||||
});
|
||||
|
||||
it('works for multi-polygon', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.MULTIPOLYGON);
|
||||
expect(filter.getType()).toBe(ol.filter.GeometryType.MULTIPOLYGON);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.filter.Geometry');
|
||||
goog.require('ol.filter.GeometryType');
|
||||
@@ -0,0 +1,79 @@
|
||||
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).toBeA(ol.geom.GeometryCollection);
|
||||
expect(multi).toBeA(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]);
|
||||
|
||||
expect(multi.components.length).toBe(3);
|
||||
expect(multi.components[0]).toBeA(ol.geom.Point);
|
||||
expect(multi.components[1]).toBeA(ol.geom.LineString);
|
||||
expect(multi.components[2]).toBeA(ol.geom.Polygon);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', 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.dimension).toBe(2);
|
||||
});
|
||||
|
||||
it('can be 3', function() {
|
||||
var multi = new ol.geom.GeometryCollection([
|
||||
new ol.geom.Point([30, 40, 50])
|
||||
]);
|
||||
expect(multi.dimension).toBe(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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.minX).toBe(1);
|
||||
expect(bounds.minY).toBe(2);
|
||||
expect(bounds.maxX).toBe(30);
|
||||
expect(bounds.maxY).toBe(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');
|
||||
@@ -0,0 +1,45 @@
|
||||
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).toBeA(ol.geom.LinearRing);
|
||||
});
|
||||
|
||||
it('throws when given mismatched dimension', function() {
|
||||
expect(function() {
|
||||
var ring = new ol.geom.LinearRing([[10, 20], [30, 40, 50]]);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
|
||||
expect(ring.dimension).toBe(2);
|
||||
});
|
||||
|
||||
it('can be 3', function() {
|
||||
var ring = new ol.geom.LinearRing([[10, 20, 30], [40, 50, 60]]);
|
||||
expect(ring.dimension).toBe(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates()', function() {
|
||||
|
||||
it('is an array', function() {
|
||||
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
|
||||
expect(ring.getCoordinates()).toEqual([[10, 20], [30, 40]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.LinearRing');
|
||||
@@ -0,0 +1,103 @@
|
||||
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).toBeA(ol.geom.LineString);
|
||||
expect(line).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
it('throws when given mismatched dimension', function() {
|
||||
expect(function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40, 50]]);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('accepts shared vertices', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
var l1 = new ol.geom.LineString([[10, 20], [30, 40]], vertices);
|
||||
var l2 = new ol.geom.LineString([[50, 60], [70, 80]], vertices);
|
||||
expect(l1.getCoordinates()).toEqual([[10, 20], [30, 40]]);
|
||||
expect(l2.getCoordinates()).toEqual([[50, 60], [70, 80]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
expect(line.dimension).toBe(2);
|
||||
});
|
||||
|
||||
it('can be 3', function() {
|
||||
var line = new ol.geom.LineString([[10, 20, 30], [40, 50, 60]]);
|
||||
expect(line.dimension).toBe(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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.minX).toBe(10);
|
||||
expect(bounds.minY).toBe(20);
|
||||
expect(bounds.maxX).toBe(30);
|
||||
expect(bounds.maxY).toBe(40);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
expect(line.getCoordinates()).toEqual([[10, 20], [30, 40]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getSharedId()', function() {
|
||||
|
||||
it('returns identifiers', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
|
||||
var l1 = new ol.geom.LineString([[10, 20], [30, 40]], vertices);
|
||||
var l2 = new ol.geom.LineString(
|
||||
[[50, 60], [70, 80], [90, 100]], vertices);
|
||||
|
||||
var id1 = l1.getSharedId();
|
||||
var id2 = l2.getSharedId();
|
||||
|
||||
expect(vertices.coordinates).toEqual(
|
||||
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]);
|
||||
|
||||
expect(vertices.getStart(id1)).toBe(0);
|
||||
expect(vertices.getCount(id1)).toBe(2);
|
||||
expect(vertices.get(id1, 0, 0)).toBe(10);
|
||||
expect(vertices.get(id1, 0, 1)).toBe(20);
|
||||
expect(vertices.get(id1, 1, 0)).toBe(30);
|
||||
expect(vertices.get(id1, 1, 1)).toBe(40);
|
||||
|
||||
expect(vertices.getStart(id2)).toBe(4);
|
||||
expect(vertices.getCount(id2)).toBe(3);
|
||||
expect(vertices.get(id2, 0, 0)).toBe(50);
|
||||
expect(vertices.get(id2, 0, 1)).toBe(60);
|
||||
expect(vertices.get(id2, 1, 0)).toBe(70);
|
||||
expect(vertices.get(id2, 1, 1)).toBe(80);
|
||||
expect(vertices.get(id2, 2, 0)).toBe(90);
|
||||
expect(vertices.get(id2, 2, 1)).toBe(100);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.SharedVertices');
|
||||
@@ -0,0 +1,88 @@
|
||||
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).toBeA(ol.geom.MultiLineString);
|
||||
expect(multi).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
it('throws when given with insufficient dimensions', function() {
|
||||
expect(function() {
|
||||
var multi = new ol.geom.MultiLineString([1]);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of linestrings', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
|
||||
expect(multi.components.length).toBe(2);
|
||||
expect(multi.components[0]).toBeA(ol.geom.LineString);
|
||||
expect(multi.components[1]).toBeA(ol.geom.LineString);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
expect(multi.dimension).toBe(2);
|
||||
});
|
||||
|
||||
it('can be 3', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20, 30], [30, 40, 50]],
|
||||
[[20, 30, 40], [40, 50, 60]]]);
|
||||
expect(multi.dimension).toBe(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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.minX).toBe(10);
|
||||
expect(bounds.minY).toBe(20);
|
||||
expect(bounds.maxX).toBe(40);
|
||||
expect(bounds.maxY).toBe(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()).toEqual(coordinates);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
@@ -0,0 +1,74 @@
|
||||
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).toBeA(ol.geom.MultiPoint);
|
||||
expect(multi).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
it('throws when given with insufficient dimensions', function() {
|
||||
expect(function() {
|
||||
var multi = new ol.geom.MultiPoint([1]);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of points', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
|
||||
expect(multi.components.length).toBe(2);
|
||||
expect(multi.components[0]).toBeA(ol.geom.Point);
|
||||
expect(multi.components[1]).toBeA(ol.geom.Point);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
expect(multi.dimension).toBe(2);
|
||||
});
|
||||
|
||||
it('can be 3', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20, 30], [30, 40, 50]]);
|
||||
expect(multi.dimension).toBe(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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.minX).toBe(10);
|
||||
expect(bounds.minY).toBe(20);
|
||||
expect(bounds.maxX).toBe(30);
|
||||
expect(bounds.maxY).toBe(40);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
expect(multi.getCoordinates()).toEqual([[10, 20], [30, 40]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.Point');
|
||||
@@ -0,0 +1,92 @@
|
||||
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).toBeA(ol.geom.MultiPolygon);
|
||||
expect(multi).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
it('throws when given with insufficient dimensions', function() {
|
||||
expect(function() {
|
||||
var multi = new ol.geom.MultiPolygon([1]);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of polygons', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
|
||||
expect(multi.components.length).toBe(2);
|
||||
expect(multi.components[0]).toBeA(ol.geom.Polygon);
|
||||
expect(multi.components[1]).toBeA(ol.geom.Polygon);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
expect(multi.dimension).toBe(2);
|
||||
});
|
||||
|
||||
it('can be 3', function() {
|
||||
var multi = new ol.geom.MultiPolygon([[[[10, 20, 30], [40, 50, 60]]]]);
|
||||
expect(multi.dimension).toBe(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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.minX).toBe(0);
|
||||
expect(bounds.minY).toBe(0);
|
||||
expect(bounds.maxX).toBe(20);
|
||||
expect(bounds.maxY).toBe(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()).toEqual(coordinates);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Polygon');
|
||||
@@ -0,0 +1,106 @@
|
||||
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).toBeA(ol.geom.Point);
|
||||
expect(point).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
it('accepts shared vertices', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
var p1 = new ol.geom.Point([10, 20], vertices);
|
||||
var p2 = new ol.geom.Point([30, 40], vertices);
|
||||
var p3 = new ol.geom.Point([50, 60], vertices);
|
||||
expect(p1.getCoordinates()).toEqual([10, 20]);
|
||||
expect(p2.getCoordinates()).toEqual([30, 40]);
|
||||
expect(p3.getCoordinates()).toEqual([50, 60]);
|
||||
});
|
||||
|
||||
it('throws when given with insufficient dimensions', function() {
|
||||
expect(function() {
|
||||
var point = new ol.geom.Point([1]);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
expect(point.dimension).toBe(2);
|
||||
});
|
||||
|
||||
it('can be 3', function() {
|
||||
var point = new ol.geom.Point([10, 20, 30]);
|
||||
expect(point.dimension).toBe(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
var bounds = point.getBounds();
|
||||
expect(bounds.minX).toBe(10);
|
||||
expect(bounds.minY).toBe(20);
|
||||
expect(bounds.maxX).toBe(10);
|
||||
expect(bounds.maxY).toBe(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates()', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
expect(point.getCoordinates()).toEqual([10, 20]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#getSharedId()', function() {
|
||||
|
||||
it('returns identifiers', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
|
||||
var p1 = new ol.geom.Point([10, 20], vertices);
|
||||
var p2 = new ol.geom.Point([30, 40], vertices);
|
||||
var p3 = new ol.geom.Point([50, 60], vertices);
|
||||
|
||||
var id1 = p1.getSharedId();
|
||||
var id2 = p2.getSharedId();
|
||||
var id3 = p3.getSharedId();
|
||||
|
||||
expect(vertices.coordinates).toEqual(
|
||||
[10, 20, 30, 40, 50, 60]);
|
||||
|
||||
expect(vertices.getStart(id1)).toBe(0);
|
||||
expect(vertices.getCount(id1)).toBe(1);
|
||||
expect(vertices.get(id1, 0, 0)).toBe(10);
|
||||
expect(vertices.get(id1, 0, 1)).toBe(20);
|
||||
|
||||
expect(vertices.getStart(id2)).toBe(2);
|
||||
expect(vertices.getCount(id2)).toBe(1);
|
||||
expect(vertices.get(id2, 0, 0)).toBe(30);
|
||||
expect(vertices.get(id2, 0, 1)).toBe(40);
|
||||
|
||||
expect(vertices.getStart(id3)).toBe(4);
|
||||
expect(vertices.getCount(id3)).toBe(1);
|
||||
expect(vertices.get(id3, 0, 0)).toBe(50);
|
||||
expect(vertices.get(id3, 0, 1)).toBe(60);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.SharedVertices');
|
||||
@@ -0,0 +1,89 @@
|
||||
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).toBeA(ol.geom.Polygon);
|
||||
expect(poly).toBeA(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
it('throws when given mismatched dimension', function() {
|
||||
expect(function() {
|
||||
var poly = new ol.geom.Polygon([[[10, 20], [30, 40, 50]]]);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('accepts shared vertices', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
var p1 = new ol.geom.Polygon([outer], vertices);
|
||||
var p2 = new ol.geom.Polygon([outer, inner1], vertices);
|
||||
var p3 = new ol.geom.Polygon([outer, inner2], vertices);
|
||||
expect(p1.getCoordinates()).toEqual([outer]);
|
||||
expect(p2.getCoordinates()).toEqual([outer, inner1]);
|
||||
expect(p3.getCoordinates()).toEqual([outer, inner2]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#rings', function() {
|
||||
|
||||
it('is an array of LinearRing', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
|
||||
expect(poly.rings.length).toBe(3);
|
||||
expect(poly.rings[0]).toBeA(ol.geom.LinearRing);
|
||||
expect(poly.rings[1]).toBeA(ol.geom.LinearRing);
|
||||
expect(poly.rings[2]).toBeA(ol.geom.LinearRing);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
expect(poly.dimension).toBe(2);
|
||||
});
|
||||
|
||||
it('can be 3', function() {
|
||||
var poly = new ol.geom.Polygon([[[10, 20, 30], [40, 50, 60]]]);
|
||||
expect(poly.dimension).toBe(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var bounds = poly.getBounds();
|
||||
expect(bounds.minX).toBe(0);
|
||||
expect(bounds.minY).toBe(0);
|
||||
expect(bounds.maxX).toBe(10);
|
||||
expect(bounds.maxY).toBe(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates()', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
expect(poly.getCoordinates()).toEqual([outer, inner1, inner2]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.geom.SharedVertices');
|
||||
@@ -0,0 +1,202 @@
|
||||
goog.provide('ol.test.geom.SharedVertices');
|
||||
|
||||
describe('ol.geom.SharedVertices', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates an instance', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
expect(vertices).toBeA(ol.geom.SharedVertices);
|
||||
});
|
||||
|
||||
it('accepts options', function() {
|
||||
var vertices = new ol.geom.SharedVertices({
|
||||
dimension: 4,
|
||||
offset: [1, 2, 3, 4]
|
||||
});
|
||||
|
||||
expect(vertices.getDimension()).toBe(4);
|
||||
expect(vertices.getOffset()).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('offset option', function() {
|
||||
it('offsets the internally stored vertex coordinates', function() {
|
||||
var vertices = new ol.geom.SharedVertices({offset: [3, -1]});
|
||||
vertices.add([[3, -1], [0, 0]]);
|
||||
vertices.add([[10, 20]]);
|
||||
expect(vertices.coordinates).toEqual([0, 0, -3, 1, 7, 21]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#add()', function() {
|
||||
it('adds vertex arrays to the shared coordinates', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
expect(vertices.coordinates.length).toBe(0);
|
||||
|
||||
vertices.add([[1, 2], [3, 4]]);
|
||||
expect(vertices.coordinates).toEqual([1, 2, 3, 4]);
|
||||
|
||||
vertices.add([[5, 6]]);
|
||||
expect(vertices.coordinates).toEqual([1, 2, 3, 4, 5, 6]);
|
||||
});
|
||||
|
||||
it('returns an identifier for coordinate access', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
var id = vertices.add([[1, 2], [3, 4]]);
|
||||
expect(typeof id).toBe('number');
|
||||
});
|
||||
|
||||
it('returns the index of the added vertices', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
|
||||
var first = vertices.add([[1, 2]]);
|
||||
var second = vertices.add([[3, 4], [5, 6]]);
|
||||
var third = vertices.add([[7, 8], [9, 10], [11, 12]]);
|
||||
|
||||
expect(vertices.coordinates).toEqual(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
|
||||
|
||||
expect(first).toBe(0);
|
||||
expect(second).toBe(1);
|
||||
expect(third).toBe(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#get()', function() {
|
||||
it('provides access to vertex coordinates', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
var first = vertices.add([[1, 2], [3, 4]]);
|
||||
var second = vertices.add([[5, 6]]);
|
||||
|
||||
expect(vertices.get(first, 0, 0)).toBe(1);
|
||||
expect(vertices.get(first, 0, 1)).toBe(2);
|
||||
expect(vertices.get(first, 1, 0)).toBe(3);
|
||||
expect(vertices.get(first, 1, 1)).toBe(4);
|
||||
expect(vertices.get(second, 0, 0)).toBe(5);
|
||||
expect(vertices.get(second, 0, 1)).toBe(6);
|
||||
});
|
||||
|
||||
it('works for non-2d vertices', function() {
|
||||
var vertices = new ol.geom.SharedVertices({dimension: 3});
|
||||
var id = vertices.add([[1, 2, 3], [4, 5, 6]]);
|
||||
|
||||
expect(vertices.get(id, 0, 0)).toBe(1);
|
||||
expect(vertices.get(id, 0, 1)).toBe(2);
|
||||
expect(vertices.get(id, 0, 2)).toBe(3);
|
||||
expect(vertices.get(id, 1, 0)).toBe(4);
|
||||
expect(vertices.get(id, 1, 1)).toBe(5);
|
||||
expect(vertices.get(id, 1, 2)).toBe(6);
|
||||
});
|
||||
|
||||
it('works when an offset is provided', function() {
|
||||
var vertices = new ol.geom.SharedVertices({offset: [3, 3]});
|
||||
var id = vertices.add([[1, 2], [3, 4], [5, 6]]);
|
||||
|
||||
expect(vertices.get(id, 0, 0)).toBe(1);
|
||||
expect(vertices.get(id, 0, 1)).toBe(2);
|
||||
expect(vertices.get(id, 1, 0)).toBe(3);
|
||||
expect(vertices.get(id, 1, 1)).toBe(4);
|
||||
expect(vertices.get(id, 2, 0)).toBe(5);
|
||||
expect(vertices.get(id, 2, 1)).toBe(6);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCount()', function() {
|
||||
it('returns the length of an identified vertex array', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
var first = vertices.add([[2, 3], [3, 4], [4, 5]]);
|
||||
var second = vertices.add([[5, 6], [6, 6]]);
|
||||
|
||||
expect(vertices.getCount(first)).toBe(3);
|
||||
expect(vertices.getCount(second)).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getCounts()', function() {
|
||||
it('returns the counts array', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
var first = vertices.add([[2, 3], [3, 4], [4, 5]]);
|
||||
var second = vertices.add([[5, 6], [6, 6]]);
|
||||
var third = vertices.add([[7, 8]]);
|
||||
|
||||
expect(vertices.getCounts()).toEqual([3, 2, 1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getDimension()', function() {
|
||||
it('returns 2 by default', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
expect(vertices.getDimension()).toBe(2);
|
||||
});
|
||||
|
||||
it('returns the dimension provided to the constructor', function() {
|
||||
var vertices = new ol.geom.SharedVertices({dimension: 10});
|
||||
expect(vertices.getDimension()).toBe(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getOffset()', function() {
|
||||
it('returns null by default', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
expect(vertices.getOffset()).toBeNull();
|
||||
});
|
||||
|
||||
it('returns the offset provided to the constructor', function() {
|
||||
var vertices = new ol.geom.SharedVertices({offset: [1, 2]});
|
||||
expect(vertices.getOffset()).toEqual([1, 2]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getStart()', function() {
|
||||
it('returns the start index of an identified vertex array', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
var first = vertices.add([[2, 3], [4, 5], [6, 7]]);
|
||||
var second = vertices.add([[8, 9], [10, 11]]);
|
||||
var third = vertices.add([[12, 13]]);
|
||||
|
||||
expect(vertices.coordinates).toEqual(
|
||||
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);
|
||||
// 0 1 2 3 4 5 6 7 8 9 10 11
|
||||
|
||||
expect(vertices.getStart(first)).toBe(0);
|
||||
expect(vertices.getStart(second)).toBe(6);
|
||||
expect(vertices.getStart(third)).toBe(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getStarts()', function() {
|
||||
it('returns the counts array', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
var first = vertices.add([[2, 3], [3, 4], [4, 5]]);
|
||||
var second = vertices.add([[5, 6], [6, 6]]);
|
||||
var third = vertices.add([[7, 8]]);
|
||||
|
||||
expect(vertices.getStarts()).toEqual([0, 6, 10]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#coordinates', function() {
|
||||
it('is a flat array of all coordinate values', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
var first = vertices.add([[1, 2], [3, 4]]);
|
||||
var second = vertices.add([[5, 6]]);
|
||||
var third = vertices.add([[7, 8], [9, 10], [11, 12]]);
|
||||
expect(vertices.coordinates).toEqual(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
|
||||
});
|
||||
|
||||
it('is not reassigned', function() {
|
||||
var vertices = new ol.geom.SharedVertices();
|
||||
var first = vertices.add([[1, 2], [3, 4]]);
|
||||
var coordinates = vertices.coordinates;
|
||||
|
||||
var second = vertices.add([[5, 6]]);
|
||||
expect(vertices.coordinates).toBe(coordinates);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.SharedVertices');
|
||||
@@ -0,0 +1,195 @@
|
||||
goog.provide('ol.test.layer.Vector');
|
||||
|
||||
describe('ol.layer.Vector', function() {
|
||||
|
||||
describe('#addFeatures()', function() {
|
||||
|
||||
it('allows adding features', function() {
|
||||
var layer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({})
|
||||
});
|
||||
layer.addFeatures([new ol.Feature(), new ol.Feature()]);
|
||||
expect(layer.getFeatures().length).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getFeatures()', function() {
|
||||
|
||||
var layer, features;
|
||||
|
||||
beforeEach(function() {
|
||||
features = [
|
||||
new ol.Feature({
|
||||
g: new ol.geom.Point([16.0, 48.0])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.Point([16.1, 48.1])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.Point([16.2, 48.2])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.Point([16.3, 48.3])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[16.4, 48.4], [16.5, 48.5]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[16.6, 48.6], [16.7, 48.7]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[16.8, 48.8], [16.9, 48.9]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[17.0, 49.0], [17.1, 49.1]])
|
||||
})
|
||||
];
|
||||
layer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({})
|
||||
});
|
||||
layer.addFeatures(features);
|
||||
});
|
||||
|
||||
var geomFilter = new ol.filter.Geometry(ol.geom.GeometryType.LINESTRING);
|
||||
var extentFilter = new ol.filter.Extent(new ol.Extent(16, 48, 16.3, 48.3));
|
||||
|
||||
it('can filter by geometry type using its GeometryType index', function() {
|
||||
spyOn(geomFilter, 'applies');
|
||||
var lineStrings = layer.getFeatures(geomFilter);
|
||||
expect(geomFilter.applies).not.toHaveBeenCalled();
|
||||
expect(lineStrings.length).toEqual(4);
|
||||
expect(lineStrings).toContain(features[4]);
|
||||
});
|
||||
|
||||
it('can filter by extent using its RTree', function() {
|
||||
spyOn(extentFilter, 'applies');
|
||||
var subset = layer.getFeatures(extentFilter);
|
||||
expect(extentFilter.applies).not.toHaveBeenCalled();
|
||||
expect(subset.length).toEqual(4);
|
||||
expect(subset).not.toContain(features[7]);
|
||||
});
|
||||
|
||||
it('can filter by extent and geometry type using its index', function() {
|
||||
var filter1 = new ol.filter.Logical([geomFilter, extentFilter],
|
||||
ol.filter.LogicalOperator.AND);
|
||||
var filter2 = new ol.filter.Logical([extentFilter, geomFilter],
|
||||
ol.filter.LogicalOperator.AND);
|
||||
spyOn(filter1, 'applies');
|
||||
spyOn(filter2, 'applies');
|
||||
var subset1 = layer.getFeatures(filter1);
|
||||
var subset2 = layer.getFeatures(filter2);
|
||||
expect(filter1.applies).not.toHaveBeenCalled();
|
||||
expect(filter2.applies).not.toHaveBeenCalled();
|
||||
expect(subset1.length).toEqual(0);
|
||||
expect(subset2.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('can handle query using the filter\'s applies function', function() {
|
||||
var filter = new ol.filter.Logical([geomFilter, extentFilter],
|
||||
ol.filter.LogicalOperator.OR);
|
||||
spyOn(filter, 'applies').andCallThrough();
|
||||
var subset = layer.getFeatures(filter);
|
||||
expect(filter.applies).toHaveBeenCalled();
|
||||
expect(subset.length).toEqual(8);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#groupFeaturesBySymbolizerLiteral()', function() {
|
||||
|
||||
var layer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
projection: ol.projection.get('EPSG:4326')
|
||||
}),
|
||||
style: new ol.style.Style({
|
||||
rules: [
|
||||
new ol.style.Rule({
|
||||
symbolizers: [
|
||||
new ol.style.Line({
|
||||
strokeWidth: 2,
|
||||
strokeColor: new ol.Expression('colorProperty'),
|
||||
opacity: 1
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
})
|
||||
});
|
||||
var features;
|
||||
|
||||
it('groups equal symbolizers', function() {
|
||||
features = [
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[-10, -10], [10, 10]]),
|
||||
colorProperty: '#BADA55'
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[-10, 10], [10, -10]]),
|
||||
colorProperty: '#013'
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[10, -10], [-10, -10]]),
|
||||
colorProperty: '#013'
|
||||
})
|
||||
];
|
||||
|
||||
var groups = layer.groupFeaturesBySymbolizerLiteral(features);
|
||||
expect(groups.length).toBe(2);
|
||||
expect(groups[0][0].length).toBe(1);
|
||||
expect(groups[0][1].strokeColor).toBe('#BADA55');
|
||||
expect(groups[1][0].length).toBe(2);
|
||||
expect(groups[1][1].strokeColor).toBe('#013');
|
||||
});
|
||||
|
||||
it('groups equal symbolizers also when defined on features', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeWidth: 3,
|
||||
strokeColor: new ol.Expression('colorProperty'),
|
||||
opacity: 1
|
||||
});
|
||||
var anotherSymbolizer = new ol.style.Line({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#BADA55',
|
||||
opacity: 1
|
||||
});
|
||||
var featureWithSymbolizers = new ol.Feature({
|
||||
g: new ol.geom.LineString([[-10, -10], [-10, 10]]),
|
||||
colorProperty: '#BADA55'
|
||||
});
|
||||
featureWithSymbolizers.setSymbolizers([symbolizer]);
|
||||
var anotherFeatureWithSymbolizers = new ol.Feature({
|
||||
g: new ol.geom.LineString([[-10, 10], [-10, -10]])
|
||||
});
|
||||
anotherFeatureWithSymbolizers.setSymbolizers([anotherSymbolizer]);
|
||||
features.push(featureWithSymbolizers, anotherFeatureWithSymbolizers);
|
||||
|
||||
var groups = layer.groupFeaturesBySymbolizerLiteral(features);
|
||||
expect(groups.length).toBe(3);
|
||||
expect(groups[2][0].length).toBe(2);
|
||||
expect(groups[2][1].strokeWidth).toBe(3);
|
||||
|
||||
});
|
||||
|
||||
layer.dispose();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Expression');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.filter.Extent');
|
||||
goog.require('ol.filter.Geometry');
|
||||
goog.require('ol.filter.Logical');
|
||||
goog.require('ol.filter.LogicalOperator');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.projection');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.style.Line');
|
||||
goog.require('ol.style.Rule');
|
||||
goog.require('ol.style.Style');
|
||||
@@ -0,0 +1,228 @@
|
||||
goog.provide('ol.test.parser.GeoJSON');
|
||||
|
||||
describe('ol.parser.GeoJSON', function() {
|
||||
|
||||
var parser = new ol.parser.GeoJSON();
|
||||
|
||||
var data = {
|
||||
'type': 'FeatureCollection',
|
||||
'features': [
|
||||
{
|
||||
'type': 'Feature',
|
||||
'properties': {
|
||||
'LINK_ID': 573730499,
|
||||
'RP_TYPE': 14,
|
||||
'RP_FUNC': 0,
|
||||
'DIRECTION': 2,
|
||||
'LOGKOD': '',
|
||||
'CHANGED': '',
|
||||
'USERID': '',
|
||||
'ST_NAME': '',
|
||||
'L_REFADDR': '',
|
||||
'L_NREFADDR': '',
|
||||
'R_REFADDR': '',
|
||||
'R_NREFADDR': '',
|
||||
'SPEED_CAT': '7',
|
||||
'ZIPCODE': '59330',
|
||||
'SHAPE_LEN': 46.3826
|
||||
},
|
||||
'geometry': {
|
||||
'type': 'LineString',
|
||||
'coordinates': [
|
||||
[1549497.66985, 6403707.96],
|
||||
[1549491.1, 6403710.1],
|
||||
[1549488.03995, 6403716.7504],
|
||||
[1549488.5401, 6403724.5504],
|
||||
[1549494.37985, 6403733.54],
|
||||
[1549499.6799, 6403738.0504],
|
||||
[1549506.22, 6403739.2504]
|
||||
]
|
||||
}
|
||||
}, {
|
||||
'type': 'Feature',
|
||||
'properties': {
|
||||
'LINK_ID': 30760556,
|
||||
'RP_TYPE': 12,
|
||||
'RP_FUNC': 1,
|
||||
'DIRECTION': 0,
|
||||
'LOGKOD': '',
|
||||
'CHANGED': '',
|
||||
'USERID': '',
|
||||
'ST_NAME': 'BRUNNSGATAN',
|
||||
'L_REFADDR': '24',
|
||||
'L_NREFADDR': '16',
|
||||
'R_REFADDR': '',
|
||||
'R_NREFADDR': '',
|
||||
'SPEED_CAT': '7',
|
||||
'ZIPCODE': '59330',
|
||||
'SHAPE_LEN': 70.3106
|
||||
},
|
||||
'geometry': {
|
||||
'type': 'LineString',
|
||||
'coordinates': [
|
||||
[1549754.2769, 6403854.8024],
|
||||
[1549728.45985, 6403920.2]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
describe('#read()', function() {
|
||||
|
||||
it('parses point', function() {
|
||||
var str = JSON.stringify({
|
||||
type: 'Point',
|
||||
coordinates: [10, 20]
|
||||
});
|
||||
|
||||
var obj = parser.read(str);
|
||||
expect(obj).toBeA(ol.geom.Point);
|
||||
expect(obj.getCoordinates()).toEqual([10, 20]);
|
||||
});
|
||||
|
||||
it('parses linestring', function() {
|
||||
var str = JSON.stringify({
|
||||
type: 'LineString',
|
||||
coordinates: [[10, 20], [30, 40]]
|
||||
});
|
||||
|
||||
var obj = parser.read(str);
|
||||
expect(obj).toBeA(ol.geom.LineString);
|
||||
expect(obj.getCoordinates()).toEqual([[10, 20], [30, 40]]);
|
||||
});
|
||||
|
||||
it('parses 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]],
|
||||
str = JSON.stringify({
|
||||
type: 'Polygon',
|
||||
coordinates: [outer, inner1, inner2]
|
||||
});
|
||||
|
||||
var obj = parser.read(str);
|
||||
expect(obj).toBeA(ol.geom.Polygon);
|
||||
expect(obj.rings.length).toBe(3);
|
||||
expect(obj.rings[0]).toBeA(ol.geom.LinearRing);
|
||||
expect(obj.rings[1]).toBeA(ol.geom.LinearRing);
|
||||
expect(obj.rings[2]).toBeA(ol.geom.LinearRing);
|
||||
});
|
||||
|
||||
it('parses geometry collection', function() {
|
||||
var str = JSON.stringify({
|
||||
type: 'GeometryCollection',
|
||||
geometries: [
|
||||
{type: 'Point', coordinates: [10, 20]},
|
||||
{type: 'LineString', coordinates: [[30, 40], [50, 60]]}
|
||||
]
|
||||
});
|
||||
|
||||
var array = parser.read(str);
|
||||
expect(array.length).toBe(2);
|
||||
expect(array[0]).toBeA(ol.geom.Point);
|
||||
expect(array[1]).toBeA(ol.geom.LineString);
|
||||
});
|
||||
|
||||
it('parses feature collection', function() {
|
||||
var str = JSON.stringify(data),
|
||||
array = parser.read(str);
|
||||
|
||||
expect(array.length).toBe(2);
|
||||
|
||||
var first = array[0];
|
||||
expect(first).toBeA(ol.Feature);
|
||||
expect(first.get('LINK_ID')).toBe(573730499);
|
||||
var firstGeom = first.getGeometry();
|
||||
expect(firstGeom).toBeA(ol.geom.LineString);
|
||||
|
||||
var second = array[1];
|
||||
expect(second).toBeA(ol.Feature);
|
||||
expect(second.get('ST_NAME')).toBe('BRUNNSGATAN');
|
||||
var secondGeom = second.getGeometry();
|
||||
expect(secondGeom).toBeA(ol.geom.LineString);
|
||||
});
|
||||
|
||||
it('parses countries.json', function() {
|
||||
afterLoadText('spec/ol/parser/geojson/countries.json', function(text) {
|
||||
var result = parser.read(text);
|
||||
expect(result.length).toBe(179);
|
||||
|
||||
var first = result[0];
|
||||
expect(first).toBeA(ol.Feature);
|
||||
expect(first.get('name')).toBe('Afghanistan');
|
||||
var firstGeom = first.getGeometry();
|
||||
expect(firstGeom).toBeA(ol.geom.Polygon);
|
||||
expect(firstGeom.getBounds().equals(
|
||||
new ol.Extent(60.52843, 29.318572, 75.158028, 38.486282)))
|
||||
.toBe(true);
|
||||
|
||||
var last = result[178];
|
||||
expect(last).toBeA(ol.Feature);
|
||||
expect(last.get('name')).toBe('Zimbabwe');
|
||||
var lastGeom = last.getGeometry();
|
||||
expect(lastGeom).toBeA(ol.geom.Polygon);
|
||||
expect(lastGeom.getBounds().equals(
|
||||
new ol.Extent(25.264226, -22.271612, 32.849861, -15.507787)))
|
||||
.toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses countries.json with shared vertices', function() {
|
||||
afterLoadText('spec/ol/parser/geojson/countries.json', function(text) {
|
||||
var pointVertices = new ol.geom.SharedVertices();
|
||||
var lineVertices = new ol.geom.SharedVertices();
|
||||
var polygonVertices = new ol.geom.SharedVertices();
|
||||
|
||||
var lookup = {
|
||||
'point': pointVertices,
|
||||
'linestring': lineVertices,
|
||||
'polygon': polygonVertices,
|
||||
'multipoint': pointVertices,
|
||||
'multilinstring': lineVertices,
|
||||
'multipolygon': polygonVertices
|
||||
};
|
||||
|
||||
var callback = function(feature, type) {
|
||||
return lookup[type];
|
||||
};
|
||||
|
||||
var result = parser.readFeaturesFromString(text, {callback: callback});
|
||||
expect(result.length).toBe(179);
|
||||
|
||||
expect(pointVertices.coordinates.length).toBe(0);
|
||||
expect(lineVertices.coordinates.length).toBe(0);
|
||||
expect(polygonVertices.coordinates.length).toBe(21344);
|
||||
|
||||
var first = result[0];
|
||||
expect(first).toBeA(ol.Feature);
|
||||
expect(first.get('name')).toBe('Afghanistan');
|
||||
var firstGeom = first.getGeometry();
|
||||
expect(firstGeom).toBeA(ol.geom.Polygon);
|
||||
expect(firstGeom.getBounds().equals(
|
||||
new ol.Extent(60.52843, 29.318572, 75.158028, 38.486282)))
|
||||
.toBe(true);
|
||||
|
||||
var last = result[178];
|
||||
expect(last).toBeA(ol.Feature);
|
||||
expect(last.get('name')).toBe('Zimbabwe');
|
||||
var lastGeom = last.getGeometry();
|
||||
expect(lastGeom).toBeA(ol.geom.Polygon);
|
||||
expect(lastGeom.getBounds().equals(
|
||||
new ol.Extent(25.264226, -22.271612, 32.849861, -15.507787)))
|
||||
.toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.geom.SharedVertices');
|
||||
goog.require('ol.parser.GeoJSON');
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,17 @@
|
||||
goog.provide('ol.test.source.Vector');
|
||||
|
||||
|
||||
describe('ol.source.Vector', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates an instance', function() {
|
||||
var source = new ol.source.Vector({});
|
||||
expect(source).toBeA(ol.source.Vector);
|
||||
expect(source).toBeA(ol.source.Source);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.source.Source');
|
||||
goog.require('ol.source.Vector');
|
||||
@@ -0,0 +1,62 @@
|
||||
goog.provide('ol.test.structs.RTree');
|
||||
|
||||
|
||||
describe('ol.structs.RTree', function() {
|
||||
|
||||
describe('put and find', function() {
|
||||
var rTree = new ol.structs.RTree();
|
||||
rTree.put(new ol.Rectangle(0, 0, 1, 1), 1);
|
||||
rTree.put(new ol.Rectangle(1, 1, 4, 4), 2);
|
||||
rTree.put(new ol.Rectangle(2, 2, 3, 3), 3);
|
||||
rTree.put(new ol.Rectangle(-5, -5, -4, -4), 4);
|
||||
rTree.put(new ol.Rectangle(-4, -4, -1, -1), 5);
|
||||
rTree.put(new ol.Rectangle(-3, -3, -2, -2), 6);
|
||||
|
||||
it('stores items', function() {
|
||||
expect(goog.object.getCount(rTree.find(new ol.Rectangle(
|
||||
Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY,
|
||||
Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY)))).toBe(6);
|
||||
});
|
||||
|
||||
it('filters by rectangle', function() {
|
||||
var result;
|
||||
result = goog.object.getValues(rTree.find(new ol.Rectangle(2, 2, 3, 3)));
|
||||
expect(result).toContain(2);
|
||||
expect(result).toContain(3);
|
||||
expect(result.length).toBe(2);
|
||||
result = goog.object.getValues(
|
||||
rTree.find(new ol.Rectangle(-1, -1, 2, 2)));
|
||||
expect(result).toContain(1);
|
||||
expect(result).toContain(2);
|
||||
expect(result).toContain(3);
|
||||
expect(result).toContain(5);
|
||||
expect(result.length).toBe(4);
|
||||
expect(goog.object.getCount(rTree.find(new ol.Rectangle(5, 5, 6, 6))))
|
||||
.toBe(0);
|
||||
});
|
||||
|
||||
it('can store thosands of items and find fast', function() {
|
||||
for (var i = 7; i <= 10000; ++i) {
|
||||
rTree.put(new ol.Rectangle(Math.random() * -10, Math.random() * -10,
|
||||
Math.random() * 10, Math.random() * 10), i);
|
||||
}
|
||||
expect(goog.object.getCount(
|
||||
rTree.find(new ol.Rectangle(-10, -10, 10, 10)))).toBe(10000);
|
||||
var result = rTree.find(new ol.Rectangle(0, 0, 0, 0));
|
||||
expect(goog.object.getCount(result)).toBe(9995);
|
||||
var values = goog.object.getValues(result);
|
||||
expect(values).toContain(1);
|
||||
expect(values).not.toContain(2);
|
||||
expect(values).not.toContain(3);
|
||||
expect(values).not.toContain(4);
|
||||
expect(values).not.toContain(5);
|
||||
expect(values).not.toContain(6);
|
||||
expect(values).toContain(7);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Rectangle');
|
||||
goog.require('ol.structs.RTree');
|
||||
@@ -0,0 +1,79 @@
|
||||
goog.provide('ol.test.style.Line');
|
||||
|
||||
describe('ol.style.LineLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.LineLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#BADA55',
|
||||
opacity: 1
|
||||
});
|
||||
var equalLiteral = new ol.style.LineLiteral({
|
||||
strokeColor: '#BADA55',
|
||||
strokeWidth: 3,
|
||||
opacity: 1
|
||||
});
|
||||
var differentLiteral = new ol.style.LineLiteral({
|
||||
strokeColor: '#013',
|
||||
strokeWidth: 3,
|
||||
opacity: 1
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).toBe(true);
|
||||
expect(literal.equals(differentLiteral)).toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.Line', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeColor: '#BADA55',
|
||||
strokeWidth: 3
|
||||
});
|
||||
expect(symbolizer).toBeA(ol.style.Line);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
opacity: new ol.Expression('value / 100'),
|
||||
strokeWidth: ol.Expression('widthAttr')
|
||||
});
|
||||
expect(symbolizer).toBeA(ol.style.Line);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
opacity: new ol.Expression('value / 100'),
|
||||
strokeWidth: ol.Expression('widthAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
value: 42,
|
||||
widthAttr: 1.5
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).toBeA(ol.style.LineLiteral);
|
||||
expect(literal.opacity).toBe(42 / 100);
|
||||
expect(literal.strokeWidth).toBe(1.5);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Expression');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.style.Line');
|
||||
goog.require('ol.style.LineLiteral');
|
||||
@@ -0,0 +1,95 @@
|
||||
goog.provide('ol.test.style.Polygon');
|
||||
|
||||
describe('ol.style.PolygonLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
fillColor: '#BADA55',
|
||||
opacity: 1
|
||||
});
|
||||
var equalLiteral = new ol.style.PolygonLiteral({
|
||||
fillColor: '#BADA55',
|
||||
strokeColor: '#013',
|
||||
strokeWidth: 3,
|
||||
opacity: 1
|
||||
});
|
||||
var differentLiteral = new ol.style.PolygonLiteral({
|
||||
fillColor: '#013',
|
||||
strokeColor: '#013',
|
||||
strokeWidth: 3,
|
||||
opacity: 1
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).toBe(true);
|
||||
expect(literal.equals(differentLiteral)).toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.Polygon', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
fillColor: '#BADA55',
|
||||
strokeWidth: 3
|
||||
});
|
||||
expect(symbolizer).toBeA(ol.style.Polygon);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
opacity: new ol.Expression('value / 100'),
|
||||
fillColor: new ol.Expression('fillAttr')
|
||||
});
|
||||
expect(symbolizer).toBeA(ol.style.Polygon);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
opacity: new ol.Expression('value / 100'),
|
||||
fillColor: new ol.Expression('fillAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
value: 42,
|
||||
fillAttr: '#ff0000'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).toBeA(ol.style.PolygonLiteral);
|
||||
expect(literal.opacity).toBe(42 / 100);
|
||||
expect(literal.fillColor).toBe('#ff0000');
|
||||
expect(literal.strokeColor).toBeUndefined();
|
||||
});
|
||||
|
||||
it('applies default strokeWidth if only strokeColor is given', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
strokeColor: '#ff0000'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral();
|
||||
expect(literal).toBeA(ol.style.PolygonLiteral);
|
||||
expect(literal.strokeColor).toBe('#ff0000');
|
||||
expect(literal.strokeWidth).toBe(1.5);
|
||||
expect(literal.fillColor).toBeUndefined();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Expression');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.style.Polygon');
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
@@ -0,0 +1,33 @@
|
||||
goog.provide('ol.test.style.Rule');
|
||||
|
||||
describe('ol.style.Rule', function() {
|
||||
|
||||
describe('#applies()', function() {
|
||||
var feature = new ol.Feature(),
|
||||
rule;
|
||||
|
||||
it('returns true for a rule without filter', function() {
|
||||
rule = new ol.style.Rule({});
|
||||
expect(rule.applies(feature)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false when the rule does not apply', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.filter.Filter(function() { return false; })
|
||||
});
|
||||
expect(rule.applies(feature)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true when the rule applies', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.filter.Filter(function() { return true; })
|
||||
});
|
||||
expect(rule.applies(feature)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.filter.Filter');
|
||||
goog.require('ol.style.Rule');
|
||||
@@ -0,0 +1,126 @@
|
||||
goog.provide('ol.test.style.Shape');
|
||||
|
||||
describe('ol.style.ShapeLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 4,
|
||||
fillColor: '#BADA55',
|
||||
strokeColor: '#013',
|
||||
strokeWidth: 3,
|
||||
opacity: 1
|
||||
});
|
||||
var equalLiteral = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 4,
|
||||
fillColor: '#BADA55',
|
||||
strokeColor: '#013',
|
||||
strokeWidth: 3,
|
||||
opacity: 1
|
||||
});
|
||||
var differentLiteral = new ol.style.ShapeLiteral({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 4,
|
||||
fillColor: '#013',
|
||||
strokeColor: '#013',
|
||||
strokeWidth: 3,
|
||||
opacity: 1
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).toBe(true);
|
||||
expect(literal.equals(differentLiteral)).toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.Shape', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: 4,
|
||||
fillColor: '#BADA55'
|
||||
});
|
||||
expect(symbolizer).toBeA(ol.style.Shape);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: new ol.Expression('sizeAttr'),
|
||||
strokeColor: new ol.Expression('color')
|
||||
});
|
||||
expect(symbolizer).toBeA(ol.style.Shape);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: new ol.Expression('sizeAttr'),
|
||||
opacity: new ol.Expression('opacityAttr'),
|
||||
fillColor: '#BADA55'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
sizeAttr: 42,
|
||||
opacityAttr: 0.4
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).toBeA(ol.style.ShapeLiteral);
|
||||
expect(literal.size).toBe(42);
|
||||
expect(literal.opacity).toBe(0.4);
|
||||
});
|
||||
|
||||
it('can be called without a feature', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: 10,
|
||||
opacity: 1,
|
||||
fillColor: '#BADA55',
|
||||
strokeColor: '#013',
|
||||
strokeWidth: 2
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral();
|
||||
expect(literal).toBeA(ol.style.ShapeLiteral);
|
||||
expect(literal.size).toBe(10);
|
||||
expect(literal.opacity).toBe(1);
|
||||
expect(literal.fillColor).toBe('#BADA55');
|
||||
expect(literal.strokeColor).toBe('#013');
|
||||
expect(literal.strokeWidth).toBe(2);
|
||||
});
|
||||
|
||||
it('applies default type if none provided', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: new ol.Expression('sizeAttr'),
|
||||
opacity: new ol.Expression('opacityAttr'),
|
||||
fillColor: '#BADA55'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
sizeAttr: 42,
|
||||
opacityAttr: 0.4
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).toBeA(ol.style.ShapeLiteral);
|
||||
expect(literal.size).toBe(42);
|
||||
expect(literal.opacity).toBe(0.4);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Expression');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.style.Shape');
|
||||
goog.require('ol.style.ShapeLiteral');
|
||||
goog.require('ol.style.ShapeType');
|
||||
@@ -0,0 +1,73 @@
|
||||
goog.provide('ol.test.style.Style');
|
||||
|
||||
describe('ol.style.Style', function() {
|
||||
|
||||
describe('#apply()', function() {
|
||||
|
||||
it('applies a style to a feature', function() {
|
||||
|
||||
var style = new ol.style.Style({
|
||||
rules: [
|
||||
new ol.style.Rule({
|
||||
filter: new ol.filter.Filter(function(feature) {
|
||||
return feature.get('foo') == 'bar';
|
||||
}),
|
||||
symbolizers: [
|
||||
new ol.style.Shape({
|
||||
size: 4,
|
||||
fillColor: '#BADA55'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
});
|
||||
var feature = new ol.Feature();
|
||||
feature.set('foo', 'bar');
|
||||
expect(style.apply(feature).length).toBe(1);
|
||||
expect(style.apply(feature)[0].fillColor).toBe('#BADA55');
|
||||
feature.set('foo', 'baz');
|
||||
expect(style.apply(feature).length).toBe(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.Style.applyDefaultStyle()', function() {
|
||||
var feature = new ol.Feature();
|
||||
|
||||
it('returns an empty array for features without geometry', function() {
|
||||
expect(ol.style.Style.applyDefaultStyle(feature).length).toBe(0);
|
||||
});
|
||||
|
||||
it('returns an array with the Shape default for points', function() {
|
||||
feature.setGeometry(new ol.geom.Point([0, 0]));
|
||||
var symbolizers = ol.style.Style.applyDefaultStyle(feature);
|
||||
expect(symbolizers.length).toBe(1);
|
||||
expect(symbolizers[0]).toBeA(ol.style.ShapeLiteral);
|
||||
expect(symbolizers[0].equals(ol.style.ShapeDefaults)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns an array with the Line default for lines', function() {
|
||||
feature.setGeometry(new ol.geom.LineString([[0, 0], [1, 1]]));
|
||||
expect(ol.style.Style.applyDefaultStyle(feature)[0]
|
||||
.equals(ol.style.LineDefaults)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns an array with the Polygon default for polygons', function() {
|
||||
feature.setGeometry(new ol.geom.Polygon([[[0, 0], [1, 1], [0, 0]]]));
|
||||
expect(ol.style.Style.applyDefaultStyle(feature)[0]
|
||||
.equals(ol.style.PolygonDefaults)).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.filter.Filter');
|
||||
goog.require('ol.style.Rule');
|
||||
goog.require('ol.style.Shape');
|
||||
goog.require('ol.style.ShapeLiteral');
|
||||
goog.require('ol.style.Style');
|
||||
Reference in New Issue
Block a user