Merge pull request #1758 from tschaub/get-features

Rename vector source methods.
This commit is contained in:
Tim Schaub
2014-03-05 17:27:36 -07:00
4 changed files with 38 additions and 38 deletions

View File

@@ -3,8 +3,8 @@
@exportProperty ol.source.Vector.prototype.addFeatures
@exportProperty ol.source.Vector.prototype.forEachFeature
@exportProperty ol.source.Vector.prototype.forEachFeatureInExtent
@exportProperty ol.source.Vector.prototype.getAllFeatures
@exportProperty ol.source.Vector.prototype.getAllFeaturesAtCoordinate
@exportProperty ol.source.Vector.prototype.getFeatures
@exportProperty ol.source.Vector.prototype.getFeaturesAtCoordinate
@exportProperty ol.source.Vector.prototype.getClosestFeatureToCoordinate
@exportProperty ol.source.Vector.prototype.getExtent
@exportProperty ol.source.Vector.prototype.removeFeature

View File

@@ -193,7 +193,7 @@ ol.source.Vector.prototype.forEachFeatureInExtent =
* @return {Array.<ol.Feature>} Features.
* @todo stability experimental
*/
ol.source.Vector.prototype.getAllFeatures = function() {
ol.source.Vector.prototype.getFeatures = function() {
var features = this.rBush_.getAll();
if (!goog.object.isEmpty(this.nullGeometryFeatures_)) {
goog.array.extend(
@@ -208,7 +208,7 @@ ol.source.Vector.prototype.getAllFeatures = function() {
* @return {Array.<ol.Feature>} Features.
* @todo stability experimental
*/
ol.source.Vector.prototype.getAllFeaturesAtCoordinate = function(coordinate) {
ol.source.Vector.prototype.getFeaturesAtCoordinate = function(coordinate) {
var features = [];
this.forEachFeatureAtCoordinate(coordinate, function(feature) {
features.push(feature);
@@ -222,7 +222,7 @@ ol.source.Vector.prototype.getAllFeaturesAtCoordinate = function(coordinate) {
* @return {Array.<ol.Feature>} Features.
* @todo stability experimental
*/
ol.source.Vector.prototype.getAllFeaturesInExtent = function(extent) {
ol.source.Vector.prototype.getFeaturesInExtent = function(extent) {
return this.rBush_.getAllInExtent(extent);
};

View File

@@ -85,7 +85,7 @@ describe('ol.interaction.Draw', function() {
simulateEvent('mousedown', 10, 20);
simulateEvent('mouseup', 10, 20);
simulateEvent('click', 10, 20);
var features = source.getAllFeatures();
var features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
expect(geometry).to.be.a(ol.geom.Point);
@@ -98,7 +98,7 @@ describe('ol.interaction.Draw', function() {
simulateEvent('mousemove', 15, 20);
simulateEvent('mouseup', 15, 20);
simulateEvent('click', 15, 20);
var features = source.getAllFeatures();
var features = source.getFeatures();
expect(features).to.have.length(0);
});
@@ -132,7 +132,7 @@ describe('ol.interaction.Draw', function() {
simulateEvent('mousedown', 30, 15);
simulateEvent('mouseup', 30, 15);
simulateEvent('click', 30, 15);
var features = source.getAllFeatures();
var features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
expect(geometry).to.be.a(ol.geom.MultiPoint);
@@ -170,7 +170,7 @@ describe('ol.interaction.Draw', function() {
simulateEvent('mouseup', 30, 20);
simulateEvent('click', 30, 20);
var features = source.getAllFeatures();
var features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
expect(geometry).to.be.a(ol.geom.LineString);
@@ -203,7 +203,7 @@ describe('ol.interaction.Draw', function() {
simulateEvent('mouseup', 30, 20);
simulateEvent('click', 30, 20);
var features = source.getAllFeatures();
var features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
expect(geometry).to.be.a(ol.geom.LineString);
@@ -267,7 +267,7 @@ describe('ol.interaction.Draw', function() {
simulateEvent('mouseup', 30, 20);
simulateEvent('click', 30, 20);
var features = source.getAllFeatures();
var features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
expect(geometry).to.be.a(ol.geom.MultiLineString);
@@ -312,7 +312,7 @@ describe('ol.interaction.Draw', function() {
simulateEvent('mouseup', 10, 20);
simulateEvent('click', 10, 20);
var features = source.getAllFeatures();
var features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
expect(geometry).to.be.a(ol.geom.Polygon);
@@ -346,7 +346,7 @@ describe('ol.interaction.Draw', function() {
simulateEvent('mouseup', 40, 10);
simulateEvent('click', 40, 11);
var features = source.getAllFeatures();
var features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
expect(geometry).to.be.a(ol.geom.Polygon);
@@ -426,7 +426,7 @@ describe('ol.interaction.Draw', function() {
simulateEvent('mouseup', 10, 20);
simulateEvent('click', 10, 20);
var features = source.getAllFeatures();
var features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
expect(geometry).to.be.a(ol.geom.MultiPolygon);
@@ -462,7 +462,7 @@ describe('ol.interaction.Draw', function() {
simulateEvent('mouseup', 40, 10);
simulateEvent('click', 40, 10);
var features = source.getAllFeatures();
var features = source.getFeatures();
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
expect(geometry).to.be.a(ol.geom.MultiPolygon);

View File

@@ -27,10 +27,10 @@ describe('ol.source.Vector', function() {
});
describe('#getAllFeaturesInExtent', function() {
describe('#getFeaturesInExtent', function() {
it('returns an empty array', function() {
var features = vectorSource.getAllFeaturesInExtent(infiniteExtent);
var features = vectorSource.getFeaturesInExtent(infiniteExtent);
expect(features).to.be.an(Array);
expect(features).to.be.empty();
});
@@ -49,7 +49,7 @@ describe('ol.source.Vector', function() {
it('can add a single point feature', function() {
vectorSource.addFeature(pointFeature);
var features = vectorSource.getAllFeaturesInExtent(infiniteExtent);
var features = vectorSource.getFeaturesInExtent(infiniteExtent);
expect(features).to.be.an(Array);
expect(features).to.have.length(1);
expect(features[0]).to.be(pointFeature);
@@ -91,7 +91,7 @@ describe('ol.source.Vector', function() {
var removeFeatureSpy = sinon.spy();
goog.events.listen(vectorSource, 'removefeature', removeFeatureSpy);
vectorSource.clear();
expect(vectorSource.getAllFeatures()).to.eql([]);
expect(vectorSource.getFeatures()).to.eql([]);
expect(vectorSource.isEmpty()).to.be(true);
expect(changeSpy).to.be.called();
expect(changeSpy.callCount).to.be(1);
@@ -121,10 +121,10 @@ describe('ol.source.Vector', function() {
});
describe('#getAllFeaturesInExtent', function() {
describe('#getFeaturesInExtent', function() {
it('returns the expected number of features', function() {
expect(vectorSource.getAllFeaturesInExtent(infiniteExtent)).
expect(vectorSource.getFeaturesInExtent(infiniteExtent)).
to.have.length(10);
});
@@ -144,7 +144,7 @@ describe('ol.source.Vector', function() {
var i;
for (i = features.length - 1; i >= 0; --i) {
vectorSource.removeFeature(features[i]);
expect(vectorSource.getAllFeaturesInExtent(infiniteExtent)).
expect(vectorSource.getFeaturesInExtent(infiniteExtent)).
have.length(i);
}
});
@@ -161,13 +161,13 @@ describe('ol.source.Vector', function() {
describe('modifying a feature\'s geometry', function() {
it('keeps the R-Tree index up to date', function() {
expect(vectorSource.getAllFeaturesInExtent([0, 0, 1, 1])).
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
to.have.length(10);
features[0].getGeometry().setCoordinates([100, 100]);
expect(vectorSource.getAllFeaturesInExtent([0, 0, 1, 1])).
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
to.have.length(9);
features[0].getGeometry().setCoordinates([0.5, 0.5]);
expect(vectorSource.getAllFeaturesInExtent([0, 0, 1, 1])).
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
to.have.length(10);
});
@@ -176,10 +176,10 @@ describe('ol.source.Vector', function() {
describe('setting a features geometry', function() {
it('keeps the R-Tree index up to date', function() {
expect(vectorSource.getAllFeaturesInExtent([0, 0, 1, 1])).
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
to.have.length(10);
features[0].setGeometry(new ol.geom.Point([100, 100]));
expect(vectorSource.getAllFeaturesInExtent([0, 0, 1, 1])).
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
to.have.length(9);
});
@@ -197,40 +197,40 @@ describe('ol.source.Vector', function() {
it('keeps its index up-to-date', function() {
var feature = new ol.Feature(new ol.geom.Point([1, 1]));
vectorSource.addFeature(feature);
expect(vectorSource.getAllFeaturesInExtent([0, 0, 2, 2])).
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
to.eql([feature]);
feature.getGeometry().setCoordinates([3, 3]);
expect(vectorSource.getAllFeaturesInExtent([0, 0, 2, 2])).
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
to.be.empty();
expect(vectorSource.getAllFeaturesInExtent([2, 2, 4, 4])).
expect(vectorSource.getFeaturesInExtent([2, 2, 4, 4])).
to.eql([feature]);
});
it('handles features with null geometries', function() {
var feature = new ol.Feature(null);
vectorSource.addFeature(feature);
expect(vectorSource.getAllFeatures()).to.eql([feature]);
expect(vectorSource.getFeatures()).to.eql([feature]);
});
it('handles features with geometries changing from null', function() {
var feature = new ol.Feature(null);
vectorSource.addFeature(feature);
expect(vectorSource.getAllFeatures()).to.eql([feature]);
expect(vectorSource.getFeatures()).to.eql([feature]);
feature.setGeometry(new ol.geom.Point([1, 1]));
expect(vectorSource.getAllFeaturesInExtent([0, 0, 2, 2])).
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
to.eql([feature]);
expect(vectorSource.getAllFeatures()).to.eql([feature]);
expect(vectorSource.getFeatures()).to.eql([feature]);
});
it('handles features with geometries changing to null', function() {
var feature = new ol.Feature(new ol.geom.Point([1, 1]));
vectorSource.addFeature(feature);
expect(vectorSource.getAllFeatures()).to.eql([feature]);
expect(vectorSource.getAllFeaturesInExtent([0, 0, 2, 2])).
expect(vectorSource.getFeatures()).to.eql([feature]);
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
to.eql([feature]);
feature.setGeometry(null);
expect(vectorSource.getAllFeaturesInExtent([0, 0, 2, 2])).to.be.empty();
expect(vectorSource.getAllFeatures()).to.eql([feature]);
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).to.be.empty();
expect(vectorSource.getFeatures()).to.eql([feature]);
});
});