Named exports from ol/format/xsd

This commit is contained in:
Tim Schaub
2018-02-19 09:58:50 -07:00
parent 7b21b41151
commit 2abc524147
10 changed files with 315 additions and 347 deletions

View File

@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
import {createOrUpdate} from '../extent.js'; import {createOrUpdate} from '../extent.js';
import {transformWithOptions} from '../format/Feature.js'; import {transformWithOptions} from '../format/Feature.js';
import GMLBase, {GMLNS} from '../format/GMLBase.js'; import GMLBase, {GMLNS} from '../format/GMLBase.js';
import XSD from '../format/XSD.js'; import {writeStringTextNode} from '../format/xsd.js';
import Geometry from '../geom/Geometry.js'; import Geometry from '../geom/Geometry.js';
import {assign} from '../obj.js'; import {assign} from '../obj.js';
import {get as getProjection, transformExtent} from '../proj.js'; import {get as getProjection, transformExtent} from '../proj.js';
@@ -199,8 +199,7 @@ GML2.prototype.writeFeatureElement = function(node, feature, objectStack) {
} }
} else { } else {
if (!(key in context.serializers[featureNS])) { if (!(key in context.serializers[featureNS])) {
context.serializers[featureNS][key] = makeChildAppender( context.serializers[featureNS][key] = makeChildAppender(writeStringTextNode);
XSD.writeStringTextNode);
} }
} }
} }
@@ -339,7 +338,7 @@ GML2.prototype.writeCoordinates_ = function(node, value, objectStack) {
point = points[i]; point = points[i];
parts[i] = this.getCoords_(point, srsName, hasZ); parts[i] = this.getCoords_(point, srsName, hasZ);
} }
XSD.writeStringTextNode(node, parts.join(' ')); writeStringTextNode(node, parts.join(' '));
}; };
@@ -473,7 +472,7 @@ GML2.prototype.writePoint_ = function(node, geometry, objectStack) {
node.appendChild(coordinates); node.appendChild(coordinates);
const point = geometry.getCoordinates(); const point = geometry.getCoordinates();
const coord = this.getCoords_(point, srsName, hasZ); const coord = this.getCoords_(point, srsName, hasZ);
XSD.writeStringTextNode(coordinates, coord); writeStringTextNode(coordinates, coord);
}; };
@@ -772,8 +771,8 @@ GML2.prototype.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
*/ */
GML2.prototype.ENVELOPE_SERIALIZERS_ = { GML2.prototype.ENVELOPE_SERIALIZERS_ = {
'http://www.opengis.net/gml': { 'http://www.opengis.net/gml': {
'lowerCorner': makeChildAppender(XSD.writeStringTextNode), 'lowerCorner': makeChildAppender(writeStringTextNode),
'upperCorner': makeChildAppender(XSD.writeStringTextNode) 'upperCorner': makeChildAppender(writeStringTextNode)
} }
}; };

View File

