Merge pull request #1758 from tschaub/get-features
Rename vector source methods.
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
@exportProperty ol.source.Vector.prototype.addFeatures
|
@exportProperty ol.source.Vector.prototype.addFeatures
|
||||||
@exportProperty ol.source.Vector.prototype.forEachFeature
|
@exportProperty ol.source.Vector.prototype.forEachFeature
|
||||||
@exportProperty ol.source.Vector.prototype.forEachFeatureInExtent
|
@exportProperty ol.source.Vector.prototype.forEachFeatureInExtent
|
||||||
@exportProperty ol.source.Vector.prototype.getAllFeatures
|
@exportProperty ol.source.Vector.prototype.getFeatures
|
||||||
@exportProperty ol.source.Vector.prototype.getAllFeaturesAtCoordinate
|
@exportProperty ol.source.Vector.prototype.getFeaturesAtCoordinate
|
||||||
@exportProperty ol.source.Vector.prototype.getClosestFeatureToCoordinate
|
@exportProperty ol.source.Vector.prototype.getClosestFeatureToCoordinate
|
||||||
@exportProperty ol.source.Vector.prototype.getExtent
|
@exportProperty ol.source.Vector.prototype.getExtent
|
||||||
@exportProperty ol.source.Vector.prototype.removeFeature
|
@exportProperty ol.source.Vector.prototype.removeFeature
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ ol.source.Vector.prototype.forEachFeatureInExtent =
|
|||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @todo stability experimental
|
* @todo stability experimental
|
||||||
*/
|
*/
|
||||||
ol.source.Vector.prototype.getAllFeatures = function() {
|
ol.source.Vector.prototype.getFeatures = function() {
|
||||||
var features = this.rBush_.getAll();
|
var features = this.rBush_.getAll();
|
||||||
if (!goog.object.isEmpty(this.nullGeometryFeatures_)) {
|
if (!goog.object.isEmpty(this.nullGeometryFeatures_)) {
|
||||||
goog.array.extend(
|
goog.array.extend(
|
||||||
@@ -208,7 +208,7 @@ ol.source.Vector.prototype.getAllFeatures = function() {
|
|||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @todo stability experimental
|
* @todo stability experimental
|
||||||
*/
|
*/
|
||||||
ol.source.Vector.prototype.getAllFeaturesAtCoordinate = function(coordinate) {
|
ol.source.Vector.prototype.getFeaturesAtCoordinate = function(coordinate) {
|
||||||
var features = [];
|
var features = [];
|
||||||
this.forEachFeatureAtCoordinate(coordinate, function(feature) {
|
this.forEachFeatureAtCoordinate(coordinate, function(feature) {
|
||||||
features.push(feature);
|
features.push(feature);
|
||||||
@@ -222,7 +222,7 @@ ol.source.Vector.prototype.getAllFeaturesAtCoordinate = function(coordinate) {
|
|||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @todo stability experimental
|
* @todo stability experimental
|
||||||
*/
|
*/
|
||||||
ol.source.Vector.prototype.getAllFeaturesInExtent = function(extent) {
|
ol.source.Vector.prototype.getFeaturesInExtent = function(extent) {
|
||||||
return this.rBush_.getAllInExtent(extent);
|
return this.rBush_.getAllInExtent(extent);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ describe('ol.interaction.Draw', function() {
|
|||||||
simulateEvent('mousedown', 10, 20);
|
simulateEvent('mousedown', 10, 20);
|
||||||
simulateEvent('mouseup', 10, 20);
|
simulateEvent('mouseup', 10, 20);
|
||||||
simulateEvent('click', 10, 20);
|
simulateEvent('click', 10, 20);
|
||||||
var features = source.getAllFeatures();
|
var features = source.getFeatures();
|
||||||
expect(features).to.have.length(1);
|
expect(features).to.have.length(1);
|
||||||
var geometry = features[0].getGeometry();
|
var geometry = features[0].getGeometry();
|
||||||
expect(geometry).to.be.a(ol.geom.Point);
|
expect(geometry).to.be.a(ol.geom.Point);
|
||||||
@@ -98,7 +98,7 @@ describe('ol.interaction.Draw', function() {
|
|||||||
simulateEvent('mousemove', 15, 20);
|
simulateEvent('mousemove', 15, 20);
|
||||||
simulateEvent('mouseup', 15, 20);
|
simulateEvent('mouseup', 15, 20);
|
||||||
simulateEvent('click', 15, 20);
|
simulateEvent('click', 15, 20);
|
||||||
var features = source.getAllFeatures();
|
var features = source.getFeatures();
|
||||||
expect(features).to.have.length(0);
|
expect(features).to.have.length(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ describe('ol.interaction.Draw', function() {
|
|||||||
simulateEvent('mousedown', 30, 15);
|
simulateEvent('mousedown', 30, 15);
|
||||||
simulateEvent('mouseup', 30, 15);
|
simulateEvent('mouseup', 30, 15);
|
||||||
simulateEvent('click', 30, 15);
|
simulateEvent('click', 30, 15);
|
||||||
var features = source.getAllFeatures();
|
var features = source.getFeatures();
|
||||||
expect(features).to.have.length(1);
|
expect(features).to.have.length(1);
|
||||||
var geometry = features[0].getGeometry();
|
var geometry = features[0].getGeometry();
|
||||||
expect(geometry).to.be.a(ol.geom.MultiPoint);
|
expect(geometry).to.be.a(ol.geom.MultiPoint);
|
||||||
@@ -170,7 +170,7 @@ describe('ol.interaction.Draw', function() {
|
|||||||
simulateEvent('mouseup', 30, 20);
|
simulateEvent('mouseup', 30, 20);
|
||||||
simulateEvent('click', 30, 20);
|
simulateEvent('click', 30, 20);
|
||||||
|
|
||||||
var features = source.getAllFeatures();
|
var features = source.getFeatures();
|
||||||
expect(features).to.have.length(1);
|
expect(features).to.have.length(1);
|
||||||
var geometry = features[0].getGeometry();
|
var geometry = features[0].getGeometry();
|
||||||
expect(geometry).to.be.a(ol.geom.LineString);
|
expect(geometry).to.be.a(ol.geom.LineString);
|
||||||
@@ -203,7 +203,7 @@ describe('ol.interaction.Draw', function() {
|
|||||||
simulateEvent('mouseup', 30, 20);
|
simulateEvent('mouseup', 30, 20);
|
||||||
simulateEvent('click', 30, 20);
|
simulateEvent('click', 30, 20);
|
||||||
|
|
||||||
var features = source.getAllFeatures();
|
var features = source.getFeatures();
|
||||||
expect(features).to.have.length(1);
|
expect(features).to.have.length(1);
|
||||||
var geometry = features[0].getGeometry();
|
var geometry = features[0].getGeometry();
|
||||||
expect(geometry).to.be.a(ol.geom.LineString);
|
expect(geometry).to.be.a(ol.geom.LineString);
|
||||||
@@ -267,7 +267,7 @@ describe('ol.interaction.Draw', function() {
|
|||||||
simulateEvent('mouseup', 30, 20);
|
simulateEvent('mouseup', 30, 20);
|
||||||
simulateEvent('click', 30, 20);
|
simulateEvent('click', 30, 20);
|
||||||
|
|
||||||
var features = source.getAllFeatures();
|
var features = source.getFeatures();
|
||||||
expect(features).to.have.length(1);
|
expect(features).to.have.length(1);
|
||||||
var geometry = features[0].getGeometry();
|
var geometry = features[0].getGeometry();
|
||||||
expect(geometry).to.be.a(ol.geom.MultiLineString);
|
expect(geometry).to.be.a(ol.geom.MultiLineString);
|
||||||
@@ -312,7 +312,7 @@ describe('ol.interaction.Draw', function() {
|
|||||||
simulateEvent('mouseup', 10, 20);
|
simulateEvent('mouseup', 10, 20);
|
||||||
simulateEvent('click', 10, 20);
|
simulateEvent('click', 10, 20);
|
||||||
|
|
||||||
var features = source.getAllFeatures();
|
var features = source.getFeatures();
|
||||||
expect(features).to.have.length(1);
|
expect(features).to.have.length(1);
|
||||||
var geometry = features[0].getGeometry();
|
var geometry = features[0].getGeometry();
|
||||||
expect(geometry).to.be.a(ol.geom.Polygon);
|
expect(geometry).to.be.a(ol.geom.Polygon);
|
||||||
@@ -346,7 +346,7 @@ describe('ol.interaction.Draw', function() {
|
|||||||
simulateEvent('mouseup', 40, 10);
|
simulateEvent('mouseup', 40, 10);
|
||||||
simulateEvent('click', 40, 11);
|
simulateEvent('click', 40, 11);
|
||||||
|
|
||||||
var features = source.getAllFeatures();
|
var features = source.getFeatures();
|
||||||
expect(features).to.have.length(1);
|
expect(features).to.have.length(1);
|
||||||
var geometry = features[0].getGeometry();
|
var geometry = features[0].getGeometry();
|
||||||
expect(geometry).to.be.a(ol.geom.Polygon);
|
expect(geometry).to.be.a(ol.geom.Polygon);
|
||||||
@@ -426,7 +426,7 @@ describe('ol.interaction.Draw', function() {
|
|||||||
simulateEvent('mouseup', 10, 20);
|
simulateEvent('mouseup', 10, 20);
|
||||||
simulateEvent('click', 10, 20);
|
simulateEvent('click', 10, 20);
|
||||||
|
|
||||||
var features = source.getAllFeatures();
|
var features = source.getFeatures();
|
||||||
expect(features).to.have.length(1);
|
expect(features).to.have.length(1);
|
||||||
var geometry = features[0].getGeometry();
|
var geometry = features[0].getGeometry();
|
||||||
expect(geometry).to.be.a(ol.geom.MultiPolygon);
|
expect(geometry).to.be.a(ol.geom.MultiPolygon);
|
||||||
@@ -462,7 +462,7 @@ describe('ol.interaction.Draw', function() {
|
|||||||
simulateEvent('mouseup', 40, 10);
|
simulateEvent('mouseup', 40, 10);
|
||||||
simulateEvent('click', 40, 10);
|
simulateEvent('click', 40, 10);
|
||||||
|
|
||||||
var features = source.getAllFeatures();
|
var features = source.getFeatures();
|
||||||
expect(features).to.have.length(1);
|
expect(features).to.have.length(1);
|
||||||
var geometry = features[0].getGeometry();
|
var geometry = features[0].getGeometry();
|
||||||
expect(geometry).to.be.a(ol.geom.MultiPolygon);
|
expect(geometry).to.be.a(ol.geom.MultiPolygon);
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ describe('ol.source.Vector', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#getAllFeaturesInExtent', function() {
|
describe('#getFeaturesInExtent', function() {
|
||||||
|
|
||||||
it('returns an empty array', 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.an(Array);
|
||||||
expect(features).to.be.empty();
|
expect(features).to.be.empty();
|
||||||
});
|
});
|
||||||
@@ -49,7 +49,7 @@ describe('ol.source.Vector', function() {
|
|||||||
|
|
||||||
it('can add a single point feature', function() {
|
it('can add a single point feature', function() {
|
||||||
vectorSource.addFeature(pointFeature);
|
vectorSource.addFeature(pointFeature);
|
||||||
var features = vectorSource.getAllFeaturesInExtent(infiniteExtent);
|
var features = vectorSource.getFeaturesInExtent(infiniteExtent);
|
||||||
expect(features).to.be.an(Array);
|
expect(features).to.be.an(Array);
|
||||||
expect(features).to.have.length(1);
|
expect(features).to.have.length(1);
|
||||||
expect(features[0]).to.be(pointFeature);
|
expect(features[0]).to.be(pointFeature);
|
||||||
@@ -91,7 +91,7 @@ describe('ol.source.Vector', function() {
|
|||||||
var removeFeatureSpy = sinon.spy();
|
var removeFeatureSpy = sinon.spy();
|
||||||
goog.events.listen(vectorSource, 'removefeature', removeFeatureSpy);
|
goog.events.listen(vectorSource, 'removefeature', removeFeatureSpy);
|
||||||
vectorSource.clear();
|
vectorSource.clear();
|
||||||
expect(vectorSource.getAllFeatures()).to.eql([]);
|
expect(vectorSource.getFeatures()).to.eql([]);
|
||||||
expect(vectorSource.isEmpty()).to.be(true);
|
expect(vectorSource.isEmpty()).to.be(true);
|
||||||
expect(changeSpy).to.be.called();
|
expect(changeSpy).to.be.called();
|
||||||
expect(changeSpy.callCount).to.be(1);
|
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() {
|
it('returns the expected number of features', function() {
|
||||||
expect(vectorSource.getAllFeaturesInExtent(infiniteExtent)).
|
expect(vectorSource.getFeaturesInExtent(infiniteExtent)).
|
||||||
to.have.length(10);
|
to.have.length(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ describe('ol.source.Vector', function() {
|
|||||||
var i;
|
var i;
|
||||||
for (i = features.length - 1; i >= 0; --i) {
|
for (i = features.length - 1; i >= 0; --i) {
|
||||||
vectorSource.removeFeature(features[i]);
|
vectorSource.removeFeature(features[i]);
|
||||||
expect(vectorSource.getAllFeaturesInExtent(infiniteExtent)).
|
expect(vectorSource.getFeaturesInExtent(infiniteExtent)).
|
||||||
have.length(i);
|
have.length(i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -161,13 +161,13 @@ describe('ol.source.Vector', function() {
|
|||||||
describe('modifying a feature\'s geometry', function() {
|
describe('modifying a feature\'s geometry', function() {
|
||||||
|
|
||||||
it('keeps the R-Tree index up to date', 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);
|
to.have.length(10);
|
||||||
features[0].getGeometry().setCoordinates([100, 100]);
|
features[0].getGeometry().setCoordinates([100, 100]);
|
||||||
expect(vectorSource.getAllFeaturesInExtent([0, 0, 1, 1])).
|
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
|
||||||
to.have.length(9);
|
to.have.length(9);
|
||||||
features[0].getGeometry().setCoordinates([0.5, 0.5]);
|
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);
|
to.have.length(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -176,10 +176,10 @@ describe('ol.source.Vector', function() {
|
|||||||
describe('setting a features geometry', function() {
|
describe('setting a features geometry', function() {
|
||||||
|
|
||||||
it('keeps the R-Tree index up to date', 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);
|
to.have.length(10);
|
||||||
features[0].setGeometry(new ol.geom.Point([100, 100]));
|
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);
|
to.have.length(9);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -197,40 +197,40 @@ describe('ol.source.Vector', function() {
|
|||||||
it('keeps its index up-to-date', function() {
|
it('keeps its index up-to-date', function() {
|
||||||
var feature = new ol.Feature(new ol.geom.Point([1, 1]));
|
var feature = new ol.Feature(new ol.geom.Point([1, 1]));
|
||||||
vectorSource.addFeature(feature);
|
vectorSource.addFeature(feature);
|
||||||
expect(vectorSource.getAllFeaturesInExtent([0, 0, 2, 2])).
|
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
|
||||||
to.eql([feature]);
|
to.eql([feature]);
|
||||||
feature.getGeometry().setCoordinates([3, 3]);
|
feature.getGeometry().setCoordinates([3, 3]);
|
||||||
expect(vectorSource.getAllFeaturesInExtent([0, 0, 2, 2])).
|
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
|
||||||
to.be.empty();
|
to.be.empty();
|
||||||
expect(vectorSource.getAllFeaturesInExtent([2, 2, 4, 4])).
|
expect(vectorSource.getFeaturesInExtent([2, 2, 4, 4])).
|
||||||
to.eql([feature]);
|
to.eql([feature]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles features with null geometries', function() {
|
it('handles features with null geometries', function() {
|
||||||
var feature = new ol.Feature(null);
|
var feature = new ol.Feature(null);
|
||||||
vectorSource.addFeature(feature);
|
vectorSource.addFeature(feature);
|
||||||
expect(vectorSource.getAllFeatures()).to.eql([feature]);
|
expect(vectorSource.getFeatures()).to.eql([feature]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles features with geometries changing from null', function() {
|
it('handles features with geometries changing from null', function() {
|
||||||
var feature = new ol.Feature(null);
|
var feature = new ol.Feature(null);
|
||||||
vectorSource.addFeature(feature);
|
vectorSource.addFeature(feature);
|
||||||
expect(vectorSource.getAllFeatures()).to.eql([feature]);
|
expect(vectorSource.getFeatures()).to.eql([feature]);
|
||||||
feature.setGeometry(new ol.geom.Point([1, 1]));
|
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]);
|
to.eql([feature]);
|
||||||
expect(vectorSource.getAllFeatures()).to.eql([feature]);
|
expect(vectorSource.getFeatures()).to.eql([feature]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles features with geometries changing to null', function() {
|
it('handles features with geometries changing to null', function() {
|
||||||
var feature = new ol.Feature(new ol.geom.Point([1, 1]));
|
var feature = new ol.Feature(new ol.geom.Point([1, 1]));
|
||||||
vectorSource.addFeature(feature);
|
vectorSource.addFeature(feature);
|
||||||
expect(vectorSource.getAllFeatures()).to.eql([feature]);
|
expect(vectorSource.getFeatures()).to.eql([feature]);
|
||||||
expect(vectorSource.getAllFeaturesInExtent([0, 0, 2, 2])).
|
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
|
||||||
to.eql([feature]);
|
to.eql([feature]);
|
||||||
feature.setGeometry(null);
|
feature.setGeometry(null);
|
||||||
expect(vectorSource.getAllFeaturesInExtent([0, 0, 2, 2])).to.be.empty();
|
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).to.be.empty();
|
||||||
expect(vectorSource.getAllFeatures()).to.eql([feature]);
|
expect(vectorSource.getFeatures()).to.eql([feature]);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user