named exports from ol/xml

This commit is contained in:
raiyni
2018-02-07 14:36:18 -06:00
parent 3266ffc58f
commit 4449da3e63
21 changed files with 1144 additions and 1131 deletions

View File

@@ -9,7 +9,9 @@ import XSD from '../format/XSD.js';
import Geometry from '../geom/Geometry.js';
import {assign} from '../obj.js';
import {get as getProjection, transformExtent} from '../proj.js';
import _ol_xml_ from '../xml.js';
import {createElementNS, getAllTextContent, makeArrayPusher, makeChildAppender,
makeReplacer, makeSimpleNodeFactory, OBJECT_PROPERTY_NODE_FACTORY, pushParseAndPop, pushSerializeAndPop} from '../xml.js';
/**
* @classdesc
@@ -29,7 +31,7 @@ const GML2 = function(opt_options) {
this.FEATURE_COLLECTION_PARSERS[GMLBase.GMLNS][
'featureMember'] =
_ol_xml_.makeArrayPusher(GMLBase.prototype.readFeaturesInternal);
makeArrayPusher(GMLBase.prototype.readFeaturesInternal);
/**
* @inheritDoc
@@ -58,7 +60,7 @@ GML2.schemaLocation_ = GMLBase.GMLNS +
* @return {Array.<number>|undefined} Flat coordinates.
*/
GML2.prototype.readFlatCoordinates_ = function(node, objectStack) {
const s = _ol_xml_.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
const s = getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
const context = /** @type {ol.XmlNodeStackItem} */ (objectStack[0]);
const containerSrs = context['srsName'];
let axisOrientation = 'enu';
@@ -94,7 +96,7 @@ GML2.prototype.readFlatCoordinates_ = function(node, objectStack) {
*/
GML2.prototype.readBox_ = function(node, objectStack) {
/** @type {Array.<number>} */
const flatCoordinates = _ol_xml_.pushParseAndPop([null],
const flatCoordinates = pushParseAndPop([null],
this.BOX_PARSERS_, node, objectStack, this);
return createOrUpdate(flatCoordinates[1][0],
flatCoordinates[1][1], flatCoordinates[1][3],
@@ -109,7 +111,7 @@ GML2.prototype.readBox_ = function(node, objectStack) {
*/
GML2.prototype.innerBoundaryIsParser_ = function(node, objectStack) {
/** @type {Array.<number>|undefined} */
const flatLinearRing = _ol_xml_.pushParseAndPop(undefined,
const flatLinearRing = pushParseAndPop(undefined,
this.RING_PARSERS, node, objectStack, this);
if (flatLinearRing) {
const flatLinearRings = /** @type {Array.<Array.<number>>} */
@@ -126,7 +128,7 @@ GML2.prototype.innerBoundaryIsParser_ = function(node, objectStack) {
*/
GML2.prototype.outerBoundaryIsParser_ = function(node, objectStack) {
/** @type {Array.<number>|undefined} */
const flatLinearRing = _ol_xml_.pushParseAndPop(undefined,
const flatLinearRing = pushParseAndPop(undefined,
this.RING_PARSERS, node, objectStack, this);
if (flatLinearRing) {
const flatLinearRings = /** @type {Array.<Array.<number>>} */
@@ -143,7 +145,7 @@ GML2.prototype.outerBoundaryIsParser_ = function(node, objectStack) {
*/
GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = {
'http://www.opengis.net/gml': {
'coordinates': _ol_xml_.makeReplacer(
'coordinates': makeReplacer(
GML2.prototype.readFlatCoordinates_)
}
};
@@ -169,7 +171,7 @@ GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = {
*/
GML2.prototype.BOX_PARSERS_ = {
'http://www.opengis.net/gml': {
'coordinates': _ol_xml_.makeArrayPusher(
'coordinates': makeArrayPusher(
GML2.prototype.readFlatCoordinates_)
}
};
@@ -182,19 +184,19 @@ GML2.prototype.BOX_PARSERS_ = {
*/
GML2.prototype.GEOMETRY_PARSERS_ = {
'http://www.opengis.net/gml': {
'Point': _ol_xml_.makeReplacer(GMLBase.prototype.readPoint),
'MultiPoint': _ol_xml_.makeReplacer(
'Point': makeReplacer(GMLBase.prototype.readPoint),
'MultiPoint': makeReplacer(
GMLBase.prototype.readMultiPoint),
'LineString': _ol_xml_.makeReplacer(
'LineString': makeReplacer(
GMLBase.prototype.readLineString),
'MultiLineString': _ol_xml_.makeReplacer(
'MultiLineString': makeReplacer(
GMLBase.prototype.readMultiLineString),
'LinearRing': _ol_xml_.makeReplacer(
'LinearRing': makeReplacer(
GMLBase.prototype.readLinearRing),
'Polygon': _ol_xml_.makeReplacer(GMLBase.prototype.readPolygon),
'MultiPolygon': _ol_xml_.makeReplacer(
'Polygon': makeReplacer(GMLBase.prototype.readPolygon),
'MultiPolygon': makeReplacer(
GMLBase.prototype.readMultiPolygon),
'Box': _ol_xml_.makeReplacer(GML2.prototype.readBox_)
'Box': makeReplacer(GML2.prototype.readBox_)
}
};
@@ -225,7 +227,7 @@ GML2.prototype.GEOMETRY_NODE_FACTORY_ = function(value, objectStack, opt_nodeNam
} else {
nodeName = 'Envelope';
}
return _ol_xml_.createElementNS('http://www.opengis.net/gml',
return createElementNS('http://www.opengis.net/gml',
nodeName);
};
@@ -257,12 +259,12 @@ GML2.prototype.writeFeatureElement = function(node, feature, objectStack) {
values.push(value);
if (key == geometryName || value instanceof Geometry) {
if (!(key in context.serializers[featureNS])) {
context.serializers[featureNS][key] = _ol_xml_.makeChildAppender(
context.serializers[featureNS][key] = makeChildAppender(
this.writeGeometryElement, this);
}
} else {
if (!(key in context.serializers[featureNS])) {
context.serializers[featureNS][key] = _ol_xml_.makeChildAppender(
context.serializers[featureNS][key] = makeChildAppender(
XSD.writeStringTextNode);
}
}
@@ -270,9 +272,9 @@ GML2.prototype.writeFeatureElement = function(node, feature, objectStack) {
}
const item = assign({}, context);
item.node = node;
_ol_xml_.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
(item), context.serializers,
_ol_xml_.makeSimpleNodeFactory(undefined, featureNS),
makeSimpleNodeFactory(undefined, featureNS),
values,
objectStack, keys);
};
@@ -298,7 +300,7 @@ GML2.prototype.writeGeometryElement = function(node, geometry, objectStack) {
} else {
value = transformWithOptions(/** @type {ol.geom.Geometry} */ (geometry), true, context);
}
_ol_xml_.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
(item), GML2.GEOMETRY_SERIALIZERS_,
this.GEOMETRY_NODE_FACTORY_, [value],
objectStack, undefined, this);
@@ -323,7 +325,7 @@ GML2.prototype.writeCurveOrLineString_ = function(node, geometry, objectStack) {
node.appendChild(coordinates);
this.writeCoordinates_(coordinates, geometry, objectStack);
} else if (node.nodeName === 'Curve') {
const segments = _ol_xml_.createElementNS(node.namespaceURI, 'segments');
const segments = createElementNS(node.namespaceURI, 'segments');
node.appendChild(segments);
this.writeCurveSegments_(segments,
geometry, objectStack);
@@ -337,7 +339,7 @@ GML2.prototype.writeCurveOrLineString_ = function(node, geometry, objectStack) {
* @private
*/
GML2.prototype.createCoordinatesNode_ = function(namespaceURI) {
const coordinates = _ol_xml_.createElementNS(namespaceURI, 'coordinates');
const coordinates = createElementNS(namespaceURI, 'coordinates');
coordinates.setAttribute('decimal', '.');
coordinates.setAttribute('cs', ',');
coordinates.setAttribute('ts', ' ');
@@ -376,7 +378,7 @@ GML2.prototype.writeCoordinates_ = function(node, value, objectStack) {
* @private
*/
GML2.prototype.writeCurveSegments_ = function(node, line, objectStack) {
const child = _ol_xml_.createElementNS(node.namespaceURI,
const child = createElementNS(node.namespaceURI,
'LineStringSegment');
node.appendChild(child);
this.writeCurveOrLineString_(child, line, objectStack);
@@ -398,13 +400,13 @@ GML2.prototype.writeSurfaceOrPolygon_ = function(node, geometry, objectStack) {
}
if (node.nodeName === 'Polygon' || node.nodeName === 'PolygonPatch') {
const rings = geometry.getLinearRings();
_ol_xml_.pushSerializeAndPop(
pushSerializeAndPop(
{node: node, hasZ: hasZ, srsName: srsName},
GML2.RING_SERIALIZERS_,
this.RING_NODE_FACTORY_,
rings, objectStack, undefined, this);
} else if (node.nodeName === 'Surface') {
const patches = _ol_xml_.createElementNS(node.namespaceURI, 'patches');
const patches = createElementNS(node.namespaceURI, 'patches');
node.appendChild(patches);
this.writeSurfacePatches_(
patches, geometry, objectStack);
@@ -426,7 +428,7 @@ GML2.prototype.RING_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
if (exteriorWritten === undefined) {
context['exteriorWritten'] = true;
}
return _ol_xml_.createElementNS(parentNode.namespaceURI,
return createElementNS(parentNode.namespaceURI,
exteriorWritten !== undefined ? 'innerBoundaryIs' : 'outerBoundaryIs');
};
@@ -438,7 +440,7 @@ GML2.prototype.RING_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
* @private
*/
GML2.prototype.writeSurfacePatches_ = function(node, polygon, objectStack) {
const child = _ol_xml_.createElementNS(node.namespaceURI, 'PolygonPatch');
const child = createElementNS(node.namespaceURI, 'PolygonPatch');
node.appendChild(child);
this.writeSurfaceOrPolygon_(child, polygon, objectStack);
};
@@ -451,7 +453,7 @@ GML2.prototype.writeSurfacePatches_ = function(node, polygon, objectStack) {
* @private
*/
GML2.prototype.writeRing_ = function(node, ring, objectStack) {
const linearRing = _ol_xml_.createElementNS(node.namespaceURI, 'LinearRing');
const linearRing = createElementNS(node.namespaceURI, 'LinearRing');
node.appendChild(linearRing);
this.writeLinearRing_(linearRing, ring, objectStack);
};
@@ -497,7 +499,7 @@ GML2.prototype.writeMultiCurveOrLineString_ = function(node, geometry, objectSta
node.setAttribute('srsName', srsName);
}
const lines = geometry.getLineStrings();
_ol_xml_.pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, curve: curve},
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, curve: curve},
GML2.LINESTRINGORCURVEMEMBER_SERIALIZERS_,
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines,
objectStack, undefined, this);
@@ -540,9 +542,9 @@ GML2.prototype.writeMultiPoint_ = function(node, geometry,
node.setAttribute('srsName', srsName);
}
const points = geometry.getPoints();
_ol_xml_.pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName},
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName},
GML2.POINTMEMBER_SERIALIZERS_,
_ol_xml_.makeSimpleNodeFactory('pointMember'), points,
makeSimpleNodeFactory('pointMember'), points,
objectStack, undefined, this);
};
@@ -554,7 +556,7 @@ GML2.prototype.writeMultiPoint_ = function(node, geometry,
* @private
*/
GML2.prototype.writePointMember_ = function(node, point, objectStack) {
const child = _ol_xml_.createElementNS(node.namespaceURI, 'Point');
const child = createElementNS(node.namespaceURI, 'Point');
node.appendChild(child);
this.writePoint_(child, point, objectStack);
};
@@ -608,7 +610,7 @@ GML2.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, objectStac
node.setAttribute('srsName', srsName);
}
const polygons = geometry.getPolygons();
_ol_xml_.pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, surface: surface},
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, surface: surface},
GML2.SURFACEORPOLYGONMEMBER_SERIALIZERS_,
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons,
objectStack, undefined, this);
@@ -645,9 +647,9 @@ GML2.prototype.writeEnvelope = function(node, extent, objectStack) {
}
const keys = ['lowerCorner', 'upperCorner'];
const values = [extent[0] + ' ' + extent[1], extent[2] + ' ' + extent[3]];
_ol_xml_.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
({node: node}), GML2.ENVELOPE_SERIALIZERS_,
_ol_xml_.OBJECT_PROPERTY_NODE_FACTORY,
OBJECT_PROPERTY_NODE_FACTORY,
values,
objectStack, keys, this);
};
@@ -660,28 +662,28 @@ GML2.prototype.writeEnvelope = function(node, extent, objectStack) {
*/
GML2.GEOMETRY_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'Curve': _ol_xml_.makeChildAppender(
'Curve': makeChildAppender(
GML2.prototype.writeCurveOrLineString_),
'MultiCurve': _ol_xml_.makeChildAppender(
'MultiCurve': makeChildAppender(
GML2.prototype.writeMultiCurveOrLineString_),
'Point': _ol_xml_.makeChildAppender(GML2.prototype.writePoint_),
'MultiPoint': _ol_xml_.makeChildAppender(
'Point': makeChildAppender(GML2.prototype.writePoint_),
'MultiPoint': makeChildAppender(
GML2.prototype.writeMultiPoint_),
'LineString': _ol_xml_.makeChildAppender(
'LineString': makeChildAppender(
GML2.prototype.writeCurveOrLineString_),
'MultiLineString': _ol_xml_.makeChildAppender(
'MultiLineString': makeChildAppender(
GML2.prototype.writeMultiCurveOrLineString_),
'LinearRing': _ol_xml_.makeChildAppender(
'LinearRing': makeChildAppender(
GML2.prototype.writeLinearRing_),
'Polygon': _ol_xml_.makeChildAppender(
'Polygon': makeChildAppender(
GML2.prototype.writeSurfaceOrPolygon_),
'MultiPolygon': _ol_xml_.makeChildAppender(
'MultiPolygon': makeChildAppender(
GML2.prototype.writeMultiSurfaceOrPolygon_),
'Surface': _ol_xml_.makeChildAppender(
'Surface': makeChildAppender(
GML2.prototype.writeSurfaceOrPolygon_),
'MultiSurface': _ol_xml_.makeChildAppender(
'MultiSurface': makeChildAppender(
GML2.prototype.writeMultiSurfaceOrPolygon_),
'Envelope': _ol_xml_.makeChildAppender(
'Envelope': makeChildAppender(
GML2.prototype.writeEnvelope)
}
};
@@ -693,8 +695,8 @@ GML2.GEOMETRY_SERIALIZERS_ = {
*/
GML2.RING_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'outerBoundaryIs': _ol_xml_.makeChildAppender(GML2.prototype.writeRing_),
'innerBoundaryIs': _ol_xml_.makeChildAppender(GML2.prototype.writeRing_)
'outerBoundaryIs': makeChildAppender(GML2.prototype.writeRing_),
'innerBoundaryIs': makeChildAppender(GML2.prototype.writeRing_)
}
};
@@ -705,7 +707,7 @@ GML2.RING_SERIALIZERS_ = {
*/
GML2.POINTMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'pointMember': _ol_xml_.makeChildAppender(
'pointMember': makeChildAppender(
GML2.prototype.writePointMember_)
}
};
@@ -717,9 +719,9 @@ GML2.POINTMEMBER_SERIALIZERS_ = {
*/
GML2.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'lineStringMember': _ol_xml_.makeChildAppender(
'lineStringMember': makeChildAppender(
GML2.prototype.writeLineStringOrCurveMember_),
'curveMember': _ol_xml_.makeChildAppender(
'curveMember': makeChildAppender(
GML2.prototype.writeLineStringOrCurveMember_)
}
};
@@ -735,7 +737,7 @@ GML2.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
*/
GML2.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
const parentNode = objectStack[objectStack.length - 1].node;
return _ol_xml_.createElementNS('http://www.opengis.net/gml',
return createElementNS('http://www.opengis.net/gml',
GML2.MULTIGEOMETRY_TO_MEMBER_NODENAME_[parentNode.nodeName]);
};
@@ -759,9 +761,9 @@ GML2.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = {
*/
GML2.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'surfaceMember': _ol_xml_.makeChildAppender(
'surfaceMember': makeChildAppender(
GML2.prototype.writeSurfaceOrPolygonMember_),
'polygonMember': _ol_xml_.makeChildAppender(
'polygonMember': makeChildAppender(
GML2.prototype.writeSurfaceOrPolygonMember_)
}
};
@@ -773,8 +775,8 @@ GML2.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
*/
GML2.ENVELOPE_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'lowerCorner': _ol_xml_.makeChildAppender(XSD.writeStringTextNode),
'upperCorner': _ol_xml_.makeChildAppender(XSD.writeStringTextNode)
'lowerCorner': makeChildAppender(XSD.writeStringTextNode),
'upperCorner': makeChildAppender(XSD.writeStringTextNode)
}
};
export default GML2;