@@ -6,7 +6,7 @@ import {extend} from '../array.js';
import {createOrUpdate} from '../extent.js'; import {createOrUpdate} from '../extent.js';
import {transformWithOptions} from '../format/Feature.js'; import {transformWithOptions} from '../format/Feature.js';
import GMLBase, {GMLNS} from '../format/GMLBase.js'; import GMLBase, {GMLNS} from '../format/GMLBase.js';
import XSD from '../format/XSD.js'; import {readNonNegativeIntegerString, writeStringTextNode} from '../format/xsd.js';
import Geometry from '../geom/Geometry.js'; import Geometry from '../geom/Geometry.js';
import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryLayout from '../geom/GeometryLayout.js';
import LineString from '../geom/LineString.js'; import LineString from '../geom/LineString.js';
@@ -366,16 +366,16 @@ GML3.prototype.readFlatPosList_ = function(node, objectStack) {
// The "dimension" attribute is from the GML 3.0.1 spec. // The "dimension" attribute is from the GML 3.0.1 spec.
let dim = 2; let dim = 2;
if (node.getAttribute('srsDimension')) { if (node.getAttribute('srsDimension')) {
dim = XSD.readNonNegativeIntegerString( dim = readNonNegativeIntegerString(
node.getAttribute('srsDimension')); node.getAttribute('srsDimension'));
} else if (node.getAttribute('dimension')) { } else if (node.getAttribute('dimension')) {
dim = XSD.readNonNegativeIntegerString( dim = readNonNegativeIntegerString(
node.getAttribute('dimension')); node.getAttribute('dimension'));
} else if (node.parentNode.getAttribute('srsDimension')) { } else if (node.parentNode.getAttribute('srsDimension')) {
dim = XSD.readNonNegativeIntegerString( dim = readNonNegativeIntegerString(
node.parentNode.getAttribute('srsDimension')); node.parentNode.getAttribute('srsDimension'));
} else if (contextDimension) { } else if (contextDimension) {
dim = XSD.readNonNegativeIntegerString(contextDimension); dim = readNonNegativeIntegerString(contextDimension);
} }
let x, y, z; let x, y, z;
const flatCoordinates = []; const flatCoordinates = [];
@@ -600,7 +600,7 @@ GML3.prototype.writePos_ = function(node, value, objectStack) {
const z = point[2] || 0; const z = point[2] || 0;
coords += ' ' + z; coords += ' ' + z;
} }
XSD.writeStringTextNode(node, coords); writeStringTextNode(node, coords);
}; };
@@ -650,7 +650,7 @@ GML3.prototype.writePosList_ = function(node, value, objectStack) {
point = points[i]; point = points[i];
parts[i] = this.getCoords_(point, srsName, hasZ); parts[i] = this.getCoords_(point, srsName, hasZ);
} }
XSD.writeStringTextNode(node, parts.join(' ')); writeStringTextNode(node, parts.join(' '));
}; };
@@ -994,8 +994,7 @@ GML3.prototype.writeFeatureElement = function(node, feature, objectStack) {
} }
} else { } else {
if (!(key in context.serializers[featureNS])) { if (!(key in context.serializers[featureNS])) {
context.serializers[featureNS][key] = makeChildAppender( context.serializers[featureNS][key] = makeChildAppender(writeStringTextNode);
XSD.writeStringTextNode);
} }
} }
} }
@@ -1181,8 +1180,8 @@ GML3.prototype.RING_SERIALIZERS_ = {
*/ */
GML3.prototype.ENVELOPE_SERIALIZERS_ = { GML3.prototype.ENVELOPE_SERIALIZERS_ = {
'http://www.opengis.net/gml': { 'http://www.opengis.net/gml': {
'lowerCorner': makeChildAppender(XSD.writeStringTextNode), 'lowerCorner': makeChildAppender(writeStringTextNode),
'upperCorner': makeChildAppender(XSD.writeStringTextNode) 'upperCorner': makeChildAppender(writeStringTextNode)
} }
}; };

View File

@@ -6,7 +6,7 @@ import Feature from '../Feature.js';
import {includes} from '../array.js'; import {includes} from '../array.js';
import {transformWithOptions} from '../format/Feature.js'; import {transformWithOptions} from '../format/Feature.js';
import XMLFeature from '../format/XMLFeature.js'; import XMLFeature from '../format/XMLFeature.js';
import XSD from '../format/XSD.js'; import {readString, readDecimal, readNonNegativeInteger, readDateTime, writeStringTextNode, writeNonNegativeIntegerTextNode, writeDecimalTextNode, writeDateTimeTextNode} from '../format/xsd.js';
import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryLayout from '../geom/GeometryLayout.js';
import LineString from '../geom/LineString.js'; import LineString from '../geom/LineString.js';
import MultiLineString from '../geom/MultiLineString.js'; import MultiLineString from '../geom/MultiLineString.js';
@@ -95,8 +95,8 @@ const GPX_PARSERS = makeStructureNS(
*/ */
const LINK_PARSERS = makeStructureNS( const LINK_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'text': makeObjectPropertySetter(XSD.readString, 'linkText'), 'text': makeObjectPropertySetter(readString, 'linkText'),
'type': makeObjectPropertySetter(XSD.readString, 'linkType') 'type': makeObjectPropertySetter(readString, 'linkType')
}); });
@@ -106,14 +106,14 @@ const LINK_PARSERS = makeStructureNS(
*/ */
const RTE_PARSERS = makeStructureNS( const RTE_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'name': makeObjectPropertySetter(XSD.readString), 'name': makeObjectPropertySetter(readString),
'cmt': makeObjectPropertySetter(XSD.readString), 'cmt': makeObjectPropertySetter(readString),
'desc': makeObjectPropertySetter(XSD.readString), 'desc': makeObjectPropertySetter(readString),
'src': makeObjectPropertySetter(XSD.readString), 'src': makeObjectPropertySetter(readString),
'link': parseLink, 'link': parseLink,
'number': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'number': makeObjectPropertySetter(readNonNegativeInteger),
'extensions': parseExtensions, 'extensions': parseExtensions,
'type': makeObjectPropertySetter(XSD.readString), 'type': makeObjectPropertySetter(readString),
'rtept': parseRtePt 'rtept': parseRtePt
}); });
@@ -124,8 +124,8 @@ const RTE_PARSERS = makeStructureNS(
*/ */
const RTEPT_PARSERS = makeStructureNS( const RTEPT_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'ele': makeObjectPropertySetter(XSD.readDecimal), 'ele': makeObjectPropertySetter(readDecimal),
'time': makeObjectPropertySetter(XSD.readDateTime) 'time': makeObjectPropertySetter(readDateTime)
}); });
@@ -135,13 +135,13 @@ const RTEPT_PARSERS = makeStructureNS(
*/ */
const TRK_PARSERS = makeStructureNS( const TRK_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'name': makeObjectPropertySetter(XSD.readString), 'name': makeObjectPropertySetter(readString),
'cmt': makeObjectPropertySetter(XSD.readString), 'cmt': makeObjectPropertySetter(readString),
'desc': makeObjectPropertySetter(XSD.readString), 'desc': makeObjectPropertySetter(readString),
'src': makeObjectPropertySetter(XSD.readString), 'src': makeObjectPropertySetter(readString),
'link': parseLink, 'link': parseLink,
'number': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'number': makeObjectPropertySetter(readNonNegativeInteger),
'type': makeObjectPropertySetter(XSD.readString), 'type': makeObjectPropertySetter(readString),
'extensions': parseExtensions, 'extensions': parseExtensions,
'trkseg': parseTrkSeg 'trkseg': parseTrkSeg
}); });
@@ -163,8 +163,8 @@ const TRKSEG_PARSERS = makeStructureNS(
*/ */
const TRKPT_PARSERS = makeStructureNS( const TRKPT_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'ele': makeObjectPropertySetter(XSD.readDecimal), 'ele': makeObjectPropertySetter(readDecimal),
'time': makeObjectPropertySetter(XSD.readDateTime) 'time': makeObjectPropertySetter(readDateTime)
}); });
@@ -174,24 +174,24 @@ const TRKPT_PARSERS = makeStructureNS(
*/ */
const WPT_PARSERS = makeStructureNS( const WPT_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'ele': makeObjectPropertySetter(XSD.readDecimal), 'ele': makeObjectPropertySetter(readDecimal),
'time': makeObjectPropertySetter(XSD.readDateTime), 'time': makeObjectPropertySetter(readDateTime),
'magvar': makeObjectPropertySetter(XSD.readDecimal), 'magvar': makeObjectPropertySetter(readDecimal),
'geoidheight': makeObjectPropertySetter(XSD.readDecimal), 'geoidheight': makeObjectPropertySetter(readDecimal),
'name': makeObjectPropertySetter(XSD.readString), 'name': makeObjectPropertySetter(readString),
'cmt': makeObjectPropertySetter(XSD.readString), 'cmt': makeObjectPropertySetter(readString),
'desc': makeObjectPropertySetter(XSD.readString), 'desc': makeObjectPropertySetter(readString),
'src': makeObjectPropertySetter(XSD.readString), 'src': makeObjectPropertySetter(readString),
'link': parseLink, 'link': parseLink,
'sym': makeObjectPropertySetter(XSD.readString), 'sym': makeObjectPropertySetter(readString),
'type': makeObjectPropertySetter(XSD.readString), 'type': makeObjectPropertySetter(readString),
'fix': makeObjectPropertySetter(XSD.readString), 'fix': makeObjectPropertySetter(readString),
'sat': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'sat': makeObjectPropertySetter(readNonNegativeInteger),
'hdop': makeObjectPropertySetter(XSD.readDecimal), 'hdop': makeObjectPropertySetter(readDecimal),
'vdop': makeObjectPropertySetter(XSD.readDecimal), 'vdop': makeObjectPropertySetter(readDecimal),
'pdop': makeObjectPropertySetter(XSD.readDecimal), 'pdop': makeObjectPropertySetter(readDecimal),
'ageofdgpsdata': makeObjectPropertySetter(XSD.readDecimal), 'ageofdgpsdata': makeObjectPropertySetter(readDecimal),
'dgpsid': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'dgpsid': makeObjectPropertySetter(readNonNegativeInteger),
'extensions': parseExtensions 'extensions': parseExtensions
}); });
@@ -209,8 +209,8 @@ const LINK_SEQUENCE = ['text', 'type'];
*/ */
const LINK_SERIALIZERS = makeStructureNS( const LINK_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'text': makeChildAppender(XSD.writeStringTextNode), 'text': makeChildAppender(writeStringTextNode),
'type': makeChildAppender(XSD.writeStringTextNode) 'type': makeChildAppender(writeStringTextNode)
}); });
@@ -230,13 +230,13 @@ const RTE_SEQUENCE = makeStructureNS(
*/ */
const RTE_SERIALIZERS = makeStructureNS( const RTE_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'name': makeChildAppender(XSD.writeStringTextNode), 'name': makeChildAppender(writeStringTextNode),
'cmt': makeChildAppender(XSD.writeStringTextNode), 'cmt': makeChildAppender(writeStringTextNode),
'desc': makeChildAppender(XSD.writeStringTextNode), 'desc': makeChildAppender(writeStringTextNode),
'src': makeChildAppender(XSD.writeStringTextNode), 'src': makeChildAppender(writeStringTextNode),
'link': makeChildAppender(writeLink), 'link': makeChildAppender(writeLink),
'number': makeChildAppender(XSD.writeNonNegativeIntegerTextNode), 'number': makeChildAppender(writeNonNegativeIntegerTextNode),
'type': makeChildAppender(XSD.writeStringTextNode), 'type': makeChildAppender(writeStringTextNode),
'rtept': makeArraySerializer(makeChildAppender(writeWptType)) 'rtept': makeArraySerializer(makeChildAppender(writeWptType))
}); });
@@ -267,13 +267,13 @@ const TRK_SEQUENCE = makeStructureNS(
*/ */
const TRK_SERIALIZERS = makeStructureNS( const TRK_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'name': makeChildAppender(XSD.writeStringTextNode), 'name': makeChildAppender(writeStringTextNode),
'cmt': makeChildAppender(XSD.writeStringTextNode), 'cmt': makeChildAppender(writeStringTextNode),
'desc': makeChildAppender(XSD.writeStringTextNode), 'desc': makeChildAppender(writeStringTextNode),
'src': makeChildAppender(XSD.writeStringTextNode), 'src': makeChildAppender(writeStringTextNode),
'link': makeChildAppender(writeLink), 'link': makeChildAppender(writeLink),
'number': makeChildAppender(XSD.writeNonNegativeIntegerTextNode), 'number': makeChildAppender(writeNonNegativeIntegerTextNode),
'type': makeChildAppender(XSD.writeStringTextNode), 'type': makeChildAppender(writeStringTextNode),
'trkseg': makeArraySerializer(makeChildAppender(writeTrkSeg)) 'trkseg': makeArraySerializer(makeChildAppender(writeTrkSeg))
}); });
@@ -313,24 +313,24 @@ const WPT_TYPE_SEQUENCE = makeStructureNS(
*/ */
const WPT_TYPE_SERIALIZERS = makeStructureNS( const WPT_TYPE_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'ele': makeChildAppender(XSD.writeDecimalTextNode), 'ele': makeChildAppender(writeDecimalTextNode),
'time': makeChildAppender(XSD.writeDateTimeTextNode), 'time': makeChildAppender(writeDateTimeTextNode),
'magvar': makeChildAppender(XSD.writeDecimalTextNode), 'magvar': makeChildAppender(writeDecimalTextNode),
'geoidheight': makeChildAppender(XSD.writeDecimalTextNode), 'geoidheight': makeChildAppender(writeDecimalTextNode),
'name': makeChildAppender(XSD.writeStringTextNode), 'name': makeChildAppender(writeStringTextNode),
'cmt': makeChildAppender(XSD.writeStringTextNode), 'cmt': makeChildAppender(writeStringTextNode),
'desc': makeChildAppender(XSD.writeStringTextNode), 'desc': makeChildAppender(writeStringTextNode),
'src': makeChildAppender(XSD.writeStringTextNode), 'src': makeChildAppender(writeStringTextNode),
'link': makeChildAppender(writeLink), 'link': makeChildAppender(writeLink),
'sym': makeChildAppender(XSD.writeStringTextNode), 'sym': makeChildAppender(writeStringTextNode),
'type': makeChildAppender(XSD.writeStringTextNode), 'type': makeChildAppender(writeStringTextNode),
'fix': makeChildAppender(XSD.writeStringTextNode), 'fix': makeChildAppender(writeStringTextNode),
'sat': makeChildAppender(XSD.writeNonNegativeIntegerTextNode), 'sat': makeChildAppender(writeNonNegativeIntegerTextNode),
'hdop': makeChildAppender(XSD.writeDecimalTextNode), 'hdop': makeChildAppender(writeDecimalTextNode),
'vdop': makeChildAppender(XSD.writeDecimalTextNode), 'vdop': makeChildAppender(writeDecimalTextNode),
'pdop': makeChildAppender(XSD.writeDecimalTextNode), 'pdop': makeChildAppender(writeDecimalTextNode),
'ageofdgpsdata': makeChildAppender(XSD.writeDecimalTextNode), 'ageofdgpsdata': makeChildAppender(writeDecimalTextNode),
'dgpsid': makeChildAppender(XSD.writeNonNegativeIntegerTextNode) 'dgpsid': makeChildAppender(writeNonNegativeIntegerTextNode)
}); });
@@ -883,8 +883,7 @@ GPX.prototype.writeFeaturesNode = function(features, opt_options) {
const xmlnsUri = 'http://www.w3.org/2000/xmlns/'; const xmlnsUri = 'http://www.w3.org/2000/xmlns/';
const xmlSchemaInstanceUri = 'http://www.w3.org/2001/XMLSchema-instance'; const xmlSchemaInstanceUri = 'http://www.w3.org/2001/XMLSchema-instance';
setAttributeNS(gpx, xmlnsUri, 'xmlns:xsi', xmlSchemaInstanceUri); setAttributeNS(gpx, xmlnsUri, 'xmlns:xsi', xmlSchemaInstanceUri);
setAttributeNS(gpx, xmlSchemaInstanceUri, 'xsi:schemaLocation', setAttributeNS(gpx, xmlSchemaInstanceUri, 'xsi:schemaLocation', SCHEMA_LOCATION);
SCHEMA_LOCATION);
gpx.setAttribute('version', '1.1'); gpx.setAttribute('version', '1.1');
gpx.setAttribute('creator', 'OpenLayers'); gpx.setAttribute('creator', 'OpenLayers');

View File

@@ -8,7 +8,7 @@ import {assert} from '../asserts.js';
import {asArray} from '../color.js'; import {asArray} from '../color.js';
import {transformWithOptions} from '../format/Feature.js'; import {transformWithOptions} from '../format/Feature.js';
import XMLFeature from '../format/XMLFeature.js'; import XMLFeature from '../format/XMLFeature.js';
import XSD from '../format/XSD.js'; import {readDecimal, readBoolean, readString, writeStringTextNode, writeCDATASection, writeDecimalTextNode, writeBooleanTextNode} from '../format/xsd.js';
import GeometryCollection from '../geom/GeometryCollection.js'; import GeometryCollection from '../geom/GeometryCollection.js';
import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryLayout from '../geom/GeometryLayout.js';
import GeometryType from '../geom/GeometryType.js'; import GeometryType from '../geom/GeometryType.js';
@@ -575,7 +575,7 @@ function readVec2(node) {
* @return {number|undefined} Scale. * @return {number|undefined} Scale.
*/ */
function readScale(node) { function readScale(node) {
return XSD.readDecimal(node); return readDecimal(node);
} }
@@ -607,7 +607,7 @@ function readStyleMapValue(node, objectStack) {
const ICON_STYLE_PARSERS = makeStructureNS( const ICON_STYLE_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Icon': makeObjectPropertySetter(readIcon), 'Icon': makeObjectPropertySetter(readIcon),
'heading': makeObjectPropertySetter(XSD.readDecimal), 'heading': makeObjectPropertySetter(readDecimal),
'hotSpot': makeObjectPropertySetter(readVec2), 'hotSpot': makeObjectPropertySetter(readVec2),
'scale': makeObjectPropertySetter(readScale) 'scale': makeObjectPropertySetter(readScale)
}); });
@@ -758,7 +758,7 @@ function labelStyleParser(node, objectStack) {
const LINE_STYLE_PARSERS = makeStructureNS( const LINE_STYLE_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'color': makeObjectPropertySetter(readColor), 'color': makeObjectPropertySetter(readColor),
'width': makeObjectPropertySetter(XSD.readDecimal) 'width': makeObjectPropertySetter(readDecimal)
}); });
@@ -794,8 +794,8 @@ function lineStyleParser(node, objectStack) {
const POLY_STYLE_PARSERS = makeStructureNS( const POLY_STYLE_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'color': makeObjectPropertySetter(readColor), 'color': makeObjectPropertySetter(readColor),
'fill': makeObjectPropertySetter(XSD.readBoolean), 'fill': makeObjectPropertySetter(readBoolean),
'outline': makeObjectPropertySetter(XSD.readBoolean) 'outline': makeObjectPropertySetter(readBoolean)
}); });
@@ -948,10 +948,10 @@ const ICON_PARSERS = makeStructureNS(
'href': makeObjectPropertySetter(readURI) 'href': makeObjectPropertySetter(readURI)
}, makeStructureNS( }, makeStructureNS(
GX_NAMESPACE_URIS, { GX_NAMESPACE_URIS, {
'x': makeObjectPropertySetter(XSD.readDecimal), 'x': makeObjectPropertySetter(readDecimal),
'y': makeObjectPropertySetter(XSD.readDecimal), 'y': makeObjectPropertySetter(readDecimal),
'w': makeObjectPropertySetter(XSD.readDecimal), 'w': makeObjectPropertySetter(readDecimal),
'h': makeObjectPropertySetter(XSD.readDecimal) 'h': makeObjectPropertySetter(readDecimal)
})); }));
@@ -998,9 +998,9 @@ function readFlatCoordinatesFromNode(node, objectStack) {
*/ */
const EXTRUDE_AND_ALTITUDE_MODE_PARSERS = makeStructureNS( const EXTRUDE_AND_ALTITUDE_MODE_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'extrude': makeObjectPropertySetter(XSD.readBoolean), 'extrude': makeObjectPropertySetter(readBoolean),
'tessellate': makeObjectPropertySetter(XSD.readBoolean), 'tessellate': makeObjectPropertySetter(readBoolean),
'altitudeMode': makeObjectPropertySetter(XSD.readString) 'altitudeMode': makeObjectPropertySetter(readString)
}); });
@@ -1286,8 +1286,8 @@ function setCommonGeometryProperties(multiGeometry,
*/ */
const DATA_PARSERS = makeStructureNS( const DATA_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'displayName': makeObjectPropertySetter(XSD.readString), 'displayName': makeObjectPropertySetter(readString),
'value': makeObjectPropertySetter(XSD.readString) 'value': makeObjectPropertySetter(readString)
}); });
@@ -1353,7 +1353,7 @@ function regionParser(node, objectStack) {
const PAIR_PARSERS = makeStructureNS( const PAIR_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Style': makeObjectPropertySetter(readStyle), 'Style': makeObjectPropertySetter(readStyle),
'key': makeObjectPropertySetter(XSD.readString), 'key': makeObjectPropertySetter(readString),
'styleUrl': makeObjectPropertySetter(readURI) 'styleUrl': makeObjectPropertySetter(readURI)
}); });
@@ -1431,7 +1431,7 @@ function schemaDataParser(node, objectStack) {
function simpleDataParser(node, objectStack) { function simpleDataParser(node, objectStack) {
const name = node.getAttribute('name'); const name = node.getAttribute('name');
if (name !== null) { if (name !== null) {
const data = XSD.readString(node); const data = readString(node);
const featureObject = const featureObject =
/** @type {Object} */ (objectStack[objectStack.length - 1]); /** @type {Object} */ (objectStack[objectStack.length - 1]);
featureObject[name] = data; featureObject[name] = data;
@@ -1445,13 +1445,13 @@ function simpleDataParser(node, objectStack) {
*/ */
const LAT_LON_ALT_BOX_PARSERS = makeStructureNS( const LAT_LON_ALT_BOX_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'altitudeMode': makeObjectPropertySetter(XSD.readString), 'altitudeMode': makeObjectPropertySetter(readString),
'minAltitude': makeObjectPropertySetter(XSD.readDecimal), 'minAltitude': makeObjectPropertySetter(readDecimal),
'maxAltitude': makeObjectPropertySetter(XSD.readDecimal), 'maxAltitude': makeObjectPropertySetter(readDecimal),
'north': makeObjectPropertySetter(XSD.readDecimal), 'north': makeObjectPropertySetter(readDecimal),
'south': makeObjectPropertySetter(XSD.readDecimal), 'south': makeObjectPropertySetter(readDecimal),
'east': makeObjectPropertySetter(XSD.readDecimal), 'east': makeObjectPropertySetter(readDecimal),
'west': makeObjectPropertySetter(XSD.readDecimal) 'west': makeObjectPropertySetter(readDecimal)
}); });
@@ -1484,10 +1484,10 @@ function latLonAltBoxParser(node, objectStack) {
*/ */
const LOD_PARSERS = makeStructureNS( const LOD_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'minLodPixels': makeObjectPropertySetter(XSD.readDecimal), 'minLodPixels': makeObjectPropertySetter(readDecimal),
'maxLodPixels': makeObjectPropertySetter(XSD.readDecimal), 'maxLodPixels': makeObjectPropertySetter(readDecimal),
'minFadeExtent': makeObjectPropertySetter(XSD.readDecimal), 'minFadeExtent': makeObjectPropertySetter(readDecimal),
'maxFadeExtent': makeObjectPropertySetter(XSD.readDecimal) 'maxFadeExtent': makeObjectPropertySetter(readDecimal)
}); });
@@ -1569,12 +1569,12 @@ const NETWORK_LINK_PARSERS = makeStructureNS(
'ExtendedData': extendedDataParser, 'ExtendedData': extendedDataParser,
'Region': regionParser, 'Region': regionParser,
'Link': linkParser, 'Link': linkParser,
'address': makeObjectPropertySetter(XSD.readString), 'address': makeObjectPropertySetter(readString),
'description': makeObjectPropertySetter(XSD.readString), 'description': makeObjectPropertySetter(readString),
'name': makeObjectPropertySetter(XSD.readString), 'name': makeObjectPropertySetter(readString),
'open': makeObjectPropertySetter(XSD.readBoolean), 'open': makeObjectPropertySetter(readBoolean),
'phoneNumber': makeObjectPropertySetter(XSD.readString), 'phoneNumber': makeObjectPropertySetter(readString),
'visibility': makeObjectPropertySetter(XSD.readBoolean) 'visibility': makeObjectPropertySetter(readBoolean)
}); });
@@ -1631,13 +1631,13 @@ const PLACEMARK_PARSERS = makeStructureNS(
readPolygon, 'geometry'), readPolygon, 'geometry'),
'Style': makeObjectPropertySetter(readStyle), 'Style': makeObjectPropertySetter(readStyle),
'StyleMap': placemarkStyleMapParser, 'StyleMap': placemarkStyleMapParser,
'address': makeObjectPropertySetter(XSD.readString), 'address': makeObjectPropertySetter(readString),
'description': makeObjectPropertySetter(XSD.readString), 'description': makeObjectPropertySetter(readString),
'name': makeObjectPropertySetter(XSD.readString), 'name': makeObjectPropertySetter(readString),
'open': makeObjectPropertySetter(XSD.readBoolean), 'open': makeObjectPropertySetter(readBoolean),
'phoneNumber': makeObjectPropertySetter(XSD.readString), 'phoneNumber': makeObjectPropertySetter(readString),
'styleUrl': makeObjectPropertySetter(readURI), 'styleUrl': makeObjectPropertySetter(readURI),
'visibility': makeObjectPropertySetter(XSD.readBoolean) 'visibility': makeObjectPropertySetter(readBoolean)
}, makeStructureNS( }, makeStructureNS(
GX_NAMESPACE_URIS, { GX_NAMESPACE_URIS, {
'MultiTrack': makeObjectPropertySetter( 'MultiTrack': makeObjectPropertySetter(
@@ -1908,7 +1908,7 @@ KML.prototype.readNameFromNode = function(node) {
for (n = node.firstElementChild; n; n = n.nextElementSibling) { for (n = node.firstElementChild; n; n = n.nextElementSibling) {
if (includes(NAMESPACE_URIS, n.namespaceURI) && if (includes(NAMESPACE_URIS, n.namespaceURI) &&
n.localName == 'name') { n.localName == 'name') {
return XSD.readString(n); return readString(n);
} }
} }
for (n = node.firstElementChild; n; n = n.nextElementSibling) { for (n = node.firstElementChild; n; n = n.nextElementSibling) {
@@ -2083,7 +2083,7 @@ function writeColorTextNode(node, color) {
const hex = parseInt(abgr[i], 10).toString(16); const hex = parseInt(abgr[i], 10).toString(16);
abgr[i] = (hex.length == 1) ? '0' + hex : hex; abgr[i] = (hex.length == 1) ? '0' + hex : hex;
} }
XSD.writeStringTextNode(node, abgr.join('')); writeStringTextNode(node, abgr.join(''));
} }
@@ -2124,7 +2124,7 @@ function writeCoordinatesTextNode(node, coordinates, objectStack) {
} }
} }
} }
XSD.writeStringTextNode(node, text); writeStringTextNode(node, text);
} }
@@ -2172,7 +2172,7 @@ function writeDataNode(node, pair, objectStack) {
* @param {string} name DisplayName. * @param {string} name DisplayName.
*/ */
function writeDataNodeName(node, name) { function writeDataNodeName(node, name) {
XSD.writeCDATASection(node, name); writeCDATASection(node, name);
} }
@@ -2181,7 +2181,7 @@ function writeDataNodeName(node, name) {
* @param {string} value Value. * @param {string} value Value.
*/ */
function writeDataNodeValue(node, value) { function writeDataNodeValue(node, value) {
XSD.writeStringTextNode(node, value); writeStringTextNode(node, value);
} }
@@ -2268,13 +2268,13 @@ const ICON_SEQUENCE = makeStructureNS(
*/ */
const ICON_SERIALIZERS = makeStructureNS( const ICON_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'href': makeChildAppender(XSD.writeStringTextNode) 'href': makeChildAppender(writeStringTextNode)
}, makeStructureNS( }, makeStructureNS(
GX_NAMESPACE_URIS, { GX_NAMESPACE_URIS, {
'x': makeChildAppender(XSD.writeDecimalTextNode), 'x': makeChildAppender(writeDecimalTextNode),
'y': makeChildAppender(XSD.writeDecimalTextNode), 'y': makeChildAppender(writeDecimalTextNode),
'w': makeChildAppender(XSD.writeDecimalTextNode), 'w': makeChildAppender(writeDecimalTextNode),
'h': makeChildAppender(XSD.writeDecimalTextNode) 'h': makeChildAppender(writeDecimalTextNode)
})); }));
@@ -2329,7 +2329,7 @@ const ICON_STYLE_SEQUENCE = makeStructureNS(
const ICON_STYLE_SERIALIZERS = makeStructureNS( const ICON_STYLE_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Icon': makeChildAppender(writeIcon), 'Icon': makeChildAppender(writeIcon),
'heading': makeChildAppender(XSD.writeDecimalTextNode), 'heading': makeChildAppender(writeDecimalTextNode),
'hotSpot': makeChildAppender(writeVec2), 'hotSpot': makeChildAppender(writeVec2),
'scale': makeChildAppender(writeScaleTextNode) 'scale': makeChildAppender(writeScaleTextNode)
}); });
@@ -2455,7 +2455,7 @@ const LINE_STYLE_SEQUENCE = makeStructureNS(
const LINE_STYLE_SERIALIZERS = makeStructureNS( const LINE_STYLE_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'color': makeChildAppender(writeColorTextNode), 'color': makeChildAppender(writeColorTextNode),
'width': makeChildAppender(XSD.writeDecimalTextNode) 'width': makeChildAppender(writeDecimalTextNode)
}); });
@@ -2625,28 +2625,20 @@ function writeBoundaryIs(node, linearRing, objectStack) {
*/ */
const PLACEMARK_SERIALIZERS = makeStructureNS( const PLACEMARK_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'ExtendedData': makeChildAppender( 'ExtendedData': makeChildAppender(writeExtendedData),
writeExtendedData), 'MultiGeometry': makeChildAppender(writeMultiGeometry),
'MultiGeometry': makeChildAppender( 'LineString': makeChildAppender(writePrimitiveGeometry),
writeMultiGeometry), 'LinearRing': makeChildAppender(writePrimitiveGeometry),
'LineString': makeChildAppender( 'Point': makeChildAppender(writePrimitiveGeometry),
writePrimitiveGeometry),
'LinearRing': makeChildAppender(
writePrimitiveGeometry),
'Point': makeChildAppender(
writePrimitiveGeometry),
'Polygon': makeChildAppender(writePolygon), 'Polygon': makeChildAppender(writePolygon),
'Style': makeChildAppender(writeStyle), 'Style': makeChildAppender(writeStyle),
'address': makeChildAppender(XSD.writeStringTextNode), 'address': makeChildAppender(writeStringTextNode),
'description': makeChildAppender( 'description': makeChildAppender(writeStringTextNode),
XSD.writeStringTextNode), 'name': makeChildAppender(writeStringTextNode),
'name': makeChildAppender(XSD.writeStringTextNode), 'open': makeChildAppender(writeBooleanTextNode),
'open': makeChildAppender(XSD.writeBooleanTextNode), 'phoneNumber': makeChildAppender(writeStringTextNode),
'phoneNumber': makeChildAppender( 'styleUrl': makeChildAppender(writeStringTextNode),
XSD.writeStringTextNode), 'visibility': makeChildAppender(writeBooleanTextNode)
'styleUrl': makeChildAppender(XSD.writeStringTextNode),
'visibility': makeChildAppender(
XSD.writeBooleanTextNode)
}); });
@@ -2752,11 +2744,10 @@ const PRIMITIVE_GEOMETRY_SEQUENCE = makeStructureNS(
*/ */
const PRIMITIVE_GEOMETRY_SERIALIZERS = makeStructureNS( const PRIMITIVE_GEOMETRY_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'extrude': makeChildAppender(XSD.writeBooleanTextNode), 'extrude': makeChildAppender(writeBooleanTextNode),
'tessellate': makeChildAppender(XSD.writeBooleanTextNode), 'tessellate': makeChildAppender(writeBooleanTextNode),
'altitudeMode': makeChildAppender(XSD.writeStringTextNode), 'altitudeMode': makeChildAppender(writeStringTextNode),
'coordinates': makeChildAppender( 'coordinates': makeChildAppender(writeCoordinatesTextNode)
writeCoordinatesTextNode)
}); });
@@ -2870,7 +2861,7 @@ function writePolyStyle(node, style, objectStack) {
*/ */
function writeScaleTextNode(node, scale) { function writeScaleTextNode(node, scale) {
// the Math is to remove any excess decimals created by float arithmetic // the Math is to remove any excess decimals created by float arithmetic
XSD.writeDecimalTextNode(node, writeDecimalTextNode(node,
Math.round(scale * 1e6) / 1e6); Math.round(scale * 1e6) / 1e6);
} }
@@ -3011,4 +3002,5 @@ KML.prototype.writeFeaturesNode = function(features, opt_options) {
this); this);
return kml; return kml;
}; };
export default KML; export default KML;

