Merge pull request #7803 from tschaub/unstatic-private

Remove private static members from constructors
This commit is contained in:
Tim Schaub
2018-02-10 10:58:53 -07:00
committed by GitHub
11 changed files with 1664 additions and 1771 deletions

View File

@@ -8,6 +8,30 @@ import {replaceNode} from '../dom.js';
import {listen} from '../events.js';
import EventType from '../events/EventType.js';
/**
* @return {string} Change type.
*/
const getChangeType = (function() {
let changeType;
return function() {
if (!changeType) {
const body = document.body;
if (body.webkitRequestFullscreen) {
changeType = 'webkitfullscreenchange';
} else if (body.mozRequestFullScreen) {
changeType = 'mozfullscreenchange';
} else if (body.msRequestFullscreen) {
changeType = 'MSFullscreenChange';
} else if (body.requestFullscreen) {
changeType = 'fullscreenchange';
}
}
return changeType;
};
})();
/**
* @classdesc
* Provides a button that when clicked fills up the full screen with the map.
@@ -162,7 +186,7 @@ FullScreen.prototype.setMap = function(map) {
Control.prototype.setMap.call(this, map);
if (map) {
this.listenerKeys.push(listen(document,
FullScreen.getChangeType_(),
getChangeType(),
this.handleFullScreenChange_, this)
);
}
@@ -236,26 +260,4 @@ FullScreen.exitFullScreen = function() {
}
};
/**
* @return {string} Change type.
* @private
*/
FullScreen.getChangeType_ = (function() {
let changeType;
return function() {
if (!changeType) {
const body = document.body;
if (body.webkitRequestFullscreen) {
changeType = 'webkitfullscreenchange';
} else if (body.mozRequestFullScreen) {
changeType = 'mozfullscreenchange';
} else if (body.msRequestFullscreen) {
changeType = 'MSFullscreenChange';
} else if (body.requestFullscreen) {
changeType = 'fullscreenchange';
}
}
return changeType;
};
})();
export default FullScreen;

View File

