Merge pull request #2407 from ahocevar/format-projection
Options for feature readers and writers to support transforms
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
// FIXME Envelopes should not be treated as geometries! readEnvelope_ is part
|
||||
// of GEOMETRY_PARSERS_ and methods using GEOMETRY_PARSERS_ do not expect
|
||||
// envelopes/extents, only geometries!
|
||||
goog.provide('ol.format.GML');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
@@ -8,6 +11,7 @@ goog.require('goog.string');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.array');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.format.Feature');
|
||||
goog.require('ol.format.XMLFeature');
|
||||
goog.require('ol.format.XSD');
|
||||
goog.require('ol.geom.Geometry');
|
||||
@@ -162,7 +166,8 @@ ol.format.GML.readGeometry = function(node, objectStack) {
|
||||
var geometry = ol.xml.pushParseAndPop(/** @type {ol.geom.Geometry} */(null),
|
||||
ol.format.GML.GEOMETRY_PARSERS_, node, objectStack);
|
||||
if (goog.isDefAndNotNull(geometry)) {
|
||||
return geometry;
|
||||
return /** @type {ol.geom.Geometry} */ (
|
||||
ol.format.Feature.transformWithOptions(geometry, false, context));
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
@@ -1037,9 +1042,10 @@ ol.format.GML.RING_PARSERS_ = {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.GML.prototype.readGeometryFromNode = function(node) {
|
||||
var geometry = ol.format.GML.readGeometry(node, [{}]);
|
||||
return (goog.isDef(geometry)) ? geometry : null;
|
||||
ol.format.GML.prototype.readGeometryFromNode = function(node, opt_options) {
|
||||
var geometry = ol.format.GML.readGeometry(node,
|
||||
[this.getReadOptions(node, goog.isDef(opt_options) ? opt_options : {})]);
|
||||
return (goog.isDef(geometry) ? geometry : null);
|
||||
};
|
||||
|
||||
|
||||
@@ -1048,6 +1054,7 @@ ol.format.GML.prototype.readGeometryFromNode = function(node) {
|
||||
*
|
||||
* @function
|
||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||
* @param {olx.format.ReadOptions=} opt_options Options.
|
||||
* @return {Array.<ol.Feature>} Features.
|
||||
* @api
|
||||
*/
|
||||
@@ -1057,12 +1064,24 @@ ol.format.GML.prototype.readFeatures;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.GML.prototype.readFeaturesFromNode = function(node) {
|
||||
var objectStack = [{
|
||||
ol.format.GML.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||
var options = {
|
||||
'featureType': this.featureType_,
|
||||
'featureNS': this.featureNS_
|
||||
}];
|
||||
return ol.format.GML.readFeatures_(node, objectStack);
|
||||
};
|
||||
if (goog.isDef(opt_options)) {
|
||||
goog.object.extend(options, this.getReadOptions(node, opt_options));
|
||||
}
|
||||
return ol.format.GML.readFeatures_(node, [options]);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.GML.prototype.readProjectionFromNode = function(node) {
|
||||
return ol.proj.get(goog.isDef(this.srsName_) ? this.srsName_ :
|
||||
node.firstElementChild.getAttribute('srsName'));
|
||||
};
|
||||
|
||||
|
||||
@@ -1443,9 +1462,22 @@ ol.format.GML.writeGeometry = function(node, geometry, objectStack) {
|
||||
goog.asserts.assert(goog.isObject(context));
|
||||
var item = goog.object.clone(context);
|
||||
item.node = node;
|
||||
var value;
|
||||
if (goog.isArray(geometry)) {
|
||||
if (goog.isDef(context.dataProjection)) {
|
||||
value = ol.proj.transformExtent(
|
||||
geometry, context.featureProjection, context.dataProjection);
|
||||
} else {
|
||||
value = geometry;
|
||||
}
|
||||
} else {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Geometry);
|
||||
value =
|
||||
ol.format.Feature.transformWithOptions(geometry, true, context);
|
||||
}
|
||||
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
||||
(item), ol.format.GML.GEOMETRY_SERIALIZERS_,
|
||||
ol.format.GML.GEOMETRY_NODE_FACTORY_, [geometry], objectStack);
|
||||
ol.format.GML.GEOMETRY_NODE_FACTORY_, [value], objectStack);
|
||||
};
|
||||
|
||||
|
||||
@@ -1673,14 +1705,15 @@ ol.format.GML.GEOMETRY_NODE_FACTORY_ = function(value, objectStack,
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.GML.prototype.writeGeometryNode = function(geometry) {
|
||||
ol.format.GML.prototype.writeGeometryNode = function(geometry, opt_options) {
|
||||
var geom = ol.xml.createElementNS('http://www.opengis.net/gml', 'geom');
|
||||
var context = {node: geom, srsName: this.srsName_,
|
||||
curve: this.curve_, surface: this.surface_,
|
||||
multiSurface: this.multiSurface_, multiCurve: this.multiCurve_};
|
||||
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
||||
(context), ol.format.GML.GEOMETRY_SERIALIZERS_,
|
||||
ol.format.GML.GEOMETRY_NODE_FACTORY_, [geometry], []);
|
||||
if (goog.isDef(opt_options)) {
|
||||
goog.object.extend(context, opt_options);
|
||||
}
|
||||
ol.format.GML.writeGeometry(geom, geometry, [context]);
|
||||
return geom;
|
||||
};
|
||||
|
||||
@@ -1690,6 +1723,7 @@ ol.format.GML.prototype.writeGeometryNode = function(geometry) {
|
||||
*
|
||||
* @function
|
||||
* @param {Array.<ol.Feature>} features Features.
|
||||
* @param {olx.format.WriteOptions=} opt_options Options.
|
||||
* @return {Node} Result.
|
||||
* @api
|
||||
*/
|
||||
@@ -1699,7 +1733,7 @@ ol.format.GML.prototype.writeFeatures;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.GML.prototype.writeFeaturesNode = function(features) {
|
||||
ol.format.GML.prototype.writeFeaturesNode = function(features, opt_options) {
|
||||
var node = ol.xml.createElementNS('http://www.opengis.net/gml',
|
||||
'featureMembers');
|
||||
ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
@@ -1713,6 +1747,9 @@ ol.format.GML.prototype.writeFeaturesNode = function(features) {
|
||||
featureNS: this.featureNS_,
|
||||
featureType: this.featureType_
|
||||
};
|
||||
if (goog.isDef(opt_options)) {
|
||||
goog.object.extend(context, opt_options);
|
||||
}
|
||||
ol.format.GML.writeFeatureMembers_(node, features, [context]);
|
||||
return node;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user