Refactor AND Fixed description Intersects and Within filters into ol.format.wfs

This commit is contained in:
cpsTinK
2016-08-03 13:18:56 +04:00
parent 9150fa2a60
commit 18101ad0e2
2 changed files with 35 additions and 30 deletions

View File

@@ -76,7 +76,7 @@ ol.format.ogc.filter.bbox = function(geometryName, extent, opt_srsName) {
/** /**
* Create a `<Intersects>` operator to test whether a geometry-valued property * Create a `<Intersects>` operator to test whether a geometry-valued property
* intersects a fixed bounding geometry * intersects a given geometry.
* *
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!ol.geom.Geometry} geometry Geometry. * @param {!ol.geom.Geometry} geometry Geometry.
@@ -91,7 +91,7 @@ ol.format.ogc.filter.intersects = function(geometryName, geometry, opt_srsName)
/** /**
* Create a `<Within>` operator to test whether a geometry-valued property * Create a `<Within>` operator to test whether a geometry-valued property
* intersects a fixed bounding geometry * is within a given geometry.
* *
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!ol.geom.Geometry} geometry Geometry. * @param {!ol.geom.Geometry} geometry Geometry.
@@ -410,10 +410,11 @@ ol.inherits(ol.format.ogc.filter.Bbox, ol.format.ogc.filter.Filter);
/** /**
* @classdesc * @classdesc
* Represents a `<Intersects>` operator to test whether a geometry-valued property * Represents a spatial operator to test whether a geometry-valued property
* intersects a fixed bounding geometry * relates to a given geometry.
* *
* @constructor * @constructor
* @param {!string} tagName The XML tag name for this filter.
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!ol.geom.Geometry} geometry Geometry. * @param {!ol.geom.Geometry} geometry Geometry.
* @param {string=} opt_srsName SRS name. No srsName attribute will be * @param {string=} opt_srsName SRS name. No srsName attribute will be
@@ -421,9 +422,9 @@ ol.inherits(ol.format.ogc.filter.Bbox, ol.format.ogc.filter.Filter);
* @extends {ol.format.ogc.filter.Filter} * @extends {ol.format.ogc.filter.Filter}
* @api * @api
*/ */
ol.format.ogc.filter.Intersects = function(geometryName, geometry, opt_srsName) { ol.format.ogc.filter.Spatial = function(tagName, geometryName, geometry, opt_srsName) {
ol.format.ogc.filter.Filter.call(this, 'Intersects'); ol.format.ogc.filter.Filter.call(this, tagName);
/** /**
* @public * @public
@@ -443,45 +444,49 @@ ol.format.ogc.filter.Intersects = function(geometryName, geometry, opt_srsName)
*/ */
this.srsName = opt_srsName; this.srsName = opt_srsName;
}; };
ol.inherits(ol.format.ogc.filter.Intersects, ol.format.ogc.filter.Filter); ol.inherits(ol.format.ogc.filter.Spatial, ol.format.ogc.filter.Filter);
/**
* @classdesc
* Represents a `<Intersects>` operator to test whether a geometry-valued property
* intersects a given geometry.
*
* @constructor
* @param {!string} geometryName Geometry name to use.
* @param {!ol.geom.Geometry} geometry Geometry.
* @param {string=} opt_srsName SRS name. No srsName attribute will be
* set on geometries when this is not provided.
* @extends {ol.format.ogc.filter.Spatial}
* @api
*/
ol.format.ogc.filter.Intersects = function(geometryName, geometry, opt_srsName) {
ol.format.ogc.filter.Spatial.call(this, 'Intersects', geometryName, geometry, opt_srsName);
};
ol.inherits(ol.format.ogc.filter.Intersects, ol.format.ogc.filter.Spatial);
/** /**
* @classdesc * @classdesc
* Represents a `<Within>` operator to test whether a geometry-valued property * Represents a `<Within>` operator to test whether a geometry-valued property
* within a fixed bounding geometry * is within a given geometry.
* *
* @constructor * @constructor
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!ol.geom.Geometry} geometry Geometry. * @param {!ol.geom.Geometry} geometry Geometry.
* @param {string=} opt_srsName SRS name. No srsName attribute will be * @param {string=} opt_srsName SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
* @extends {ol.format.ogc.filter.Filter} * @extends {ol.format.ogc.filter.Spatial}
* @api * @api
*/ */
ol.format.ogc.filter.Within = function(geometryName, geometry, opt_srsName) { ol.format.ogc.filter.Within = function(geometryName, geometry, opt_srsName) {
ol.format.ogc.filter.Filter.call(this, 'Within'); ol.format.ogc.filter.Spatial.call(this, 'Within', geometryName, geometry, opt_srsName);
/**
* @public
* @type {!string}
*/
this.geometryName = geometryName || 'the_geom';
/**
* @public
* @type {ol.geom.Geometry}
*/
this.geometry = geometry;
/**
* @public
* @type {string|undefined}
*/
this.srsName = opt_srsName;
}; };
ol.inherits(ol.format.ogc.filter.Within, ol.format.ogc.filter.Filter); ol.inherits(ol.format.ogc.filter.Within, ol.format.ogc.filter.Spatial);
// Property comparison filters // Property comparison filters

View File

@@ -504,7 +504,7 @@ describe('ol.format.WFS', function() {
expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text));
}); });
it('creates an AND intersects filter', function() { it('creates a intersects filter', function() {
var text = var text =
'<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" ' + '<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" ' +
' typeName="area" srsName="EPSG:4326" ' + ' typeName="area" srsName="EPSG:4326" ' +
@@ -542,7 +542,7 @@ describe('ol.format.WFS', function() {
expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text));
}); });
it('creates an AND within filter', function() { it('creates a within filter', function() {
var text = var text =
'<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" ' + '<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" ' +
' typeName="area" srsName="EPSG:4326" ' + ' typeName="area" srsName="EPSG:4326" ' +