Work with clones rather than the original features

This commit is contained in:
ahocevar
2013-08-19 15:35:21 +02:00
parent fdd79a385a
commit f05629b3c3
6 changed files with 93 additions and 12 deletions

View File

@@ -120,8 +120,8 @@ describe('ol.control.Select', function() {
it('can clear a selection before selecting new features', function() {
select.select([[features[0]]], true);
select.select([[features[1]]], true);
expect(goog.object.getValues(select.layer.featureCache_.idLookup_)[0])
.to.eql(features[1]);
expect(goog.object.getCount(select.layer.featureCache_.idLookup_))
.to.be(1);
});
});

View File

@@ -34,6 +34,24 @@ describe('ol.Feature', function() {
});
describe('#clone()', function() {
it('creates a clone with a cloned geometry', function() {
var feature = new ol.Feature({
loc: new ol.geom.Point([10, 20]),
foo: 'bar'
});
feature.setFeatureId('foo');
var clone = feature.clone();
expect(clone).to.not.be(feature);
expect(clone.get('foo')).to.be('bar');
expect(clone.getFeatureId()).to.be('foo');
expect(clone.getGeometry()).to.not.be(feature.getGeometry());
expect(clone.getGeometry().getCoordinates()).to.eql([10, 20]);
});
});
describe('#get()', function() {
it('returns values set at construction', function() {

View File

@@ -55,6 +55,23 @@ describe('ol.geom.GeometryCollection', function() {
});
describe('#clone()', function() {
it('has a working clone method', 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]);
var clone = multi.clone();
expect(clone).to.not.be(multi);
var components = clone.components;
expect(components[0]).to.eql([10, 20]);
expect(components[1]).to.eql([[10, 20], [30, 40]]);
expect(components[2]).to.eql([outer, inner1, inner2]);
});
});
describe('#getBounds()', function() {
it('returns the bounding extent', function() {