Added Intersects and Within filters into ol.format.wfs
This commit is contained in:
@@ -6,6 +6,8 @@ goog.provide('ol.format.ogc.filter.And');
|
||||
goog.provide('ol.format.ogc.filter.Or');
|
||||
goog.provide('ol.format.ogc.filter.Not');
|
||||
goog.provide('ol.format.ogc.filter.Bbox');
|
||||
goog.provide('ol.format.ogc.filter.Intersects');
|
||||
goog.provide('ol.format.ogc.filter.Within');
|
||||
goog.provide('ol.format.ogc.filter.Comparison');
|
||||
goog.provide('ol.format.ogc.filter.ComparisonBinary');
|
||||
goog.provide('ol.format.ogc.filter.EqualTo');
|
||||
@@ -72,6 +74,36 @@ ol.format.ogc.filter.bbox = function(geometryName, extent, opt_srsName) {
|
||||
return new ol.format.ogc.filter.Bbox(geometryName, extent, opt_srsName);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a `<Intersects>` operator to test whether a geometry-valued property
|
||||
* intersects a fixed bounding geometry
|
||||
*
|
||||
* @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.
|
||||
* @returns {!ol.format.ogc.filter.Intersects} `<Intersects>` operator.
|
||||
* @api
|
||||
*/
|
||||
ol.format.ogc.filter.intersects = function(geometryName, geometry, opt_srsName) {
|
||||
return new ol.format.ogc.filter.Intersects(geometryName, geometry, opt_srsName);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a `<Within>` operator to test whether a geometry-valued property
|
||||
* intersects a fixed bounding geometry
|
||||
*
|
||||
* @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.
|
||||
* @returns {!ol.format.ogc.filter.Within} `<Within>` operator.
|
||||
* @api
|
||||
*/
|
||||
ol.format.ogc.filter.within = function(geometryName, geometry, opt_srsName) {
|
||||
return new ol.format.ogc.filter.Within(geometryName, geometry, opt_srsName);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates a `<PropertyIsEqualTo>` comparison operator.
|
||||
@@ -376,6 +408,82 @@ ol.format.ogc.filter.Bbox = function(geometryName, extent, opt_srsName) {
|
||||
ol.inherits(ol.format.ogc.filter.Bbox, ol.format.ogc.filter.Filter);
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Represents a `<Intersects>` operator to test whether a geometry-valued property
|
||||
* intersects a fixed bounding 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.Filter}
|
||||
* @api
|
||||
*/
|
||||
ol.format.ogc.filter.Intersects = function(geometryName, geometry, opt_srsName) {
|
||||
|
||||
ol.format.ogc.filter.Filter.call(this, 'Intersects');
|
||||
|
||||
/**
|
||||
* @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.Intersects, ol.format.ogc.filter.Filter);
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Represents a `<Within>` operator to test whether a geometry-valued property
|
||||
* within a fixed bounding 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.Filter}
|
||||
* @api
|
||||
*/
|
||||
ol.format.ogc.filter.Within = function(geometryName, geometry, opt_srsName) {
|
||||
|
||||
ol.format.ogc.filter.Filter.call(this, 'Within');
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
|
||||
// Property comparison filters
|
||||
|
||||
|
||||
|
||||
@@ -582,6 +582,44 @@ ol.format.WFS.writeBboxFilter_ = function(node, filter, objectStack) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.format.ogc.filter.Filter} filter Filter.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeIntersectsFilter_ = function(node, filter, objectStack) {
|
||||
goog.asserts.assertInstanceof(filter, ol.format.ogc.filter.Intersects,
|
||||
'must be intersects filter');
|
||||
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
|
||||
context['srsName'] = filter.srsName;
|
||||
|
||||
ol.format.WFS.writeOgcPropertyName_(node, filter.geometryName);
|
||||
ol.format.GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.format.ogc.filter.Filter} filter Filter.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeWithinFilter_ = function(node, filter, objectStack) {
|
||||
goog.asserts.assertInstanceof(filter, ol.format.ogc.filter.Within,
|
||||
'must be within filter');
|
||||
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
|
||||
context['srsName'] = filter.srsName;
|
||||
|
||||
ol.format.WFS.writeOgcPropertyName_(node, filter.geometryName);
|
||||
ol.format.GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.format.ogc.filter.Filter} filter Filter.
|
||||
@@ -736,6 +774,8 @@ ol.format.WFS.GETFEATURE_SERIALIZERS_ = {
|
||||
'Or': ol.xml.makeChildAppender(ol.format.WFS.writeLogicalFilter_),
|
||||
'Not': ol.xml.makeChildAppender(ol.format.WFS.writeNotFilter_),
|
||||
'BBOX': ol.xml.makeChildAppender(ol.format.WFS.writeBboxFilter_),
|
||||
'Intersects': ol.xml.makeChildAppender(ol.format.WFS.writeIntersectsFilter_),
|
||||
'Within': ol.xml.makeChildAppender(ol.format.WFS.writeWithinFilter_),
|
||||
'PropertyIsEqualTo': ol.xml.makeChildAppender(ol.format.WFS.writeComparisonFilter_),
|
||||
'PropertyIsNotEqualTo': ol.xml.makeChildAppender(ol.format.WFS.writeComparisonFilter_),
|
||||
'PropertyIsLessThan': ol.xml.makeChildAppender(ol.format.WFS.writeComparisonFilter_),
|
||||
|
||||
@@ -504,6 +504,82 @@ describe('ol.format.WFS', function() {
|
||||
expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text));
|
||||
});
|
||||
|
||||
it('creates an AND intersects filter', function() {
|
||||
var text =
|
||||
'<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" ' +
|
||||
' typeName="area" srsName="EPSG:4326" ' +
|
||||
' xmlns:topp="http://www.openplans.org/topp">' +
|
||||
' <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
' <ogc:Intersects>' +
|
||||
' <ogc:PropertyName>the_geom</ogc:PropertyName>' +
|
||||
' <gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
|
||||
' <gml:exterior>' +
|
||||
' <gml:LinearRing>' +
|
||||
' <gml:posList>' +
|
||||
' 10 20 10 25 15 25 15 20 10 20' +
|
||||
' </gml:posList>' +
|
||||
' </gml:LinearRing>' +
|
||||
' </gml:exterior>' +
|
||||
' </gml:Polygon>' +
|
||||
' </ogc:Intersects>' +
|
||||
' </ogc:Filter>' +
|
||||
'</wfs:Query>';
|
||||
var f = ol.format.ogc.filter;
|
||||
var serialized = new ol.format.WFS().writeGetFeature({
|
||||
srsName: 'EPSG:4326',
|
||||
featureTypes: ['area'],
|
||||
filter: f.intersects(
|
||||
'the_geom',
|
||||
new ol.geom.Polygon([[
|
||||
[10, 20],
|
||||
[10, 25],
|
||||
[15, 25],
|
||||
[15, 20],
|
||||
[10, 20]
|
||||
]])
|
||||
)
|
||||
});
|
||||
expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text));
|
||||
});
|
||||
|
||||
it('creates an AND within filter', function() {
|
||||
var text =
|
||||
'<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" ' +
|
||||
' typeName="area" srsName="EPSG:4326" ' +
|
||||
' xmlns:topp="http://www.openplans.org/topp">' +
|
||||
' <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
' <ogc:Within>' +
|
||||
' <ogc:PropertyName>the_geom</ogc:PropertyName>' +
|
||||
' <gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
|
||||
' <gml:exterior>' +
|
||||
' <gml:LinearRing>' +
|
||||
' <gml:posList>' +
|
||||
' 10 20 10 25 15 25 15 20 10 20' +
|
||||
' </gml:posList>' +
|
||||
' </gml:LinearRing>' +
|
||||
' </gml:exterior>' +
|
||||
' </gml:Polygon>' +
|
||||
' </ogc:Within>' +
|
||||
' </ogc:Filter>' +
|
||||
'</wfs:Query>';
|
||||
var f = ol.format.ogc.filter;
|
||||
var serialized = new ol.format.WFS().writeGetFeature({
|
||||
srsName: 'EPSG:4326',
|
||||
featureTypes: ['area'],
|
||||
filter: f.within(
|
||||
'the_geom',
|
||||
new ol.geom.Polygon([[
|
||||
[10, 20],
|
||||
[10, 25],
|
||||
[15, 25],
|
||||
[15, 20],
|
||||
[10, 20]
|
||||
]])
|
||||
)
|
||||
});
|
||||
expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('when writing out a Transaction request', function() {
|
||||
|
||||
Reference in New Issue
Block a user