Treating geometry as just another attribute
The first set geometry is considered the default. As an added bonus, we're back to a single argument constructor. Later, we could allow a schema to be set. This would be done before setting values (calling constructor with no args).
This commit is contained in:
161
test/spec/ol/feature.test.js
Normal file
161
test/spec/ol/feature.test.js
Normal file
@@ -0,0 +1,161 @@
|
||||
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('#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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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('ol.Feature');
|
||||
goog.require('ol.geom.Point');
|
||||
@@ -21,9 +21,9 @@ describe('ol.filter.Extent', function() {
|
||||
describe('#evaluate()', function() {
|
||||
|
||||
it('returns true if a feature intersects, false if not', function() {
|
||||
expect(filter.evaluate(new ol.Feature(new ol.geom.Point([44, 89]))))
|
||||
expect(filter.evaluate(new ol.Feature({g: new ol.geom.Point([44, 89])})))
|
||||
.toBe(true);
|
||||
expect(filter.evaluate(new ol.Feature(new ol.geom.Point([46, 91]))))
|
||||
expect(filter.evaluate(new ol.Feature({g: new ol.geom.Point([46, 91])})))
|
||||
.toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -22,14 +22,30 @@ describe('ol.source.Vector', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
features = [
|
||||
new ol.Feature(new ol.geom.Point([16.0, 48.0])),
|
||||
new ol.Feature(new ol.geom.Point([16.1, 48.1])),
|
||||
new ol.Feature(new ol.geom.Point([16.2, 48.2])),
|
||||
new ol.Feature(new ol.geom.Point([16.3, 48.3])),
|
||||
new ol.Feature(new ol.geom.LineString([[16.4, 48.4], [16.5, 48.5]])),
|
||||
new ol.Feature(new ol.geom.LineString([[16.6, 48.6], [16.7, 48.7]])),
|
||||
new ol.Feature(new ol.geom.LineString([[16.8, 48.8], [16.9, 48.9]])),
|
||||
new ol.Feature(new ol.geom.LineString([[17.0, 49.0], [17.1, 49.1]]))
|
||||
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]])
|
||||
})
|
||||
];
|
||||
vectorSource = new ol.source.Vector({
|
||||
projection: ol.Projection.getFromCode('EPSG:4326')
|
||||
@@ -71,8 +87,7 @@ describe('ol.source.Vector', function() {
|
||||
expect(subset2.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('can handle any query using the filter\'s evaluate function',
|
||||
function() {
|
||||
it('can handle query using the filter\'s evaluate function', function() {
|
||||
var filter = new ol.filter.Logical([geomFilter, extentFilter],
|
||||
ol.filter.LogicalOperator.OR);
|
||||
spyOn(filter, 'evaluate').andCallThrough();
|
||||
|
||||
@@ -30,7 +30,7 @@ describe('ol.style.Line', function() {
|
||||
strokeWidth: ol.Expression('widthAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature(undefined, {
|
||||
var feature = new ol.Feature({
|
||||
value: 42,
|
||||
widthAttr: 1.5
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ describe('ol.style.Polygon', function() {
|
||||
fillStyle: new ol.Expression('fillAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature(undefined, {
|
||||
var feature = new ol.Feature({
|
||||
value: 42,
|
||||
fillAttr: '#ff0000'
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ describe('ol.style.Shape', function() {
|
||||
opacity: new ol.Expression('opacityAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature(undefined, {
|
||||
var feature = new ol.Feature({
|
||||
sizeAttr: 42,
|
||||
opacityAttr: 0.4
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user