Add new ol.format.filter.Contains spatial operator
This commit is contained in:
@@ -2,6 +2,7 @@ goog.provide('ol.format.filter');
|
||||
|
||||
goog.require('ol.format.filter.And');
|
||||
goog.require('ol.format.filter.Bbox');
|
||||
goog.require('ol.format.filter.Contains');
|
||||
goog.require('ol.format.filter.During');
|
||||
goog.require('ol.format.filter.EqualTo');
|
||||
goog.require('ol.format.filter.GreaterThan');
|
||||
@@ -71,6 +72,21 @@ ol.format.filter.bbox = function(geometryName, extent, opt_srsName) {
|
||||
return new ol.format.filter.Bbox(geometryName, extent, opt_srsName);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a `<Contains>` operator to test whether a geometry-valued property
|
||||
* contains a given 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.filter.Contains} `<Contains>` operator.
|
||||
* @api
|
||||
*/
|
||||
ol.format.filter.contains = function(geometryName, geometry, opt_srsName) {
|
||||
return new ol.format.filter.Contains(geometryName, geometry, opt_srsName);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a `<Intersects>` operator to test whether a geometry-valued property
|
||||
* intersects a given geometry.
|
||||
|
||||
25
src/ol/format/filter/contains.js
Normal file
25
src/ol/format/filter/contains.js
Normal file
@@ -0,0 +1,25 @@
|
||||
goog.provide('ol.format.filter.Contains');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.format.filter.Spatial');
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Represents a `<Contains>` operator to test whether a geometry-valued property
|
||||
* contains 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.filter.Spatial}
|
||||
* @api
|
||||
*/
|
||||
ol.format.filter.Contains = function(geometryName, geometry, opt_srsName) {
|
||||
|
||||
ol.format.filter.Spatial.call(this, 'Contains', geometryName, geometry, opt_srsName);
|
||||
|
||||
};
|
||||
ol.inherits(ol.format.filter.Contains, ol.format.filter.Spatial);
|
||||
@@ -628,6 +628,21 @@ ol.format.WFS.writeBboxFilter_ = function(node, filter, objectStack) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.format.filter.Contains} filter Filter.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeContainsFilter_ = function(node, filter, objectStack) {
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
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.filter.Intersects} filter Filter.
|
||||
@@ -846,6 +861,7 @@ 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_),
|
||||
'Contains': ol.xml.makeChildAppender(ol.format.WFS.writeContainsFilter_),
|
||||
'Intersects': ol.xml.makeChildAppender(ol.format.WFS.writeIntersectsFilter_),
|
||||
'Within': ol.xml.makeChildAppender(ol.format.WFS.writeWithinFilter_),
|
||||
'PropertyIsEqualTo': ol.xml.makeChildAppender(ol.format.WFS.writeComparisonFilter_),
|
||||
|
||||
@@ -514,6 +514,43 @@ describe('ol.format.WFS', function() {
|
||||
expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text));
|
||||
});
|
||||
|
||||
it('creates a contains 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:Contains>' +
|
||||
' <ogc:PropertyName>the_geom</ogc:PropertyName>' +
|
||||
' <gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
|
||||
' <gml:exterior>' +
|
||||
' <gml:LinearRing>' +
|
||||
' <gml:posList srsDimension="2">' +
|
||||
' 10 20 10 25 15 25 15 20 10 20' +
|
||||
' </gml:posList>' +
|
||||
' </gml:LinearRing>' +
|
||||
' </gml:exterior>' +
|
||||
' </gml:Polygon>' +
|
||||
' </ogc:Contains>' +
|
||||
' </ogc:Filter>' +
|
||||
'</wfs:Query>';
|
||||
var serialized = new ol.format.WFS().writeGetFeature({
|
||||
srsName: 'EPSG:4326',
|
||||
featureTypes: ['area'],
|
||||
filter: ol.format.filter.contains(
|
||||
'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 a intersects filter', function() {
|
||||
var text =
|
||||
'<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" ' +
|
||||
|
||||
Reference in New Issue
Block a user