@@ -9,6 +9,18 @@ import BaseObject from '../Object.js';
import Control from '../control/Control.js';
import {getTransformFromProjections, identityTransform, get as getProjection} from '../proj.js';
/**
* @type {string}
*/
const PROJECTION = 'projection';
/**
* @type {string}
*/
const COORDINATE_FORMAT = 'coordinateFormat';
/**
* @classdesc
* A control to show the 2D coordinates of the mouse cursor. By default, these
@@ -39,7 +51,7 @@ const MousePosition = function(opt_options) {
});
listen(this,
BaseObject.getChangeEventType(MousePosition.Property_.PROJECTION),
BaseObject.getChangeEventType(PROJECTION),
this.handleProjectionChanged_, this);
if (options.coordinateFormat) {
@@ -122,7 +134,7 @@ MousePosition.prototype.handleProjectionChanged_ = function() {
*/
MousePosition.prototype.getCoordinateFormat = function() {
return (
/** @type {ol.CoordinateFormatType|undefined} */ this.get(MousePosition.Property_.COORDINATE_FORMAT)
/** @type {ol.CoordinateFormatType|undefined} */ this.get(COORDINATE_FORMAT)
);
};
@@ -136,7 +148,7 @@ MousePosition.prototype.getCoordinateFormat = function() {
*/
MousePosition.prototype.getProjection = function() {
return (
/** @type {ol.proj.Projection|undefined} */ this.get(MousePosition.Property_.PROJECTION)
/** @type {ol.proj.Projection|undefined} */ this.get(PROJECTION)
);
};
@@ -188,7 +200,7 @@ MousePosition.prototype.setMap = function(map) {
* @api
*/
MousePosition.prototype.setCoordinateFormat = function(format) {
this.set(MousePosition.Property_.COORDINATE_FORMAT, format);
this.set(COORDINATE_FORMAT, format);
};
@@ -200,7 +212,7 @@ MousePosition.prototype.setCoordinateFormat = function(format) {
* @api
*/
MousePosition.prototype.setProjection = function(projection) {
this.set(MousePosition.Property_.PROJECTION, getProjection(projection));
this.set(PROJECTION, getProjection(projection));
};
@@ -239,12 +251,4 @@ MousePosition.prototype.updateHTML_ = function(pixel) {
};
/**
* @enum {string}
* @private
*/
MousePosition.Property_ = {
PROJECTION: 'projection',
COORDINATE_FORMAT: 'coordinateFormat'
};
export default MousePosition;

View File

@@ -11,6 +11,20 @@ import {listen} from '../events.js';
import {getPointResolution, METERS_PER_UNIT} from '../proj.js';
import Units from '../proj/Units.js';
/**
* @type {string}
*/
const UNITS = 'units';
/**
* @const
* @type {Array.<number>}
*/
const LEADING_DIGITS = [1, 2, 5];
/**
* @classdesc
* A control displaying rough y-axis distances, calculated for the center of the
@@ -86,7 +100,7 @@ const ScaleLine = function(opt_options) {
});
listen(
this, BaseObject.getChangeEventType(ScaleLine.Property_.UNITS),
this, BaseObject.getChangeEventType(UNITS),
this.handleUnitsChanged_, this);
this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) ||
@@ -97,13 +111,6 @@ const ScaleLine = function(opt_options) {
inherits(ScaleLine, Control);
/**
* @const
* @type {Array.<number>}
*/
ScaleLine.LEADING_DIGITS = [1, 2, 5];
/**
* Return the units to use in the scale line.
* @return {ol.control.ScaleLineUnits|undefined} The units to use in the scale
@@ -113,7 +120,7 @@ ScaleLine.LEADING_DIGITS = [1, 2, 5];
*/
ScaleLine.prototype.getUnits = function() {
return (
/** @type {ol.control.ScaleLineUnits|undefined} */ this.get(ScaleLine.Property_.UNITS)
/** @type {ol.control.ScaleLineUnits|undefined} */ this.get(UNITS)
);
};
@@ -150,7 +157,7 @@ ScaleLine.prototype.handleUnitsChanged_ = function() {
* @api
*/
ScaleLine.prototype.setUnits = function(units) {
this.set(ScaleLine.Property_.UNITS, units);
this.set(UNITS, units);
};
@@ -244,7 +251,7 @@ ScaleLine.prototype.updateElement_ = function() {
Math.log(this.minWidth_ * pointResolution) / Math.log(10));
let count, width;
while (true) {
count = ScaleLine.LEADING_DIGITS[((i % 3) + 3) % 3] *
count = LEADING_DIGITS[((i % 3) + 3) % 3] *
Math.pow(10, Math.floor(i / 3));
width = Math.round(count / pointResolution);
if (isNaN(width)) {
@@ -275,12 +282,4 @@ ScaleLine.prototype.updateElement_ = function() {
};
/**
* @enum {string}
* @private
*/
ScaleLine.Property_ = {
UNITS: 'units'
};
export default ScaleLine;

View File

@@ -1,8 +1,6 @@
/**
* @module ol/control/ZoomSlider
*/
// FIXME should possibly show tooltip when dragging?
import {inherits} from '../index.js';
import ViewHint from '../ViewHint.js';
import Control from '../control/Control.js';
@@ -15,6 +13,18 @@ import {clamp} from '../math.js';
import PointerEventType from '../pointer/EventType.js';
import PointerEventHandler from '../pointer/PointerEventHandler.js';
/**
* The enum for available directions.
*
* @enum {number}
*/
const Direction = {
VERTICAL: 0,
HORIZONTAL: 1
};
/**
* @classdesc
* A slider type of control for zooming.
@@ -42,12 +52,12 @@ const ZoomSlider = function(opt_options) {
/**
* The direction of the slider. Will be determined from actual display of the
* container and defaults to ol.control.ZoomSlider.Direction_.VERTICAL.
* container and defaults to Direction.VERTICAL.
*
* @type {ol.control.ZoomSlider.Direction_}
* @type {Direction}
* @private
*/
this.direction_ = ZoomSlider.Direction_.VERTICAL;
this.direction_ = Direction.VERTICAL;
/**
* @type {boolean}
@@ -145,18 +155,6 @@ ZoomSlider.prototype.disposeInternal = function() {
};
/**
* The enum for available directions.
*
* @enum {number}
* @private
*/
ZoomSlider.Direction_ = {
VERTICAL: 0,
HORIZONTAL: 1
};
/**
* @inheritDoc
*/
@@ -192,10 +190,10 @@ ZoomSlider.prototype.initSlider_ = function() {
this.thumbSize_ = [thumbWidth, thumbHeight];
if (containerSize.width > containerSize.height) {
this.direction_ = ZoomSlider.Direction_.HORIZONTAL;
this.direction_ = Direction.HORIZONTAL;
this.widthLimit_ = containerSize.width - thumbWidth;
} else {
this.direction_ = ZoomSlider.Direction_.VERTICAL;
this.direction_ = Direction.VERTICAL;
this.heightLimit_ = containerSize.height - thumbHeight;
}
this.sliderInitialized_ = true;
@@ -313,7 +311,7 @@ ZoomSlider.prototype.setThumbPosition_ = function(res) {
const position = this.getPositionForResolution_(res);
const thumb = this.element.firstElementChild;
if (this.direction_ == ZoomSlider.Direction_.HORIZONTAL) {
if (this.direction_ == Direction.HORIZONTAL) {
thumb.style.left = this.widthLimit_ * position + 'px';
} else {
thumb.style.top = this.heightLimit_ * position + 'px';
@@ -333,7 +331,7 @@ ZoomSlider.prototype.setThumbPosition_ = function(res) {
*/
ZoomSlider.prototype.getRelativePosition_ = function(x, y) {
let amount;
if (this.direction_ === ZoomSlider.Direction_.HORIZONTAL) {
if (this.direction_ === Direction.HORIZONTAL) {
amount = x / this.widthLimit_;
} else {
amount = y / this.heightLimit_;
@@ -369,4 +367,5 @@ ZoomSlider.prototype.getPositionForResolution_ = function(res) {
const fn = this.getMap().getView().getValueForResolutionFunction();
return 1 - fn(res);
};
export default ZoomSlider;

View File

@@ -21,6 +21,33 @@ import _ol_geom_flat_orient_ from '../geom/flat/orient.js';
import {assign, isEmpty} from '../obj.js';
import {get as getProjection} from '../proj.js';
/**
* @const
* @type {Object.<ol.geom.GeometryType, function(EsriJSONGeometry): ol.geom.Geometry>}
*/
const GEOMETRY_READERS = {};
GEOMETRY_READERS[GeometryType.POINT] = readPointGeometry;
GEOMETRY_READERS[GeometryType.LINE_STRING] = readLineStringGeometry;
GEOMETRY_READERS[GeometryType.POLYGON] = readPolygonGeometry;
GEOMETRY_READERS[GeometryType.MULTI_POINT] = readMultiPointGeometry;
GEOMETRY_READERS[GeometryType.MULTI_LINE_STRING] = readMultiLineStringGeometry;
GEOMETRY_READERS[GeometryType.MULTI_POLYGON] = readMultiPolygonGeometry;
/**
* @const
* @type {Object.<string, function(ol.geom.Geometry, olx.format.WriteOptions=): (EsriJSONGeometry)>}
*/
const GEOMETRY_WRITERS = {};
GEOMETRY_WRITERS[GeometryType.POINT] = writePointGeometry;
GEOMETRY_WRITERS[GeometryType.LINE_STRING] = writeLineStringGeometry;
GEOMETRY_WRITERS[GeometryType.POLYGON] = writePolygonGeometry;
GEOMETRY_WRITERS[GeometryType.MULTI_POINT] = writeMultiPointGeometry;
GEOMETRY_WRITERS[GeometryType.MULTI_LINE_STRING] = writeMultiLineStringGeometry;
GEOMETRY_WRITERS[GeometryType.MULTI_POLYGON] = writeMultiPolygonGeometry;
/**
* @classdesc
* Feature format for reading and writing data in the EsriJSON format.
@@ -51,10 +78,9 @@ inherits(EsriJSON, JSONFeature);
/**
* @param {EsriJSONGeometry} object Object.
* @param {olx.format.ReadOptions=} opt_options Read options.
* @private
* @return {ol.geom.Geometry} Geometry.
*/
EsriJSON.readGeometry_ = function(object, opt_options) {
function readGeometry(object, opt_options) {
if (!object) {
return null;
}
@@ -71,8 +97,8 @@ EsriJSON.readGeometry_ = function(object, opt_options) {
type = GeometryType.MULTI_LINE_STRING;
}
} else if (object.rings) {
const layout = EsriJSON.getGeometryLayout_(object);
const rings = EsriJSON.convertRings_(object.rings, layout);
const layout = getGeometryLayout(object);
const rings = convertRings(object.rings, layout);
object = /** @type {EsriJSONGeometry} */(assign({}, object));
if (rings.length === 1) {
type = GeometryType.POLYGON;
@@ -82,12 +108,12 @@ EsriJSON.readGeometry_ = function(object, opt_options) {
object.rings = rings;
}
}
const geometryReader = EsriJSON.GEOMETRY_READERS_[type];
const geometryReader = GEOMETRY_READERS[type];
return (
/** @type {ol.geom.Geometry} */ transformWithOptions(
geometryReader(object), false, opt_options)
);
};
}
/**
@@ -97,10 +123,9 @@ EsriJSON.readGeometry_ = function(object, opt_options) {
* Logic inspired by: https://github.com/Esri/terraformer-arcgis-parser
* @param {Array.<!Array.<!Array.<number>>>} rings Rings.
* @param {ol.geom.GeometryLayout} layout Geometry layout.
* @private
* @return {Array.<!Array.<!Array.<number>>>} Transformed rings.
*/
EsriJSON.convertRings_ = function(rings, layout) {
function convertRings(rings, layout) {
const flatRing = [];
const outerRings = [];
const holes = [];
@@ -141,15 +166,14 @@ EsriJSON.convertRings_ = function(rings, layout) {
}
}
return outerRings;
};
}
/**
* @param {EsriJSONGeometry} object Object.
* @private
* @return {ol.geom.Geometry} Point.
*/
EsriJSON.readPointGeometry_ = function(object) {
function readPointGeometry(object) {
let point;
if (object.m !== undefined && object.z !== undefined) {
point = new Point([object.x, object.y, object.z, object.m],
@@ -164,37 +188,34 @@ EsriJSON.readPointGeometry_ = function(object) {
point = new Point([object.x, object.y]);
}
return point;
};
}
/**
* @param {EsriJSONGeometry} object Object.
* @private
* @return {ol.geom.Geometry} LineString.
*/
EsriJSON.readLineStringGeometry_ = function(object) {
const layout = EsriJSON.getGeometryLayout_(object);
function readLineStringGeometry(object) {
const layout = getGeometryLayout(object);
return new LineString(object.paths[0], layout);
};
}
/**
* @param {EsriJSONGeometry} object Object.
* @private
* @return {ol.geom.Geometry} MultiLineString.
*/
EsriJSON.readMultiLineStringGeometry_ = function(object) {
const layout = EsriJSON.getGeometryLayout_(object);
function readMultiLineStringGeometry(object) {
const layout = getGeometryLayout(object);
return new MultiLineString(object.paths, layout);
};
}
/**
* @param {EsriJSONGeometry} object Object.
* @private
* @return {ol.geom.GeometryLayout} The geometry layout to use.
*/
EsriJSON.getGeometryLayout_ = function(object) {
function getGeometryLayout(object) {
let layout = GeometryLayout.XY;
if (object.hasZ === true && object.hasM === true) {
layout = GeometryLayout.XYZM;
@@ -204,51 +225,47 @@ EsriJSON.getGeometryLayout_ = function(object) {
layout = GeometryLayout.XYM;
}
return layout;
};
}
/**
* @param {EsriJSONGeometry} object Object.
* @private
* @return {ol.geom.Geometry} MultiPoint.
*/
EsriJSON.readMultiPointGeometry_ = function(object) {
const layout = EsriJSON.getGeometryLayout_(object);
function readMultiPointGeometry(object) {
const layout = getGeometryLayout(object);
return new MultiPoint(object.points, layout);
};
}
/**
* @param {EsriJSONGeometry} object Object.
* @private
* @return {ol.geom.Geometry} MultiPolygon.
*/
EsriJSON.readMultiPolygonGeometry_ = function(object) {
const layout = EsriJSON.getGeometryLayout_(object);
function readMultiPolygonGeometry(object) {
const layout = getGeometryLayout(object);
return new MultiPolygon(
/** @type {Array.<Array.<Array.<Array.<number>>>>} */(object.rings),
layout);
};
}
/**
* @param {EsriJSONGeometry} object Object.
* @private
* @return {ol.geom.Geometry} Polygon.
*/
EsriJSON.readPolygonGeometry_ = function(object) {
const layout = EsriJSON.getGeometryLayout_(object);
function readPolygonGeometry(object) {
const layout = getGeometryLayout(object);
return new Polygon(object.rings, layout);
};
}
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {EsriJSONGeometry} EsriJSON geometry.
*/
EsriJSON.writePointGeometry_ = function(geometry, opt_options) {
function writePointGeometry(geometry, opt_options) {
const coordinates = /** @type {ol.geom.Point} */ (geometry).getCoordinates();
let esriJSON;
const layout = /** @type {ol.geom.Point} */ (geometry).getLayout();
@@ -280,15 +297,14 @@ EsriJSON.writePointGeometry_ = function(geometry, opt_options) {
assert(false, 34); // Invalid geometry layout
}
return /** @type {EsriJSONGeometry} */ (esriJSON);
};
}
/**
* @param {ol.geom.SimpleGeometry} geometry Geometry.
* @private
* @return {Object} Object with boolean hasZ and hasM keys.
*/
EsriJSON.getHasZM_ = function(geometry) {
function getHasZM(geometry) {
const layout = geometry.getLayout();
return {
hasZ: (layout === GeometryLayout.XYZ ||
@@ -296,17 +312,16 @@ EsriJSON.getHasZM_ = function(geometry) {
hasM: (layout === GeometryLayout.XYM ||
layout === GeometryLayout.XYZM)
};
};
}
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {EsriJSONPolyline} EsriJSON geometry.
*/
EsriJSON.writeLineStringGeometry_ = function(geometry, opt_options) {
const hasZM = EsriJSON.getHasZM_(/** @type {ol.geom.LineString} */(geometry));
function writeLineStringGeometry(geometry, opt_options) {
const hasZM = getHasZM(/** @type {ol.geom.LineString} */(geometry));
return /** @type {EsriJSONPolyline} */ ({
hasZ: hasZM.hasZ,
hasM: hasZM.hasM,
@@ -314,67 +329,62 @@ EsriJSON.writeLineStringGeometry_ = function(geometry, opt_options) {
/** @type {ol.geom.LineString} */ (geometry).getCoordinates()
]
});
};
}
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {EsriJSONPolygon} EsriJSON geometry.
*/
EsriJSON.writePolygonGeometry_ = function(geometry, opt_options) {
function writePolygonGeometry(geometry, opt_options) {
// Esri geometries use the left-hand rule
const hasZM = EsriJSON.getHasZM_(/** @type {ol.geom.Polygon} */(geometry));
const hasZM = getHasZM(/** @type {ol.geom.Polygon} */(geometry));
return /** @type {EsriJSONPolygon} */ ({
hasZ: hasZM.hasZ,
hasM: hasZM.hasM,
rings: /** @type {ol.geom.Polygon} */ (geometry).getCoordinates(false)
});
};
}
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {EsriJSONPolyline} EsriJSON geometry.
*/
EsriJSON.writeMultiLineStringGeometry_ = function(geometry, opt_options) {
const hasZM = EsriJSON.getHasZM_(/** @type {ol.geom.MultiLineString} */(geometry));
function writeMultiLineStringGeometry(geometry, opt_options) {
const hasZM = getHasZM(/** @type {ol.geom.MultiLineString} */(geometry));
return /** @type {EsriJSONPolyline} */ ({
hasZ: hasZM.hasZ,
hasM: hasZM.hasM,
paths: /** @type {ol.geom.MultiLineString} */ (geometry).getCoordinates()
});
};
}
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {EsriJSONMultipoint} EsriJSON geometry.
*/
EsriJSON.writeMultiPointGeometry_ = function(geometry, opt_options) {
const hasZM = EsriJSON.getHasZM_(/** @type {ol.geom.MultiPoint} */(geometry));
function writeMultiPointGeometry(geometry, opt_options) {
const hasZM = getHasZM(/** @type {ol.geom.MultiPoint} */(geometry));
return /** @type {EsriJSONMultipoint} */ ({
hasZ: hasZM.hasZ,
hasM: hasZM.hasM,
points: /** @type {ol.geom.MultiPoint} */ (geometry).getCoordinates()
});
};
}
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {EsriJSONPolygon} EsriJSON geometry.
*/
EsriJSON.writeMultiPolygonGeometry_ = function(geometry,
opt_options) {
const hasZM = EsriJSON.getHasZM_(/** @type {ol.geom.MultiPolygon} */(geometry));
function writeMultiPolygonGeometry(geometry, opt_options) {
const hasZM = getHasZM(/** @type {ol.geom.MultiPolygon} */(geometry));
const coordinates = /** @type {ol.geom.MultiPolygon} */ (geometry).getCoordinates(false);
const output = [];
for (let i = 0; i < coordinates.length; i++) {
@@ -387,47 +397,7 @@ EsriJSON.writeMultiPolygonGeometry_ = function(geometry,
hasM: hasZM.hasM,
rings: output
});
};
/**
* @const
* @private
* @type {Object.<ol.geom.GeometryType, function(EsriJSONGeometry): ol.geom.Geometry>}
*/
EsriJSON.GEOMETRY_READERS_ = {};
EsriJSON.GEOMETRY_READERS_[GeometryType.POINT] =
EsriJSON.readPointGeometry_;
EsriJSON.GEOMETRY_READERS_[GeometryType.LINE_STRING] =
EsriJSON.readLineStringGeometry_;
EsriJSON.GEOMETRY_READERS_[GeometryType.POLYGON] =
EsriJSON.readPolygonGeometry_;
EsriJSON.GEOMETRY_READERS_[GeometryType.MULTI_POINT] =
EsriJSON.readMultiPointGeometry_;
EsriJSON.GEOMETRY_READERS_[GeometryType.MULTI_LINE_STRING] =
EsriJSON.readMultiLineStringGeometry_;
EsriJSON.GEOMETRY_READERS_[GeometryType.MULTI_POLYGON] =
EsriJSON.readMultiPolygonGeometry_;
/**
* @const
* @private
* @type {Object.<string, function(ol.geom.Geometry, olx.format.WriteOptions=): (EsriJSONGeometry)>}
*/
EsriJSON.GEOMETRY_WRITERS_ = {};
EsriJSON.GEOMETRY_WRITERS_[GeometryType.POINT] =
EsriJSON.writePointGeometry_;
EsriJSON.GEOMETRY_WRITERS_[GeometryType.LINE_STRING] =
EsriJSON.writeLineStringGeometry_;
EsriJSON.GEOMETRY_WRITERS_[GeometryType.POLYGON] =
EsriJSON.writePolygonGeometry_;
EsriJSON.GEOMETRY_WRITERS_[GeometryType.MULTI_POINT] =
EsriJSON.writeMultiPointGeometry_;
EsriJSON.GEOMETRY_WRITERS_[GeometryType.MULTI_LINE_STRING] =
EsriJSON.writeMultiLineStringGeometry_;
EsriJSON.GEOMETRY_WRITERS_[GeometryType.MULTI_POLYGON] =
EsriJSON.writeMultiPolygonGeometry_;
}
/**
@@ -462,7 +432,7 @@ EsriJSON.prototype.readFeatures;
EsriJSON.prototype.readFeatureFromObject = function(
object, opt_options) {
const esriJSONFeature = /** @type {EsriJSONFeature} */ (object);
const geometry = EsriJSON.readGeometry_(esriJSONFeature.geometry,
const geometry = readGeometry(esriJSONFeature.geometry,
opt_options);
const feature = new Feature();
if (this.geometryName_) {
@@ -524,7 +494,7 @@ EsriJSON.prototype.readGeometry;
*/
EsriJSON.prototype.readGeometryFromObject = function(
object, opt_options) {
return EsriJSON.readGeometry_(
return readGeometry(
/** @type {EsriJSONGeometry} */(object), opt_options);
};
@@ -557,14 +527,13 @@ EsriJSON.prototype.readProjectionFromObject = function(object) {
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {EsriJSONGeometry} EsriJSON geometry.
*/
EsriJSON.writeGeometry_ = function(geometry, opt_options) {
const geometryWriter = EsriJSON.GEOMETRY_WRITERS_[geometry.getType()];
function writeGeometry(geometry, opt_options) {
const geometryWriter = GEOMETRY_WRITERS[geometry.getType()];
return geometryWriter(/** @type {ol.geom.Geometry} */(
transformWithOptions(geometry, true, opt_options)), opt_options);
};
}
/**
@@ -590,7 +559,7 @@ EsriJSON.prototype.writeGeometry;
*/
EsriJSON.prototype.writeGeometryObject = function(geometry,
opt_options) {
return EsriJSON.writeGeometry_(geometry,
return writeGeometry(geometry,
this.adaptOptions(opt_options));
};
@@ -623,7 +592,7 @@ EsriJSON.prototype.writeFeatureObject = function(
const geometry = feature.getGeometry();
if (geometry) {
object['geometry'] =
EsriJSON.writeGeometry_(geometry, opt_options);
writeGeometry(geometry, opt_options);
if (opt_options && opt_options.featureProjection) {
object['geometry']['spatialReference'] = /** @type {EsriJSONCRS} */({
wkid: getProjection(opt_options.featureProjection).getCode().split(':').pop()
@@ -673,4 +642,5 @@ EsriJSON.prototype.writeFeaturesObject = function(features, opt_options) {
'features': objects
});
};
export default EsriJSON;

View File

@@ -13,6 +13,13 @@ import {createElementNS, getAllTextContent, makeArrayPusher, makeChildAppender,
makeReplacer, makeSimpleNodeFactory, OBJECT_PROPERTY_NODE_FACTORY, pushParseAndPop, pushSerializeAndPop} from '../xml.js';
/**
* @const
* @type {string}
*/
const schemaLocation = GMLBase.GMLNS + ' http://schemas.opengis.net/gml/2.1.2/feature.xsd';
/**
* @classdesc
* Feature format for reading and writing data in the GML format,
@@ -37,22 +44,13 @@ const GML2 = function(opt_options) {
* @inheritDoc
*/
this.schemaLocation = options.schemaLocation ?
options.schemaLocation : GML2.schemaLocation_;
options.schemaLocation : schemaLocation;
};
inherits(GML2, GMLBase);
/**
* @const
* @type {string}
* @private
*/
GML2.schemaLocation_ = GMLBase.GMLNS +
' http://schemas.opengis.net/gml/2.1.2/feature.xsd';
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
@@ -138,69 +136,6 @@ GML2.prototype.outerBoundaryIsParser_ = function(node, objectStack) {
};
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlParser>>}
* @private
*/
GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = {
'http://www.opengis.net/gml': {
'coordinates': makeReplacer(
GML2.prototype.readFlatCoordinates_)
}
};
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlParser>>}
* @private
*/
GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = {
'http://www.opengis.net/gml': {
'innerBoundaryIs': GML2.prototype.innerBoundaryIsParser_,
'outerBoundaryIs': GML2.prototype.outerBoundaryIsParser_
}
};
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlParser>>}
* @private
*/
GML2.prototype.BOX_PARSERS_ = {
'http://www.opengis.net/gml': {
'coordinates': makeArrayPusher(
GML2.prototype.readFlatCoordinates_)
}
};
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlParser>>}
* @private
*/
GML2.prototype.GEOMETRY_PARSERS_ = {
'http://www.opengis.net/gml': {
'Point': makeReplacer(GMLBase.prototype.readPoint),
'MultiPoint': makeReplacer(
GMLBase.prototype.readMultiPoint),
'LineString': makeReplacer(
GMLBase.prototype.readLineString),
'MultiLineString': makeReplacer(
GMLBase.prototype.readMultiLineString),
'LinearRing': makeReplacer(
GMLBase.prototype.readLinearRing),
'Polygon': makeReplacer(GMLBase.prototype.readPolygon),
'MultiPolygon': makeReplacer(
GMLBase.prototype.readMultiPolygon),
'Box': makeReplacer(GML2.prototype.readBox_)
}
};
/**
* @const
* @param {*} value Value.
@@ -280,33 +215,6 @@ GML2.prototype.writeFeatureElement = function(node, feature, objectStack) {
};
/**
* @param {Node} node Node.
* @param {ol.geom.Geometry|ol.Extent} geometry Geometry.
* @param {Array.<*>} objectStack Node stack.
*/
GML2.prototype.writeGeometryElement = function(node, geometry, objectStack) {
const context = /** @type {olx.format.WriteOptions} */ (objectStack[objectStack.length - 1]);
const item = assign({}, context);
item.node = node;
let value;
if (Array.isArray(geometry)) {
if (context.dataProjection) {
value = transformExtent(
geometry, context.featureProjection, context.dataProjection);
} else {
value = geometry;
}
} else {
value = transformWithOptions(/** @type {ol.geom.Geometry} */ (geometry), true, context);
}
pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
(item), GML2.GEOMETRY_SERIALIZERS_,
this.GEOMETRY_NODE_FACTORY_, [value],
objectStack, undefined, this);
};
/**
* @param {Node} node Node.
* @param {ol.geom.LineString} geometry LineString geometry.
@@ -333,6 +241,70 @@ GML2.prototype.writeCurveOrLineString_ = function(node, geometry, objectStack) {
};
/**
* @param {Node} node Node.
* @param {ol.geom.LineString} line LineString geometry.
* @param {Array.<*>} objectStack Node stack.
* @private
*/
GML2.prototype.writeLineStringOrCurveMember_ = function(node, line, objectStack) {
const child = this.GEOMETRY_NODE_FACTORY_(line, objectStack);
if (child) {
node.appendChild(child);
this.writeCurveOrLineString_(child, line, objectStack);
}
};
/**
* @param {Node} node Node.
* @param {ol.geom.MultiLineString} geometry MultiLineString geometry.
* @param {Array.<*>} objectStack Node stack.
* @private
*/
GML2.prototype.writeMultiCurveOrLineString_ = function(node, geometry, objectStack) {
const context = objectStack[objectStack.length - 1];
const hasZ = context['hasZ'];
const srsName = context['srsName'];
const curve = context['curve'];
if (srsName) {
node.setAttribute('srsName', srsName);
}
const lines = geometry.getLineStrings();
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, curve: curve},
this.LINESTRINGORCURVEMEMBER_SERIALIZERS_,
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines,
objectStack, undefined, this);
};
/**
* @param {Node} node Node.
* @param {ol.geom.Geometry|ol.Extent} geometry Geometry.
* @param {Array.<*>} objectStack Node stack.
*/
GML2.prototype.writeGeometryElement = function(node, geometry, objectStack) {
const context = /** @type {olx.format.WriteOptions} */ (objectStack[objectStack.length - 1]);
const item = assign({}, context);
item.node = node;
let value;
if (Array.isArray(geometry)) {
if (context.dataProjection) {
value = transformExtent(
geometry, context.featureProjection, context.dataProjection);
} else {
value = geometry;
}
} else {
value = transformWithOptions(/** @type {ol.geom.Geometry} */ (geometry), true, context);
}
pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
(item), this.GEOMETRY_SERIALIZERS_,
this.GEOMETRY_NODE_FACTORY_, [value],
objectStack, undefined, this);
};
/**
* @param {string} namespaceURI XML namespace.
* @returns {Node} coordinates node.
@@ -402,7 +374,7 @@ GML2.prototype.writeSurfaceOrPolygon_ = function(node, geometry, objectStack) {
const rings = geometry.getLinearRings();
pushSerializeAndPop(
{node: node, hasZ: hasZ, srsName: srsName},
GML2.RING_SERIALIZERS_,
this.RING_SERIALIZERS_,
this.RING_NODE_FACTORY_,
rings, objectStack, undefined, this);
} else if (node.nodeName === 'Surface') {
@@ -484,28 +456,6 @@ GML2.prototype.getCoords_ = function(point, opt_srsName, opt_hasZ) {
};
/**
* @param {Node} node Node.
* @param {ol.geom.MultiLineString} geometry MultiLineString geometry.
* @param {Array.<*>} objectStack Node stack.
* @private
*/
GML2.prototype.writeMultiCurveOrLineString_ = function(node, geometry, objectStack) {
const context = objectStack[objectStack.length - 1];
const hasZ = context['hasZ'];
const srsName = context['srsName'];
const curve = context['curve'];
if (srsName) {
node.setAttribute('srsName', srsName);
}
const lines = geometry.getLineStrings();
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, curve: curve},
GML2.LINESTRINGORCURVEMEMBER_SERIALIZERS_,
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines,
objectStack, undefined, this);
};
/**
* @param {Node} node Node.
* @param {ol.geom.Point} geometry Point geometry.
@@ -543,7 +493,7 @@ GML2.prototype.writeMultiPoint_ = function(node, geometry,
}
const points = geometry.getPoints();
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName},
GML2.POINTMEMBER_SERIALIZERS_,
this.POINTMEMBER_SERIALIZERS_,
makeSimpleNodeFactory('pointMember'), points,
objectStack, undefined, this);
};
@@ -562,21 +512,6 @@ GML2.prototype.writePointMember_ = function(node, point, objectStack) {
};
/**
* @param {Node} node Node.
* @param {ol.geom.LineString} line LineString geometry.
* @param {Array.<*>} objectStack Node stack.
* @private
*/
GML2.prototype.writeLineStringOrCurveMember_ = function(node, line, objectStack) {
const child = this.GEOMETRY_NODE_FACTORY_(line, objectStack);
if (child) {
node.appendChild(child);
this.writeCurveOrLineString_(child, line, objectStack);
}
};
/**
* @param {Node} node Node.
* @param {ol.geom.LinearRing} geometry LinearRing geometry.
@@ -611,7 +546,7 @@ GML2.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, objectStac
}
const polygons = geometry.getPolygons();
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, surface: surface},
GML2.SURFACEORPOLYGONMEMBER_SERIALIZERS_,
this.SURFACEORPOLYGONMEMBER_SERIALIZERS_,
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons,
objectStack, undefined, this);
};
@@ -648,19 +583,108 @@ GML2.prototype.writeEnvelope = function(node, extent, objectStack) {
const keys = ['lowerCorner', 'upperCorner'];
const values = [extent[0] + ' ' + extent[1], extent[2] + ' ' + extent[3]];
pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
({node: node}), GML2.ENVELOPE_SERIALIZERS_,
({node: node}), this.ENVELOPE_SERIALIZERS_,
OBJECT_PROPERTY_NODE_FACTORY,
values,
objectStack, keys, this);
};
/**
* @const
* @type {Object.<string, string>}
*/
const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
'MultiLineString': 'lineStringMember',
'MultiCurve': 'curveMember',
'MultiPolygon': 'polygonMember',
'MultiSurface': 'surfaceMember'
};
/**
* @const
* @param {*} value Value.
* @param {Array.<*>} objectStack Object stack.
* @param {string=} opt_nodeName Node name.
* @return {Node|undefined} Node.
* @private
*/
GML2.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
const parentNode = objectStack[objectStack.length - 1].node;
return createElementNS('http://www.opengis.net/gml',
MULTIGEOMETRY_TO_MEMBER_NODENAME[parentNode.nodeName]);
};
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlParser>>}
* @private
*/
GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = {
'http://www.opengis.net/gml': {
'coordinates': makeReplacer(GML2.prototype.readFlatCoordinates_)
}
};
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlParser>>}
* @private
*/
GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = {
'http://www.opengis.net/gml': {
'innerBoundaryIs': GML2.prototype.innerBoundaryIsParser_,
'outerBoundaryIs': GML2.prototype.outerBoundaryIsParser_
}
};
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlParser>>}
* @private
*/
GML2.prototype.BOX_PARSERS_ = {
'http://www.opengis.net/gml': {
'coordinates': makeArrayPusher(
GML2.prototype.readFlatCoordinates_)
}
};
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlParser>>}
* @private
*/
GML2.prototype.GEOMETRY_PARSERS_ = {
'http://www.opengis.net/gml': {
'Point': makeReplacer(GMLBase.prototype.readPoint),
'MultiPoint': makeReplacer(
GMLBase.prototype.readMultiPoint),
'LineString': makeReplacer(
GMLBase.prototype.readLineString),
'MultiLineString': makeReplacer(
GMLBase.prototype.readMultiLineString),
'LinearRing': makeReplacer(
GMLBase.prototype.readLinearRing),
'Polygon': makeReplacer(GMLBase.prototype.readPolygon),
'MultiPolygon': makeReplacer(
GMLBase.prototype.readMultiPolygon),
'Box': makeReplacer(GML2.prototype.readBox_)
}
};
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML2.GEOMETRY_SERIALIZERS_ = {
GML2.prototype.GEOMETRY_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'Curve': makeChildAppender(
GML2.prototype.writeCurveOrLineString_),
@@ -693,7 +717,21 @@ GML2.GEOMETRY_SERIALIZERS_ = {
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML2.RING_SERIALIZERS_ = {
GML2.prototype.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'lineStringMember': makeChildAppender(
GML2.prototype.writeLineStringOrCurveMember_),
'curveMember': makeChildAppender(
GML2.prototype.writeLineStringOrCurveMember_)
}
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML2.prototype.RING_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'outerBoundaryIs': makeChildAppender(GML2.prototype.writeRing_),
'innerBoundaryIs': makeChildAppender(GML2.prototype.writeRing_)
@@ -705,7 +743,7 @@ GML2.RING_SERIALIZERS_ = {
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML2.POINTMEMBER_SERIALIZERS_ = {
GML2.prototype.POINTMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'pointMember': makeChildAppender(
GML2.prototype.writePointMember_)
@@ -713,53 +751,12 @@ GML2.POINTMEMBER_SERIALIZERS_ = {
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML2.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'lineStringMember': makeChildAppender(
GML2.prototype.writeLineStringOrCurveMember_),
'curveMember': makeChildAppender(
GML2.prototype.writeLineStringOrCurveMember_)
}
};
/**
* @const
* @param {*} value Value.
* @param {Array.<*>} objectStack Object stack.
* @param {string=} opt_nodeName Node name.
* @return {Node|undefined} Node.
* @private
*/
GML2.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
const parentNode = objectStack[objectStack.length - 1].node;
return createElementNS('http://www.opengis.net/gml',
GML2.MULTIGEOMETRY_TO_MEMBER_NODENAME_[parentNode.nodeName]);
};
/**
* @const
* @type {Object.<string, string>}
* @private
*/
GML2.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = {
'MultiLineString': 'lineStringMember',
'MultiCurve': 'curveMember',
'MultiPolygon': 'polygonMember',
'MultiSurface': 'surfaceMember'
};
/**
* @const
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML2.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
GML2.prototype.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'surfaceMember': makeChildAppender(
GML2.prototype.writeSurfaceOrPolygonMember_),
@@ -773,10 +770,11 @@ GML2.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML2.ENVELOPE_SERIALIZERS_ = {
GML2.prototype.ENVELOPE_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'lowerCorner': makeChildAppender(XSD.writeStringTextNode),
'upperCorner': makeChildAppender(XSD.writeStringTextNode)
}
};
export default GML2;

View File

@@ -19,6 +19,17 @@ import {createElementNS, getAllTextContent, makeArrayPusher, makeChildAppender,
makeReplacer, makeSimpleNodeFactory, OBJECT_PROPERTY_NODE_FACTORY, parseNode,
pushParseAndPop, pushSerializeAndPop, setAttributeNS} from '../xml.js';
/**
* @const
* @type {string}
* @private
*/
const schemaLocation = GMLBase.GMLNS +
' http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' +
'1.0.0/gmlsf.xsd';
/**
* @classdesc
* Feature format for reading and writing data in the GML format
@@ -67,7 +78,7 @@ const GML3 = function(opt_options) {
* @inheritDoc
*/
this.schemaLocation = options.schemaLocation ?
options.schemaLocation : GML3.schemaLocation_;
options.schemaLocation : schemaLocation;
/**
* @private
@@ -81,16 +92,6 @@ const GML3 = function(opt_options) {
inherits(GML3, GMLBase);
/**
* @const
* @type {string}
* @private
*/
GML3.schemaLocation_ = GMLBase.GMLNS +
' http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' +
'1.0.0/gmlsf.xsd';
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
@@ -671,18 +672,6 @@ GML3.prototype.writePoint_ = function(node, geometry, objectStack) {
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.ENVELOPE_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'lowerCorner': makeChildAppender(XSD.writeStringTextNode),
'upperCorner': makeChildAppender(XSD.writeStringTextNode)
}
};
/**
* @param {Node} node Node.
* @param {ol.Extent} extent Extent.
@@ -697,7 +686,7 @@ GML3.prototype.writeEnvelope = function(node, extent, objectStack) {
const keys = ['lowerCorner', 'upperCorner'];
const values = [extent[0] + ' ' + extent[1], extent[2] + ' ' + extent[3]];
pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
({node: node}), GML3.ENVELOPE_SERIALIZERS_,
({node: node}), this.ENVELOPE_SERIALIZERS_,
OBJECT_PROPERTY_NODE_FACTORY,
values,
objectStack, keys, this);
@@ -758,7 +747,7 @@ GML3.prototype.writeSurfaceOrPolygon_ = function(node, geometry, objectStack) {
const rings = geometry.getLinearRings();
pushSerializeAndPop(
{node: node, hasZ: hasZ, srsName: srsName},
GML3.RING_SERIALIZERS_,
this.RING_SERIALIZERS_,
this.RING_NODE_FACTORY_,
rings, objectStack, undefined, this);
} else if (node.nodeName === 'Surface') {
@@ -812,7 +801,7 @@ GML3.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, objectStac
}
const polygons = geometry.getPolygons();
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, surface: surface},
GML3.SURFACEORPOLYGONMEMBER_SERIALIZERS_,
this.SURFACEORPOLYGONMEMBER_SERIALIZERS_,
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons,
objectStack, undefined, this);
};
@@ -834,7 +823,7 @@ GML3.prototype.writeMultiPoint_ = function(node, geometry,
}
const points = geometry.getPoints();
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName},
GML3.POINTMEMBER_SERIALIZERS_,
this.POINTMEMBER_SERIALIZERS_,
makeSimpleNodeFactory('pointMember'), points,
objectStack, undefined, this);
};
@@ -856,7 +845,7 @@ GML3.prototype.writeMultiCurveOrLineString_ = function(node, geometry, objectSta
}
const lines = geometry.getLineStrings();
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, curve: curve},
GML3.LINESTRINGORCURVEMEMBER_SERIALIZERS_,
this.LINESTRINGORCURVEMEMBER_SERIALIZERS_,
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines,
objectStack, undefined, this);
};
@@ -967,7 +956,7 @@ GML3.prototype.writeGeometryElement = function(node, geometry, objectStack) {
value = transformWithOptions(/** @type {ol.geom.Geometry} */ (geometry), true, context);
}
pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
(item), GML3.GEOMETRY_SERIALIZERS_,
(item), this.GEOMETRY_SERIALIZERS_,
this.GEOMETRY_NODE_FACTORY_, [value],
objectStack, undefined, this);
};
@@ -1045,97 +1034,11 @@ GML3.prototype.writeFeatureMembers_ = function(node, features, objectStack) {
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'surfaceMember': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygonMember_),
'polygonMember': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygonMember_)
}
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.POINTMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'pointMember': makeChildAppender(
GML3.prototype.writePointMember_)
}
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'lineStringMember': makeChildAppender(
GML3.prototype.writeLineStringOrCurveMember_),
'curveMember': makeChildAppender(
GML3.prototype.writeLineStringOrCurveMember_)
}
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.RING_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'exterior': makeChildAppender(GML3.prototype.writeRing_),
'interior': makeChildAppender(GML3.prototype.writeRing_)
}
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.GEOMETRY_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'Curve': makeChildAppender(
GML3.prototype.writeCurveOrLineString_),
'MultiCurve': makeChildAppender(
GML3.prototype.writeMultiCurveOrLineString_),
'Point': makeChildAppender(GML3.prototype.writePoint_),
'MultiPoint': makeChildAppender(
GML3.prototype.writeMultiPoint_),
'LineString': makeChildAppender(
GML3.prototype.writeCurveOrLineString_),
'MultiLineString': makeChildAppender(
GML3.prototype.writeMultiCurveOrLineString_),
'LinearRing': makeChildAppender(
GML3.prototype.writeLinearRing_),
'Polygon': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygon_),
'MultiPolygon': makeChildAppender(
GML3.prototype.writeMultiSurfaceOrPolygon_),
'Surface': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygon_),
'MultiSurface': makeChildAppender(
GML3.prototype.writeMultiSurfaceOrPolygon_),
'Envelope': makeChildAppender(
GML3.prototype.writeEnvelope)
}
};
/**
* @const
* @type {Object.<string, string>}
* @private
*/
GML3.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = {
const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
'MultiLineString': 'lineStringMember',
'MultiCurve': 'curveMember',
'MultiPolygon': 'polygonMember',
@@ -1154,7 +1057,7 @@ GML3.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = {
GML3.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
const parentNode = objectStack[objectStack.length - 1].node;
return createElementNS('http://www.opengis.net/gml',
GML3.MULTIGEOMETRY_TO_MEMBER_NODENAME_[parentNode.nodeName]);
MULTIGEOMETRY_TO_MEMBER_NODENAME[parentNode.nodeName]);
};
@@ -1258,4 +1161,103 @@ GML3.prototype.writeFeaturesNode = function(features, opt_options) {
this.writeFeatureMembers_(node, features, [context]);
return node;
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.prototype.RING_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'exterior': makeChildAppender(GML3.prototype.writeRing_),
'interior': makeChildAppender(GML3.prototype.writeRing_)
}
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.prototype.ENVELOPE_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'lowerCorner': makeChildAppender(XSD.writeStringTextNode),
'upperCorner': makeChildAppender(XSD.writeStringTextNode)
}
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.prototype.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'surfaceMember': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygonMember_),
'polygonMember': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygonMember_)
}
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.prototype.POINTMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'pointMember': makeChildAppender(
GML3.prototype.writePointMember_)
}
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.prototype.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'lineStringMember': makeChildAppender(
GML3.prototype.writeLineStringOrCurveMember_),
'curveMember': makeChildAppender(
GML3.prototype.writeLineStringOrCurveMember_)
}
};
/**
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
* @private
*/
GML3.prototype.GEOMETRY_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'Curve': makeChildAppender(
GML3.prototype.writeCurveOrLineString_),
'MultiCurve': makeChildAppender(
GML3.prototype.writeMultiCurveOrLineString_),
'Point': makeChildAppender(GML3.prototype.writePoint_),
'MultiPoint': makeChildAppender(
GML3.prototype.writeMultiPoint_),
'LineString': makeChildAppender(
GML3.prototype.writeCurveOrLineString_),
'MultiLineString': makeChildAppender(
GML3.prototype.writeMultiCurveOrLineString_),
'LinearRing': makeChildAppender(
GML3.prototype.writeLinearRing_),
'Polygon': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygon_),
'MultiPolygon': makeChildAppender(
GML3.prototype.writeMultiSurfaceOrPolygon_),
'Surface': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygon_),
'MultiSurface': makeChildAppender(
GML3.prototype.writeMultiSurfaceOrPolygon_),
'Envelope': makeChildAppender(
GML3.prototype.writeEnvelope)
}
};
export default GML3;

