merge with master - solving conflicts
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
goog.provide('ol.parser.ogc.GML');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.Geometry');
|
||||
@@ -14,6 +15,7 @@ goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.StringFeatureParser');
|
||||
goog.require('ol.parser.XML');
|
||||
goog.require('ol.proj');
|
||||
|
||||
|
||||
|
||||
@@ -27,8 +29,6 @@ goog.require('ol.parser.XML');
|
||||
ol.parser.ogc.GML = function(opt_options) {
|
||||
var options = /** @type {ol.parser.GMLOptions} */
|
||||
(goog.isDef(opt_options) ? opt_options : {});
|
||||
this.axisOrientation = goog.isDef(options.axisOrientation) ?
|
||||
options.axisOrientation : 'enu';
|
||||
this.extractAttributes = goog.isDef(options.extractAttributes) ?
|
||||
options.extractAttributes : true;
|
||||
this.surface = goog.isDef(options.surface) ?
|
||||
@@ -39,8 +39,21 @@ ol.parser.ogc.GML = function(opt_options) {
|
||||
options.multiCurve : true;
|
||||
this.multiSurface = goog.isDef(options.multiSurface) ?
|
||||
options.multiSurface : true;
|
||||
this.srsName = goog.isDef(options.srsName) ?
|
||||
options.srsName : null;
|
||||
this.readOptions = options.readOptions;
|
||||
this.writeOptions = options.writeOptions;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.srsName;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.axisOrientation;
|
||||
|
||||
if (goog.isDef(options.schemaLocation)) {
|
||||
this.schemaLocation = options.schemaLocation;
|
||||
}
|
||||
@@ -61,7 +74,18 @@ ol.parser.ogc.GML = function(opt_options) {
|
||||
},
|
||||
'http://www.opengis.net/gml': {
|
||||
'_inherit': function(node, obj, container) {
|
||||
// To be implemented by version specific parsers
|
||||
// Version specific parsers extend this with goog.functions.sequence
|
||||
var srsName;
|
||||
if (!goog.isDef(this.srsName)) {
|
||||
srsName = this.srsName = node.getAttribute('srsName');
|
||||
}
|
||||
if (!goog.isDef(this.axisOrientation)) {
|
||||
if (goog.isDefAndNotNull(srsName)) {
|
||||
this.axisOrientation = ol.proj.get(srsName).getAxisOrientation();
|
||||
} else {
|
||||
this.axisOrientation = 'enu';
|
||||
}
|
||||
}
|
||||
},
|
||||
'name': function(node, obj) {
|
||||
obj.name = this.getChildValue(node);
|
||||
@@ -126,6 +150,8 @@ ol.parser.ogc.GML = function(opt_options) {
|
||||
},
|
||||
'Point': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
var point = {
|
||||
type: ol.geom.GeometryType.POINT,
|
||||
@@ -315,9 +341,9 @@ ol.parser.ogc.GML = function(opt_options) {
|
||||
}
|
||||
this.writers = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'featureMember': function(feature) {
|
||||
'featureMember': function(obj) {
|
||||
var node = this.createElementNS('gml:featureMember');
|
||||
this.writeNode('_typeName', feature, this.featureNS, node);
|
||||
this.writeNode('_typeName', obj, this.featureNS, node);
|
||||
return node;
|
||||
},
|
||||
'MultiPoint': function(geometry) {
|
||||
@@ -455,17 +481,38 @@ goog.inherits(ol.parser.ogc.GML, ol.parser.XML);
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element|Object} data Data to read.
|
||||
* @return {Object} An object representing the document.
|
||||
* @param {ol.parser.GMLReadOptions=} opt_options Read options.
|
||||
* @return {ol.parser.ReadFeaturesResult} An object representing the document.
|
||||
*/
|
||||
ol.parser.ogc.GML.prototype.read = function(data) {
|
||||
ol.parser.ogc.GML.prototype.read = function(data, opt_options) {
|
||||
var srsName;
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.srsName)) {
|
||||
srsName = opt_options.srsName;
|
||||
} else if (goog.isDef(this.readOptions) &&
|
||||
goog.isDef(this.readOptions.srsName)) {
|
||||
srsName = this.readOptions.srsName;
|
||||
}
|
||||
if (goog.isDef(srsName)) {
|
||||
this.srsName = goog.isString(srsName) ? srsName : srsName.getCode();
|
||||
}
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.axisOrientation)) {
|
||||
this.axisOrientation = opt_options.axisOrientation;
|
||||
} else if (goog.isDef(this.readOptions) &&
|
||||
goog.isDef(this.readOptions.axisOrientation)) {
|
||||
this.axisOrientation = this.readOptions.axisOrientation;
|
||||
}
|
||||
if (typeof data == 'string') {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = {features: []};
|
||||
var obj = /** @type {ol.parser.ReadFeaturesResult} */
|
||||
({features: [], metadata: {}});
|
||||
this.readNode(data, obj, true);
|
||||
obj.metadata.projection = this.srsName;
|
||||
delete this.srsName;
|
||||
delete this.axisOrientation;
|
||||
return obj;
|
||||
};
|
||||
|
||||
@@ -569,10 +616,41 @@ ol.parser.ogc.GML.prototype.createGeometry = function(container,
|
||||
* Parse a GML document provided as a string.
|
||||
* @param {string} str GML document.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.ogc.GML.prototype.readFeaturesFromString =
|
||||
function(str, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
return this.read(str).features;
|
||||
return this.read(str);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Applies the writeOptions passed into the write function.
|
||||
* @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as
|
||||
* GML.
|
||||
* @param {ol.parser.GMLWriteOptions=} opt_options Write options.
|
||||
*/
|
||||
ol.parser.ogc.GML.prototype.applyWriteOptions = function(obj, opt_options) {
|
||||
// srsName handling: opt_options -> this.writeOptions -> obj.metadata
|
||||
var srsName;
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.srsName)) {
|
||||
srsName = opt_options.srsName;
|
||||
} else if (goog.isDef(this.writeOptions) &&
|
||||
goog.isDef(this.writeOptions.srsName)) {
|
||||
srsName = this.writeOptions.srsName;
|
||||
} else if (goog.isDef(obj.metadata)) {
|
||||
srsName = obj.metadata.projection;
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(srsName), 'srsName required for writing GML');
|
||||
this.srsName = goog.isString(srsName) ? srsName : srsName.getCode();
|
||||
// axisOrientation handling: opt_options -> this.writeOptions
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.axisOrientation)) {
|
||||
this.axisOrientation = opt_options.axisOrientation;
|
||||
} else if (goog.isDef(this.writeOptions) &&
|
||||
goog.isDef(this.writeOptions.axisOrientation)) {
|
||||
this.axisOrientation = this.writeOptions.axisOrientation;
|
||||
} else {
|
||||
this.axisOrientation = ol.proj.get(this.srsName).getAxisOrientation();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -28,6 +28,8 @@ ol.parser.ogc.GML_v2 = function(opt_options) {
|
||||
},
|
||||
'Box': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
container.projection = node.getAttribute('srsName');
|
||||
container.bounds = [coordinates[0][0][0], coordinates[0][1][0],
|
||||
@@ -68,9 +70,17 @@ ol.parser.ogc.GML_v2 = function(opt_options) {
|
||||
'Polygon': function(geometry) {
|
||||
var node = this.createElementNS('gml:Polygon');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
this.writeNode('outerBoundaryIs', coordinates[0], null, node);
|
||||
/**
|
||||
* Though there continues to be ambiguity around this, GML references
|
||||
* ISO 19107, which says polygons have counter-clockwise exterior rings
|
||||
* and clockwise interior rings. The ambiguity comes because the
|
||||
* the Simple Feature Access - SQL spec (ISO 19125-2) says that no
|
||||
* winding order is enforced. Anyway, we write out counter-clockwise
|
||||
* exterior and clockwise interior here but accept either when reading.
|
||||
*/
|
||||
this.writeNode('outerBoundaryIs', coordinates[0].reverse(), null, node);
|
||||
for (var i = 1; i < coordinates.length; ++i) {
|
||||
this.writeNode('innerBoundaryIs', coordinates[i], null, node);
|
||||
this.writeNode('innerBoundaryIs', coordinates[i].reverse(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
@@ -105,14 +115,20 @@ goog.inherits(ol.parser.ogc.GML_v2, ol.parser.ogc.GML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object structure to write out as XML.
|
||||
* @return {string} An string representing the XML document.
|
||||
* @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as
|
||||
* GML.
|
||||
* @param {ol.parser.GMLWriteOptions=} opt_options Write options.
|
||||
* @return {string} A string representing the GML document.
|
||||
*/
|
||||
ol.parser.ogc.GML_v2.prototype.write = function(obj) {
|
||||
ol.parser.ogc.GML_v2.prototype.write = function(obj, opt_options) {
|
||||
this.applyWriteOptions(obj, opt_options);
|
||||
var root = this.writeNode('FeatureCollection', obj.features,
|
||||
'http://www.opengis.net/wfs');
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
return this.serialize(root);
|
||||
var gml = this.serialize(root);
|
||||
delete this.srsName;
|
||||
delete this.axisOrientation;
|
||||
return gml;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
goog.provide('ol.parser.ogc.GML_v3');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.functions');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.parser.ogc.GML');
|
||||
@@ -61,14 +62,16 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
|
||||
return node;
|
||||
};
|
||||
goog.object.extend(this.readers['http://www.opengis.net/gml'], {
|
||||
'_inherit': function(node, obj, container) {
|
||||
// SRSReferenceGroup attributes
|
||||
var dim = parseInt(node.getAttribute('srsDimension'), 10) ||
|
||||
(container && container.srsDimension);
|
||||
if (dim) {
|
||||
obj.srsDimension = dim;
|
||||
}
|
||||
},
|
||||
'_inherit': goog.functions.sequence(
|
||||
this.readers['http://www.opengis.net/gml']['_inherit'],
|
||||
function(node, obj, container) {
|
||||
// SRSReferenceGroup attributes
|
||||
var dim = parseInt(node.getAttribute('srsDimension'), 10) ||
|
||||
(container && container.srsDimension);
|
||||
if (dim) {
|
||||
obj.srsDimension = dim;
|
||||
}
|
||||
}),
|
||||
'featureMembers': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
@@ -205,6 +208,8 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
|
||||
},
|
||||
'Envelope': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
container.projection = node.getAttribute('srsName');
|
||||
container.bounds = [coordinates[0][0][0][0], coordinates[1][0][0][0],
|
||||
@@ -299,18 +304,26 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
|
||||
var node = this.createElementNS('gml:PolygonPatch');
|
||||
node.setAttribute('interpolation', 'planar');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
this.writeNode('exterior', coordinates[0], null, node);
|
||||
this.writeNode('exterior', coordinates[0].reverse(), null, node);
|
||||
for (var i = 1, len = coordinates.length; i < len; ++i) {
|
||||
this.writeNode('interior', coordinates[i], null, node);
|
||||
this.writeNode('interior', coordinates[i].reverse(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'Polygon': function(geometry) {
|
||||
var node = this.createElementNS('gml:Polygon');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
this.writeNode('exterior', coordinates[0], null, node);
|
||||
/**
|
||||
* Though there continues to be ambiguity around this, GML references
|
||||
* ISO 19107, which says polygons have counter-clockwise exterior rings
|
||||
* and clockwise interior rings. The ambiguity comes because the
|
||||
* the Simple Feature Access - SQL spec (ISO 19125-2) says that no
|
||||
* winding order is enforced. Anyway, we write out counter-clockwise
|
||||
* exterior and clockwise interior here but accept either when reading.
|
||||
*/
|
||||
this.writeNode('exterior', coordinates[0].reverse(), null, node);
|
||||
for (var i = 1, len = coordinates.length; i < len; ++i) {
|
||||
this.writeNode('interior', coordinates[i], null, node);
|
||||
this.writeNode('interior', coordinates[i].reverse(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
@@ -366,7 +379,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
|
||||
this.writeNode('lowerCorner', bounds, null, node);
|
||||
this.writeNode('upperCorner', bounds, null, node);
|
||||
// srsName attribute is required for gml:Envelope
|
||||
if (this.srsName) {
|
||||
if (goog.isDef(this.srsName)) {
|
||||
node.setAttribute('srsName', this.srsName);
|
||||
}
|
||||
return node;
|
||||
@@ -401,13 +414,19 @@ goog.inherits(ol.parser.ogc.GML_v3, ol.parser.ogc.GML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object structure to write out as XML.
|
||||
* @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as
|
||||
* XML.
|
||||
* @param {ol.parser.GMLWriteOptions=} opt_options Write options.
|
||||
* @return {string} An string representing the XML document.
|
||||
*/
|
||||
ol.parser.ogc.GML_v3.prototype.write = function(obj) {
|
||||
ol.parser.ogc.GML_v3.prototype.write = function(obj, opt_options) {
|
||||
this.applyWriteOptions(obj, opt_options);
|
||||
var root = this.writeNode('featureMembers', obj.features);
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
return this.serialize(root);
|
||||
var gml = this.serialize(root);
|
||||
delete this.srsName;
|
||||
delete this.axisOrientation;
|
||||
return gml;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user