View File

@@ -4,7 +4,7 @@
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import {readHref} from '../format/XLink.js'; import {readHref} from '../format/XLink.js';
import XML from '../format/XML.js'; import XML from '../format/XML.js';
import XSD from '../format/XSD.js'; import {readString} from '../format/xsd.js';
import {makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pushParseAndPop} from '../xml.js'; import {makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pushParseAndPop} from '../xml.js';
/** /**
@@ -31,12 +31,9 @@ const NAMESPACE_URIS = [null, 'http://www.opengis.net/ows/1.1'];
*/ */
const PARSERS = makeStructureNS( const PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'ServiceIdentification': makeObjectPropertySetter( 'ServiceIdentification': makeObjectPropertySetter(readServiceIdentification),
readServiceIdentification), 'ServiceProvider': makeObjectPropertySetter(readServiceProvider),
'ServiceProvider': makeObjectPropertySetter( 'OperationsMetadata': makeObjectPropertySetter(readOperationsMetadata)
readServiceProvider),
'OperationsMetadata': makeObjectPropertySetter(
readOperationsMetadata)
}); });
@@ -46,15 +43,12 @@ const PARSERS = makeStructureNS(
*/ */
const ADDRESS_PARSERS = makeStructureNS( const ADDRESS_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'DeliveryPoint': makeObjectPropertySetter( 'DeliveryPoint': makeObjectPropertySetter(readString),
XSD.readString), 'City': makeObjectPropertySetter(readString),
'City': makeObjectPropertySetter(XSD.readString), 'AdministrativeArea': makeObjectPropertySetter(readString),
'AdministrativeArea': makeObjectPropertySetter( 'PostalCode': makeObjectPropertySetter(readString),
XSD.readString), 'Country': makeObjectPropertySetter(readString),
'PostalCode': makeObjectPropertySetter(XSD.readString), 'ElectronicMailAddress': makeObjectPropertySetter(readString)
'Country': makeObjectPropertySetter(XSD.readString),
'ElectronicMailAddress': makeObjectPropertySetter(
XSD.readString)
}); });
@@ -74,8 +68,7 @@ const ALLOWED_VALUES_PARSERS = makeStructureNS(
*/ */
const CONSTRAINT_PARSERS = makeStructureNS( const CONSTRAINT_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'AllowedValues': makeObjectPropertySetter( 'AllowedValues': makeObjectPropertySetter(readAllowedValues)
readAllowedValues)
}); });
@@ -137,8 +130,8 @@ const OPERATIONS_METADATA_PARSERS = makeStructureNS(
*/ */
const PHONE_PARSERS = makeStructureNS( const PHONE_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Voice': makeObjectPropertySetter(XSD.readString), 'Voice': makeObjectPropertySetter(readString),
'Facsimile': makeObjectPropertySetter(XSD.readString) 'Facsimile': makeObjectPropertySetter(readString)
}); });
@@ -148,8 +141,7 @@ const PHONE_PARSERS = makeStructureNS(
*/ */
const REQUEST_METHOD_PARSERS = makeStructureNS( const REQUEST_METHOD_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Constraint': makeObjectPropertyPusher( 'Constraint': makeObjectPropertyPusher(readConstraint)
readConstraint)
}); });
@@ -160,11 +152,9 @@ const REQUEST_METHOD_PARSERS = makeStructureNS(
const SERVICE_CONTACT_PARSERS = const SERVICE_CONTACT_PARSERS =
makeStructureNS( makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'IndividualName': makeObjectPropertySetter( 'IndividualName': makeObjectPropertySetter(readString),
XSD.readString), 'PositionName': makeObjectPropertySetter(readString),
'PositionName': makeObjectPropertySetter(XSD.readString), 'ContactInfo': makeObjectPropertySetter(readContactInfo)
'ContactInfo': makeObjectPropertySetter(
readContactInfo)
}); });
@@ -175,13 +165,12 @@ const SERVICE_CONTACT_PARSERS =
const SERVICE_IDENTIFICATION_PARSERS = const SERVICE_IDENTIFICATION_PARSERS =
makeStructureNS( makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Abstract': makeObjectPropertySetter(XSD.readString), 'Abstract': makeObjectPropertySetter(readString),
'AccessConstraints': makeObjectPropertySetter(XSD.readString), 'AccessConstraints': makeObjectPropertySetter(readString),
'Fees': makeObjectPropertySetter(XSD.readString), 'Fees': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(XSD.readString), 'Title': makeObjectPropertySetter(readString),
'ServiceTypeVersion': makeObjectPropertySetter( 'ServiceTypeVersion': makeObjectPropertySetter(readString),
XSD.readString), 'ServiceType': makeObjectPropertySetter(readString)
'ServiceType': makeObjectPropertySetter(XSD.readString)
}); });
@@ -192,10 +181,9 @@ const SERVICE_IDENTIFICATION_PARSERS =
const SERVICE_PROVIDER_PARSERS = const SERVICE_PROVIDER_PARSERS =
makeStructureNS( makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'ProviderName': makeObjectPropertySetter(XSD.readString), 'ProviderName': makeObjectPropertySetter(readString),
'ProviderSite': makeObjectPropertySetter(readHref), 'ProviderSite': makeObjectPropertySetter(readHref),
'ServiceContact': makeObjectPropertySetter( 'ServiceContact': makeObjectPropertySetter(readServiceContact)
readServiceContact)
}); });
@@ -303,8 +291,7 @@ function readGet(node, objectStack) {
* @return {Object|undefined} The HTTP object. * @return {Object|undefined} The HTTP object.
*/ */
function readHttp(node, objectStack) { function readHttp(node, objectStack) {
return pushParseAndPop({}, HTTP_PARSERS, return pushParseAndPop({}, HTTP_PARSERS, node, objectStack);
node, objectStack);
} }
@@ -331,8 +318,7 @@ function readOperation(node, objectStack) {
* @param {Array.<*>} objectStack Object stack. * @param {Array.<*>} objectStack Object stack.
* @return {Object|undefined} The operations metadata. * @return {Object|undefined} The operations metadata.
*/ */
function readOperationsMetadata(node, function readOperationsMetadata(node, objectStack) {
objectStack) {
return pushParseAndPop({}, return pushParseAndPop({},
OPERATIONS_METADATA_PARSERS, node, OPERATIONS_METADATA_PARSERS, node,
objectStack); objectStack);
@@ -355,8 +341,7 @@ function readPhone(node, objectStack) {
* @param {Array.<*>} objectStack Object stack. * @param {Array.<*>} objectStack Object stack.
* @return {Object|undefined} The service identification. * @return {Object|undefined} The service identification.
*/ */
function readServiceIdentification(node, function readServiceIdentification(node, objectStack) {
objectStack) {
return pushParseAndPop( return pushParseAndPop(
{}, SERVICE_IDENTIFICATION_PARSERS, node, {}, SERVICE_IDENTIFICATION_PARSERS, node,
objectStack); objectStack);
@@ -393,7 +378,7 @@ function readServiceProvider(node, objectStack) {
* @return {string|undefined} The value. * @return {string|undefined} The value.
*/ */
function readValue(node, objectStack) { function readValue(node, objectStack) {
return XSD.readString(node); return readString(node);
} }

View File

@@ -8,7 +8,7 @@ import GML3 from '../format/GML3.js';
import GMLBase, {GMLNS} from '../format/GMLBase.js'; import GMLBase, {GMLNS} from '../format/GMLBase.js';
import {and as andFilter, bbox as bboxFilter} from '../format/filter.js'; import {and as andFilter, bbox as bboxFilter} from '../format/filter.js';
import XMLFeature from '../format/XMLFeature.js'; import XMLFeature from '../format/XMLFeature.js';
import XSD from '../format/XSD.js'; import {readNonNegativeIntegerString, readNonNegativeInteger, writeStringTextNode} from '../format/xsd.js';
import Geometry from '../geom/Geometry.js'; import Geometry from '../geom/Geometry.js';
import {assign} from '../obj.js'; import {assign} from '../obj.js';
import {get as getProjection} from '../proj.js'; import {get as getProjection} from '../proj.js';
@@ -242,7 +242,7 @@ const FEATURE_COLLECTION_PARSERS = {
*/ */
WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) { WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) {
const result = {}; const result = {};
const value = XSD.readNonNegativeIntegerString( const value = readNonNegativeIntegerString(
node.getAttribute('numberOfFeatures')); node.getAttribute('numberOfFeatures'));
result['numberOfFeatures'] = value; result['numberOfFeatures'] = value;
return pushParseAndPop( return pushParseAndPop(
@@ -257,12 +257,9 @@ WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) {
*/ */
const TRANSACTION_SUMMARY_PARSERS = { const TRANSACTION_SUMMARY_PARSERS = {
'http://www.opengis.net/wfs': { 'http://www.opengis.net/wfs': {
'totalInserted': makeObjectPropertySetter( 'totalInserted': makeObjectPropertySetter(readNonNegativeInteger),
XSD.readNonNegativeInteger), 'totalUpdated': makeObjectPropertySetter(readNonNegativeInteger),
'totalUpdated': makeObjectPropertySetter( 'totalDeleted': makeObjectPropertySetter(readNonNegativeInteger)
XSD.readNonNegativeInteger),
'totalDeleted': makeObjectPropertySetter(
XSD.readNonNegativeInteger)
} }
}; };
@@ -366,7 +363,7 @@ WFS.prototype.readTransactionResponseFromNode = function(node) {
*/ */
const QUERY_SERIALIZERS = { const QUERY_SERIALIZERS = {
'http://www.opengis.net/wfs': { 'http://www.opengis.net/wfs': {
'PropertyName': makeChildAppender(XSD.writeStringTextNode) 'PropertyName': makeChildAppender(writeStringTextNode)
} }
}; };
@@ -507,7 +504,7 @@ function writeProperty(node, pair, objectStack) {
const context = objectStack[objectStack.length - 1]; const context = objectStack[objectStack.length - 1];
const gmlVersion = context['gmlVersion']; const gmlVersion = context['gmlVersion'];
node.appendChild(name); node.appendChild(name);
XSD.writeStringTextNode(name, pair.name); writeStringTextNode(name, pair.name);
if (pair.value !== undefined && pair.value !== null) { if (pair.value !== undefined && pair.value !== null) {
const value = createElementNS(WFSNS, 'Value'); const value = createElementNS(WFSNS, 'Value');
node.appendChild(value); node.appendChild(value);
@@ -520,7 +517,7 @@ function writeProperty(node, pair, objectStack) {
pair.value, objectStack); pair.value, objectStack);
} }
} else { } else {
XSD.writeStringTextNode(value, pair.value); writeStringTextNode(value, pair.value);
} }
} }
} }
@@ -540,7 +537,7 @@ function writeNative(node, nativeElement, objectStack) {
node.setAttribute('safeToIgnore', nativeElement.safeToIgnore); node.setAttribute('safeToIgnore', nativeElement.safeToIgnore);
} }
if (nativeElement.value !== undefined) { if (nativeElement.value !== undefined) {
XSD.writeStringTextNode(node, nativeElement.value); writeStringTextNode(node, nativeElement.value);
} }
} }
@@ -693,7 +690,7 @@ function writeWithinFilter(node, filter, objectStack) {
function writeDuringFilter(node, filter, objectStack) { function writeDuringFilter(node, filter, objectStack) {
const valueReference = createElementNS(FESNS, 'ValueReference'); const valueReference = createElementNS(FESNS, 'ValueReference');
XSD.writeStringTextNode(valueReference, filter.propertyName); writeStringTextNode(valueReference, filter.propertyName);
node.appendChild(valueReference); node.appendChild(valueReference);
const timePeriod = createElementNS(GMLNS, 'TimePeriod'); const timePeriod = createElementNS(GMLNS, 'TimePeriod');
@@ -811,7 +808,7 @@ function writeIsLikeFilter(node, filter, objectStack) {
*/ */
function writeOgcExpression(tagName, node, value) { function writeOgcExpression(tagName, node, value) {
const property = createElementNS(OGCNS, tagName); const property = createElementNS(OGCNS, tagName);
XSD.writeStringTextNode(property, value); writeStringTextNode(property, value);
node.appendChild(property); node.appendChild(property);
} }
@@ -844,7 +841,7 @@ function writeTimeInstant(node, time) {
const timePosition = createElementNS(GMLNS, 'timePosition'); const timePosition = createElementNS(GMLNS, 'timePosition');
timeInstant.appendChild(timePosition); timeInstant.appendChild(timePosition);
XSD.writeStringTextNode(timePosition, time); writeStringTextNode(timePosition, time);
} }

View File

@@ -4,7 +4,7 @@
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import {readHref} from '../format/XLink.js'; import {readHref} from '../format/XLink.js';
import XML from '../format/XML.js'; import XML from '../format/XML.js';
import XSD from '../format/XSD.js'; import {readDecimalString, readString, readNonNegativeInteger, readDecimal, readBooleanString, readNonNegativeIntegerString} from '../format/xsd.js';
import {makeArrayPusher, makeObjectPropertyPusher, makeObjectPropertySetter, import {makeArrayPusher, makeObjectPropertyPusher, makeObjectPropertySetter,
makeStructureNS, pushParseAndPop} from '../xml.js'; makeStructureNS, pushParseAndPop} from '../xml.js';
@@ -69,17 +69,17 @@ const CAPABILITY_PARSERS = makeStructureNS(
*/ */
const SERVICE_PARSERS = makeStructureNS( const SERVICE_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Name': makeObjectPropertySetter(XSD.readString), 'Name': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(XSD.readString), 'Title': makeObjectPropertySetter(readString),
'Abstract': makeObjectPropertySetter(XSD.readString), 'Abstract': makeObjectPropertySetter(readString),
'KeywordList': makeObjectPropertySetter(readKeywordList), 'KeywordList': makeObjectPropertySetter(readKeywordList),
'OnlineResource': makeObjectPropertySetter(readHref), 'OnlineResource': makeObjectPropertySetter(readHref),
'ContactInformation': makeObjectPropertySetter(readContactInformation), 'ContactInformation': makeObjectPropertySetter(readContactInformation),
'Fees': makeObjectPropertySetter(XSD.readString), 'Fees': makeObjectPropertySetter(readString),
'AccessConstraints': makeObjectPropertySetter(XSD.readString), 'AccessConstraints': makeObjectPropertySetter(readString),
'LayerLimit': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'LayerLimit': makeObjectPropertySetter(readNonNegativeInteger),
'MaxWidth': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'MaxWidth': makeObjectPropertySetter(readNonNegativeInteger),
'MaxHeight': makeObjectPropertySetter(XSD.readNonNegativeInteger) 'MaxHeight': makeObjectPropertySetter(readNonNegativeInteger)
}); });
@@ -90,11 +90,11 @@ const SERVICE_PARSERS = makeStructureNS(
const CONTACT_INFORMATION_PARSERS = makeStructureNS( const CONTACT_INFORMATION_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'ContactPersonPrimary': makeObjectPropertySetter(readContactPersonPrimary), 'ContactPersonPrimary': makeObjectPropertySetter(readContactPersonPrimary),
'ContactPosition': makeObjectPropertySetter(XSD.readString), 'ContactPosition': makeObjectPropertySetter(readString),
'ContactAddress': makeObjectPropertySetter(readContactAddress), 'ContactAddress': makeObjectPropertySetter(readContactAddress),
'ContactVoiceTelephone': makeObjectPropertySetter(XSD.readString), 'ContactVoiceTelephone': makeObjectPropertySetter(readString),
'ContactFacsimileTelephone': makeObjectPropertySetter(XSD.readString), 'ContactFacsimileTelephone': makeObjectPropertySetter(readString),
'ContactElectronicMailAddress': makeObjectPropertySetter(XSD.readString) 'ContactElectronicMailAddress': makeObjectPropertySetter(readString)
}); });
@@ -104,8 +104,8 @@ const CONTACT_INFORMATION_PARSERS = makeStructureNS(
*/ */
const CONTACT_PERSON_PARSERS = makeStructureNS( const CONTACT_PERSON_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'ContactPerson': makeObjectPropertySetter(XSD.readString), 'ContactPerson': makeObjectPropertySetter(readString),
'ContactOrganization': makeObjectPropertySetter(XSD.readString) 'ContactOrganization': makeObjectPropertySetter(readString)
}); });
@@ -115,12 +115,12 @@ const CONTACT_PERSON_PARSERS = makeStructureNS(
*/ */
const CONTACT_ADDRESS_PARSERS = makeStructureNS( const CONTACT_ADDRESS_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'AddressType': makeObjectPropertySetter(XSD.readString), 'AddressType': makeObjectPropertySetter(readString),
'Address': makeObjectPropertySetter(XSD.readString), 'Address': makeObjectPropertySetter(readString),
'City': makeObjectPropertySetter(XSD.readString), 'City': makeObjectPropertySetter(readString),
'StateOrProvince': makeObjectPropertySetter(XSD.readString), 'StateOrProvince': makeObjectPropertySetter(readString),
'PostCode': makeObjectPropertySetter(XSD.readString), 'PostCode': makeObjectPropertySetter(readString),
'Country': makeObjectPropertySetter(XSD.readString) 'Country': makeObjectPropertySetter(readString)
}); });
@@ -130,7 +130,7 @@ const CONTACT_ADDRESS_PARSERS = makeStructureNS(
*/ */
const EXCEPTION_PARSERS = makeStructureNS( const EXCEPTION_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Format': makeArrayPusher(XSD.readString) 'Format': makeArrayPusher(readString)
}); });
@@ -140,23 +140,23 @@ const EXCEPTION_PARSERS = makeStructureNS(
*/ */
const LAYER_PARSERS = makeStructureNS( const LAYER_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Name': makeObjectPropertySetter(XSD.readString), 'Name': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(XSD.readString), 'Title': makeObjectPropertySetter(readString),
'Abstract': makeObjectPropertySetter(XSD.readString), 'Abstract': makeObjectPropertySetter(readString),
'KeywordList': makeObjectPropertySetter(readKeywordList), 'KeywordList': makeObjectPropertySetter(readKeywordList),
'CRS': makeObjectPropertyPusher(XSD.readString), 'CRS': makeObjectPropertyPusher(readString),
'EX_GeographicBoundingBox': makeObjectPropertySetter(readEXGeographicBoundingBox), 'EX_GeographicBoundingBox': makeObjectPropertySetter(readEXGeographicBoundingBox),
'BoundingBox': makeObjectPropertyPusher(readBoundingBox), 'BoundingBox': makeObjectPropertyPusher(readBoundingBox),
'Dimension': makeObjectPropertyPusher(readDimension), 'Dimension': makeObjectPropertyPusher(readDimension),
'Attribution': makeObjectPropertySetter(readAttribution), 'Attribution': makeObjectPropertySetter(readAttribution),
'AuthorityURL': makeObjectPropertyPusher(readAuthorityURL), 'AuthorityURL': makeObjectPropertyPusher(readAuthorityURL),
'Identifier': makeObjectPropertyPusher(XSD.readString), 'Identifier': makeObjectPropertyPusher(readString),
'MetadataURL': makeObjectPropertyPusher(readMetadataURL), 'MetadataURL': makeObjectPropertyPusher(readMetadataURL),
'DataURL': makeObjectPropertyPusher(readFormatOnlineresource), 'DataURL': makeObjectPropertyPusher(readFormatOnlineresource),
'FeatureListURL': makeObjectPropertyPusher(readFormatOnlineresource), 'FeatureListURL': makeObjectPropertyPusher(readFormatOnlineresource),
'Style': makeObjectPropertyPusher(readStyle), 'Style': makeObjectPropertyPusher(readStyle),
'MinScaleDenominator': makeObjectPropertySetter(XSD.readDecimal), 'MinScaleDenominator': makeObjectPropertySetter(readDecimal),
'MaxScaleDenominator': makeObjectPropertySetter(XSD.readDecimal), 'MaxScaleDenominator': makeObjectPropertySetter(readDecimal),
'Layer': makeObjectPropertyPusher(readLayer) 'Layer': makeObjectPropertyPusher(readLayer)
}); });
@@ -167,7 +167,7 @@ const LAYER_PARSERS = makeStructureNS(
*/ */
const ATTRIBUTION_PARSERS = makeStructureNS( const ATTRIBUTION_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Title': makeObjectPropertySetter(XSD.readString), 'Title': makeObjectPropertySetter(readString),
'OnlineResource': makeObjectPropertySetter(readHref), 'OnlineResource': makeObjectPropertySetter(readHref),
'LogoURL': makeObjectPropertySetter(readSizedFormatOnlineresource) 'LogoURL': makeObjectPropertySetter(readSizedFormatOnlineresource)
}); });
@@ -179,10 +179,10 @@ const ATTRIBUTION_PARSERS = makeStructureNS(
*/ */
const EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS = const EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS =
makeStructureNS(NAMESPACE_URIS, { makeStructureNS(NAMESPACE_URIS, {
'westBoundLongitude': makeObjectPropertySetter(XSD.readDecimal), 'westBoundLongitude': makeObjectPropertySetter(readDecimal),
'eastBoundLongitude': makeObjectPropertySetter(XSD.readDecimal), 'eastBoundLongitude': makeObjectPropertySetter(readDecimal),
'southBoundLatitude': makeObjectPropertySetter(XSD.readDecimal), 'southBoundLatitude': makeObjectPropertySetter(readDecimal),
'northBoundLatitude': makeObjectPropertySetter(XSD.readDecimal) 'northBoundLatitude': makeObjectPropertySetter(readDecimal)
}); });
@@ -204,7 +204,7 @@ const REQUEST_PARSERS = makeStructureNS(
*/ */
const OPERATIONTYPE_PARSERS = makeStructureNS( const OPERATIONTYPE_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Format': makeObjectPropertyPusher(XSD.readString), 'Format': makeObjectPropertyPusher(readString),
'DCPType': makeObjectPropertyPusher(readDCPType) 'DCPType': makeObjectPropertyPusher(readDCPType)
}); });
@@ -236,9 +236,9 @@ const HTTP_PARSERS = makeStructureNS(
*/ */
const STYLE_PARSERS = makeStructureNS( const STYLE_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Name': makeObjectPropertySetter(XSD.readString), 'Name': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(XSD.readString), 'Title': makeObjectPropertySetter(readString),
'Abstract': makeObjectPropertySetter(XSD.readString), 'Abstract': makeObjectPropertySetter(readString),
'LegendURL': makeObjectPropertyPusher(readSizedFormatOnlineresource), 'LegendURL': makeObjectPropertyPusher(readSizedFormatOnlineresource),
'StyleSheetURL': makeObjectPropertySetter(readFormatOnlineresource), 'StyleSheetURL': makeObjectPropertySetter(readFormatOnlineresource),
'StyleURL': makeObjectPropertySetter(readFormatOnlineresource) 'StyleURL': makeObjectPropertySetter(readFormatOnlineresource)
@@ -251,7 +251,7 @@ const STYLE_PARSERS = makeStructureNS(
*/ */
const FORMAT_ONLINERESOURCE_PARSERS = const FORMAT_ONLINERESOURCE_PARSERS =
makeStructureNS(NAMESPACE_URIS, { makeStructureNS(NAMESPACE_URIS, {
'Format': makeObjectPropertySetter(XSD.readString), 'Format': makeObjectPropertySetter(readString),
'OnlineResource': makeObjectPropertySetter(readHref) 'OnlineResource': makeObjectPropertySetter(readHref)
}); });
@@ -262,7 +262,7 @@ const FORMAT_ONLINERESOURCE_PARSERS =
*/ */
const KEYWORDLIST_PARSERS = makeStructureNS( const KEYWORDLIST_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Keyword': makeArrayPusher(XSD.readString) 'Keyword': makeArrayPusher(readString)
}); });
@@ -319,15 +319,15 @@ function readAttribution(node, objectStack) {
*/ */
function readBoundingBox(node, objectStack) { function readBoundingBox(node, objectStack) {
const extent = [ const extent = [
XSD.readDecimalString(node.getAttribute('minx')), readDecimalString(node.getAttribute('minx')),
XSD.readDecimalString(node.getAttribute('miny')), readDecimalString(node.getAttribute('miny')),
XSD.readDecimalString(node.getAttribute('maxx')), readDecimalString(node.getAttribute('maxx')),
XSD.readDecimalString(node.getAttribute('maxy')) readDecimalString(node.getAttribute('maxy'))
]; ];
const resolutions = [ const resolutions = [
XSD.readDecimalString(node.getAttribute('resx')), readDecimalString(node.getAttribute('resx')),
XSD.readDecimalString(node.getAttribute('resy')) readDecimalString(node.getAttribute('resy'))
]; ];
return { return {
@@ -454,38 +454,38 @@ function readLayer(node, objectStack) {
if (!layerObject) { if (!layerObject) {
return undefined; return undefined;
} }
let queryable = XSD.readBooleanString(node.getAttribute('queryable')); let queryable = readBooleanString(node.getAttribute('queryable'));
if (queryable === undefined) { if (queryable === undefined) {
queryable = parentLayerObject['queryable']; queryable = parentLayerObject['queryable'];
} }
layerObject['queryable'] = queryable !== undefined ? queryable : false; layerObject['queryable'] = queryable !== undefined ? queryable : false;
let cascaded = XSD.readNonNegativeIntegerString( let cascaded = readNonNegativeIntegerString(
node.getAttribute('cascaded')); node.getAttribute('cascaded'));
if (cascaded === undefined) { if (cascaded === undefined) {
cascaded = parentLayerObject['cascaded']; cascaded = parentLayerObject['cascaded'];
} }
layerObject['cascaded'] = cascaded; layerObject['cascaded'] = cascaded;
let opaque = XSD.readBooleanString(node.getAttribute('opaque')); let opaque = readBooleanString(node.getAttribute('opaque'));
if (opaque === undefined) { if (opaque === undefined) {
opaque = parentLayerObject['opaque']; opaque = parentLayerObject['opaque'];
} }
layerObject['opaque'] = opaque !== undefined ? opaque : false; layerObject['opaque'] = opaque !== undefined ? opaque : false;
let noSubsets = XSD.readBooleanString(node.getAttribute('noSubsets')); let noSubsets = readBooleanString(node.getAttribute('noSubsets'));
if (noSubsets === undefined) { if (noSubsets === undefined) {
noSubsets = parentLayerObject['noSubsets']; noSubsets = parentLayerObject['noSubsets'];
} }
layerObject['noSubsets'] = noSubsets !== undefined ? noSubsets : false; layerObject['noSubsets'] = noSubsets !== undefined ? noSubsets : false;
let fixedWidth = XSD.readDecimalString(node.getAttribute('fixedWidth')); let fixedWidth = readDecimalString(node.getAttribute('fixedWidth'));
if (!fixedWidth) { if (!fixedWidth) {
fixedWidth = parentLayerObject['fixedWidth']; fixedWidth = parentLayerObject['fixedWidth'];
} }
layerObject['fixedWidth'] = fixedWidth; layerObject['fixedWidth'] = fixedWidth;
let fixedHeight = XSD.readDecimalString(node.getAttribute('fixedHeight')); let fixedHeight = readDecimalString(node.getAttribute('fixedHeight'));
if (!fixedHeight) { if (!fixedHeight) {
fixedHeight = parentLayerObject['fixedHeight']; fixedHeight = parentLayerObject['fixedHeight'];
} }
@@ -524,10 +524,10 @@ function readDimension(node, objectStack) {
'units': node.getAttribute('units'), 'units': node.getAttribute('units'),
'unitSymbol': node.getAttribute('unitSymbol'), 'unitSymbol': node.getAttribute('unitSymbol'),
'default': node.getAttribute('default'), 'default': node.getAttribute('default'),
'multipleValues': XSD.readBooleanString(node.getAttribute('multipleValues')), 'multipleValues': readBooleanString(node.getAttribute('multipleValues')),
'nearestValue': XSD.readBooleanString(node.getAttribute('nearestValue')), 'nearestValue': readBooleanString(node.getAttribute('nearestValue')),
'current': XSD.readBooleanString(node.getAttribute('current')), 'current': readBooleanString(node.getAttribute('current')),
'values': XSD.readString(node) 'values': readString(node)
}; };
return dimensionObject; return dimensionObject;
} }
@@ -592,8 +592,8 @@ function readSizedFormatOnlineresource(node, objectStack) {
const formatOnlineresource = readFormatOnlineresource(node, objectStack); const formatOnlineresource = readFormatOnlineresource(node, objectStack);
if (formatOnlineresource) { if (formatOnlineresource) {
const size = [ const size = [
XSD.readNonNegativeIntegerString(node.getAttribute('width')), readNonNegativeIntegerString(node.getAttribute('width')),
XSD.readNonNegativeIntegerString(node.getAttribute('height')) readNonNegativeIntegerString(node.getAttribute('height'))
]; ];
formatOnlineresource['size'] = size; formatOnlineresource['size'] = size;
return formatOnlineresource; return formatOnlineresource;

View File

@@ -6,7 +6,7 @@ import {boundingExtent} from '../extent.js';
import OWS from '../format/OWS.js'; import OWS from '../format/OWS.js';
import {readHref} from '../format/XLink.js'; import {readHref} from '../format/XLink.js';
import XML from '../format/XML.js'; import XML from '../format/XML.js';
import XSD from '../format/XSD.js'; import {readString, readNonNegativeInteger, readDecimal} from '../format/xsd.js';
import {pushParseAndPop, makeStructureNS, import {pushParseAndPop, makeStructureNS,
makeObjectPropertySetter, makeObjectPropertyPusher, makeArrayPusher} from '../xml.js'; makeObjectPropertySetter, makeObjectPropertyPusher, makeArrayPusher} from '../xml.js';
@@ -79,15 +79,15 @@ const CONTENTS_PARSERS = makeStructureNS(
const LAYER_PARSERS = makeStructureNS( const LAYER_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Style': makeObjectPropertyPusher(readStyle), 'Style': makeObjectPropertyPusher(readStyle),
'Format': makeObjectPropertyPusher(XSD.readString), 'Format': makeObjectPropertyPusher(readString),
'TileMatrixSetLink': makeObjectPropertyPusher(readTileMatrixSetLink), 'TileMatrixSetLink': makeObjectPropertyPusher(readTileMatrixSetLink),
'Dimension': makeObjectPropertyPusher(readDimensions), 'Dimension': makeObjectPropertyPusher(readDimensions),
'ResourceURL': makeObjectPropertyPusher(readResourceUrl) 'ResourceURL': makeObjectPropertyPusher(readResourceUrl)
}, makeStructureNS(OWS_NAMESPACE_URIS, { }, makeStructureNS(OWS_NAMESPACE_URIS, {
'Title': makeObjectPropertySetter(XSD.readString), 'Title': makeObjectPropertySetter(readString),
'Abstract': makeObjectPropertySetter(XSD.readString), 'Abstract': makeObjectPropertySetter(readString),
'WGS84BoundingBox': makeObjectPropertySetter(readWgs84BoundingBox), 'WGS84BoundingBox': makeObjectPropertySetter(readWgs84BoundingBox),
'Identifier': makeObjectPropertySetter(XSD.readString) 'Identifier': makeObjectPropertySetter(readString)
})); }));
@@ -99,8 +99,8 @@ const STYLE_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'LegendURL': makeObjectPropertyPusher(readLegendUrl) 'LegendURL': makeObjectPropertyPusher(readLegendUrl)
}, makeStructureNS(OWS_NAMESPACE_URIS, { }, makeStructureNS(OWS_NAMESPACE_URIS, {
'Title': makeObjectPropertySetter(XSD.readString), 'Title': makeObjectPropertySetter(readString),
'Identifier': makeObjectPropertySetter(XSD.readString) 'Identifier': makeObjectPropertySetter(readString)
})); }));
@@ -110,7 +110,7 @@ const STYLE_PARSERS = makeStructureNS(
*/ */
const TMS_LINKS_PARSERS = makeStructureNS( const TMS_LINKS_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'TileMatrixSet': makeObjectPropertySetter(XSD.readString), 'TileMatrixSet': makeObjectPropertySetter(readString),
'TileMatrixSetLimits': makeObjectPropertySetter(readTileMatrixLimitsList) 'TileMatrixSetLimits': makeObjectPropertySetter(readTileMatrixLimitsList)
}); });
@@ -130,11 +130,11 @@ const TMS_LIMITS_LIST_PARSERS = makeStructureNS(
*/ */
const TMS_LIMITS_PARSERS = makeStructureNS( const TMS_LIMITS_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'TileMatrix': makeObjectPropertySetter(XSD.readString), 'TileMatrix': makeObjectPropertySetter(readString),
'MinTileRow': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'MinTileRow': makeObjectPropertySetter(readNonNegativeInteger),
'MaxTileRow': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'MaxTileRow': makeObjectPropertySetter(readNonNegativeInteger),
'MinTileCol': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'MinTileCol': makeObjectPropertySetter(readNonNegativeInteger),
'MaxTileCol': makeObjectPropertySetter(XSD.readNonNegativeInteger) 'MaxTileCol': makeObjectPropertySetter(readNonNegativeInteger)
}); });
@@ -144,10 +144,10 @@ const TMS_LIMITS_PARSERS = makeStructureNS(
*/ */
const DIMENSION_PARSERS = makeStructureNS( const DIMENSION_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'Default': makeObjectPropertySetter(XSD.readString), 'Default': makeObjectPropertySetter(readString),
'Value': makeObjectPropertyPusher(XSD.readString) 'Value': makeObjectPropertyPusher(readString)
}, makeStructureNS(OWS_NAMESPACE_URIS, { }, makeStructureNS(OWS_NAMESPACE_URIS, {
'Identifier': makeObjectPropertySetter(XSD.readString) 'Identifier': makeObjectPropertySetter(readString)
})); }));
@@ -168,11 +168,11 @@ const WGS84_BBOX_READERS = makeStructureNS(
*/ */
const TMS_PARSERS = makeStructureNS( const TMS_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'WellKnownScaleSet': makeObjectPropertySetter(XSD.readString), 'WellKnownScaleSet': makeObjectPropertySetter(readString),
'TileMatrix': makeObjectPropertyPusher(readTileMatrix) 'TileMatrix': makeObjectPropertyPusher(readTileMatrix)
}, makeStructureNS(OWS_NAMESPACE_URIS, { }, makeStructureNS(OWS_NAMESPACE_URIS, {
'SupportedCRS': makeObjectPropertySetter(XSD.readString), 'SupportedCRS': makeObjectPropertySetter(readString),
'Identifier': makeObjectPropertySetter(XSD.readString) 'Identifier': makeObjectPropertySetter(readString)
})); }));
@@ -183,13 +183,13 @@ const TMS_PARSERS = makeStructureNS(
const TM_PARSERS = makeStructureNS( const TM_PARSERS = makeStructureNS(
NAMESPACE_URIS, { NAMESPACE_URIS, {
'TopLeftCorner': makeObjectPropertySetter(readCoordinates), 'TopLeftCorner': makeObjectPropertySetter(readCoordinates),
'ScaleDenominator': makeObjectPropertySetter(XSD.readDecimal), 'ScaleDenominator': makeObjectPropertySetter(readDecimal),
'TileWidth': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'TileWidth': makeObjectPropertySetter(readNonNegativeInteger),
'TileHeight': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'TileHeight': makeObjectPropertySetter(readNonNegativeInteger),
'MatrixWidth': makeObjectPropertySetter(XSD.readNonNegativeInteger), 'MatrixWidth': makeObjectPropertySetter(readNonNegativeInteger),
'MatrixHeight': makeObjectPropertySetter(XSD.readNonNegativeInteger) 'MatrixHeight': makeObjectPropertySetter(readNonNegativeInteger)
}, makeStructureNS(OWS_NAMESPACE_URIS, { }, makeStructureNS(OWS_NAMESPACE_URIS, {
'Identifier': makeObjectPropertySetter(XSD.readString) 'Identifier': makeObjectPropertySetter(readString)
})); }));
@@ -355,7 +355,7 @@ function readLegendUrl(node, objectStack) {
* @return {Object|undefined} Coordinates object. * @return {Object|undefined} Coordinates object.
*/ */
function readCoordinates(node, objectStack) { function readCoordinates(node, objectStack) {
const coordinates = XSD.readString(node).split(' '); const coordinates = readString(node).split(' ');
if (!coordinates || coordinates.length != 2) { if (!coordinates || coordinates.length != 2) {
return undefined; return undefined;
} }

View File

@@ -1,61 +1,60 @@
/** /**
* @module ol/format/XSD * @module ol/format/xsd
*/ */
import {getAllTextContent, DOCUMENT} from '../xml.js'; import {getAllTextContent, DOCUMENT} from '../xml.js';
import {padNumber} from '../string.js'; import {padNumber} from '../string.js';
const XSD = {};
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @return {boolean|undefined} Boolean. * @return {boolean|undefined} Boolean.
*/ */
XSD.readBoolean = function(node) { export function readBoolean(node) {
const s = getAllTextContent(node, false); const s = getAllTextContent(node, false);
return XSD.readBooleanString(s); return readBooleanString(s);
}; }
/** /**
* @param {string} string String. * @param {string} string String.
* @return {boolean|undefined} Boolean. * @return {boolean|undefined} Boolean.
*/ */
XSD.readBooleanString = function(string) { export function readBooleanString(string) {
const m = /^\s*(true|1)|(false|0)\s*$/.exec(string); const m = /^\s*(true|1)|(false|0)\s*$/.exec(string);
if (m) { if (m) {
return m[1] !== undefined || false; return m[1] !== undefined || false;
} else { } else {
return undefined; return undefined;
} }
}; }
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @return {number|undefined} DateTime in seconds. * @return {number|undefined} DateTime in seconds.
*/ */
XSD.readDateTime = function(node) { export function readDateTime(node) {
const s = getAllTextContent(node, false); const s = getAllTextContent(node, false);
const dateTime = Date.parse(s); const dateTime = Date.parse(s);
return isNaN(dateTime) ? undefined : dateTime / 1000; return isNaN(dateTime) ? undefined : dateTime / 1000;
}; }
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @return {number|undefined} Decimal. * @return {number|undefined} Decimal.
*/ */
XSD.readDecimal = function(node) { export function readDecimal(node) {
const s = getAllTextContent(node, false); const s = getAllTextContent(node, false);
return XSD.readDecimalString(s); return readDecimalString(s);
}; }
/** /**
* @param {string} string String. * @param {string} string String.
* @return {number|undefined} Decimal. * @return {number|undefined} Decimal.
*/ */
XSD.readDecimalString = function(string) { export function readDecimalString(string) {
// FIXME check spec // FIXME check spec
const m = /^\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)\s*$/i.exec(string); const m = /^\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)\s*$/i.exec(string);
if (m) { if (m) {
@@ -63,65 +62,65 @@ XSD.readDecimalString = function(string) {
} else { } else {
return undefined; return undefined;
} }
}; }
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @return {number|undefined} Non negative integer. * @return {number|undefined} Non negative integer.
*/ */
XSD.readNonNegativeInteger = function(node) { export function readNonNegativeInteger(node) {
const s = getAllTextContent(node, false); const s = getAllTextContent(node, false);
return XSD.readNonNegativeIntegerString(s); return readNonNegativeIntegerString(s);
}; }
/** /**
* @param {string} string String. * @param {string} string String.
* @return {number|undefined} Non negative integer. * @return {number|undefined} Non negative integer.
*/ */
XSD.readNonNegativeIntegerString = function(string) { export function readNonNegativeIntegerString(string) {
const m = /^\s*(\d+)\s*$/.exec(string); const m = /^\s*(\d+)\s*$/.exec(string);
if (m) { if (m) {
return parseInt(m[1], 10); return parseInt(m[1], 10);
} else { } else {
return undefined; return undefined;
} }
}; }
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @return {string|undefined} String. * @return {string|undefined} String.
*/ */
XSD.readString = function(node) { export function readString(node) {
return getAllTextContent(node, false).trim(); return getAllTextContent(node, false).trim();
}; }
/** /**
* @param {Node} node Node to append a TextNode with the boolean to. * @param {Node} node Node to append a TextNode with the boolean to.
* @param {boolean} bool Boolean. * @param {boolean} bool Boolean.
*/ */
XSD.writeBooleanTextNode = function(node, bool) { export function writeBooleanTextNode(node, bool) {
XSD.writeStringTextNode(node, (bool) ? '1' : '0'); writeStringTextNode(node, (bool) ? '1' : '0');
}; }
/** /**
* @param {Node} node Node to append a CDATA Section with the string to. * @param {Node} node Node to append a CDATA Section with the string to.
* @param {string} string String. * @param {string} string String.
*/ */
XSD.writeCDATASection = function(node, string) { export function writeCDATASection(node, string) {
node.appendChild(DOCUMENT.createCDATASection(string)); node.appendChild(DOCUMENT.createCDATASection(string));
}; }
/** /**
* @param {Node} node Node to append a TextNode with the dateTime to. * @param {Node} node Node to append a TextNode with the dateTime to.
* @param {number} dateTime DateTime in seconds. * @param {number} dateTime DateTime in seconds.
*/ */
XSD.writeDateTimeTextNode = function(node, dateTime) { export function writeDateTimeTextNode(node, dateTime) {
const date = new Date(dateTime * 1000); const date = new Date(dateTime * 1000);
const string = date.getUTCFullYear() + '-' + const string = date.getUTCFullYear() + '-' +
padNumber(date.getUTCMonth() + 1, 2) + '-' + padNumber(date.getUTCMonth() + 1, 2) + '-' +
@@ -130,34 +129,33 @@ XSD.writeDateTimeTextNode = function(node, dateTime) {
padNumber(date.getUTCMinutes(), 2) + ':' + padNumber(date.getUTCMinutes(), 2) + ':' +
padNumber(date.getUTCSeconds(), 2) + 'Z'; padNumber(date.getUTCSeconds(), 2) + 'Z';
node.appendChild(DOCUMENT.createTextNode(string)); node.appendChild(DOCUMENT.createTextNode(string));
}; }
/** /**
* @param {Node} node Node to append a TextNode with the decimal to. * @param {Node} node Node to append a TextNode with the decimal to.
* @param {number} decimal Decimal. * @param {number} decimal Decimal.
*/ */
XSD.writeDecimalTextNode = function(node, decimal) { export function writeDecimalTextNode(node, decimal) {
const string = decimal.toPrecision(); const string = decimal.toPrecision();
node.appendChild(DOCUMENT.createTextNode(string)); node.appendChild(DOCUMENT.createTextNode(string));
}; }
/** /**
* @param {Node} node Node to append a TextNode with the decimal to. * @param {Node} node Node to append a TextNode with the decimal to.
* @param {number} nonNegativeInteger Non negative integer. * @param {number} nonNegativeInteger Non negative integer.
*/ */
XSD.writeNonNegativeIntegerTextNode = function(node, nonNegativeInteger) { export function writeNonNegativeIntegerTextNode(node, nonNegativeInteger) {
const string = nonNegativeInteger.toString(); const string = nonNegativeInteger.toString();
node.appendChild(DOCUMENT.createTextNode(string)); node.appendChild(DOCUMENT.createTextNode(string));
}; }
/** /**
* @param {Node} node Node to append a TextNode with the string to. * @param {Node} node Node to append a TextNode with the string to.
* @param {string} string String. * @param {string} string String.
*/ */
XSD.writeStringTextNode = function(node, string) { export function writeStringTextNode(node, string) {
node.appendChild(DOCUMENT.createTextNode(string)); node.appendChild(DOCUMENT.createTextNode(string));
}; }
export default XSD;

View File

@@ -1,13 +1,12 @@
import XSD from '../../../../src/ol/format/XSD.js'; import {readDateTime} from '../../../../src/ol/format/xsd.js';
describe('ol/format/xsd', function() {
describe('ol.format.XSD', function() {
describe('readDateTime', function() { describe('readDateTime', function() {
it('can handle non-Zulu time zones', function() { it('can handle non-Zulu time zones', function() {
const node = document.createElement('time'); const node = document.createElement('time');
node.textContent = '2016-07-12T15:00:00+03:00'; node.textContent = '2016-07-12T15:00:00+03:00';
expect(new Date(XSD.readDateTime(node) * 1000).toISOString()).to.eql('2016-07-12T12:00:00.000Z'); expect(new Date(readDateTime(node) * 1000).toISOString()).to.eql('2016-07-12T12:00:00.000Z');
}); });
}); });