View File

@@ -98,9 +98,8 @@ GMLBase.GMLNS = 'http://www.opengis.net/gml';
*
* @const
* @type {RegExp}
* @private
*/
GMLBase.ONLY_WHITESPACE_RE_ = /^[\s\xa0]*$/;
const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
/**
@@ -235,7 +234,7 @@ GMLBase.prototype.readFeatureElement = function(node, objectStack) {
(n.childNodes.length === 1 &&
(n.firstChild.nodeType === 3 || n.firstChild.nodeType === 4))) {
let value = getAllTextContent(n, false);
if (GMLBase.ONLY_WHITESPACE_RE_.test(value)) {
if (ONLY_WHITESPACE_RE.test(value)) {
value = undefined;
}
values[localName] = value;

View File

@@ -413,7 +413,7 @@ function appendCoordinate(flatCoordinates, layoutOptions, node, values) {
* @param {Array.<number>=} ends Ends.
* @return {ol.geom.GeometryLayout} Layout.
*/
GPX.applyLayoutOptions_ = function(layoutOptions, flatCoordinates, ends) {
function applyLayoutOptions(layoutOptions, flatCoordinates, ends) {
let layout = GeometryLayout.XY;
let stride = 2;
if (layoutOptions.hasZ && layoutOptions.hasM) {
@@ -446,7 +446,7 @@ GPX.applyLayoutOptions_ = function(layoutOptions, flatCoordinates, ends) {
}
}
return layout;
};
}
/**
@@ -541,7 +541,7 @@ function readRte(node, objectStack) {
delete values['flatCoordinates'];
const layoutOptions = /** @type {ol.LayoutOptions} */ (values['layoutOptions']);
delete values['layoutOptions'];
const layout = GPX.applyLayoutOptions_(layoutOptions, flatCoordinates);
const layout = applyLayoutOptions(layoutOptions, flatCoordinates);
const geometry = new LineString(null);
geometry.setFlatCoordinates(layout, flatCoordinates);
transformWithOptions(geometry, false, options);
@@ -573,7 +573,7 @@ function readTrk(node, objectStack) {
delete values['ends'];
const layoutOptions = /** @type {ol.LayoutOptions} */ (values['layoutOptions']);
delete values['layoutOptions'];
const layout = GPX.applyLayoutOptions_(layoutOptions, flatCoordinates, ends);
const layout = applyLayoutOptions(layoutOptions, flatCoordinates, ends);
const geometry = new MultiLineString(null);
geometry.setFlatCoordinates(layout, flatCoordinates, ends);
transformWithOptions(geometry, false, options);
@@ -596,7 +596,7 @@ function readWpt(node, objectStack) {
}
const layoutOptions = /** @type {ol.LayoutOptions} */ ({});
const coordinates = appendCoordinate([], layoutOptions, node, values);
const layout = GPX.applyLayoutOptions_(layoutOptions, coordinates);
const layout = applyLayoutOptions(layoutOptions, coordinates);
const geometry = new Point(coordinates, layout);
transformWithOptions(geometry, false, options);
const feature = new Feature(geometry);

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
import Feature from '../../../../src/ol/Feature.js';
import {find} from '../../../../src/ol/array.js';
import GeoJSON from '../../../../src/ol/format/GeoJSON.js';
import KML from '../../../../src/ol/format/KML.js';
import KML, {getDefaultStyle, getDefaultStyleArray, getDefaultFillStyle, getDefaultImageStyle, getDefaultStrokeStyle, getDefaultTextStyle, readFlatCoordinates} from '../../../../src/ol/format/KML.js';
import GeometryCollection from '../../../../src/ol/geom/GeometryCollection.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import LinearRing from '../../../../src/ol/geom/LinearRing.js';
@@ -39,7 +39,7 @@ describe('ol.format.KML', function() {
});
it('set constant variables', function() {
expect(KML.DEFAULT_STYLE_ARRAY_).to.be.an(Array);
expect(getDefaultStyleArray()).to.be.an(Array);
});
describe('#readFeatures', function() {
@@ -74,7 +74,7 @@ describe('ol.format.KML', function() {
});
it('set constant variables', function() {
expect(KML.DEFAULT_STYLE_ARRAY_).to.be.an(Array);
expect(getDefaultStyleArray()).to.be.an(Array);
});
describe('#readProjection', function() {
@@ -1720,11 +1720,11 @@ describe('ol.format.KML', function() {
expect(styleArray).to.have.length(1);
const style = styleArray[0];
expect(style).to.be.an(Style);
expect(style.getFill()).to.be(KML.DEFAULT_FILL_STYLE_);
expect(style.getFill()).to.be(getDefaultFillStyle());
expect(style.getFill().getColor()).to.eql([255, 255, 255, 1]);
expect(style.getImage()).to.be(KML.DEFAULT_IMAGE_STYLE_);
expect(style.getImage()).to.be(getDefaultImageStyle());
// FIXME check image style
expect(style.getStroke()).to.be(KML.DEFAULT_STROKE_STYLE_);
expect(style.getStroke()).to.be(getDefaultStrokeStyle());
expect(style.getStroke().getColor()).to.eql([255, 255, 255, 1]);
expect(style.getStroke().getWidth()).to.be(1);
});
@@ -1753,8 +1753,8 @@ describe('ol.format.KML', function() {
expect(styleArray).to.have.length(1);
const style = styleArray[0];
expect(style).to.be.an(Style);
expect(style.getFill()).to.be(KML.DEFAULT_FILL_STYLE_);
expect(style.getStroke()).to.be(KML.DEFAULT_STROKE_STYLE_);
expect(style.getFill()).to.be(getDefaultFillStyle());
expect(style.getStroke()).to.be(getDefaultStrokeStyle());
const imageStyle = style.getImage();
expect(imageStyle).to.be.an(Icon);
expect(new URL(imageStyle.getSrc()).href).to.eql(new URL('http://foo.png').href);
@@ -1763,7 +1763,7 @@ describe('ol.format.KML', function() {
expect(imageStyle.getRotation()).to.eql(0);
expect(imageStyle.getSize()).to.be(null);
expect(imageStyle.getScale()).to.be(1);
expect(style.getText()).to.be(KML.DEFAULT_TEXT_STYLE_);
expect(style.getText()).to.be(getDefaultTextStyle());
expect(style.getZIndex()).to.be(undefined);
});
@@ -1833,8 +1833,8 @@ describe('ol.format.KML', function() {
expect(styleArray).to.have.length(1);
const style = styleArray[0];
expect(style).to.be.an(Style);
expect(style.getFill()).to.be(KML.DEFAULT_FILL_STYLE_);
expect(style.getStroke()).to.be(KML.DEFAULT_STROKE_STYLE_);
expect(style.getFill()).to.be(getDefaultFillStyle());
expect(style.getStroke()).to.be(getDefaultStrokeStyle());
const imageStyle = style.getImage();
expect(imageStyle).to.be.an(Icon);
expect(new URL(imageStyle.getSrc()).href).to.eql(new URL('http://foo.png').href);
@@ -1867,7 +1867,7 @@ describe('ol.format.KML', function() {
expect(imageStyle.getRotation()).to.eql(0);
expect(imageStyle.getSize()).to.be(null);
expect(imageStyle.getScale()).to.be(1);
expect(style.getText()).to.be(KML.DEFAULT_TEXT_STYLE_);
expect(style.getText()).to.be(getDefaultTextStyle());
expect(style.getZIndex()).to.be(undefined);
});
});
@@ -1904,8 +1904,8 @@ describe('ol.format.KML', function() {
expect(styleArray).to.have.length(1);
const style = styleArray[0];
expect(style).to.be.an(Style);
expect(style.getFill()).to.be(KML.DEFAULT_FILL_STYLE_);
expect(style.getStroke()).to.be(KML.DEFAULT_STROKE_STYLE_);
expect(style.getFill()).to.be(getDefaultFillStyle());
expect(style.getStroke()).to.be(getDefaultStrokeStyle());
const imageStyle = style.getImage();
imageStyle.iconImage_.size_ = [144, 192];
expect(imageStyle.getSize()).to.eql([48, 48]);
@@ -1913,7 +1913,7 @@ describe('ol.format.KML', function() {
expect(imageStyle.getOrigin()).to.eql([24, 108]);
expect(imageStyle.getRotation()).to.eql(0);
expect(imageStyle.getScale()).to.eql(3.0);
expect(style.getText()).to.be(KML.DEFAULT_TEXT_STYLE_);
expect(style.getText()).to.be(getDefaultTextStyle());
expect(style.getZIndex()).to.be(undefined);
});
@@ -1940,9 +1940,9 @@ describe('ol.format.KML', function() {
expect(styleArray).to.have.length(1);
const style = styleArray[0];
expect(style).to.be.an(Style);
expect(style.getFill()).to.be(KML.DEFAULT_FILL_STYLE_);
expect(style.getImage()).to.be(KML.DEFAULT_IMAGE_STYLE_);
expect(style.getStroke()).to.be(KML.DEFAULT_STROKE_STYLE_);
expect(style.getFill()).to.be(getDefaultFillStyle());
expect(style.getImage()).to.be(getDefaultImageStyle());
expect(style.getStroke()).to.be(getDefaultStrokeStyle());
const textStyle = style.getText();
expect(textStyle).to.be.an(Text);
expect(textStyle.getScale()).to.be(0.25);
@@ -1975,13 +1975,13 @@ describe('ol.format.KML', function() {
expect(styleArray).to.have.length(1);
const style = styleArray[0];
expect(style).to.be.an(Style);
expect(style.getFill()).to.be(KML.DEFAULT_FILL_STYLE_);
expect(style.getImage()).to.be(KML.DEFAULT_IMAGE_STYLE_);
expect(style.getFill()).to.be(getDefaultFillStyle());
expect(style.getImage()).to.be(getDefaultImageStyle());
const strokeStyle = style.getStroke();
expect(strokeStyle).to.be.an(Stroke);
expect(strokeStyle.getColor()).to.eql([0x78, 0x56, 0x34, 0x12 / 255]);
expect(strokeStyle.getWidth()).to.be(9);
expect(style.getText()).to.be(KML.DEFAULT_TEXT_STYLE_);
expect(style.getText()).to.be(getDefaultTextStyle());
expect(style.getZIndex()).to.be(undefined);
});
@@ -2010,9 +2010,9 @@ describe('ol.format.KML', function() {
const fillStyle = style.getFill();
expect(fillStyle).to.be.an(Fill);
expect(fillStyle.getColor()).to.eql([0x78, 0x56, 0x34, 0x12 / 255]);
expect(style.getImage()).to.be(KML.DEFAULT_IMAGE_STYLE_);
expect(style.getStroke()).to.be(KML.DEFAULT_STROKE_STYLE_);
expect(style.getText()).to.be(KML.DEFAULT_TEXT_STYLE_);
expect(style.getImage()).to.be(getDefaultImageStyle());
expect(style.getStroke()).to.be(getDefaultStrokeStyle());
expect(style.getText()).to.be(getDefaultTextStyle());
expect(style.getZIndex()).to.be(undefined);
});
@@ -2047,12 +2047,12 @@ describe('ol.format.KML', function() {
const fillStyle = style.getFill();
expect(fillStyle).to.be.an(Fill);
expect(fillStyle.getColor()).to.eql([0x78, 0x56, 0x34, 0x12 / 255]);
expect(style.getImage()).to.be(KML.DEFAULT_IMAGE_STYLE_);
expect(style.getImage()).to.be(getDefaultImageStyle());
const strokeStyle = style.getStroke();
expect(strokeStyle).to.be.an(Stroke);
expect(strokeStyle.getColor()).to.eql([0x78, 0x56, 0x34, 0x12 / 255]);
expect(strokeStyle.getWidth()).to.be(9);
expect(style.getText()).to.be(KML.DEFAULT_TEXT_STYLE_);
expect(style.getText()).to.be(getDefaultTextStyle());
expect(style.getZIndex()).to.be(undefined);
});
@@ -2084,12 +2084,12 @@ describe('ol.format.KML', function() {
const style = styleArray[0];
expect(style).to.be.an(Style);
expect(style.getFill()).to.be(null);
expect(style.getImage()).to.be(KML.DEFAULT_IMAGE_STYLE_);
expect(style.getImage()).to.be(getDefaultImageStyle());
const strokeStyle = style.getStroke();
expect(strokeStyle).to.be.an(Stroke);
expect(strokeStyle.getColor()).to.eql([0x78, 0x56, 0x34, 0x12 / 255]);
expect(strokeStyle.getWidth()).to.be(9);
expect(style.getText()).to.be(KML.DEFAULT_TEXT_STYLE_);
expect(style.getText()).to.be(getDefaultTextStyle());
expect(style.getZIndex()).to.be(undefined);
});
@@ -2123,9 +2123,9 @@ describe('ol.format.KML', function() {
const fillStyle = style.getFill();
expect(fillStyle).to.be.an(Fill);
expect(fillStyle.getColor()).to.eql([0x78, 0x56, 0x34, 0x12 / 255]);
expect(style.getImage()).to.be(KML.DEFAULT_IMAGE_STYLE_);
expect(style.getImage()).to.be(getDefaultImageStyle());
expect(style.getStroke()).to.be(null);
expect(style.getText()).to.be(KML.DEFAULT_TEXT_STYLE_);
expect(style.getText()).to.be(getDefaultTextStyle());
expect(style.getZIndex()).to.be(undefined);
});
@@ -2159,9 +2159,9 @@ describe('ol.format.KML', function() {
const style = styleArray[0];
expect(style).to.be.an(Style);
expect(style.getFill()).to.be(null);
expect(style.getImage()).to.be(KML.DEFAULT_IMAGE_STYLE_);
expect(style.getImage()).to.be(getDefaultImageStyle());
expect(style.getStroke()).to.be(null);
expect(style.getText()).to.be(KML.DEFAULT_TEXT_STYLE_);
expect(style.getText()).to.be(getDefaultTextStyle());
expect(style.getZIndex()).to.be(undefined);
});
@@ -2547,7 +2547,7 @@ describe('ol.format.KML', function() {
expect(styleArray).to.have.length(1);
const s = styleArray[0];
expect(s).to.be.an(Style);
expect(s).to.be(KML.DEFAULT_STYLE_);
expect(s).to.be(getDefaultStyle());
});
@@ -2656,7 +2656,7 @@ describe('ol.format.KML', function() {
expect(styleArray).to.have.length(1);
const s = styleArray[0];
expect(s).to.be.an(Style);
expect(s).to.be(KML.DEFAULT_STYLE_);
expect(s).to.be(getDefaultStyle());
});
it('can use Styles in StyleMaps before they are defined', function() {
@@ -3018,7 +3018,7 @@ describe('ol.format.KML', function() {
it('should ignore invalid coordinates', function() {
const doc = new DOMParser().parseFromString('<coordinates>INVALID</coordinates>', 'application/xml');
const node = doc.firstChild;
expect(KML.readFlatCoordinates_(node)).to.be(undefined);
expect(readFlatCoordinates(node)).to.be(undefined);
});
it('should ignore Points with invalid coordinates', function() {