Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -9,14 +9,17 @@ import {VERSION} from './util.js';
|
||||
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error.
|
||||
*/
|
||||
class AssertionError extends Error {
|
||||
|
||||
/**
|
||||
* @param {number} code Error code.
|
||||
*/
|
||||
constructor(code) {
|
||||
const path = VERSION === 'latest' ? VERSION : 'v' + VERSION.split('-')[0];
|
||||
const message = 'Assertion failed. See https://openlayers.org/en/' + path +
|
||||
'/doc/errors/#' + code + ' for details.';
|
||||
const message =
|
||||
'Assertion failed. See https://openlayers.org/en/' +
|
||||
path +
|
||||
'/doc/errors/#' +
|
||||
code +
|
||||
' for details.';
|
||||
|
||||
super(message);
|
||||
|
||||
@@ -38,7 +41,6 @@ class AssertionError extends Error {
|
||||
// Re-assign message, see https://github.com/Rich-Harris/buble/issues/40
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default AssertionError;
|
||||
|
||||
@@ -2,27 +2,24 @@
|
||||
* @module ol/Collection
|
||||
*/
|
||||
import AssertionError from './AssertionError.js';
|
||||
import CollectionEventType from './CollectionEventType.js';
|
||||
import BaseObject from './Object.js';
|
||||
import CollectionEventType from './CollectionEventType.js';
|
||||
import Event from './events/Event.js';
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
* @private
|
||||
*/
|
||||
const Property = {
|
||||
LENGTH: 'length'
|
||||
LENGTH: 'length',
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Events emitted by {@link module:ol/Collection~Collection} instances are instances of this
|
||||
* type.
|
||||
*/
|
||||
export class CollectionEvent extends Event {
|
||||
|
||||
/**
|
||||
* @param {CollectionEventType} type Type.
|
||||
* @param {*=} opt_element Element.
|
||||
@@ -45,10 +42,8 @@ export class CollectionEvent extends Event {
|
||||
*/
|
||||
this.index = opt_index;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {boolean} [unique=false] Disallow the same item from being added to
|
||||
@@ -69,13 +64,11 @@ export class CollectionEvent extends Event {
|
||||
* @api
|
||||
*/
|
||||
class Collection extends BaseObject {
|
||||
|
||||
/**
|
||||
* @param {Array<T>=} opt_array Array.
|
||||
* @param {Options=} opt_options Collection options.
|
||||
*/
|
||||
constructor(opt_array, opt_options) {
|
||||
|
||||
super();
|
||||
|
||||
const options = opt_options || {};
|
||||
@@ -99,7 +92,6 @@ class Collection extends BaseObject {
|
||||
}
|
||||
|
||||
this.updateLength_();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,7 +177,8 @@ class Collection extends BaseObject {
|
||||
this.array_.splice(index, 0, elem);
|
||||
this.updateLength_();
|
||||
this.dispatchEvent(
|
||||
new CollectionEvent(CollectionEventType.ADD, elem, index));
|
||||
new CollectionEvent(CollectionEventType.ADD, elem, index)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,7 +233,9 @@ class Collection extends BaseObject {
|
||||
const prev = this.array_[index];
|
||||
this.array_.splice(index, 1);
|
||||
this.updateLength_();
|
||||
this.dispatchEvent(new CollectionEvent(CollectionEventType.REMOVE, prev, index));
|
||||
this.dispatchEvent(
|
||||
new CollectionEvent(CollectionEventType.REMOVE, prev, index)
|
||||
);
|
||||
return prev;
|
||||
}
|
||||
|
||||
@@ -259,9 +254,11 @@ class Collection extends BaseObject {
|
||||
const prev = this.array_[index];
|
||||
this.array_[index] = elem;
|
||||
this.dispatchEvent(
|
||||
new CollectionEvent(CollectionEventType.REMOVE, prev, index));
|
||||
new CollectionEvent(CollectionEventType.REMOVE, prev, index)
|
||||
);
|
||||
this.dispatchEvent(
|
||||
new CollectionEvent(CollectionEventType.ADD, elem, index));
|
||||
new CollectionEvent(CollectionEventType.ADD, elem, index)
|
||||
);
|
||||
} else {
|
||||
for (let j = n; j < index; ++j) {
|
||||
this.insertAt(j, undefined);
|
||||
@@ -291,5 +288,4 @@ class Collection extends BaseObject {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Collection;
|
||||
|
||||
@@ -17,5 +17,5 @@ export default {
|
||||
* @event module:ol/Collection.CollectionEvent#remove
|
||||
* @api
|
||||
*/
|
||||
REMOVE: 'remove'
|
||||
REMOVE: 'remove',
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* Objects that need to clean up after themselves.
|
||||
*/
|
||||
class Disposable {
|
||||
|
||||
constructor() {
|
||||
/**
|
||||
* The object has already been disposed.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/**
|
||||
* @module ol/Feature
|
||||
*/
|
||||
import BaseObject, {getChangeEventType} from './Object.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import {assert} from './asserts.js';
|
||||
import {listen, unlistenByKey} from './events.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import BaseObject, {getChangeEventType} from './Object.js';
|
||||
|
||||
/**
|
||||
* @typedef {typeof Feature|typeof import("./render/Feature.js").default} FeatureClass
|
||||
@@ -67,7 +67,6 @@ class Feature extends BaseObject {
|
||||
* associated with a `geometry` key.
|
||||
*/
|
||||
constructor(opt_geometryOrProperties) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -101,10 +100,17 @@ class Feature extends BaseObject {
|
||||
*/
|
||||
this.geometryChangeKey_ = null;
|
||||
|
||||
this.addEventListener(getChangeEventType(this.geometryName_), this.handleGeometryChanged_);
|
||||
this.addEventListener(
|
||||
getChangeEventType(this.geometryName_),
|
||||
this.handleGeometryChanged_
|
||||
);
|
||||
|
||||
if (opt_geometryOrProperties) {
|
||||
if (typeof /** @type {?} */ (opt_geometryOrProperties).getSimplifiedGeometry === 'function') {
|
||||
if (
|
||||
typeof (
|
||||
/** @type {?} */ (opt_geometryOrProperties).getSimplifiedGeometry
|
||||
) === 'function'
|
||||
) {
|
||||
const geometry = /** @type {Geometry} */ (opt_geometryOrProperties);
|
||||
this.setGeometry(geometry);
|
||||
} else {
|
||||
@@ -144,9 +150,7 @@ class Feature extends BaseObject {
|
||||
* @observable
|
||||
*/
|
||||
getGeometry() {
|
||||
return (
|
||||
/** @type {Geometry|undefined} */ (this.get(this.geometryName_))
|
||||
);
|
||||
return /** @type {Geometry|undefined} */ (this.get(this.geometryName_));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,8 +212,12 @@ class Feature extends BaseObject {
|
||||
}
|
||||
const geometry = this.getGeometry();
|
||||
if (geometry) {
|
||||
this.geometryChangeKey_ = listen(geometry,
|
||||
EventType.CHANGE, this.handleGeometryChange_, this);
|
||||
this.geometryChangeKey_ = listen(
|
||||
geometry,
|
||||
EventType.CHANGE,
|
||||
this.handleGeometryChange_,
|
||||
this
|
||||
);
|
||||
}
|
||||
this.changed();
|
||||
}
|
||||
@@ -261,14 +269,19 @@ class Feature extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
setGeometryName(name) {
|
||||
this.removeEventListener(getChangeEventType(this.geometryName_), this.handleGeometryChanged_);
|
||||
this.removeEventListener(
|
||||
getChangeEventType(this.geometryName_),
|
||||
this.handleGeometryChanged_
|
||||
);
|
||||
this.geometryName_ = name;
|
||||
this.addEventListener(getChangeEventType(this.geometryName_), this.handleGeometryChanged_);
|
||||
this.addEventListener(
|
||||
getChangeEventType(this.geometryName_),
|
||||
this.handleGeometryChanged_
|
||||
);
|
||||
this.handleGeometryChanged_();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert the provided object into a feature style function. Functions passed
|
||||
* through unchanged. Arrays of Style or single style objects wrapped
|
||||
@@ -288,12 +301,11 @@ export function createStyleFunction(obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
styles = obj;
|
||||
} else {
|
||||
assert(typeof /** @type {?} */ (obj).getZIndex === 'function',
|
||||
41); // Expected an `import("./style/Style.js").Style` or an array of `import("./style/Style.js").Style`
|
||||
assert(typeof (/** @type {?} */ (obj).getZIndex) === 'function', 41); // Expected an `import("./style/Style.js").Style` or an array of `import("./style/Style.js").Style`
|
||||
const style = /** @type {import("./style/Style.js").default} */ (obj);
|
||||
styles = [style];
|
||||
}
|
||||
return function() {
|
||||
return function () {
|
||||
return styles;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
/**
|
||||
* @module ol/Geolocation
|
||||
*/
|
||||
import BaseObject, {getChangeEventType} from './Object.js';
|
||||
import BaseEvent from './events/Event.js';
|
||||
import BaseObject, {getChangeEventType} from './Object.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import {circular as circularPolygon} from './geom/Polygon.js';
|
||||
import {
|
||||
get as getProjection,
|
||||
getTransformFromProjections,
|
||||
identityTransform,
|
||||
} from './proj.js';
|
||||
import {toRadians} from './math.js';
|
||||
import {get as getProjection, getTransformFromProjections, identityTransform} from './proj.js';
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
@@ -22,10 +25,9 @@ const Property = {
|
||||
PROJECTION: 'projection',
|
||||
SPEED: 'speed',
|
||||
TRACKING: 'tracking',
|
||||
TRACKING_OPTIONS: 'trackingOptions'
|
||||
TRACKING_OPTIONS: 'trackingOptions',
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Events emitted on Geolocation error.
|
||||
@@ -49,7 +51,6 @@ class GeolocationError extends BaseEvent {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {boolean} [tracking=false] Start Tracking right after
|
||||
@@ -60,7 +61,6 @@ class GeolocationError extends BaseEvent {
|
||||
* is reported in.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Helper class for providing HTML5 Geolocation capabilities.
|
||||
@@ -85,12 +85,10 @@ class GeolocationError extends BaseEvent {
|
||||
* @api
|
||||
*/
|
||||
class Geolocation extends BaseObject {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
super();
|
||||
|
||||
const options = opt_options || {};
|
||||
@@ -114,8 +112,14 @@ class Geolocation extends BaseObject {
|
||||
*/
|
||||
this.watchId_ = undefined;
|
||||
|
||||
this.addEventListener(getChangeEventType(Property.PROJECTION), this.handleProjectionChanged_);
|
||||
this.addEventListener(getChangeEventType(Property.TRACKING), this.handleTrackingChanged_);
|
||||
this.addEventListener(
|
||||
getChangeEventType(Property.PROJECTION),
|
||||
this.handleProjectionChanged_
|
||||
);
|
||||
this.addEventListener(
|
||||
getChangeEventType(Property.TRACKING),
|
||||
this.handleTrackingChanged_
|
||||
);
|
||||
|
||||
if (options.projection !== undefined) {
|
||||
this.setProjection(options.projection);
|
||||
@@ -125,7 +129,6 @@ class Geolocation extends BaseObject {
|
||||
}
|
||||
|
||||
this.setTracking(options.tracking !== undefined ? options.tracking : false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,7 +146,9 @@ class Geolocation extends BaseObject {
|
||||
const projection = this.getProjection();
|
||||
if (projection) {
|
||||
this.transform_ = getTransformFromProjections(
|
||||
getProjection('EPSG:4326'), projection);
|
||||
getProjection('EPSG:4326'),
|
||||
projection
|
||||
);
|
||||
if (this.position_) {
|
||||
this.set(Property.POSITION, this.transform_(this.position_));
|
||||
}
|
||||
@@ -160,7 +165,8 @@ class Geolocation extends BaseObject {
|
||||
this.watchId_ = navigator.geolocation.watchPosition(
|
||||
this.positionChange_.bind(this),
|
||||
this.positionError_.bind(this),
|
||||
this.getTrackingOptions());
|
||||
this.getTrackingOptions()
|
||||
);
|
||||
} else if (!tracking && this.watchId_ !== undefined) {
|
||||
navigator.geolocation.clearWatch(this.watchId_);
|
||||
this.watchId_ = undefined;
|
||||
@@ -175,13 +181,18 @@ class Geolocation extends BaseObject {
|
||||
positionChange_(position) {
|
||||
const coords = position.coords;
|
||||
this.set(Property.ACCURACY, coords.accuracy);
|
||||
this.set(Property.ALTITUDE,
|
||||
coords.altitude === null ? undefined : coords.altitude);
|
||||
this.set(Property.ALTITUDE_ACCURACY,
|
||||
coords.altitudeAccuracy === null ?
|
||||
undefined : coords.altitudeAccuracy);
|
||||
this.set(Property.HEADING, coords.heading === null ?
|
||||
undefined : toRadians(coords.heading));
|
||||
this.set(
|
||||
Property.ALTITUDE,
|
||||
coords.altitude === null ? undefined : coords.altitude
|
||||
);
|
||||
this.set(
|
||||
Property.ALTITUDE_ACCURACY,
|
||||
coords.altitudeAccuracy === null ? undefined : coords.altitudeAccuracy
|
||||
);
|
||||
this.set(
|
||||
Property.HEADING,
|
||||
coords.heading === null ? undefined : toRadians(coords.heading)
|
||||
);
|
||||
if (!this.position_) {
|
||||
this.position_ = [coords.longitude, coords.latitude];
|
||||
} else {
|
||||
@@ -190,8 +201,7 @@ class Geolocation extends BaseObject {
|
||||
}
|
||||
const projectedPosition = this.transform_(this.position_);
|
||||
this.set(Property.POSITION, projectedPosition);
|
||||
this.set(Property.SPEED,
|
||||
coords.speed === null ? undefined : coords.speed);
|
||||
this.set(Property.SPEED, coords.speed === null ? undefined : coords.speed);
|
||||
const geometry = circularPolygon(this.position_, coords.accuracy);
|
||||
geometry.applyTransform(this.transform_);
|
||||
this.set(Property.ACCURACY_GEOMETRY, geometry);
|
||||
@@ -225,9 +235,9 @@ class Geolocation extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getAccuracyGeometry() {
|
||||
return (
|
||||
/** @type {?import("./geom/Polygon.js").default} */ (this.get(Property.ACCURACY_GEOMETRY) || null)
|
||||
);
|
||||
return /** @type {?import("./geom/Polygon.js").default} */ (this.get(
|
||||
Property.ACCURACY_GEOMETRY
|
||||
) || null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,7 +259,9 @@ class Geolocation extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getAltitudeAccuracy() {
|
||||
return /** @type {number|undefined} */ (this.get(Property.ALTITUDE_ACCURACY));
|
||||
return /** @type {number|undefined} */ (this.get(
|
||||
Property.ALTITUDE_ACCURACY
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,9 +284,9 @@ class Geolocation extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getPosition() {
|
||||
return (
|
||||
/** @type {import("./coordinate.js").Coordinate|undefined} */ (this.get(Property.POSITION))
|
||||
);
|
||||
return /** @type {import("./coordinate.js").Coordinate|undefined} */ (this.get(
|
||||
Property.POSITION
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,9 +297,9 @@ class Geolocation extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getProjection() {
|
||||
return (
|
||||
/** @type {import("./proj/Projection.js").default|undefined} */ (this.get(Property.PROJECTION))
|
||||
);
|
||||
return /** @type {import("./proj/Projection.js").default|undefined} */ (this.get(
|
||||
Property.PROJECTION
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,7 +333,9 @@ class Geolocation extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getTrackingOptions() {
|
||||
return /** @type {PositionOptions|undefined} */ (this.get(Property.TRACKING_OPTIONS));
|
||||
return /** @type {PositionOptions|undefined} */ (this.get(
|
||||
Property.TRACKING_OPTIONS
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,5 +373,4 @@ class Geolocation extends BaseObject {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Geolocation;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
/**
|
||||
* @module ol/Image
|
||||
*/
|
||||
import EventType from './events/EventType.js';
|
||||
import ImageBase from './ImageBase.js';
|
||||
import ImageState from './ImageState.js';
|
||||
import {listenOnce, unlistenByKey} from './events.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import {getHeight} from './extent.js';
|
||||
import {IMAGE_DECODE} from './has.js';
|
||||
|
||||
import {getHeight} from './extent.js';
|
||||
import {listenOnce, unlistenByKey} from './events.js';
|
||||
|
||||
/**
|
||||
* A function that takes an {@link module:ol/Image~Image} for the image and a
|
||||
@@ -27,9 +26,7 @@ import {IMAGE_DECODE} from './has.js';
|
||||
* @api
|
||||
*/
|
||||
|
||||
|
||||
class ImageWrapper extends ImageBase {
|
||||
|
||||
/**
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
@@ -38,8 +35,14 @@ class ImageWrapper extends ImageBase {
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {LoadFunction} imageLoadFunction Image load function.
|
||||
*/
|
||||
constructor(extent, resolution, pixelRatio, src, crossOrigin, imageLoadFunction) {
|
||||
|
||||
constructor(
|
||||
extent,
|
||||
resolution,
|
||||
pixelRatio,
|
||||
src,
|
||||
crossOrigin,
|
||||
imageLoadFunction
|
||||
) {
|
||||
super(extent, resolution, pixelRatio, ImageState.IDLE);
|
||||
|
||||
/**
|
||||
@@ -74,7 +77,6 @@ class ImageWrapper extends ImageBase {
|
||||
* @type {LoadFunction}
|
||||
*/
|
||||
this.imageLoadFunction_ = imageLoadFunction;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,35 +163,39 @@ export function listenImage(image, loadHandler, errorHandler) {
|
||||
if (img.src && IMAGE_DECODE) {
|
||||
const promise = img.decode();
|
||||
let listening = true;
|
||||
const unlisten = function() {
|
||||
const unlisten = function () {
|
||||
listening = false;
|
||||
};
|
||||
promise.then(function() {
|
||||
if (listening) {
|
||||
loadHandler();
|
||||
}
|
||||
}).catch(function(error) {
|
||||
if (listening) {
|
||||
// FIXME: Unconditionally call errorHandler() when this bug is fixed upstream:
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=198527
|
||||
if (error.name === 'EncodingError' && error.message === 'Invalid image type.') {
|
||||
promise
|
||||
.then(function () {
|
||||
if (listening) {
|
||||
loadHandler();
|
||||
} else {
|
||||
errorHandler();
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (listening) {
|
||||
// FIXME: Unconditionally call errorHandler() when this bug is fixed upstream:
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=198527
|
||||
if (
|
||||
error.name === 'EncodingError' &&
|
||||
error.message === 'Invalid image type.'
|
||||
) {
|
||||
loadHandler();
|
||||
} else {
|
||||
errorHandler();
|
||||
}
|
||||
}
|
||||
});
|
||||
return unlisten;
|
||||
}
|
||||
|
||||
const listenerKeys = [
|
||||
listenOnce(img, EventType.LOAD, loadHandler),
|
||||
listenOnce(img, EventType.ERROR, errorHandler)
|
||||
listenOnce(img, EventType.ERROR, errorHandler),
|
||||
];
|
||||
return function unlisten() {
|
||||
listenerKeys.forEach(unlistenByKey);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export default ImageWrapper;
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
/**
|
||||
* @module ol/ImageBase
|
||||
*/
|
||||
import {abstract} from './util.js';
|
||||
import EventTarget from './events/Target.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import {abstract} from './util.js';
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
*/
|
||||
class ImageBase extends EventTarget {
|
||||
|
||||
/**
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
@@ -17,7 +16,6 @@ class ImageBase extends EventTarget {
|
||||
* @param {import("./ImageState.js").default} state State.
|
||||
*/
|
||||
constructor(extent, resolution, pixelRatio, state) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -43,7 +41,6 @@ class ImageBase extends EventTarget {
|
||||
* @type {import("./ImageState.js").default}
|
||||
*/
|
||||
this.state = state;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,5 +95,4 @@ class ImageBase extends EventTarget {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default ImageBase;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import ImageBase from './ImageBase.js';
|
||||
import ImageState from './ImageState.js';
|
||||
|
||||
|
||||
/**
|
||||
* A function that is called to trigger asynchronous canvas drawing. It is
|
||||
* called with a "done" callback that should be called when drawing is done.
|
||||
@@ -14,9 +13,7 @@ import ImageState from './ImageState.js';
|
||||
* @typedef {function(function(Error=): void): void} Loader
|
||||
*/
|
||||
|
||||
|
||||
class ImageCanvas extends ImageBase {
|
||||
|
||||
/**
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {number} resolution Resolution.
|
||||
@@ -26,8 +23,8 @@ class ImageCanvas extends ImageBase {
|
||||
* support asynchronous canvas drawing.
|
||||
*/
|
||||
constructor(extent, resolution, pixelRatio, canvas, opt_loader) {
|
||||
|
||||
const state = opt_loader !== undefined ? ImageState.IDLE : ImageState.LOADED;
|
||||
const state =
|
||||
opt_loader !== undefined ? ImageState.IDLE : ImageState.LOADED;
|
||||
|
||||
super(extent, resolution, pixelRatio, state);
|
||||
|
||||
@@ -49,7 +46,6 @@ class ImageCanvas extends ImageBase {
|
||||
* @type {?Error}
|
||||
*/
|
||||
this.error_ = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,5 +90,4 @@ class ImageCanvas extends ImageBase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default ImageCanvas;
|
||||
|
||||
@@ -10,5 +10,5 @@ export default {
|
||||
LOADING: 1,
|
||||
LOADED: 2,
|
||||
ERROR: 3,
|
||||
EMPTY: 4
|
||||
EMPTY: 4,
|
||||
};
|
||||
|
||||
@@ -6,9 +6,7 @@ import TileState from './TileState.js';
|
||||
import {createCanvasContext2D} from './dom.js';
|
||||
import {listenImage} from './Image.js';
|
||||
|
||||
|
||||
class ImageTile extends Tile {
|
||||
|
||||
/**
|
||||
* @param {import("./tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
||||
* @param {TileState} state State.
|
||||
@@ -17,8 +15,14 @@ class ImageTile extends Tile {
|
||||
* @param {import("./Tile.js").LoadFunction} tileLoadFunction Tile load function.
|
||||
* @param {import("./Tile.js").Options=} opt_options Tile options.
|
||||
*/
|
||||
constructor(tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
|
||||
|
||||
constructor(
|
||||
tileCoord,
|
||||
state,
|
||||
src,
|
||||
crossOrigin,
|
||||
tileLoadFunction,
|
||||
opt_options
|
||||
) {
|
||||
super(tileCoord, state, opt_options);
|
||||
|
||||
/**
|
||||
@@ -55,7 +59,6 @@ class ImageTile extends Tile {
|
||||
* @type {import("./Tile.js").LoadFunction}
|
||||
*/
|
||||
this.tileLoadFunction_ = tileLoadFunction;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,7 +142,6 @@ class ImageTile extends Tile {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a 1-pixel blank image.
|
||||
* @return {HTMLCanvasElement} Blank image.
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
* @api
|
||||
*/
|
||||
class Kinetic {
|
||||
|
||||
/**
|
||||
* @param {number} decay Rate of decay (must be negative).
|
||||
* @param {number} minVelocity Minimum velocity (pixels/millisecond).
|
||||
@@ -17,7 +16,6 @@ class Kinetic {
|
||||
* initial values (milliseconds).
|
||||
*/
|
||||
constructor(decay, minVelocity, delay) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* @module ol/Map
|
||||
*/
|
||||
import CompositeMapRenderer from './renderer/Composite.js';
|
||||
import PluggableMap from './PluggableMap.js';
|
||||
import {assign} from './obj.js';
|
||||
import {defaults as defaultControls} from './control.js';
|
||||
import {defaults as defaultInteractions} from './interaction.js';
|
||||
import {assign} from './obj.js';
|
||||
import CompositeMapRenderer from './renderer/Composite.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -55,7 +55,6 @@ import CompositeMapRenderer from './renderer/Composite.js';
|
||||
* @api
|
||||
*/
|
||||
class Map extends PluggableMap {
|
||||
|
||||
/**
|
||||
* @param {import("./PluggableMap.js").MapOptions} options Map options.
|
||||
*/
|
||||
@@ -76,5 +75,4 @@ class Map extends PluggableMap {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Map;
|
||||
|
||||
@@ -9,7 +9,6 @@ import MapEvent from './MapEvent.js';
|
||||
* See {@link module:ol/PluggableMap~PluggableMap} for which events trigger a map browser event.
|
||||
*/
|
||||
class MapBrowserEvent extends MapEvent {
|
||||
|
||||
/**
|
||||
* @param {string} type Event type.
|
||||
* @param {import("./PluggableMap.js").default} map Map.
|
||||
@@ -18,7 +17,6 @@ class MapBrowserEvent extends MapEvent {
|
||||
* @param {?import("./PluggableMap.js").FrameState=} opt_frameState Frame state.
|
||||
*/
|
||||
constructor(type, map, browserEvent, opt_dragging, opt_frameState) {
|
||||
|
||||
super(type, map, opt_frameState);
|
||||
|
||||
/**
|
||||
@@ -49,7 +47,6 @@ class MapBrowserEvent extends MapEvent {
|
||||
* @api
|
||||
*/
|
||||
this.dragging = opt_dragging !== undefined ? opt_dragging : false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,5 +101,4 @@ class MapBrowserEvent extends MapEvent {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default MapBrowserEvent;
|
||||
|
||||
@@ -3,22 +3,20 @@
|
||||
*/
|
||||
|
||||
import 'elm-pep';
|
||||
import {DEVICE_PIXEL_RATIO, PASSIVE_EVENT_LISTENERS} from './has.js';
|
||||
import EventTarget from './events/Target.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import MapBrowserEventType from './MapBrowserEventType.js';
|
||||
import MapBrowserPointerEvent from './MapBrowserPointerEvent.js';
|
||||
import {listen, unlistenByKey} from './events.js';
|
||||
import EventTarget from './events/Target.js';
|
||||
import PointerEventType from './pointer/EventType.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import {DEVICE_PIXEL_RATIO, PASSIVE_EVENT_LISTENERS} from './has.js';
|
||||
import {listen, unlistenByKey} from './events.js';
|
||||
|
||||
class MapBrowserEventHandler extends EventTarget {
|
||||
|
||||
/**
|
||||
* @param {import("./PluggableMap.js").default} map The map with the viewport to listen to events on.
|
||||
* @param {number=} moveTolerance The minimal distance the pointer must travel to trigger a move.
|
||||
*/
|
||||
constructor(map, moveTolerance) {
|
||||
|
||||
super(map);
|
||||
|
||||
/**
|
||||
@@ -50,8 +48,9 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.moveTolerance_ = moveTolerance ?
|
||||
moveTolerance * DEVICE_PIXEL_RATIO : DEVICE_PIXEL_RATIO;
|
||||
this.moveTolerance_ = moveTolerance
|
||||
? moveTolerance * DEVICE_PIXEL_RATIO
|
||||
: DEVICE_PIXEL_RATIO;
|
||||
|
||||
/**
|
||||
* The most recent "down" type event (or null if none have occurred).
|
||||
@@ -81,9 +80,12 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
* @type {?import("./events.js").EventsKey}
|
||||
* @private
|
||||
*/
|
||||
this.pointerdownListenerKey_ = listen(element,
|
||||
this.pointerdownListenerKey_ = listen(
|
||||
element,
|
||||
PointerEventType.POINTERDOWN,
|
||||
this.handlePointerDown_, this);
|
||||
this.handlePointerDown_,
|
||||
this
|
||||
);
|
||||
|
||||
/**
|
||||
* @type {PointerEvent}
|
||||
@@ -95,17 +97,23 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
* @type {?import("./events.js").EventsKey}
|
||||
* @private
|
||||
*/
|
||||
this.relayedListenerKey_ = listen(element,
|
||||
this.relayedListenerKey_ = listen(
|
||||
element,
|
||||
PointerEventType.POINTERMOVE,
|
||||
this.relayEvent_, this);
|
||||
this.relayEvent_,
|
||||
this
|
||||
);
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
this.boundHandleTouchMove_ = this.handleTouchMove_.bind(this);
|
||||
|
||||
this.element_.addEventListener(EventType.TOUCHMOVE, this.boundHandleTouchMove_,
|
||||
PASSIVE_EVENT_LISTENERS ? {passive: false} : false);
|
||||
this.element_.addEventListener(
|
||||
EventType.TOUCHMOVE,
|
||||
this.boundHandleTouchMove_,
|
||||
PASSIVE_EVENT_LISTENERS ? {passive: false} : false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,23 +123,35 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
*/
|
||||
emulateClick_(pointerEvent) {
|
||||
let newEvent = new MapBrowserPointerEvent(
|
||||
MapBrowserEventType.CLICK, this.map_, pointerEvent);
|
||||
MapBrowserEventType.CLICK,
|
||||
this.map_,
|
||||
pointerEvent
|
||||
);
|
||||
this.dispatchEvent(newEvent);
|
||||
if (this.clickTimeoutId_ !== undefined) {
|
||||
// double-click
|
||||
clearTimeout(this.clickTimeoutId_);
|
||||
this.clickTimeoutId_ = undefined;
|
||||
newEvent = new MapBrowserPointerEvent(
|
||||
MapBrowserEventType.DBLCLICK, this.map_, pointerEvent);
|
||||
MapBrowserEventType.DBLCLICK,
|
||||
this.map_,
|
||||
pointerEvent
|
||||
);
|
||||
this.dispatchEvent(newEvent);
|
||||
} else {
|
||||
// click
|
||||
this.clickTimeoutId_ = setTimeout(function() {
|
||||
this.clickTimeoutId_ = undefined;
|
||||
const newEvent = new MapBrowserPointerEvent(
|
||||
MapBrowserEventType.SINGLECLICK, this.map_, pointerEvent);
|
||||
this.dispatchEvent(newEvent);
|
||||
}.bind(this), 250);
|
||||
this.clickTimeoutId_ = setTimeout(
|
||||
function () {
|
||||
this.clickTimeoutId_ = undefined;
|
||||
const newEvent = new MapBrowserPointerEvent(
|
||||
MapBrowserEventType.SINGLECLICK,
|
||||
this.map_,
|
||||
pointerEvent
|
||||
);
|
||||
this.dispatchEvent(newEvent);
|
||||
}.bind(this),
|
||||
250
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,8 +165,10 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
updateActivePointers_(pointerEvent) {
|
||||
const event = pointerEvent;
|
||||
|
||||
if (event.type == MapBrowserEventType.POINTERUP ||
|
||||
event.type == MapBrowserEventType.POINTERCANCEL) {
|
||||
if (
|
||||
event.type == MapBrowserEventType.POINTERUP ||
|
||||
event.type == MapBrowserEventType.POINTERCANCEL
|
||||
) {
|
||||
delete this.trackedTouches_[event.pointerId];
|
||||
} else if (event.type == MapBrowserEventType.POINTERDOWN) {
|
||||
this.trackedTouches_[event.pointerId] = true;
|
||||
@@ -162,7 +184,10 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
handlePointerUp_(pointerEvent) {
|
||||
this.updateActivePointers_(pointerEvent);
|
||||
const newEvent = new MapBrowserPointerEvent(
|
||||
MapBrowserEventType.POINTERUP, this.map_, pointerEvent);
|
||||
MapBrowserEventType.POINTERUP,
|
||||
this.map_,
|
||||
pointerEvent
|
||||
);
|
||||
this.dispatchEvent(newEvent);
|
||||
|
||||
// We emulate click events on left mouse button click, touch contact, and pen
|
||||
@@ -171,7 +196,11 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
// See http://www.w3.org/TR/pointerevents/#button-states
|
||||
// We only fire click, singleclick, and doubleclick if nobody has called
|
||||
// event.stopPropagation() or event.preventDefault().
|
||||
if (!newEvent.propagationStopped && !this.dragging_ && this.isMouseActionButton_(pointerEvent)) {
|
||||
if (
|
||||
!newEvent.propagationStopped &&
|
||||
!this.dragging_ &&
|
||||
this.isMouseActionButton_(pointerEvent)
|
||||
) {
|
||||
this.emulateClick_(this.down_);
|
||||
}
|
||||
|
||||
@@ -201,19 +230,28 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
handlePointerDown_(pointerEvent) {
|
||||
this.updateActivePointers_(pointerEvent);
|
||||
const newEvent = new MapBrowserPointerEvent(
|
||||
MapBrowserEventType.POINTERDOWN, this.map_, pointerEvent);
|
||||
MapBrowserEventType.POINTERDOWN,
|
||||
this.map_,
|
||||
pointerEvent
|
||||
);
|
||||
this.dispatchEvent(newEvent);
|
||||
|
||||
this.down_ = pointerEvent;
|
||||
|
||||
if (this.dragListenerKeys_.length === 0) {
|
||||
this.dragListenerKeys_.push(
|
||||
listen(document,
|
||||
listen(
|
||||
document,
|
||||
MapBrowserEventType.POINTERMOVE,
|
||||
this.handlePointerMove_, this),
|
||||
listen(document,
|
||||
this.handlePointerMove_,
|
||||
this
|
||||
),
|
||||
listen(
|
||||
document,
|
||||
MapBrowserEventType.POINTERUP,
|
||||
this.handlePointerUp_, this),
|
||||
this.handlePointerUp_,
|
||||
this
|
||||
),
|
||||
/* Note that the listener for `pointercancel is set up on
|
||||
* `pointerEventHandler_` and not `documentPointerEventHandler_` like
|
||||
* the `pointerup` and `pointermove` listeners.
|
||||
@@ -227,9 +265,12 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
* only receive a `touchcancel` from `pointerEventHandler_`, because it is
|
||||
* only registered there.
|
||||
*/
|
||||
listen(this.element_,
|
||||
listen(
|
||||
this.element_,
|
||||
MapBrowserEventType.POINTERCANCEL,
|
||||
this.handlePointerUp_, this)
|
||||
this.handlePointerUp_,
|
||||
this
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -246,8 +287,11 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
if (this.isMoving_(pointerEvent)) {
|
||||
this.dragging_ = true;
|
||||
const newEvent = new MapBrowserPointerEvent(
|
||||
MapBrowserEventType.POINTERDRAG, this.map_, pointerEvent,
|
||||
this.dragging_);
|
||||
MapBrowserEventType.POINTERDRAG,
|
||||
this.map_,
|
||||
pointerEvent,
|
||||
this.dragging_
|
||||
);
|
||||
this.dispatchEvent(newEvent);
|
||||
}
|
||||
}
|
||||
@@ -262,8 +306,14 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
relayEvent_(pointerEvent) {
|
||||
this.originalPointerMoveEvent_ = pointerEvent;
|
||||
const dragging = !!(this.down_ && this.isMoving_(pointerEvent));
|
||||
this.dispatchEvent(new MapBrowserPointerEvent(
|
||||
pointerEvent.type, this.map_, pointerEvent, dragging));
|
||||
this.dispatchEvent(
|
||||
new MapBrowserPointerEvent(
|
||||
pointerEvent.type,
|
||||
this.map_,
|
||||
pointerEvent,
|
||||
dragging
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,7 +327,10 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
handleTouchMove_(event) {
|
||||
// Due to https://github.com/mpizenberg/elm-pep/issues/2, `this.originalPointerMoveEvent_`
|
||||
// may not be initialized yet when we get here on a platform without native pointer events.
|
||||
if (!this.originalPointerMoveEvent_ || this.originalPointerMoveEvent_.defaultPrevented) {
|
||||
if (
|
||||
!this.originalPointerMoveEvent_ ||
|
||||
this.originalPointerMoveEvent_.defaultPrevented
|
||||
) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
@@ -289,9 +342,12 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
* @private
|
||||
*/
|
||||
isMoving_(pointerEvent) {
|
||||
return this.dragging_ ||
|
||||
Math.abs(pointerEvent.clientX - this.down_.clientX) > this.moveTolerance_ ||
|
||||
Math.abs(pointerEvent.clientY - this.down_.clientY) > this.moveTolerance_;
|
||||
return (
|
||||
this.dragging_ ||
|
||||
Math.abs(pointerEvent.clientX - this.down_.clientX) >
|
||||
this.moveTolerance_ ||
|
||||
Math.abs(pointerEvent.clientY - this.down_.clientY) > this.moveTolerance_
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,7 +358,10 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
unlistenByKey(this.relayedListenerKey_);
|
||||
this.relayedListenerKey_ = null;
|
||||
}
|
||||
this.element_.removeEventListener(EventType.TOUCHMOVE, this.boundHandleTouchMove_);
|
||||
this.element_.removeEventListener(
|
||||
EventType.TOUCHMOVE,
|
||||
this.boundHandleTouchMove_
|
||||
);
|
||||
|
||||
if (this.pointerdownListenerKey_) {
|
||||
unlistenByKey(this.pointerdownListenerKey_);
|
||||
@@ -317,5 +376,4 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default MapBrowserEventHandler;
|
||||
|
||||
@@ -8,7 +8,6 @@ import EventType from './events/EventType.js';
|
||||
* @enum {string}
|
||||
*/
|
||||
export default {
|
||||
|
||||
/**
|
||||
* A true single click with no dragging and no double click. Note that this
|
||||
* event is delayed by 250 ms to ensure that it is not a double click.
|
||||
@@ -52,5 +51,5 @@ export default {
|
||||
POINTEROUT: 'pointerout',
|
||||
POINTERENTER: 'pointerenter',
|
||||
POINTERLEAVE: 'pointerleave',
|
||||
POINTERCANCEL: 'pointercancel'
|
||||
POINTERCANCEL: 'pointercancel',
|
||||
};
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import MapBrowserEvent from './MapBrowserEvent.js';
|
||||
|
||||
class MapBrowserPointerEvent extends MapBrowserEvent {
|
||||
|
||||
/**
|
||||
* @param {string} type Event type.
|
||||
* @param {import("./PluggableMap.js").default} map Map.
|
||||
@@ -13,7 +12,6 @@ class MapBrowserPointerEvent extends MapBrowserEvent {
|
||||
* @param {?import("./PluggableMap.js").FrameState=} opt_frameState Frame state.
|
||||
*/
|
||||
constructor(type, map, pointerEvent, opt_dragging, opt_frameState) {
|
||||
|
||||
super(type, map, pointerEvent, opt_dragging, opt_frameState);
|
||||
|
||||
/**
|
||||
@@ -21,9 +19,7 @@ class MapBrowserPointerEvent extends MapBrowserEvent {
|
||||
* @type {PointerEvent}
|
||||
*/
|
||||
this.pointerEvent = pointerEvent;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default MapBrowserPointerEvent;
|
||||
|
||||
@@ -9,14 +9,12 @@ import Event from './events/Event.js';
|
||||
* See {@link module:ol/PluggableMap~PluggableMap} for which events trigger a map event.
|
||||
*/
|
||||
class MapEvent extends Event {
|
||||
|
||||
/**
|
||||
* @param {string} type Event type.
|
||||
* @param {import("./PluggableMap.js").default} map Map.
|
||||
* @param {?import("./PluggableMap.js").FrameState=} opt_frameState Frame state.
|
||||
*/
|
||||
constructor(type, map, opt_frameState) {
|
||||
|
||||
super(type);
|
||||
|
||||
/**
|
||||
@@ -32,9 +30,7 @@ class MapEvent extends Event {
|
||||
* @api
|
||||
*/
|
||||
this.frameState = opt_frameState !== undefined ? opt_frameState : null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default MapEvent;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
* @enum {string}
|
||||
*/
|
||||
export default {
|
||||
|
||||
/**
|
||||
* Triggered after a map frame is rendered.
|
||||
* @event module:ol/MapEvent~MapEvent#postrender
|
||||
@@ -26,6 +25,5 @@ export default {
|
||||
* @event module:ol/MapEvent~MapEvent#moveend
|
||||
* @api
|
||||
*/
|
||||
MOVEEND: 'moveend'
|
||||
|
||||
MOVEEND: 'moveend',
|
||||
};
|
||||
|
||||
@@ -9,5 +9,5 @@ export default {
|
||||
LAYERGROUP: 'layergroup',
|
||||
SIZE: 'size',
|
||||
TARGET: 'target',
|
||||
VIEW: 'view'
|
||||
VIEW: 'view',
|
||||
};
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
/**
|
||||
* @module ol/Object
|
||||
*/
|
||||
import {getUid} from './util.js';
|
||||
import Event from './events/Event.js';
|
||||
import ObjectEventType from './ObjectEventType.js';
|
||||
import Observable from './Observable.js';
|
||||
import Event from './events/Event.js';
|
||||
import {assign} from './obj.js';
|
||||
|
||||
import {getUid} from './util.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Events emitted by {@link module:ol/Object~BaseObject} instances are instances of this type.
|
||||
*/
|
||||
export class ObjectEvent extends Event {
|
||||
|
||||
/**
|
||||
* @param {string} type The event type.
|
||||
* @param {string} key The property name.
|
||||
@@ -36,12 +34,9 @@ export class ObjectEvent extends Event {
|
||||
* @api
|
||||
*/
|
||||
this.oldValue = oldValue;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Abstract base class; normally only used for creating subclasses and not
|
||||
@@ -86,7 +81,6 @@ export class ObjectEvent extends Event {
|
||||
* @api
|
||||
*/
|
||||
class BaseObject extends Observable {
|
||||
|
||||
/**
|
||||
* @param {Object<string, *>=} opt_values An object with key-value pairs.
|
||||
*/
|
||||
@@ -203,22 +197,19 @@ class BaseObject extends Observable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, string>}
|
||||
*/
|
||||
const changeEventTypeCache = {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} key Key name.
|
||||
* @return {string} Change name.
|
||||
*/
|
||||
export function getChangeEventType(key) {
|
||||
return changeEventTypeCache.hasOwnProperty(key) ?
|
||||
changeEventTypeCache[key] :
|
||||
(changeEventTypeCache[key] = 'change:' + key);
|
||||
return changeEventTypeCache.hasOwnProperty(key)
|
||||
? changeEventTypeCache[key]
|
||||
: (changeEventTypeCache[key] = 'change:' + key);
|
||||
}
|
||||
|
||||
|
||||
export default BaseObject;
|
||||
|
||||
@@ -11,5 +11,5 @@ export default {
|
||||
* @event module:ol/Object.ObjectEvent#propertychange
|
||||
* @api
|
||||
*/
|
||||
PROPERTYCHANGE: 'propertychange'
|
||||
PROPERTYCHANGE: 'propertychange',
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* @module ol/Observable
|
||||
*/
|
||||
import {listen, unlistenByKey, listenOnce} from './events.js';
|
||||
import EventTarget from './events/Target.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import {listen, listenOnce, unlistenByKey} from './events.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -18,7 +18,6 @@ import EventType from './events/EventType.js';
|
||||
*/
|
||||
class Observable extends EventTarget {
|
||||
constructor() {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -26,7 +25,6 @@ class Observable extends EventTarget {
|
||||
* @type {number}
|
||||
*/
|
||||
this.revision_ = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +107,6 @@ class Observable extends EventTarget {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes an event listener using the key returned by `on()` or `once()`.
|
||||
* @param {import("./events.js").EventsKey|Array<import("./events.js").EventsKey>} key The key returned by `on()`
|
||||
@@ -126,5 +123,4 @@ export function unByKey(key) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Observable;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
/**
|
||||
* @module ol/Overlay
|
||||
*/
|
||||
import MapEventType from './MapEventType.js';
|
||||
import BaseObject, {getChangeEventType} from './Object.js';
|
||||
import MapEventType from './MapEventType.js';
|
||||
import OverlayPositioning from './OverlayPositioning.js';
|
||||
import {CLASS_SELECTABLE} from './css.js';
|
||||
import {removeNode, removeChildren, outerWidth, outerHeight} from './dom.js';
|
||||
import {listen, unlistenByKey} from './events.js';
|
||||
import {containsExtent} from './extent.js';
|
||||
|
||||
import {listen, unlistenByKey} from './events.js';
|
||||
import {outerHeight, outerWidth, removeChildren, removeNode} from './dom.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
@@ -56,7 +55,6 @@ import {containsExtent} from './extent.js';
|
||||
* name.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} PanOptions
|
||||
* @property {number} [duration=1000] The duration of the animation in
|
||||
@@ -82,10 +80,9 @@ const Property = {
|
||||
MAP: 'map',
|
||||
OFFSET: 'offset',
|
||||
POSITION: 'position',
|
||||
POSITIONING: 'positioning'
|
||||
POSITIONING: 'positioning',
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* An element to be displayed over the map and attached to a single map
|
||||
@@ -107,12 +104,10 @@ const Property = {
|
||||
* @api
|
||||
*/
|
||||
class Overlay extends BaseObject {
|
||||
|
||||
/**
|
||||
* @param {Options} options Overlay options.
|
||||
*/
|
||||
constructor(options) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -131,8 +126,8 @@ class Overlay extends BaseObject {
|
||||
* @protected
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.insertFirst = options.insertFirst !== undefined ?
|
||||
options.insertFirst : true;
|
||||
this.insertFirst =
|
||||
options.insertFirst !== undefined ? options.insertFirst : true;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
@@ -145,22 +140,24 @@ class Overlay extends BaseObject {
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
this.element = document.createElement('div');
|
||||
this.element.className = options.className !== undefined ?
|
||||
options.className : 'ol-overlay-container ' + CLASS_SELECTABLE;
|
||||
this.element.className =
|
||||
options.className !== undefined
|
||||
? options.className
|
||||
: 'ol-overlay-container ' + CLASS_SELECTABLE;
|
||||
this.element.style.position = 'absolute';
|
||||
|
||||
let autoPan = options.autoPan;
|
||||
if (autoPan && ('object' !== typeof autoPan)) {
|
||||
if (autoPan && 'object' !== typeof autoPan) {
|
||||
autoPan = {
|
||||
animation: options.autoPanAnimation,
|
||||
margin: options.autoPanMargin
|
||||
margin: options.autoPanMargin,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @protected
|
||||
* @type {PanIntoViewOptions|false}
|
||||
*/
|
||||
this.autoPan = /** @type {PanIntoViewOptions} */(autoPan) || false;
|
||||
this.autoPan = /** @type {PanIntoViewOptions} */ (autoPan) || false;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
@@ -169,7 +166,7 @@ class Overlay extends BaseObject {
|
||||
*/
|
||||
this.rendered = {
|
||||
transform_: '',
|
||||
visible: true
|
||||
visible: true,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -178,11 +175,26 @@ class Overlay extends BaseObject {
|
||||
*/
|
||||
this.mapPostrenderListenerKey = null;
|
||||
|
||||
this.addEventListener(getChangeEventType(Property.ELEMENT), this.handleElementChanged);
|
||||
this.addEventListener(getChangeEventType(Property.MAP), this.handleMapChanged);
|
||||
this.addEventListener(getChangeEventType(Property.OFFSET), this.handleOffsetChanged);
|
||||
this.addEventListener(getChangeEventType(Property.POSITION), this.handlePositionChanged);
|
||||
this.addEventListener(getChangeEventType(Property.POSITIONING), this.handlePositioningChanged);
|
||||
this.addEventListener(
|
||||
getChangeEventType(Property.ELEMENT),
|
||||
this.handleElementChanged
|
||||
);
|
||||
this.addEventListener(
|
||||
getChangeEventType(Property.MAP),
|
||||
this.handleMapChanged
|
||||
);
|
||||
this.addEventListener(
|
||||
getChangeEventType(Property.OFFSET),
|
||||
this.handleOffsetChanged
|
||||
);
|
||||
this.addEventListener(
|
||||
getChangeEventType(Property.POSITION),
|
||||
this.handlePositionChanged
|
||||
);
|
||||
this.addEventListener(
|
||||
getChangeEventType(Property.POSITIONING),
|
||||
this.handlePositioningChanged
|
||||
);
|
||||
|
||||
if (options.element !== undefined) {
|
||||
this.setElement(options.element);
|
||||
@@ -190,14 +202,15 @@ class Overlay extends BaseObject {
|
||||
|
||||
this.setOffset(options.offset !== undefined ? options.offset : [0, 0]);
|
||||
|
||||
this.setPositioning(options.positioning !== undefined ?
|
||||
/** @type {OverlayPositioning} */ (options.positioning) :
|
||||
OverlayPositioning.TOP_LEFT);
|
||||
this.setPositioning(
|
||||
options.positioning !== undefined
|
||||
? /** @type {OverlayPositioning} */ (options.positioning)
|
||||
: OverlayPositioning.TOP_LEFT
|
||||
);
|
||||
|
||||
if (options.position !== undefined) {
|
||||
this.setPosition(options.position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,9 +240,9 @@ class Overlay extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getMap() {
|
||||
return (
|
||||
/** @type {import("./PluggableMap.js").default|undefined} */ (this.get(Property.MAP))
|
||||
);
|
||||
return /** @type {import("./PluggableMap.js").default|undefined} */ (this.get(
|
||||
Property.MAP
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,9 +263,9 @@ class Overlay extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getPosition() {
|
||||
return (
|
||||
/** @type {import("./coordinate.js").Coordinate|undefined} */ (this.get(Property.POSITION))
|
||||
);
|
||||
return /** @type {import("./coordinate.js").Coordinate|undefined} */ (this.get(
|
||||
Property.POSITION
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,9 +276,7 @@ class Overlay extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getPositioning() {
|
||||
return (
|
||||
/** @type {OverlayPositioning} */ (this.get(Property.POSITIONING))
|
||||
);
|
||||
return /** @type {OverlayPositioning} */ (this.get(Property.POSITIONING));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,11 +301,16 @@ class Overlay extends BaseObject {
|
||||
}
|
||||
const map = this.getMap();
|
||||
if (map) {
|
||||
this.mapPostrenderListenerKey = listen(map,
|
||||
MapEventType.POSTRENDER, this.render, this);
|
||||
this.mapPostrenderListenerKey = listen(
|
||||
map,
|
||||
MapEventType.POSTRENDER,
|
||||
this.render,
|
||||
this
|
||||
);
|
||||
this.updatePixelPosition();
|
||||
const container = this.stopEvent ?
|
||||
map.getOverlayContainerStopEvent() : map.getOverlayContainer();
|
||||
const container = this.stopEvent
|
||||
? map.getOverlayContainerStopEvent()
|
||||
: map.getOverlayContainer();
|
||||
if (this.insertFirst) {
|
||||
container.insertBefore(this.element, container.childNodes[0] || null);
|
||||
} else {
|
||||
@@ -402,9 +418,13 @@ class Overlay extends BaseObject {
|
||||
|
||||
const mapRect = this.getRect(map.getTargetElement(), map.getSize());
|
||||
const element = this.getElement();
|
||||
const overlayRect = this.getRect(element, [outerWidth(element), outerHeight(element)]);
|
||||
const overlayRect = this.getRect(element, [
|
||||
outerWidth(element),
|
||||
outerHeight(element),
|
||||
]);
|
||||
|
||||
const myMargin = (panIntoViewOptions.margin === undefined) ? 20 : panIntoViewOptions.margin;
|
||||
const myMargin =
|
||||
panIntoViewOptions.margin === undefined ? 20 : panIntoViewOptions.margin;
|
||||
if (!containsExtent(mapRect, overlayRect)) {
|
||||
// the overlay is not completely inside the viewport, so pan the map
|
||||
const offsetLeft = overlayRect[0] - mapRect[0];
|
||||
@@ -429,18 +449,17 @@ class Overlay extends BaseObject {
|
||||
}
|
||||
|
||||
if (delta[0] !== 0 || delta[1] !== 0) {
|
||||
const center = /** @type {import("./coordinate.js").Coordinate} */ (map.getView().getCenterInternal());
|
||||
const center = /** @type {import("./coordinate.js").Coordinate} */ (map
|
||||
.getView()
|
||||
.getCenterInternal());
|
||||
const centerPx = map.getPixelFromCoordinateInternal(center);
|
||||
const newCenterPx = [
|
||||
centerPx[0] + delta[0],
|
||||
centerPx[1] + delta[1]
|
||||
];
|
||||
const newCenterPx = [centerPx[0] + delta[0], centerPx[1] + delta[1]];
|
||||
|
||||
const panOptions = panIntoViewOptions.animation || {};
|
||||
map.getView().animateInternal({
|
||||
center: map.getCoordinateFromPixelInternal(newCenterPx),
|
||||
duration: panOptions.duration,
|
||||
easing: panOptions.easing
|
||||
easing: panOptions.easing,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -457,12 +476,7 @@ class Overlay extends BaseObject {
|
||||
const box = element.getBoundingClientRect();
|
||||
const offsetX = box.left + window.pageXOffset;
|
||||
const offsetY = box.top + window.pageYOffset;
|
||||
return [
|
||||
offsetX,
|
||||
offsetY,
|
||||
offsetX + size[0],
|
||||
offsetY + size[1]
|
||||
];
|
||||
return [offsetX, offsetY, offsetX + size[0], offsetY + size[1]];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -522,22 +536,30 @@ class Overlay extends BaseObject {
|
||||
const y = Math.round(pixel[1] + offset[1]) + 'px';
|
||||
let posX = '0%';
|
||||
let posY = '0%';
|
||||
if (positioning == OverlayPositioning.BOTTOM_RIGHT ||
|
||||
positioning == OverlayPositioning.CENTER_RIGHT ||
|
||||
positioning == OverlayPositioning.TOP_RIGHT) {
|
||||
if (
|
||||
positioning == OverlayPositioning.BOTTOM_RIGHT ||
|
||||
positioning == OverlayPositioning.CENTER_RIGHT ||
|
||||
positioning == OverlayPositioning.TOP_RIGHT
|
||||
) {
|
||||
posX = '-100%';
|
||||
} else if (positioning == OverlayPositioning.BOTTOM_CENTER ||
|
||||
positioning == OverlayPositioning.CENTER_CENTER ||
|
||||
positioning == OverlayPositioning.TOP_CENTER) {
|
||||
} else if (
|
||||
positioning == OverlayPositioning.BOTTOM_CENTER ||
|
||||
positioning == OverlayPositioning.CENTER_CENTER ||
|
||||
positioning == OverlayPositioning.TOP_CENTER
|
||||
) {
|
||||
posX = '-50%';
|
||||
}
|
||||
if (positioning == OverlayPositioning.BOTTOM_LEFT ||
|
||||
positioning == OverlayPositioning.BOTTOM_CENTER ||
|
||||
positioning == OverlayPositioning.BOTTOM_RIGHT) {
|
||||
if (
|
||||
positioning == OverlayPositioning.BOTTOM_LEFT ||
|
||||
positioning == OverlayPositioning.BOTTOM_CENTER ||
|
||||
positioning == OverlayPositioning.BOTTOM_RIGHT
|
||||
) {
|
||||
posY = '-100%';
|
||||
} else if (positioning == OverlayPositioning.CENTER_LEFT ||
|
||||
positioning == OverlayPositioning.CENTER_CENTER ||
|
||||
positioning == OverlayPositioning.CENTER_RIGHT) {
|
||||
} else if (
|
||||
positioning == OverlayPositioning.CENTER_LEFT ||
|
||||
positioning == OverlayPositioning.CENTER_CENTER ||
|
||||
positioning == OverlayPositioning.CENTER_RIGHT
|
||||
) {
|
||||
posY = '-50%';
|
||||
}
|
||||
const transform = `translate(${posX}, ${posY}) translate(${x}, ${y})`;
|
||||
@@ -558,5 +580,4 @@ class Overlay extends BaseObject {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Overlay;
|
||||
|
||||
@@ -17,5 +17,5 @@ export default {
|
||||
CENTER_RIGHT: 'center-right',
|
||||
TOP_LEFT: 'top-left',
|
||||
TOP_CENTER: 'top-center',
|
||||
TOP_RIGHT: 'top-right'
|
||||
TOP_RIGHT: 'top-right',
|
||||
};
|
||||
|
||||
@@ -1,32 +1,44 @@
|
||||
/**
|
||||
* @module ol/PluggableMap
|
||||
*/
|
||||
import BaseObject, {getChangeEventType} from './Object.js';
|
||||
import Collection from './Collection.js';
|
||||
import CollectionEventType from './CollectionEventType.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import LayerGroup from './layer/Group.js';
|
||||
import MapBrowserEvent from './MapBrowserEvent.js';
|
||||
import MapBrowserEventHandler from './MapBrowserEventHandler.js';
|
||||
import MapBrowserEventType from './MapBrowserEventType.js';
|
||||
import MapEvent from './MapEvent.js';
|
||||
import MapEventType from './MapEventType.js';
|
||||
import MapProperty from './MapProperty.js';
|
||||
import RenderEventType from './render/EventType.js';
|
||||
import BaseObject, {getChangeEventType} from './Object.js';
|
||||
import ObjectEventType from './ObjectEventType.js';
|
||||
import RenderEventType from './render/EventType.js';
|
||||
import TileQueue, {getTilePriority} from './TileQueue.js';
|
||||
import View from './View.js';
|
||||
import ViewHint from './ViewHint.js';
|
||||
import {assert} from './asserts.js';
|
||||
import {removeNode} from './dom.js';
|
||||
import {listen, unlistenByKey} from './events.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import {clone, createOrUpdateEmpty, equals, getForViewAndSize, isEmpty} from './extent.js';
|
||||
import {
|
||||
DEVICE_PIXEL_RATIO,
|
||||
IMAGE_DECODE,
|
||||
PASSIVE_EVENT_LISTENERS,
|
||||
} from './has.js';
|
||||
import {TRUE} from './functions.js';
|
||||
import {DEVICE_PIXEL_RATIO, IMAGE_DECODE, PASSIVE_EVENT_LISTENERS} from './has.js';
|
||||
import LayerGroup from './layer/Group.js';
|
||||
import {
|
||||
apply as applyTransform,
|
||||
create as createTransform,
|
||||
} from './transform.js';
|
||||
import {assert} from './asserts.js';
|
||||
import {
|
||||
clone,
|
||||
createOrUpdateEmpty,
|
||||
equals,
|
||||
getForViewAndSize,
|
||||
isEmpty,
|
||||
} from './extent.js';
|
||||
import {fromUserCoordinate, toUserCoordinate} from './proj.js';
|
||||
import {hasArea} from './size.js';
|
||||
import {create as createTransform, apply as applyTransform} from './transform.js';
|
||||
import {toUserCoordinate, fromUserCoordinate} from './proj.js';
|
||||
|
||||
import {listen, unlistenByKey} from './events.js';
|
||||
import {removeNode} from './dom.js';
|
||||
|
||||
/**
|
||||
* State of the current frame. Only `pixelRatio`, `time` and `viewState` should
|
||||
@@ -51,19 +63,16 @@ import {toUserCoordinate, fromUserCoordinate} from './proj.js';
|
||||
* @property {!Object<string, Object<string, boolean>>} wantedTiles
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} DeclutterItems
|
||||
* @property {Array<*>} items Declutter items of an executor.
|
||||
* @property {number} opacity Layer opacity.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function(PluggableMap, ?FrameState): any} PostRenderFunction
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} AtPixelOptions
|
||||
* @property {undefined|function(import("./layer/Layer.js").default): boolean} [layerFilter] Layer filter
|
||||
@@ -77,7 +86,6 @@ import {toUserCoordinate, fromUserCoordinate} from './proj.js';
|
||||
* +/- 1 world width. Works only if a projection is used that can be wrapped.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} MapOptionsInternal
|
||||
* @property {Collection<import("./control/Control.js").default>} [controls]
|
||||
@@ -87,7 +95,6 @@ import {toUserCoordinate, fromUserCoordinate} from './proj.js';
|
||||
* @property {Object<string, *>} values
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Object literal with config options for the map.
|
||||
* @typedef {Object} MapOptions
|
||||
@@ -128,7 +135,6 @@ import {toUserCoordinate, fromUserCoordinate} from './proj.js';
|
||||
* {@link module:ol/Map~Map#setView}.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @fires import("./MapBrowserEvent.js").MapBrowserEvent
|
||||
* @fires import("./MapEvent.js").MapEvent
|
||||
@@ -138,12 +144,10 @@ import {toUserCoordinate, fromUserCoordinate} from './proj.js';
|
||||
* @api
|
||||
*/
|
||||
class PluggableMap extends BaseObject {
|
||||
|
||||
/**
|
||||
* @param {MapOptions} options Map options.
|
||||
*/
|
||||
constructor(options) {
|
||||
|
||||
super();
|
||||
|
||||
const optionsInternal = createOptionsInternal(options);
|
||||
@@ -151,19 +155,21 @@ class PluggableMap extends BaseObject {
|
||||
/** @private */
|
||||
this.boundHandleBrowserEvent_ = this.handleBrowserEvent.bind(this);
|
||||
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.maxTilesLoading_ = options.maxTilesLoading !== undefined ? options.maxTilesLoading : 16;
|
||||
this.maxTilesLoading_ =
|
||||
options.maxTilesLoading !== undefined ? options.maxTilesLoading : 16;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.pixelRatio_ = options.pixelRatio !== undefined ?
|
||||
options.pixelRatio : DEVICE_PIXEL_RATIO;
|
||||
this.pixelRatio_ =
|
||||
options.pixelRatio !== undefined
|
||||
? options.pixelRatio
|
||||
: DEVICE_PIXEL_RATIO;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -180,7 +186,7 @@ class PluggableMap extends BaseObject {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
this.animationDelay_ = function() {
|
||||
this.animationDelay_ = function () {
|
||||
this.animationDelayKey_ = undefined;
|
||||
this.renderFrame_(Date.now());
|
||||
}.bind(this);
|
||||
@@ -239,13 +245,13 @@ class PluggableMap extends BaseObject {
|
||||
* @type {!HTMLElement}
|
||||
*/
|
||||
this.viewport_ = document.createElement('div');
|
||||
this.viewport_.className = 'ol-viewport' + ('ontouchstart' in window ? ' ol-touch' : '');
|
||||
this.viewport_.className =
|
||||
'ol-viewport' + ('ontouchstart' in window ? ' ol-touch' : '');
|
||||
this.viewport_.style.position = 'relative';
|
||||
this.viewport_.style.overflow = 'hidden';
|
||||
this.viewport_.style.width = '100%';
|
||||
this.viewport_.style.height = '100%';
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!HTMLElement}
|
||||
@@ -274,10 +280,16 @@ class PluggableMap extends BaseObject {
|
||||
* @private
|
||||
* @type {MapBrowserEventHandler}
|
||||
*/
|
||||
this.mapBrowserEventHandler_ = new MapBrowserEventHandler(this, options.moveTolerance);
|
||||
this.mapBrowserEventHandler_ = new MapBrowserEventHandler(
|
||||
this,
|
||||
options.moveTolerance
|
||||
);
|
||||
const handleMapBrowserEvent = this.handleMapBrowserEvent.bind(this);
|
||||
for (const key in MapBrowserEventType) {
|
||||
this.mapBrowserEventHandler_.addEventListener(MapBrowserEventType[key], handleMapBrowserEvent);
|
||||
this.mapBrowserEventHandler_.addEventListener(
|
||||
MapBrowserEventType[key],
|
||||
handleMapBrowserEvent
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,9 +305,16 @@ class PluggableMap extends BaseObject {
|
||||
this.keyHandlerKeys_ = null;
|
||||
|
||||
const handleBrowserEvent = this.handleBrowserEvent.bind(this);
|
||||
this.viewport_.addEventListener(EventType.CONTEXTMENU, handleBrowserEvent, false);
|
||||
this.viewport_.addEventListener(EventType.WHEEL, handleBrowserEvent,
|
||||
PASSIVE_EVENT_LISTENERS ? {passive: false} : false);
|
||||
this.viewport_.addEventListener(
|
||||
EventType.CONTEXTMENU,
|
||||
handleBrowserEvent,
|
||||
false
|
||||
);
|
||||
this.viewport_.addEventListener(
|
||||
EventType.WHEEL,
|
||||
handleBrowserEvent,
|
||||
PASSIVE_EVENT_LISTENERS ? {passive: false} : false
|
||||
);
|
||||
|
||||
/**
|
||||
* @type {Collection<import("./control/Control.js").default>}
|
||||
@@ -346,12 +365,25 @@ class PluggableMap extends BaseObject {
|
||||
*/
|
||||
this.tileQueue_ = new TileQueue(
|
||||
this.getTilePriority.bind(this),
|
||||
this.handleTileChange_.bind(this));
|
||||
this.handleTileChange_.bind(this)
|
||||
);
|
||||
|
||||
this.addEventListener(getChangeEventType(MapProperty.LAYERGROUP), this.handleLayerGroupChanged_);
|
||||
this.addEventListener(getChangeEventType(MapProperty.VIEW), this.handleViewChanged_);
|
||||
this.addEventListener(getChangeEventType(MapProperty.SIZE), this.handleSizeChanged_);
|
||||
this.addEventListener(getChangeEventType(MapProperty.TARGET), this.handleTargetChanged_);
|
||||
this.addEventListener(
|
||||
getChangeEventType(MapProperty.LAYERGROUP),
|
||||
this.handleLayerGroupChanged_
|
||||
);
|
||||
this.addEventListener(
|
||||
getChangeEventType(MapProperty.VIEW),
|
||||
this.handleViewChanged_
|
||||
);
|
||||
this.addEventListener(
|
||||
getChangeEventType(MapProperty.SIZE),
|
||||
this.handleSizeChanged_
|
||||
);
|
||||
this.addEventListener(
|
||||
getChangeEventType(MapProperty.TARGET),
|
||||
this.handleTargetChanged_
|
||||
);
|
||||
|
||||
// setProperties will trigger the rendering of the map if the map
|
||||
// is "defined" already.
|
||||
@@ -362,74 +394,89 @@ class PluggableMap extends BaseObject {
|
||||
* @param {import("./control/Control.js").default} control Control.
|
||||
* @this {PluggableMap}
|
||||
*/
|
||||
function(control) {
|
||||
function (control) {
|
||||
control.setMap(this);
|
||||
}.bind(this));
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.controls.addEventListener(CollectionEventType.ADD,
|
||||
this.controls.addEventListener(
|
||||
CollectionEventType.ADD,
|
||||
/**
|
||||
* @param {import("./Collection.js").CollectionEvent} event CollectionEvent.
|
||||
*/
|
||||
function(event) {
|
||||
function (event) {
|
||||
event.element.setMap(this);
|
||||
}.bind(this));
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.controls.addEventListener(CollectionEventType.REMOVE,
|
||||
this.controls.addEventListener(
|
||||
CollectionEventType.REMOVE,
|
||||
/**
|
||||
* @param {import("./Collection.js").CollectionEvent} event CollectionEvent.
|
||||
*/
|
||||
function(event) {
|
||||
function (event) {
|
||||
event.element.setMap(null);
|
||||
}.bind(this));
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.interactions.forEach(
|
||||
/**
|
||||
* @param {import("./interaction/Interaction.js").default} interaction Interaction.
|
||||
* @this {PluggableMap}
|
||||
*/
|
||||
function(interaction) {
|
||||
function (interaction) {
|
||||
interaction.setMap(this);
|
||||
}.bind(this));
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.interactions.addEventListener(CollectionEventType.ADD,
|
||||
this.interactions.addEventListener(
|
||||
CollectionEventType.ADD,
|
||||
/**
|
||||
* @param {import("./Collection.js").CollectionEvent} event CollectionEvent.
|
||||
*/
|
||||
function(event) {
|
||||
function (event) {
|
||||
event.element.setMap(this);
|
||||
}.bind(this));
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.interactions.addEventListener(CollectionEventType.REMOVE,
|
||||
this.interactions.addEventListener(
|
||||
CollectionEventType.REMOVE,
|
||||
/**
|
||||
* @param {import("./Collection.js").CollectionEvent} event CollectionEvent.
|
||||
*/
|
||||
function(event) {
|
||||
function (event) {
|
||||
event.element.setMap(null);
|
||||
}.bind(this));
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.overlays_.forEach(this.addOverlayInternal_.bind(this));
|
||||
|
||||
this.overlays_.addEventListener(CollectionEventType.ADD,
|
||||
this.overlays_.addEventListener(
|
||||
CollectionEventType.ADD,
|
||||
/**
|
||||
* @param {import("./Collection.js").CollectionEvent} event CollectionEvent.
|
||||
*/
|
||||
function(event) {
|
||||
this.addOverlayInternal_(/** @type {import("./Overlay.js").default} */ (event.element));
|
||||
}.bind(this));
|
||||
function (event) {
|
||||
this.addOverlayInternal_(
|
||||
/** @type {import("./Overlay.js").default} */ (event.element)
|
||||
);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.overlays_.addEventListener(CollectionEventType.REMOVE,
|
||||
this.overlays_.addEventListener(
|
||||
CollectionEventType.REMOVE,
|
||||
/**
|
||||
* @param {import("./Collection.js").CollectionEvent} event CollectionEvent.
|
||||
*/
|
||||
function(event) {
|
||||
function (event) {
|
||||
const overlay = /** @type {import("./Overlay.js").default} */ (event.element);
|
||||
const id = overlay.getId();
|
||||
if (id !== undefined) {
|
||||
delete this.overlayIdIndex_[id.toString()];
|
||||
}
|
||||
event.element.setMap(null);
|
||||
}.bind(this));
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -502,8 +549,14 @@ class PluggableMap extends BaseObject {
|
||||
*/
|
||||
disposeInternal() {
|
||||
this.mapBrowserEventHandler_.dispose();
|
||||
this.viewport_.removeEventListener(EventType.CONTEXTMENU, this.boundHandleBrowserEvent_);
|
||||
this.viewport_.removeEventListener(EventType.WHEEL, this.boundHandleBrowserEvent_);
|
||||
this.viewport_.removeEventListener(
|
||||
EventType.CONTEXTMENU,
|
||||
this.boundHandleBrowserEvent_
|
||||
);
|
||||
this.viewport_.removeEventListener(
|
||||
EventType.WHEEL,
|
||||
this.boundHandleBrowserEvent_
|
||||
);
|
||||
if (this.handleResize_ !== undefined) {
|
||||
removeEventListener(EventType.RESIZE, this.handleResize_, false);
|
||||
this.handleResize_ = undefined;
|
||||
@@ -537,14 +590,23 @@ class PluggableMap extends BaseObject {
|
||||
}
|
||||
const coordinate = this.getCoordinateFromPixelInternal(pixel);
|
||||
opt_options = opt_options !== undefined ? opt_options : {};
|
||||
const hitTolerance = opt_options.hitTolerance !== undefined ?
|
||||
opt_options.hitTolerance * this.frameState_.pixelRatio : 0;
|
||||
const layerFilter = opt_options.layerFilter !== undefined ?
|
||||
opt_options.layerFilter : TRUE;
|
||||
const hitTolerance =
|
||||
opt_options.hitTolerance !== undefined
|
||||
? opt_options.hitTolerance * this.frameState_.pixelRatio
|
||||
: 0;
|
||||
const layerFilter =
|
||||
opt_options.layerFilter !== undefined ? opt_options.layerFilter : TRUE;
|
||||
const checkWrapped = opt_options.checkWrapped !== false;
|
||||
return this.renderer_.forEachFeatureAtCoordinate(
|
||||
coordinate, this.frameState_, hitTolerance, checkWrapped, callback, null,
|
||||
layerFilter, null);
|
||||
coordinate,
|
||||
this.frameState_,
|
||||
hitTolerance,
|
||||
checkWrapped,
|
||||
callback,
|
||||
null,
|
||||
layerFilter,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -557,9 +619,13 @@ class PluggableMap extends BaseObject {
|
||||
*/
|
||||
getFeaturesAtPixel(pixel, opt_options) {
|
||||
const features = [];
|
||||
this.forEachFeatureAtPixel(pixel, function(feature) {
|
||||
features.push(feature);
|
||||
}, opt_options);
|
||||
this.forEachFeatureAtPixel(
|
||||
pixel,
|
||||
function (feature) {
|
||||
features.push(feature);
|
||||
},
|
||||
opt_options
|
||||
);
|
||||
return features;
|
||||
}
|
||||
|
||||
@@ -589,10 +655,18 @@ class PluggableMap extends BaseObject {
|
||||
return;
|
||||
}
|
||||
const options = opt_options || {};
|
||||
const hitTolerance = options.hitTolerance !== undefined ?
|
||||
options.hitTolerance * this.frameState_.pixelRatio : 0;
|
||||
const hitTolerance =
|
||||
options.hitTolerance !== undefined
|
||||
? options.hitTolerance * this.frameState_.pixelRatio
|
||||
: 0;
|
||||
const layerFilter = options.layerFilter || TRUE;
|
||||
return this.renderer_.forEachLayerAtPixel(pixel, this.frameState_, hitTolerance, callback, layerFilter);
|
||||
return this.renderer_.forEachLayerAtPixel(
|
||||
pixel,
|
||||
this.frameState_,
|
||||
hitTolerance,
|
||||
callback,
|
||||
layerFilter
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -609,12 +683,21 @@ class PluggableMap extends BaseObject {
|
||||
}
|
||||
const coordinate = this.getCoordinateFromPixelInternal(pixel);
|
||||
opt_options = opt_options !== undefined ? opt_options : {};
|
||||
const layerFilter = opt_options.layerFilter !== undefined ? opt_options.layerFilter : TRUE;
|
||||
const hitTolerance = opt_options.hitTolerance !== undefined ?
|
||||
opt_options.hitTolerance * this.frameState_.pixelRatio : 0;
|
||||
const layerFilter =
|
||||
opt_options.layerFilter !== undefined ? opt_options.layerFilter : TRUE;
|
||||
const hitTolerance =
|
||||
opt_options.hitTolerance !== undefined
|
||||
? opt_options.hitTolerance * this.frameState_.pixelRatio
|
||||
: 0;
|
||||
const checkWrapped = opt_options.checkWrapped !== false;
|
||||
return this.renderer_.hasFeatureAtCoordinate(
|
||||
coordinate, this.frameState_, hitTolerance, checkWrapped, layerFilter, null);
|
||||
coordinate,
|
||||
this.frameState_,
|
||||
hitTolerance,
|
||||
checkWrapped,
|
||||
layerFilter,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -644,13 +727,14 @@ class PluggableMap extends BaseObject {
|
||||
*/
|
||||
getEventPixel(event) {
|
||||
const viewportPosition = this.viewport_.getBoundingClientRect();
|
||||
const eventPosition = 'changedTouches' in event ?
|
||||
/** @type {TouchEvent} */ (event).changedTouches[0] :
|
||||
/** @type {MouseEvent} */ (event);
|
||||
const eventPosition =
|
||||
'changedTouches' in event
|
||||
? /** @type {TouchEvent} */ (event).changedTouches[0]
|
||||
: /** @type {MouseEvent} */ (event);
|
||||
|
||||
return [
|
||||
eventPosition.clientX - viewportPosition.left,
|
||||
eventPosition.clientY - viewportPosition.top
|
||||
eventPosition.clientY - viewportPosition.top,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -664,7 +748,9 @@ class PluggableMap extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getTarget() {
|
||||
return /** @type {HTMLElement|string|undefined} */ (this.get(MapProperty.TARGET));
|
||||
return /** @type {HTMLElement|string|undefined} */ (this.get(
|
||||
MapProperty.TARGET
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -677,7 +763,9 @@ class PluggableMap extends BaseObject {
|
||||
getTargetElement() {
|
||||
const target = this.getTarget();
|
||||
if (target !== undefined) {
|
||||
return typeof target === 'string' ? document.getElementById(target) : target;
|
||||
return typeof target === 'string'
|
||||
? document.getElementById(target)
|
||||
: target;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -691,7 +779,10 @@ class PluggableMap extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getCoordinateFromPixel(pixel) {
|
||||
return toUserCoordinate(this.getCoordinateFromPixelInternal(pixel), this.getView().getProjection());
|
||||
return toUserCoordinate(
|
||||
this.getCoordinateFromPixelInternal(pixel),
|
||||
this.getView().getProjection()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -705,7 +796,10 @@ class PluggableMap extends BaseObject {
|
||||
if (!frameState) {
|
||||
return null;
|
||||
} else {
|
||||
return applyTransform(frameState.pixelToCoordinateTransform, pixel.slice());
|
||||
return applyTransform(
|
||||
frameState.pixelToCoordinateTransform,
|
||||
pixel.slice()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -761,9 +855,7 @@ class PluggableMap extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getLayerGroup() {
|
||||
return (
|
||||
/** @type {LayerGroup} */ (this.get(MapProperty.LAYERGROUP))
|
||||
);
|
||||
return /** @type {LayerGroup} */ (this.get(MapProperty.LAYERGROUP));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -799,7 +891,10 @@ class PluggableMap extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getPixelFromCoordinate(coordinate) {
|
||||
const viewCoordinate = fromUserCoordinate(coordinate, this.getView().getProjection());
|
||||
const viewCoordinate = fromUserCoordinate(
|
||||
coordinate,
|
||||
this.getView().getProjection()
|
||||
);
|
||||
return this.getPixelFromCoordinateInternal(viewCoordinate);
|
||||
}
|
||||
|
||||
@@ -814,7 +909,10 @@ class PluggableMap extends BaseObject {
|
||||
if (!frameState) {
|
||||
return null;
|
||||
} else {
|
||||
return applyTransform(frameState.coordinateToPixelTransform, coordinate.slice(0, 2));
|
||||
return applyTransform(
|
||||
frameState.coordinateToPixelTransform,
|
||||
coordinate.slice(0, 2)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -833,9 +931,9 @@ class PluggableMap extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getSize() {
|
||||
return (
|
||||
/** @type {import("./size.js").Size|undefined} */ (this.get(MapProperty.SIZE))
|
||||
);
|
||||
return /** @type {import("./size.js").Size|undefined} */ (this.get(
|
||||
MapProperty.SIZE
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -846,9 +944,7 @@ class PluggableMap extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getView() {
|
||||
return (
|
||||
/** @type {View} */ (this.get(MapProperty.VIEW))
|
||||
);
|
||||
return /** @type {View} */ (this.get(MapProperty.VIEW));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -890,7 +986,13 @@ class PluggableMap extends BaseObject {
|
||||
* @return {number} Tile priority.
|
||||
*/
|
||||
getTilePriority(tile, tileSourceKey, tileCenter, tileResolution) {
|
||||
return getTilePriority(this.frameState_, tile, tileSourceKey, tileCenter, tileResolution);
|
||||
return getTilePriority(
|
||||
this.frameState_,
|
||||
tile,
|
||||
tileSourceKey,
|
||||
tileCenter,
|
||||
tileResolution
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -914,7 +1016,14 @@ class PluggableMap extends BaseObject {
|
||||
}
|
||||
const target = /** @type {Node} */ (mapBrowserEvent.originalEvent.target);
|
||||
if (!mapBrowserEvent.dragging) {
|
||||
if (this.overlayContainerStopEvent_.contains(target) || !(document.body.contains(target) || this.viewport_.getRootNode && this.viewport_.getRootNode().contains(target))) {
|
||||
if (
|
||||
this.overlayContainerStopEvent_.contains(target) ||
|
||||
!(
|
||||
document.body.contains(target) ||
|
||||
(this.viewport_.getRootNode &&
|
||||
this.viewport_.getRootNode().contains(target))
|
||||
)
|
||||
) {
|
||||
// Abort if the event target is a child of the container that doesn't allow
|
||||
// event propagation or is no longer in the page. It's possible for the target to no longer
|
||||
// be in the page if it has been removed in an event listener, this might happen in a Control
|
||||
@@ -943,7 +1052,6 @@ class PluggableMap extends BaseObject {
|
||||
* @protected
|
||||
*/
|
||||
handlePostRender() {
|
||||
|
||||
const frameState = this.frameState_;
|
||||
|
||||
// Manage the tile queue
|
||||
@@ -962,7 +1070,8 @@ class PluggableMap extends BaseObject {
|
||||
if (frameState) {
|
||||
const hints = frameState.viewHints;
|
||||
if (hints[ViewHint.ANIMATING] || hints[ViewHint.INTERACTING]) {
|
||||
const lowOnFrameBudget = !IMAGE_DECODE && Date.now() - frameState.time > 8;
|
||||
const lowOnFrameBudget =
|
||||
!IMAGE_DECODE && Date.now() - frameState.time > 8;
|
||||
maxTotalLoading = lowOnFrameBudget ? 0 : 8;
|
||||
maxNewLoads = lowOnFrameBudget ? 0 : 2;
|
||||
}
|
||||
@@ -973,9 +1082,17 @@ class PluggableMap extends BaseObject {
|
||||
}
|
||||
}
|
||||
|
||||
if (frameState && this.hasListener(RenderEventType.RENDERCOMPLETE) && !frameState.animate &&
|
||||
!this.tileQueue_.getTilesLoading() && !this.getLoading()) {
|
||||
this.renderer_.dispatchRenderEvent(RenderEventType.RENDERCOMPLETE, frameState);
|
||||
if (
|
||||
frameState &&
|
||||
this.hasListener(RenderEventType.RENDERCOMPLETE) &&
|
||||
!frameState.animate &&
|
||||
!this.tileQueue_.getTilesLoading() &&
|
||||
!this.getLoading()
|
||||
) {
|
||||
this.renderer_.dispatchRenderEvent(
|
||||
RenderEventType.RENDERCOMPLETE,
|
||||
frameState
|
||||
);
|
||||
}
|
||||
|
||||
const postRenderFunctions = this.postRenderFunctions_;
|
||||
@@ -1039,11 +1156,22 @@ class PluggableMap extends BaseObject {
|
||||
this.renderer_ = this.createRenderer();
|
||||
}
|
||||
|
||||
const keyboardEventTarget = !this.keyboardEventTarget_ ?
|
||||
targetElement : this.keyboardEventTarget_;
|
||||
const keyboardEventTarget = !this.keyboardEventTarget_
|
||||
? targetElement
|
||||
: this.keyboardEventTarget_;
|
||||
this.keyHandlerKeys_ = [
|
||||
listen(keyboardEventTarget, EventType.KEYDOWN, this.handleBrowserEvent, this),
|
||||
listen(keyboardEventTarget, EventType.KEYPRESS, this.handleBrowserEvent, this)
|
||||
listen(
|
||||
keyboardEventTarget,
|
||||
EventType.KEYDOWN,
|
||||
this.handleBrowserEvent,
|
||||
this
|
||||
),
|
||||
listen(
|
||||
keyboardEventTarget,
|
||||
EventType.KEYPRESS,
|
||||
this.handleBrowserEvent,
|
||||
this
|
||||
),
|
||||
];
|
||||
|
||||
if (!this.handleResize_) {
|
||||
@@ -1088,11 +1216,17 @@ class PluggableMap extends BaseObject {
|
||||
this.updateViewportSize_();
|
||||
|
||||
this.viewPropertyListenerKey_ = listen(
|
||||
view, ObjectEventType.PROPERTYCHANGE,
|
||||
this.handleViewPropertyChanged_, this);
|
||||
view,
|
||||
ObjectEventType.PROPERTYCHANGE,
|
||||
this.handleViewPropertyChanged_,
|
||||
this
|
||||
);
|
||||
this.viewChangeListenerKey_ = listen(
|
||||
view, EventType.CHANGE,
|
||||
this.handleViewPropertyChanged_, this);
|
||||
view,
|
||||
EventType.CHANGE,
|
||||
this.handleViewPropertyChanged_,
|
||||
this
|
||||
);
|
||||
|
||||
view.resolveConstraints(0);
|
||||
}
|
||||
@@ -1110,12 +1244,8 @@ class PluggableMap extends BaseObject {
|
||||
const layerGroup = this.getLayerGroup();
|
||||
if (layerGroup) {
|
||||
this.layerGroupPropertyListenerKeys_ = [
|
||||
listen(
|
||||
layerGroup, ObjectEventType.PROPERTYCHANGE,
|
||||
this.render, this),
|
||||
listen(
|
||||
layerGroup, EventType.CHANGE,
|
||||
this.render, this)
|
||||
listen(layerGroup, ObjectEventType.PROPERTYCHANGE, this.render, this),
|
||||
listen(layerGroup, EventType.CHANGE, this.render, this),
|
||||
];
|
||||
}
|
||||
this.render();
|
||||
@@ -1218,13 +1348,22 @@ class PluggableMap extends BaseObject {
|
||||
/** @type {?FrameState} */
|
||||
let frameState = null;
|
||||
if (size !== undefined && hasArea(size) && view && view.isDef()) {
|
||||
const viewHints = view.getHints(this.frameState_ ? this.frameState_.viewHints : undefined);
|
||||
const viewHints = view.getHints(
|
||||
this.frameState_ ? this.frameState_.viewHints : undefined
|
||||
);
|
||||
const viewState = view.getState();
|
||||
frameState = {
|
||||
animate: false,
|
||||
coordinateToPixelTransform: this.coordinateToPixelTransform_,
|
||||
declutterItems: previousFrameState ? previousFrameState.declutterItems : [],
|
||||
extent: getForViewAndSize(viewState.center, viewState.resolution, viewState.rotation, size),
|
||||
declutterItems: previousFrameState
|
||||
? previousFrameState.declutterItems
|
||||
: [],
|
||||
extent: getForViewAndSize(
|
||||
viewState.center,
|
||||
viewState.resolution,
|
||||
viewState.rotation,
|
||||
size
|
||||
),
|
||||
index: this.frameIndex_++,
|
||||
layerIndex: 0,
|
||||
layerStatesArray: this.getLayerGroup().getLayerStatesArray(),
|
||||
@@ -1237,7 +1376,7 @@ class PluggableMap extends BaseObject {
|
||||
usedTiles: {},
|
||||
viewState: viewState,
|
||||
viewHints: viewHints,
|
||||
wantedTiles: {}
|
||||
wantedTiles: {},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1248,34 +1387,44 @@ class PluggableMap extends BaseObject {
|
||||
if (frameState.animate) {
|
||||
this.render();
|
||||
}
|
||||
Array.prototype.push.apply(this.postRenderFunctions_, frameState.postRenderFunctions);
|
||||
Array.prototype.push.apply(
|
||||
this.postRenderFunctions_,
|
||||
frameState.postRenderFunctions
|
||||
);
|
||||
|
||||
if (previousFrameState) {
|
||||
const moveStart = !this.previousExtent_ ||
|
||||
(!isEmpty(this.previousExtent_) &&
|
||||
!equals(frameState.extent, this.previousExtent_));
|
||||
const moveStart =
|
||||
!this.previousExtent_ ||
|
||||
(!isEmpty(this.previousExtent_) &&
|
||||
!equals(frameState.extent, this.previousExtent_));
|
||||
if (moveStart) {
|
||||
this.dispatchEvent(
|
||||
new MapEvent(MapEventType.MOVESTART, this, previousFrameState));
|
||||
new MapEvent(MapEventType.MOVESTART, this, previousFrameState)
|
||||
);
|
||||
this.previousExtent_ = createOrUpdateEmpty(this.previousExtent_);
|
||||
}
|
||||
}
|
||||
|
||||
const idle = this.previousExtent_ &&
|
||||
!frameState.viewHints[ViewHint.ANIMATING] &&
|
||||
!frameState.viewHints[ViewHint.INTERACTING] &&
|
||||
!equals(frameState.extent, this.previousExtent_);
|
||||
const idle =
|
||||
this.previousExtent_ &&
|
||||
!frameState.viewHints[ViewHint.ANIMATING] &&
|
||||
!frameState.viewHints[ViewHint.INTERACTING] &&
|
||||
!equals(frameState.extent, this.previousExtent_);
|
||||
|
||||
if (idle) {
|
||||
this.dispatchEvent(new MapEvent(MapEventType.MOVEEND, this, frameState));
|
||||
this.dispatchEvent(
|
||||
new MapEvent(MapEventType.MOVEEND, this, frameState)
|
||||
);
|
||||
clone(frameState.extent, this.previousExtent_);
|
||||
}
|
||||
}
|
||||
|
||||
this.dispatchEvent(new MapEvent(MapEventType.POSTRENDER, this, frameState));
|
||||
|
||||
this.postRenderTimeoutHandle_ = setTimeout(this.handlePostRender.bind(this), 0);
|
||||
|
||||
this.postRenderTimeoutHandle_ = setTimeout(
|
||||
this.handlePostRender.bind(this),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1333,15 +1482,15 @@ class PluggableMap extends BaseObject {
|
||||
const computedStyle = getComputedStyle(targetElement);
|
||||
this.setSize([
|
||||
targetElement.offsetWidth -
|
||||
parseFloat(computedStyle['borderLeftWidth']) -
|
||||
parseFloat(computedStyle['paddingLeft']) -
|
||||
parseFloat(computedStyle['paddingRight']) -
|
||||
parseFloat(computedStyle['borderRightWidth']),
|
||||
parseFloat(computedStyle['borderLeftWidth']) -
|
||||
parseFloat(computedStyle['paddingLeft']) -
|
||||
parseFloat(computedStyle['paddingRight']) -
|
||||
parseFloat(computedStyle['borderRightWidth']),
|
||||
targetElement.offsetHeight -
|
||||
parseFloat(computedStyle['borderTopWidth']) -
|
||||
parseFloat(computedStyle['paddingTop']) -
|
||||
parseFloat(computedStyle['paddingBottom']) -
|
||||
parseFloat(computedStyle['borderBottomWidth'])
|
||||
parseFloat(computedStyle['borderTopWidth']) -
|
||||
parseFloat(computedStyle['paddingTop']) -
|
||||
parseFloat(computedStyle['paddingBottom']) -
|
||||
parseFloat(computedStyle['borderBottomWidth']),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -1360,7 +1509,7 @@ class PluggableMap extends BaseObject {
|
||||
if (computedStyle.width && computedStyle.height) {
|
||||
size = [
|
||||
parseInt(computedStyle.width, 10),
|
||||
parseInt(computedStyle.height, 10)
|
||||
parseInt(computedStyle.height, 10),
|
||||
];
|
||||
}
|
||||
view.setViewportSize(size);
|
||||
@@ -1368,21 +1517,20 @@ class PluggableMap extends BaseObject {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {MapOptions} options Map options.
|
||||
* @return {MapOptionsInternal} Internal map options.
|
||||
*/
|
||||
function createOptionsInternal(options) {
|
||||
|
||||
/**
|
||||
* @type {HTMLElement|Document}
|
||||
*/
|
||||
let keyboardEventTarget = null;
|
||||
if (options.keyboardEventTarget !== undefined) {
|
||||
keyboardEventTarget = typeof options.keyboardEventTarget === 'string' ?
|
||||
document.getElementById(options.keyboardEventTarget) :
|
||||
options.keyboardEventTarget;
|
||||
keyboardEventTarget =
|
||||
typeof options.keyboardEventTarget === 'string'
|
||||
? document.getElementById(options.keyboardEventTarget)
|
||||
: options.keyboardEventTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1390,22 +1538,27 @@ function createOptionsInternal(options) {
|
||||
*/
|
||||
const values = {};
|
||||
|
||||
const layerGroup = options.layers && typeof /** @type {?} */ (options.layers).getLayers === 'function' ?
|
||||
/** @type {LayerGroup} */ (options.layers) : new LayerGroup({layers: /** @type {Collection} */ (options.layers)});
|
||||
const layerGroup =
|
||||
options.layers &&
|
||||
typeof (/** @type {?} */ (options.layers).getLayers) === 'function'
|
||||
? /** @type {LayerGroup} */ (options.layers)
|
||||
: new LayerGroup({layers: /** @type {Collection} */ (options.layers)});
|
||||
values[MapProperty.LAYERGROUP] = layerGroup;
|
||||
|
||||
values[MapProperty.TARGET] = options.target;
|
||||
|
||||
values[MapProperty.VIEW] = options.view !== undefined ?
|
||||
options.view : new View();
|
||||
values[MapProperty.VIEW] =
|
||||
options.view !== undefined ? options.view : new View();
|
||||
|
||||
let controls;
|
||||
if (options.controls !== undefined) {
|
||||
if (Array.isArray(options.controls)) {
|
||||
controls = new Collection(options.controls.slice());
|
||||
} else {
|
||||
assert(typeof /** @type {?} */ (options.controls).getArray === 'function',
|
||||
47); // Expected `controls` to be an array or an `import("./Collection.js").Collection`
|
||||
assert(
|
||||
typeof (/** @type {?} */ (options.controls).getArray) === 'function',
|
||||
47
|
||||
); // Expected `controls` to be an array or an `import("./Collection.js").Collection`
|
||||
controls = /** @type {Collection} */ (options.controls);
|
||||
}
|
||||
}
|
||||
@@ -1415,8 +1568,11 @@ function createOptionsInternal(options) {
|
||||
if (Array.isArray(options.interactions)) {
|
||||
interactions = new Collection(options.interactions.slice());
|
||||
} else {
|
||||
assert(typeof /** @type {?} */ (options.interactions).getArray === 'function',
|
||||
48); // Expected `interactions` to be an array or an `import("./Collection.js").Collection`
|
||||
assert(
|
||||
typeof (/** @type {?} */ (options.interactions).getArray) ===
|
||||
'function',
|
||||
48
|
||||
); // Expected `interactions` to be an array or an `import("./Collection.js").Collection`
|
||||
interactions = /** @type {Collection} */ (options.interactions);
|
||||
}
|
||||
}
|
||||
@@ -1426,8 +1582,10 @@ function createOptionsInternal(options) {
|
||||
if (Array.isArray(options.overlays)) {
|
||||
overlays = new Collection(options.overlays.slice());
|
||||
} else {
|
||||
assert(typeof /** @type {?} */ (options.overlays).getArray === 'function',
|
||||
49); // Expected `overlays` to be an array or an `import("./Collection.js").Collection`
|
||||
assert(
|
||||
typeof (/** @type {?} */ (options.overlays).getArray) === 'function',
|
||||
49
|
||||
); // Expected `overlays` to be an array or an `import("./Collection.js").Collection`
|
||||
overlays = options.overlays;
|
||||
}
|
||||
} else {
|
||||
@@ -1439,8 +1597,7 @@ function createOptionsInternal(options) {
|
||||
interactions: interactions,
|
||||
keyboardEventTarget: keyboardEventTarget,
|
||||
overlays: overlays,
|
||||
values: values
|
||||
values: values,
|
||||
};
|
||||
|
||||
}
|
||||
export default PluggableMap;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
/**
|
||||
* @module ol/Tile
|
||||
*/
|
||||
import TileState from './TileState.js';
|
||||
import {easeIn} from './easing.js';
|
||||
import EventTarget from './events/Target.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import TileState from './TileState.js';
|
||||
import {abstract} from './util.js';
|
||||
|
||||
import {easeIn} from './easing.js';
|
||||
|
||||
/**
|
||||
* A function that takes an {@link module:ol/Tile} for the tile and a
|
||||
@@ -60,7 +59,6 @@ import {abstract} from './util.js';
|
||||
* @api
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {number} [transition=250] A duration for tile opacity
|
||||
@@ -68,7 +66,6 @@ import {abstract} from './util.js';
|
||||
* @api
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Base class for tiles.
|
||||
@@ -76,7 +73,6 @@ import {abstract} from './util.js';
|
||||
* @abstract
|
||||
*/
|
||||
class Tile extends EventTarget {
|
||||
|
||||
/**
|
||||
* @param {import("./tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
||||
* @param {TileState} state State.
|
||||
@@ -126,7 +122,8 @@ class Tile extends EventTarget {
|
||||
* The duration for the opacity transition.
|
||||
* @type {number}
|
||||
*/
|
||||
this.transition_ = options.transition === undefined ? 250 : options.transition;
|
||||
this.transition_ =
|
||||
options.transition === undefined ? 250 : options.transition;
|
||||
|
||||
/**
|
||||
* Lookup of start times for rendering transitions. If the start time is
|
||||
@@ -134,7 +131,6 @@ class Tile extends EventTarget {
|
||||
* @type {Object<string, number>}
|
||||
*/
|
||||
this.transitionStarts_ = {};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,8 +143,7 @@ class Tile extends EventTarget {
|
||||
/**
|
||||
* Called by the tile cache when the tile is removed from the cache due to expiry
|
||||
*/
|
||||
release() {
|
||||
}
|
||||
release() {}
|
||||
|
||||
/**
|
||||
* @return {string} Key.
|
||||
@@ -284,7 +279,7 @@ class Tile extends EventTarget {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const delta = time - start + (1000 / 60); // avoid rendering at 0
|
||||
const delta = time - start + 1000 / 60; // avoid rendering at 0
|
||||
if (delta >= this.transition_) {
|
||||
return 1;
|
||||
}
|
||||
@@ -316,5 +311,4 @@ class Tile extends EventTarget {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Tile;
|
||||
|
||||
@@ -5,7 +5,6 @@ import LRUCache from './structs/LRUCache.js';
|
||||
import {fromKey, getKey} from './tilecoord.js';
|
||||
|
||||
class TileCache extends LRUCache {
|
||||
|
||||
/**
|
||||
* @param {!Object<string, boolean>} usedTiles Used tiles.
|
||||
*/
|
||||
@@ -30,14 +29,15 @@ class TileCache extends LRUCache {
|
||||
const key = this.peekFirstKey();
|
||||
const tileCoord = fromKey(key);
|
||||
const z = tileCoord[0];
|
||||
this.forEach(function(tile) {
|
||||
if (tile.tileCoord[0] !== z) {
|
||||
this.remove(getKey(tile.tileCoord));
|
||||
tile.release();
|
||||
}
|
||||
}.bind(this));
|
||||
this.forEach(
|
||||
function (tile) {
|
||||
if (tile.tileCoord[0] !== z) {
|
||||
this.remove(getKey(tile.tileCoord));
|
||||
tile.release();
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default TileCache;
|
||||
|
||||
@@ -1,39 +1,36 @@
|
||||
/**
|
||||
* @module ol/TileQueue
|
||||
*/
|
||||
import TileState from './TileState.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import PriorityQueue, {DROP} from './structs/PriorityQueue.js';
|
||||
|
||||
import TileState from './TileState.js';
|
||||
|
||||
/**
|
||||
* @typedef {function(import("./Tile.js").default, string, import("./coordinate.js").Coordinate, number): number} PriorityFunction
|
||||
*/
|
||||
|
||||
|
||||
class TileQueue extends PriorityQueue {
|
||||
|
||||
/**
|
||||
* @param {PriorityFunction} tilePriorityFunction Tile priority function.
|
||||
* @param {function(): ?} tileChangeCallback Function called on each tile change event.
|
||||
*/
|
||||
constructor(tilePriorityFunction, tileChangeCallback) {
|
||||
|
||||
super(
|
||||
/**
|
||||
* @param {Array} element Element.
|
||||
* @return {number} Priority.
|
||||
*/
|
||||
function(element) {
|
||||
function (element) {
|
||||
return tilePriorityFunction.apply(null, element);
|
||||
},
|
||||
/**
|
||||
* @param {Array} element Element.
|
||||
* @return {string} Key.
|
||||
*/
|
||||
function(element) {
|
||||
return (/** @type {import("./Tile.js").default} */ (element[0]).getKey());
|
||||
});
|
||||
function (element) {
|
||||
return /** @type {import("./Tile.js").default} */ (element[0]).getKey();
|
||||
}
|
||||
);
|
||||
|
||||
/** @private */
|
||||
this.boundHandleTileChange_ = this.handleTileChange.bind(this);
|
||||
@@ -55,7 +52,6 @@ class TileQueue extends PriorityQueue {
|
||||
* @type {!Object<string,boolean>}
|
||||
*/
|
||||
this.tilesLoadingKeys_ = {};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +81,11 @@ class TileQueue extends PriorityQueue {
|
||||
handleTileChange(event) {
|
||||
const tile = /** @type {import("./Tile.js").default} */ (event.target);
|
||||
const state = tile.getState();
|
||||
if (tile.hifi && state === TileState.LOADED || state === TileState.ERROR || state === TileState.EMPTY) {
|
||||
if (
|
||||
(tile.hifi && state === TileState.LOADED) ||
|
||||
state === TileState.ERROR ||
|
||||
state === TileState.EMPTY
|
||||
) {
|
||||
tile.removeEventListener(EventType.CHANGE, this.boundHandleTileChange_);
|
||||
const tileKey = tile.getKey();
|
||||
if (tileKey in this.tilesLoadingKeys_) {
|
||||
@@ -103,8 +103,11 @@ class TileQueue extends PriorityQueue {
|
||||
loadMoreTiles(maxTotalLoading, maxNewLoads) {
|
||||
let newLoads = 0;
|
||||
let state, tile, tileKey;
|
||||
while (this.tilesLoading_ < maxTotalLoading && newLoads < maxNewLoads &&
|
||||
this.getCount() > 0) {
|
||||
while (
|
||||
this.tilesLoading_ < maxTotalLoading &&
|
||||
newLoads < maxNewLoads &&
|
||||
this.getCount() > 0
|
||||
) {
|
||||
tile = /** @type {import("./Tile.js").default} */ (this.dequeue()[0]);
|
||||
tileKey = tile.getKey();
|
||||
state = tile.getState();
|
||||
@@ -118,10 +121,8 @@ class TileQueue extends PriorityQueue {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default TileQueue;
|
||||
|
||||
|
||||
/**
|
||||
* @param {import('./PluggableMap.js').FrameState} frameState Frame state.
|
||||
* @param {import("./Tile.js").default} tile Tile.
|
||||
@@ -130,7 +131,13 @@ export default TileQueue;
|
||||
* @param {number} tileResolution Tile resolution.
|
||||
* @return {number} Tile priority.
|
||||
*/
|
||||
export function getTilePriority(frameState, tile, tileSourceKey, tileCenter, tileResolution) {
|
||||
export function getTilePriority(
|
||||
frameState,
|
||||
tile,
|
||||
tileSourceKey,
|
||||
tileCenter,
|
||||
tileResolution
|
||||
) {
|
||||
// Filter out tiles at higher zoom levels than the current zoom level, or that
|
||||
// are outside the visible extent.
|
||||
if (!frameState || !(tileSourceKey in frameState.wantedTiles)) {
|
||||
@@ -148,6 +155,8 @@ export function getTilePriority(frameState, tile, tileSourceKey, tileCenter, til
|
||||
const center = frameState.viewState.center;
|
||||
const deltaX = tileCenter[0] - center[0];
|
||||
const deltaY = tileCenter[1] - center[1];
|
||||
return 65536 * Math.log(tileResolution) +
|
||||
Math.sqrt(deltaX * deltaX + deltaY * deltaY) / tileResolution;
|
||||
return (
|
||||
65536 * Math.log(tileResolution) +
|
||||
Math.sqrt(deltaX * deltaX + deltaY * deltaY) / tileResolution
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* by its min/max tile coordinates and is inclusive of coordinates.
|
||||
*/
|
||||
class TileRange {
|
||||
|
||||
/**
|
||||
* @param {number} minX Minimum X.
|
||||
* @param {number} maxX Maximum X.
|
||||
@@ -15,7 +14,6 @@ class TileRange {
|
||||
* @param {number} maxY Maximum Y.
|
||||
*/
|
||||
constructor(minX, maxX, minY, maxY) {
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
@@ -35,7 +33,6 @@ class TileRange {
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxY = maxY;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,8 +48,12 @@ class TileRange {
|
||||
* @return {boolean} Contains.
|
||||
*/
|
||||
containsTileRange(tileRange) {
|
||||
return this.minX <= tileRange.minX && tileRange.maxX <= this.maxX &&
|
||||
this.minY <= tileRange.minY && tileRange.maxY <= this.maxY;
|
||||
return (
|
||||
this.minX <= tileRange.minX &&
|
||||
tileRange.maxX <= this.maxX &&
|
||||
this.minY <= tileRange.minY &&
|
||||
tileRange.maxY <= this.maxY
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,8 +70,12 @@ class TileRange {
|
||||
* @return {boolean} Equals.
|
||||
*/
|
||||
equals(tileRange) {
|
||||
return this.minX == tileRange.minX && this.minY == tileRange.minY &&
|
||||
this.maxX == tileRange.maxX && this.maxY == tileRange.maxY;
|
||||
return (
|
||||
this.minX == tileRange.minX &&
|
||||
this.minY == tileRange.minY &&
|
||||
this.maxX == tileRange.maxX &&
|
||||
this.maxY == tileRange.maxY
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,14 +122,15 @@ class TileRange {
|
||||
* @return {boolean} Intersects.
|
||||
*/
|
||||
intersects(tileRange) {
|
||||
return this.minX <= tileRange.maxX &&
|
||||
this.maxX >= tileRange.minX &&
|
||||
this.minY <= tileRange.maxY &&
|
||||
this.maxY >= tileRange.minY;
|
||||
return (
|
||||
this.minX <= tileRange.maxX &&
|
||||
this.maxX >= tileRange.minX &&
|
||||
this.minY <= tileRange.maxY &&
|
||||
this.maxY >= tileRange.minY
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} minX Minimum X.
|
||||
* @param {number} maxX Maximum X.
|
||||
@@ -145,5 +151,4 @@ export function createOrUpdate(minX, maxX, minY, maxY, tileRange) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default TileRange;
|
||||
|
||||
@@ -14,5 +14,5 @@ export default {
|
||||
* @type {number}
|
||||
*/
|
||||
ERROR: 3,
|
||||
EMPTY: 4
|
||||
EMPTY: 4,
|
||||
};
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* @module ol/VectorRenderTile
|
||||
*/
|
||||
import {getUid} from './util.js';
|
||||
import Tile from './Tile.js';
|
||||
import {createCanvasContext2D} from './dom.js';
|
||||
|
||||
import {getUid} from './util.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} ReplayState
|
||||
@@ -24,7 +23,6 @@ import {createCanvasContext2D} from './dom.js';
|
||||
const canvasPool = [];
|
||||
|
||||
class VectorRenderTile extends Tile {
|
||||
|
||||
/**
|
||||
* @param {import("./tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
||||
* @param {import("./TileState.js").default} state State.
|
||||
@@ -33,7 +31,6 @@ class VectorRenderTile extends Tile {
|
||||
* to get source tiles for this tile.
|
||||
*/
|
||||
constructor(tileCoord, state, urlTileCoord, getSourceTiles) {
|
||||
|
||||
super(tileCoord, state, {transition: 0});
|
||||
|
||||
/**
|
||||
@@ -148,7 +145,7 @@ class VectorRenderTile extends Tile {
|
||||
renderedTileResolution: NaN,
|
||||
renderedTileRevision: -1,
|
||||
renderedZ: -1,
|
||||
renderedTileZ: -1
|
||||
renderedTileZ: -1,
|
||||
};
|
||||
}
|
||||
return this.replayState_[key];
|
||||
@@ -172,5 +169,4 @@ class VectorRenderTile extends Tile {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default VectorRenderTile;
|
||||
|
||||
@@ -5,7 +5,6 @@ import Tile from './Tile.js';
|
||||
import TileState from './TileState.js';
|
||||
|
||||
class VectorTile extends Tile {
|
||||
|
||||
/**
|
||||
* @param {import("./tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
||||
* @param {TileState} state State.
|
||||
@@ -15,7 +14,6 @@ class VectorTile extends Tile {
|
||||
* @param {import("./Tile.js").Options=} opt_options Tile options.
|
||||
*/
|
||||
constructor(tileCoord, state, src, format, tileLoadFunction, opt_options) {
|
||||
|
||||
super(tileCoord, state, opt_options);
|
||||
|
||||
/**
|
||||
@@ -65,7 +63,6 @@ class VectorTile extends Tile {
|
||||
* @type {string}
|
||||
*/
|
||||
this.url_ = src;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
474
src/ol/View.js
474
src/ol/View.js
@@ -1,29 +1,54 @@
|
||||
/**
|
||||
* @module ol/View
|
||||
*/
|
||||
import {DEFAULT_TILE_SIZE} from './tilegrid/common.js';
|
||||
import {VOID} from './functions.js';
|
||||
import {createExtent, none as centerNone} from './centerconstraint.js';
|
||||
import BaseObject from './Object.js';
|
||||
import {createSnapToResolutions, createSnapToPower} from './resolutionconstraint.js';
|
||||
import {createSnapToZero, createSnapToN, none as rotationNone, disable} from './rotationconstraint.js';
|
||||
import GeometryType from './geom/GeometryType.js';
|
||||
import Units from './proj/Units.js';
|
||||
import ViewHint from './ViewHint.js';
|
||||
import ViewProperty from './ViewProperty.js';
|
||||
import {linearFindNearest} from './array.js';
|
||||
import {DEFAULT_TILE_SIZE} from './tilegrid/common.js';
|
||||
import {
|
||||
METERS_PER_UNIT,
|
||||
createProjection,
|
||||
fromUserCoordinate,
|
||||
fromUserExtent,
|
||||
getUserProjection,
|
||||
toUserCoordinate,
|
||||
toUserExtent,
|
||||
} from './proj.js';
|
||||
import {VOID} from './functions.js';
|
||||
import {
|
||||
add as addCoordinate,
|
||||
equals as coordinatesEqual,
|
||||
rotate as rotateCoordinate,
|
||||
} from './coordinate.js';
|
||||
import {assert} from './asserts.js';
|
||||
import {add as addCoordinate, rotate as rotateCoordinate, equals as coordinatesEqual} from './coordinate.js';
|
||||
import {inAndOut} from './easing.js';
|
||||
import {getForViewAndSize, getCenter, getHeight, getWidth, isEmpty} from './extent.js';
|
||||
import GeometryType from './geom/GeometryType.js';
|
||||
import {fromExtent as polygonFromExtent} from './geom/Polygon.js';
|
||||
import {clamp, modulo} from './math.js';
|
||||
import {assign} from './obj.js';
|
||||
import {createProjection, METERS_PER_UNIT, toUserCoordinate, toUserExtent, fromUserCoordinate, fromUserExtent, getUserProjection} from './proj.js';
|
||||
import Units from './proj/Units.js';
|
||||
import {equals} from './coordinate.js';
|
||||
import {easeOut} from './easing.js';
|
||||
import {none as centerNone, createExtent} from './centerconstraint.js';
|
||||
import {clamp, modulo} from './math.js';
|
||||
import {createMinMaxResolution} from './resolutionconstraint.js';
|
||||
|
||||
import {
|
||||
createSnapToN,
|
||||
createSnapToZero,
|
||||
disable,
|
||||
none as rotationNone,
|
||||
} from './rotationconstraint.js';
|
||||
import {
|
||||
createSnapToPower,
|
||||
createSnapToResolutions,
|
||||
} from './resolutionconstraint.js';
|
||||
import {easeOut} from './easing.js';
|
||||
import {equals} from './coordinate.js';
|
||||
import {
|
||||
getCenter,
|
||||
getForViewAndSize,
|
||||
getHeight,
|
||||
getWidth,
|
||||
isEmpty,
|
||||
} from './extent.js';
|
||||
import {inAndOut} from './easing.js';
|
||||
import {linearFindNearest} from './array.js';
|
||||
import {fromExtent as polygonFromExtent} from './geom/Polygon.js';
|
||||
|
||||
/**
|
||||
* An animation configuration
|
||||
@@ -43,7 +68,6 @@ import {createMinMaxResolution} from './resolutionconstraint.js';
|
||||
* @property {function(boolean)} callback
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Constraints
|
||||
* @property {import("./centerconstraint.js").Type} center
|
||||
@@ -51,7 +75,6 @@ import {createMinMaxResolution} from './resolutionconstraint.js';
|
||||
* @property {import("./rotationconstraint.js").Type} rotation
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} FitOptions
|
||||
* @property {import("./size.js").Size} [size] The size in pixels of the box to fit
|
||||
@@ -77,7 +100,6 @@ import {createMinMaxResolution} from './resolutionconstraint.js';
|
||||
* series completed on its own or `false` if it was cancelled.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} ViewOptions
|
||||
* @property {import("./coordinate.js").Coordinate} [center] The initial center for
|
||||
@@ -155,7 +177,6 @@ import {createMinMaxResolution} from './resolutionconstraint.js';
|
||||
* corresponding resolution.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} AnimationOptions
|
||||
* @property {import("./coordinate.js").Coordinate} [center] The center of the view at the end of
|
||||
@@ -176,7 +197,6 @@ import {createMinMaxResolution} from './resolutionconstraint.js';
|
||||
* between 0 and 1 representing the progress toward the destination state.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} State
|
||||
* @property {import("./coordinate.js").Coordinate} center
|
||||
@@ -186,14 +206,12 @@ import {createMinMaxResolution} from './resolutionconstraint.js';
|
||||
* @property {number} zoom
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Default min zoom level for the map view.
|
||||
* @type {number}
|
||||
*/
|
||||
const DEFAULT_MIN_ZOOM = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A View object represents a simple 2D view of the map.
|
||||
@@ -267,7 +285,6 @@ const DEFAULT_MIN_ZOOM = 0;
|
||||
* @api
|
||||
*/
|
||||
class View extends BaseObject {
|
||||
|
||||
/**
|
||||
* @param {ViewOptions=} opt_options View options.
|
||||
*/
|
||||
@@ -346,7 +363,6 @@ class View extends BaseObject {
|
||||
* @param {ViewOptions} options View options.
|
||||
*/
|
||||
applyOptions_(options) {
|
||||
|
||||
/**
|
||||
* @type {Object<string, *>}
|
||||
*/
|
||||
@@ -395,11 +411,13 @@ class View extends BaseObject {
|
||||
this.constraints_ = {
|
||||
center: centerConstraint,
|
||||
resolution: resolutionConstraint,
|
||||
rotation: rotationConstraint
|
||||
rotation: rotationConstraint,
|
||||
};
|
||||
|
||||
this.setRotation(options.rotation !== undefined ? options.rotation : 0);
|
||||
this.setCenterInternal(options.center !== undefined ? options.center : null);
|
||||
this.setCenterInternal(
|
||||
options.center !== undefined ? options.center : null
|
||||
);
|
||||
if (options.resolution !== undefined) {
|
||||
this.setResolution(options.resolution);
|
||||
} else if (options.zoom !== undefined) {
|
||||
@@ -408,13 +426,11 @@ class View extends BaseObject {
|
||||
|
||||
this.setProperties(properties);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ViewOptions}
|
||||
*/
|
||||
this.options_ = options;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -486,11 +502,17 @@ class View extends BaseObject {
|
||||
let options = arguments[i];
|
||||
if (options.center) {
|
||||
options = assign({}, options);
|
||||
options.center = fromUserCoordinate(options.center, this.getProjection());
|
||||
options.center = fromUserCoordinate(
|
||||
options.center,
|
||||
this.getProjection()
|
||||
);
|
||||
}
|
||||
if (options.anchor) {
|
||||
options = assign({}, options);
|
||||
options.anchor = fromUserCoordinate(options.anchor, this.getProjection());
|
||||
options.anchor = fromUserCoordinate(
|
||||
options.anchor,
|
||||
this.getProjection()
|
||||
);
|
||||
}
|
||||
args[i] = options;
|
||||
}
|
||||
@@ -503,7 +525,10 @@ class View extends BaseObject {
|
||||
animateInternal(var_args) {
|
||||
let animationCount = arguments.length;
|
||||
let callback;
|
||||
if (animationCount > 1 && typeof arguments[animationCount - 1] === 'function') {
|
||||
if (
|
||||
animationCount > 1 &&
|
||||
typeof arguments[animationCount - 1] === 'function'
|
||||
) {
|
||||
callback = arguments[animationCount - 1];
|
||||
--animationCount;
|
||||
}
|
||||
@@ -538,7 +563,7 @@ class View extends BaseObject {
|
||||
anchor: options.anchor,
|
||||
duration: options.duration !== undefined ? options.duration : 1000,
|
||||
easing: options.easing || inAndOut,
|
||||
callback: callback
|
||||
callback: callback,
|
||||
};
|
||||
|
||||
if (options.center) {
|
||||
@@ -559,7 +584,8 @@ class View extends BaseObject {
|
||||
|
||||
if (options.rotation !== undefined) {
|
||||
animation.sourceRotation = rotation;
|
||||
const delta = modulo(options.rotation - rotation + Math.PI, 2 * Math.PI) - Math.PI;
|
||||
const delta =
|
||||
modulo(options.rotation - rotation + Math.PI, 2 * Math.PI) - Math.PI;
|
||||
animation.targetRotation = rotation + delta;
|
||||
rotation = animation.targetRotation;
|
||||
}
|
||||
@@ -644,7 +670,8 @@ class View extends BaseObject {
|
||||
continue;
|
||||
}
|
||||
const elapsed = now - animation.start;
|
||||
let fraction = animation.duration > 0 ? elapsed / animation.duration : 1;
|
||||
let fraction =
|
||||
animation.duration > 0 ? elapsed / animation.duration : 1;
|
||||
if (fraction >= 1) {
|
||||
animation.complete = true;
|
||||
fraction = 1;
|
||||
@@ -662,24 +689,48 @@ class View extends BaseObject {
|
||||
this.targetCenter_ = [x, y];
|
||||
}
|
||||
if (animation.sourceResolution && animation.targetResolution) {
|
||||
const resolution = progress === 1 ?
|
||||
animation.targetResolution :
|
||||
animation.sourceResolution + progress * (animation.targetResolution - animation.sourceResolution);
|
||||
const resolution =
|
||||
progress === 1
|
||||
? animation.targetResolution
|
||||
: animation.sourceResolution +
|
||||
progress *
|
||||
(animation.targetResolution - animation.sourceResolution);
|
||||
if (animation.anchor) {
|
||||
const size = this.getViewportSize_(this.getRotation());
|
||||
const constrainedResolution = this.constraints_.resolution(resolution, 0, size, true);
|
||||
this.targetCenter_ = this.calculateCenterZoom(constrainedResolution, animation.anchor);
|
||||
const constrainedResolution = this.constraints_.resolution(
|
||||
resolution,
|
||||
0,
|
||||
size,
|
||||
true
|
||||
);
|
||||
this.targetCenter_ = this.calculateCenterZoom(
|
||||
constrainedResolution,
|
||||
animation.anchor
|
||||
);
|
||||
}
|
||||
this.targetResolution_ = resolution;
|
||||
this.applyTargetState_(true);
|
||||
}
|
||||
if (animation.sourceRotation !== undefined && animation.targetRotation !== undefined) {
|
||||
const rotation = progress === 1 ?
|
||||
modulo(animation.targetRotation + Math.PI, 2 * Math.PI) - Math.PI :
|
||||
animation.sourceRotation + progress * (animation.targetRotation - animation.sourceRotation);
|
||||
if (
|
||||
animation.sourceRotation !== undefined &&
|
||||
animation.targetRotation !== undefined
|
||||
) {
|
||||
const rotation =
|
||||
progress === 1
|
||||
? modulo(animation.targetRotation + Math.PI, 2 * Math.PI) -
|
||||
Math.PI
|
||||
: animation.sourceRotation +
|
||||
progress *
|
||||
(animation.targetRotation - animation.sourceRotation);
|
||||
if (animation.anchor) {
|
||||
const constrainedRotation = this.constraints_.rotation(rotation, true);
|
||||
this.targetCenter_ = this.calculateCenterRotate(constrainedRotation, animation.anchor);
|
||||
const constrainedRotation = this.constraints_.rotation(
|
||||
rotation,
|
||||
true
|
||||
);
|
||||
this.targetCenter_ = this.calculateCenterRotate(
|
||||
constrainedRotation,
|
||||
animation.anchor
|
||||
);
|
||||
}
|
||||
this.targetRotation_ = rotation;
|
||||
}
|
||||
@@ -701,7 +752,9 @@ class View extends BaseObject {
|
||||
// prune completed series
|
||||
this.animations_ = this.animations_.filter(Boolean);
|
||||
if (more && this.updateAnimationKey_ === undefined) {
|
||||
this.updateAnimationKey_ = requestAnimationFrame(this.updateAnimations_.bind(this));
|
||||
this.updateAnimationKey_ = requestAnimationFrame(
|
||||
this.updateAnimations_.bind(this)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,8 +784,12 @@ class View extends BaseObject {
|
||||
const currentCenter = this.getCenterInternal();
|
||||
const currentResolution = this.getResolution();
|
||||
if (currentCenter !== undefined && currentResolution !== undefined) {
|
||||
const x = anchor[0] - resolution * (anchor[0] - currentCenter[0]) / currentResolution;
|
||||
const y = anchor[1] - resolution * (anchor[1] - currentCenter[1]) / currentResolution;
|
||||
const x =
|
||||
anchor[0] -
|
||||
(resolution * (anchor[0] - currentCenter[0])) / currentResolution;
|
||||
const y =
|
||||
anchor[1] -
|
||||
(resolution * (anchor[1] - currentCenter[1])) / currentResolution;
|
||||
center = [x, y];
|
||||
}
|
||||
return center;
|
||||
@@ -750,8 +807,10 @@ class View extends BaseObject {
|
||||
const w = size[0];
|
||||
const h = size[1];
|
||||
return [
|
||||
Math.abs(w * Math.cos(opt_rotation)) + Math.abs(h * Math.sin(opt_rotation)),
|
||||
Math.abs(w * Math.sin(opt_rotation)) + Math.abs(h * Math.cos(opt_rotation))
|
||||
Math.abs(w * Math.cos(opt_rotation)) +
|
||||
Math.abs(h * Math.sin(opt_rotation)),
|
||||
Math.abs(w * Math.sin(opt_rotation)) +
|
||||
Math.abs(h * Math.cos(opt_rotation)),
|
||||
];
|
||||
} else {
|
||||
return size;
|
||||
@@ -766,7 +825,9 @@ class View extends BaseObject {
|
||||
* @param {import("./size.js").Size=} opt_size Viewport size; if undefined, [100, 100] is assumed
|
||||
*/
|
||||
setViewportSize(opt_size) {
|
||||
this.viewportSize_ = Array.isArray(opt_size) ? opt_size.slice() : [100, 100];
|
||||
this.viewportSize_ = Array.isArray(opt_size)
|
||||
? opt_size.slice()
|
||||
: [100, 100];
|
||||
if (!this.getAnimating()) {
|
||||
this.resolveConstraints(0);
|
||||
}
|
||||
@@ -791,7 +852,9 @@ class View extends BaseObject {
|
||||
* @return {import("./coordinate.js").Coordinate|undefined} The center of the view.
|
||||
*/
|
||||
getCenterInternal() {
|
||||
return /** @type {import("./coordinate.js").Coordinate|undefined} */ (this.get(ViewProperty.CENTER));
|
||||
return /** @type {import("./coordinate.js").Coordinate|undefined} */ (this.get(
|
||||
ViewProperty.CENTER
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -878,7 +941,9 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getMaxZoom() {
|
||||
return /** @type {number} */ (this.getZoomForResolution(this.minResolution_));
|
||||
return /** @type {number} */ (this.getZoomForResolution(
|
||||
this.minResolution_
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -896,7 +961,9 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getMinZoom() {
|
||||
return /** @type {number} */ (this.getZoomForResolution(this.maxResolution_));
|
||||
return /** @type {number} */ (this.getZoomForResolution(
|
||||
this.maxResolution_
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -955,7 +1022,10 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
getResolutionForExtent(extent, opt_size) {
|
||||
return this.getResolutionForExtentInternal(fromUserExtent(extent, this.getProjection()), opt_size);
|
||||
return this.getResolutionForExtentInternal(
|
||||
fromUserExtent(extent, this.getProjection()),
|
||||
opt_size
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -988,10 +1058,11 @@ class View extends BaseObject {
|
||||
* @param {number} value Value.
|
||||
* @return {number} Resolution.
|
||||
*/
|
||||
function(value) {
|
||||
function (value) {
|
||||
const resolution = maxResolution / Math.pow(power, value * max);
|
||||
return resolution;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1020,10 +1091,11 @@ class View extends BaseObject {
|
||||
* @param {number} resolution Resolution.
|
||||
* @return {number} Value.
|
||||
*/
|
||||
function(resolution) {
|
||||
const value = (Math.log(maxResolution / resolution) / logPower) / max;
|
||||
function (resolution) {
|
||||
const value = Math.log(maxResolution / resolution) / logPower / max;
|
||||
return value;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1039,7 +1111,7 @@ class View extends BaseObject {
|
||||
projection: projection !== undefined ? projection : null,
|
||||
resolution: resolution,
|
||||
rotation: rotation,
|
||||
zoom: this.getZoom()
|
||||
zoom: this.getZoom(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1095,11 +1167,21 @@ class View extends BaseObject {
|
||||
if (this.resolutions_.length <= 1) {
|
||||
return 0;
|
||||
}
|
||||
const baseLevel = clamp(Math.floor(zoom), 0, this.resolutions_.length - 2);
|
||||
const zoomFactor = this.resolutions_[baseLevel] / this.resolutions_[baseLevel + 1];
|
||||
return this.resolutions_[baseLevel] / Math.pow(zoomFactor, clamp(zoom - baseLevel, 0, 1));
|
||||
const baseLevel = clamp(
|
||||
Math.floor(zoom),
|
||||
0,
|
||||
this.resolutions_.length - 2
|
||||
);
|
||||
const zoomFactor =
|
||||
this.resolutions_[baseLevel] / this.resolutions_[baseLevel + 1];
|
||||
return (
|
||||
this.resolutions_[baseLevel] /
|
||||
Math.pow(zoomFactor, clamp(zoom - baseLevel, 0, 1))
|
||||
);
|
||||
} else {
|
||||
return this.maxResolution_ / Math.pow(this.zoomFactor_, zoom - this.minZoom_);
|
||||
return (
|
||||
this.maxResolution_ / Math.pow(this.zoomFactor_, zoom - this.minZoom_)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1118,21 +1200,29 @@ class View extends BaseObject {
|
||||
|
||||
/** @type {import("./geom/SimpleGeometry.js").default} */
|
||||
let geometry;
|
||||
assert(Array.isArray(geometryOrExtent) || typeof /** @type {?} */ (geometryOrExtent).getSimplifiedGeometry === 'function',
|
||||
24); // Invalid extent or geometry provided as `geometry`
|
||||
assert(
|
||||
Array.isArray(geometryOrExtent) ||
|
||||
typeof (/** @type {?} */ (geometryOrExtent).getSimplifiedGeometry) ===
|
||||
'function',
|
||||
24
|
||||
); // Invalid extent or geometry provided as `geometry`
|
||||
if (Array.isArray(geometryOrExtent)) {
|
||||
assert(!isEmpty(geometryOrExtent),
|
||||
25); // Cannot fit empty extent provided as `geometry`
|
||||
assert(!isEmpty(geometryOrExtent), 25); // Cannot fit empty extent provided as `geometry`
|
||||
const extent = fromUserExtent(geometryOrExtent, this.getProjection());
|
||||
geometry = polygonFromExtent(extent);
|
||||
} else if (geometryOrExtent.getType() === GeometryType.CIRCLE) {
|
||||
const extent = fromUserExtent(geometryOrExtent.getExtent(), this.getProjection());
|
||||
const extent = fromUserExtent(
|
||||
geometryOrExtent.getExtent(),
|
||||
this.getProjection()
|
||||
);
|
||||
geometry = polygonFromExtent(extent);
|
||||
geometry.rotate(this.getRotation(), getCenter(extent));
|
||||
} else {
|
||||
const userProjection = getUserProjection();
|
||||
if (userProjection) {
|
||||
geometry = /** @type {import("./geom/SimpleGeometry.js").default} */ (geometryOrExtent.clone().transform(userProjection, this.getProjection()));
|
||||
geometry = /** @type {import("./geom/SimpleGeometry.js").default} */ (geometryOrExtent
|
||||
.clone()
|
||||
.transform(userProjection, this.getProjection()));
|
||||
} else {
|
||||
geometry = geometryOrExtent;
|
||||
}
|
||||
@@ -1151,7 +1241,8 @@ class View extends BaseObject {
|
||||
if (!size) {
|
||||
size = this.getViewportSize_();
|
||||
}
|
||||
const padding = options.padding !== undefined ? options.padding : [0, 0, 0, 0];
|
||||
const padding =
|
||||
options.padding !== undefined ? options.padding : [0, 0, 0, 0];
|
||||
const nearest = options.nearest !== undefined ? options.nearest : false;
|
||||
let minResolution;
|
||||
if (options.minResolution !== undefined) {
|
||||
@@ -1184,29 +1275,34 @@ class View extends BaseObject {
|
||||
// calculate resolution
|
||||
let resolution = this.getResolutionForExtentInternal(
|
||||
[minRotX, minRotY, maxRotX, maxRotY],
|
||||
[size[0] - padding[1] - padding[3], size[1] - padding[0] - padding[2]]);
|
||||
resolution = isNaN(resolution) ? minResolution :
|
||||
Math.max(resolution, minResolution);
|
||||
[size[0] - padding[1] - padding[3], size[1] - padding[0] - padding[2]]
|
||||
);
|
||||
resolution = isNaN(resolution)
|
||||
? minResolution
|
||||
: Math.max(resolution, minResolution);
|
||||
resolution = this.getConstrainedResolution(resolution, nearest ? 0 : 1);
|
||||
|
||||
// calculate center
|
||||
sinAngle = -sinAngle; // go back to original rotation
|
||||
let centerRotX = (minRotX + maxRotX) / 2;
|
||||
let centerRotY = (minRotY + maxRotY) / 2;
|
||||
centerRotX += (padding[1] - padding[3]) / 2 * resolution;
|
||||
centerRotY += (padding[0] - padding[2]) / 2 * resolution;
|
||||
centerRotX += ((padding[1] - padding[3]) / 2) * resolution;
|
||||
centerRotY += ((padding[0] - padding[2]) / 2) * resolution;
|
||||
const centerX = centerRotX * cosAngle - centerRotY * sinAngle;
|
||||
const centerY = centerRotY * cosAngle + centerRotX * sinAngle;
|
||||
const center = [centerX, centerY];
|
||||
const callback = options.callback ? options.callback : VOID;
|
||||
|
||||
if (options.duration !== undefined) {
|
||||
this.animateInternal({
|
||||
resolution: resolution,
|
||||
center: this.getConstrainedCenter(center, resolution),
|
||||
duration: options.duration,
|
||||
easing: options.easing
|
||||
}, callback);
|
||||
this.animateInternal(
|
||||
{
|
||||
resolution: resolution,
|
||||
center: this.getConstrainedCenter(center, resolution),
|
||||
duration: options.duration,
|
||||
easing: options.easing,
|
||||
},
|
||||
callback
|
||||
);
|
||||
} else {
|
||||
this.targetResolution_ = resolution;
|
||||
this.targetCenter_ = center;
|
||||
@@ -1223,7 +1319,11 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
centerOn(coordinate, size, position) {
|
||||
this.centerOnInternal(fromUserCoordinate(coordinate, this.getProjection()), size, position);
|
||||
this.centerOnInternal(
|
||||
fromUserCoordinate(coordinate, this.getProjection()),
|
||||
size,
|
||||
position
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1264,7 +1364,10 @@ class View extends BaseObject {
|
||||
*/
|
||||
adjustCenter(deltaCoordinates) {
|
||||
const center = toUserCoordinate(this.targetCenter_, this.getProjection());
|
||||
this.setCenter([center[0] + deltaCoordinates[0], center[1] + deltaCoordinates[1]]);
|
||||
this.setCenter([
|
||||
center[0] + deltaCoordinates[0],
|
||||
center[1] + deltaCoordinates[1],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1273,7 +1376,10 @@ class View extends BaseObject {
|
||||
*/
|
||||
adjustCenterInternal(deltaCoordinates) {
|
||||
const center = this.targetCenter_;
|
||||
this.setCenterInternal([center[0] + deltaCoordinates[0], center[1] + deltaCoordinates[1]]);
|
||||
this.setCenterInternal([
|
||||
center[0] + deltaCoordinates[0],
|
||||
center[1] + deltaCoordinates[1],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1284,7 +1390,8 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
adjustResolution(ratio, opt_anchor) {
|
||||
const anchor = opt_anchor && fromUserCoordinate(opt_anchor, this.getProjection());
|
||||
const anchor =
|
||||
opt_anchor && fromUserCoordinate(opt_anchor, this.getProjection());
|
||||
this.adjustResolutionInternal(ratio, anchor);
|
||||
}
|
||||
|
||||
@@ -1297,7 +1404,12 @@ class View extends BaseObject {
|
||||
adjustResolutionInternal(ratio, opt_anchor) {
|
||||
const isMoving = this.getAnimating() || this.getInteracting();
|
||||
const size = this.getViewportSize_(this.getRotation());
|
||||
const newResolution = this.constraints_.resolution(this.targetResolution_ * ratio, 0, size, isMoving);
|
||||
const newResolution = this.constraints_.resolution(
|
||||
this.targetResolution_ * ratio,
|
||||
0,
|
||||
size,
|
||||
isMoving
|
||||
);
|
||||
|
||||
if (opt_anchor) {
|
||||
this.targetCenter_ = this.calculateCenterZoom(newResolution, opt_anchor);
|
||||
@@ -1338,7 +1450,10 @@ class View extends BaseObject {
|
||||
*/
|
||||
adjustRotationInternal(delta, opt_anchor) {
|
||||
const isMoving = this.getAnimating() || this.getInteracting();
|
||||
const newRotation = this.constraints_.rotation(this.targetRotation_ + delta, isMoving);
|
||||
const newRotation = this.constraints_.rotation(
|
||||
this.targetRotation_ + delta,
|
||||
isMoving
|
||||
);
|
||||
if (opt_anchor) {
|
||||
this.targetCenter_ = this.calculateCenterRotate(newRotation, opt_anchor);
|
||||
}
|
||||
@@ -1416,13 +1531,27 @@ class View extends BaseObject {
|
||||
* @private
|
||||
*/
|
||||
applyTargetState_(opt_doNotCancelAnims, opt_forceMoving) {
|
||||
const isMoving = this.getAnimating() || this.getInteracting() || opt_forceMoving;
|
||||
const isMoving =
|
||||
this.getAnimating() || this.getInteracting() || opt_forceMoving;
|
||||
|
||||
// compute rotation
|
||||
const newRotation = this.constraints_.rotation(this.targetRotation_, isMoving);
|
||||
const newRotation = this.constraints_.rotation(
|
||||
this.targetRotation_,
|
||||
isMoving
|
||||
);
|
||||
const size = this.getViewportSize_(newRotation);
|
||||
const newResolution = this.constraints_.resolution(this.targetResolution_, 0, size, isMoving);
|
||||
const newCenter = this.constraints_.center(this.targetCenter_, newResolution, size, isMoving);
|
||||
const newResolution = this.constraints_.resolution(
|
||||
this.targetResolution_,
|
||||
0,
|
||||
size,
|
||||
isMoving
|
||||
);
|
||||
const newCenter = this.constraints_.center(
|
||||
this.targetCenter_,
|
||||
newResolution,
|
||||
size,
|
||||
isMoving
|
||||
);
|
||||
|
||||
if (this.get(ViewProperty.ROTATION) !== newRotation) {
|
||||
this.set(ViewProperty.ROTATION, newRotation);
|
||||
@@ -1430,7 +1559,10 @@ class View extends BaseObject {
|
||||
if (this.get(ViewProperty.RESOLUTION) !== newResolution) {
|
||||
this.set(ViewProperty.RESOLUTION, newResolution);
|
||||
}
|
||||
if (!this.get(ViewProperty.CENTER) || !equals(this.get(ViewProperty.CENTER), newCenter)) {
|
||||
if (
|
||||
!this.get(ViewProperty.CENTER) ||
|
||||
!equals(this.get(ViewProperty.CENTER), newCenter)
|
||||
) {
|
||||
this.set(ViewProperty.CENTER, newCenter);
|
||||
}
|
||||
|
||||
@@ -1455,8 +1587,16 @@ class View extends BaseObject {
|
||||
|
||||
const newRotation = this.constraints_.rotation(this.targetRotation_);
|
||||
const size = this.getViewportSize_(newRotation);
|
||||
const newResolution = this.constraints_.resolution(this.targetResolution_, direction, size);
|
||||
const newCenter = this.constraints_.center(this.targetCenter_, newResolution, size);
|
||||
const newResolution = this.constraints_.resolution(
|
||||
this.targetResolution_,
|
||||
direction,
|
||||
size
|
||||
);
|
||||
const newCenter = this.constraints_.center(
|
||||
this.targetCenter_,
|
||||
newResolution,
|
||||
size
|
||||
);
|
||||
|
||||
if (duration === 0 && !this.cancelAnchor_) {
|
||||
this.targetResolution_ = newResolution;
|
||||
@@ -1466,14 +1606,16 @@ class View extends BaseObject {
|
||||
return;
|
||||
}
|
||||
|
||||
const anchor = opt_anchor || (duration === 0 ? this.cancelAnchor_ : undefined);
|
||||
const anchor =
|
||||
opt_anchor || (duration === 0 ? this.cancelAnchor_ : undefined);
|
||||
this.cancelAnchor_ = undefined;
|
||||
|
||||
if (this.getResolution() !== newResolution ||
|
||||
if (
|
||||
this.getResolution() !== newResolution ||
|
||||
this.getRotation() !== newRotation ||
|
||||
!this.getCenterInternal() ||
|
||||
!equals(this.getCenterInternal(), newCenter)) {
|
||||
|
||||
!equals(this.getCenterInternal(), newCenter)
|
||||
) {
|
||||
if (this.getAnimating()) {
|
||||
this.cancelAnimations();
|
||||
}
|
||||
@@ -1484,7 +1626,7 @@ class View extends BaseObject {
|
||||
resolution: newResolution,
|
||||
duration: duration,
|
||||
easing: easeOut,
|
||||
anchor: anchor
|
||||
anchor: anchor,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1510,7 +1652,8 @@ class View extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
endInteraction(opt_duration, opt_resolutionDirection, opt_anchor) {
|
||||
const anchor = opt_anchor && fromUserCoordinate(opt_anchor, this.getProjection());
|
||||
const anchor =
|
||||
opt_anchor && fromUserCoordinate(opt_anchor, this.getProjection());
|
||||
this.endInteractionInternal(opt_duration, opt_resolutionDirection, anchor);
|
||||
}
|
||||
|
||||
@@ -1536,7 +1679,11 @@ class View extends BaseObject {
|
||||
*/
|
||||
getConstrainedCenter(targetCenter, opt_targetResolution) {
|
||||
const size = this.getViewportSize_(this.getRotation());
|
||||
return this.constraints_.center(targetCenter, opt_targetResolution || this.getResolution(), size);
|
||||
return this.constraints_.center(
|
||||
targetCenter,
|
||||
opt_targetResolution || this.getResolution(),
|
||||
size
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1550,7 +1697,9 @@ class View extends BaseObject {
|
||||
*/
|
||||
getConstrainedZoom(targetZoom, opt_direction) {
|
||||
const targetRes = this.getResolutionForZoom(targetZoom);
|
||||
return this.getZoomForResolution(this.getConstrainedResolution(targetRes, opt_direction));
|
||||
return this.getZoomForResolution(
|
||||
this.getConstrainedResolution(targetRes, opt_direction)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1570,25 +1719,26 @@ class View extends BaseObject {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Function} callback Callback.
|
||||
* @param {*} returnValue Return value.
|
||||
*/
|
||||
function animationCallback(callback, returnValue) {
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
callback(returnValue);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {ViewOptions} options View options.
|
||||
* @return {import("./centerconstraint.js").Type} The constraint.
|
||||
*/
|
||||
export function createCenterConstraint(options) {
|
||||
if (options.extent !== undefined) {
|
||||
const smooth = options.smoothExtentConstraint !== undefined ? options.smoothExtentConstraint : true;
|
||||
const smooth =
|
||||
options.smoothExtentConstraint !== undefined
|
||||
? options.smoothExtentConstraint
|
||||
: true;
|
||||
return createExtent(options.extent, options.constrainOnlyCenter, smooth);
|
||||
}
|
||||
|
||||
@@ -1603,7 +1753,6 @@ export function createCenterConstraint(options) {
|
||||
return centerNone;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {ViewOptions} options View options.
|
||||
* @return {{constraint: import("./resolutionconstraint.js").Type, maxResolution: number,
|
||||
@@ -1619,23 +1768,25 @@ export function createResolutionConstraint(options) {
|
||||
const defaultMaxZoom = 28;
|
||||
const defaultZoomFactor = 2;
|
||||
|
||||
let minZoom = options.minZoom !== undefined ?
|
||||
options.minZoom : DEFAULT_MIN_ZOOM;
|
||||
let minZoom =
|
||||
options.minZoom !== undefined ? options.minZoom : DEFAULT_MIN_ZOOM;
|
||||
|
||||
let maxZoom = options.maxZoom !== undefined ?
|
||||
options.maxZoom : defaultMaxZoom;
|
||||
let maxZoom =
|
||||
options.maxZoom !== undefined ? options.maxZoom : defaultMaxZoom;
|
||||
|
||||
const zoomFactor = options.zoomFactor !== undefined ?
|
||||
options.zoomFactor : defaultZoomFactor;
|
||||
const zoomFactor =
|
||||
options.zoomFactor !== undefined ? options.zoomFactor : defaultZoomFactor;
|
||||
|
||||
const multiWorld = options.multiWorld !== undefined ?
|
||||
options.multiWorld : false;
|
||||
const multiWorld =
|
||||
options.multiWorld !== undefined ? options.multiWorld : false;
|
||||
|
||||
const smooth =
|
||||
options.smoothResolutionConstraint !== undefined ? options.smoothResolutionConstraint : true;
|
||||
options.smoothResolutionConstraint !== undefined
|
||||
? options.smoothResolutionConstraint
|
||||
: true;
|
||||
|
||||
const showFullExtent =
|
||||
options.showFullExtent !== undefined ? options.showFullExtent : false;
|
||||
options.showFullExtent !== undefined ? options.showFullExtent : false;
|
||||
|
||||
const projection = createProjection(options.projection, 'EPSG:3857');
|
||||
const projExtent = projection.getExtent();
|
||||
@@ -1649,29 +1800,40 @@ export function createResolutionConstraint(options) {
|
||||
if (options.resolutions !== undefined) {
|
||||
const resolutions = options.resolutions;
|
||||
maxResolution = resolutions[minZoom];
|
||||
minResolution = resolutions[maxZoom] !== undefined ?
|
||||
resolutions[maxZoom] : resolutions[resolutions.length - 1];
|
||||
minResolution =
|
||||
resolutions[maxZoom] !== undefined
|
||||
? resolutions[maxZoom]
|
||||
: resolutions[resolutions.length - 1];
|
||||
|
||||
if (options.constrainResolution) {
|
||||
resolutionConstraint = createSnapToResolutions(resolutions, smooth,
|
||||
!constrainOnlyCenter && extent, showFullExtent);
|
||||
resolutionConstraint = createSnapToResolutions(
|
||||
resolutions,
|
||||
smooth,
|
||||
!constrainOnlyCenter && extent,
|
||||
showFullExtent
|
||||
);
|
||||
} else {
|
||||
resolutionConstraint = createMinMaxResolution(maxResolution, minResolution, smooth,
|
||||
!constrainOnlyCenter && extent, showFullExtent);
|
||||
resolutionConstraint = createMinMaxResolution(
|
||||
maxResolution,
|
||||
minResolution,
|
||||
smooth,
|
||||
!constrainOnlyCenter && extent,
|
||||
showFullExtent
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// calculate the default min and max resolution
|
||||
const size = !projExtent ?
|
||||
// use an extent that can fit the whole world if need be
|
||||
360 * METERS_PER_UNIT[Units.DEGREES] /
|
||||
projection.getMetersPerUnit() :
|
||||
Math.max(getWidth(projExtent), getHeight(projExtent));
|
||||
const size = !projExtent
|
||||
? // use an extent that can fit the whole world if need be
|
||||
(360 * METERS_PER_UNIT[Units.DEGREES]) / projection.getMetersPerUnit()
|
||||
: Math.max(getWidth(projExtent), getHeight(projExtent));
|
||||
|
||||
const defaultMaxResolution = size / DEFAULT_TILE_SIZE / Math.pow(
|
||||
defaultZoomFactor, DEFAULT_MIN_ZOOM);
|
||||
const defaultMaxResolution =
|
||||
size / DEFAULT_TILE_SIZE / Math.pow(defaultZoomFactor, DEFAULT_MIN_ZOOM);
|
||||
|
||||
const defaultMinResolution = defaultMaxResolution / Math.pow(
|
||||
defaultZoomFactor, defaultMaxZoom - DEFAULT_MIN_ZOOM);
|
||||
const defaultMinResolution =
|
||||
defaultMaxResolution /
|
||||
Math.pow(defaultZoomFactor, defaultMaxZoom - DEFAULT_MIN_ZOOM);
|
||||
|
||||
// user provided maxResolution takes precedence
|
||||
maxResolution = options.maxResolution;
|
||||
@@ -1696,31 +1858,48 @@ export function createResolutionConstraint(options) {
|
||||
}
|
||||
|
||||
// given discrete zoom levels, minResolution may be different than provided
|
||||
maxZoom = minZoom + Math.floor(
|
||||
Math.log(maxResolution / minResolution) / Math.log(zoomFactor));
|
||||
maxZoom =
|
||||
minZoom +
|
||||
Math.floor(
|
||||
Math.log(maxResolution / minResolution) / Math.log(zoomFactor)
|
||||
);
|
||||
minResolution = maxResolution / Math.pow(zoomFactor, maxZoom - minZoom);
|
||||
|
||||
if (options.constrainResolution) {
|
||||
resolutionConstraint = createSnapToPower(
|
||||
zoomFactor, maxResolution, minResolution, smooth,
|
||||
!constrainOnlyCenter && extent, showFullExtent);
|
||||
zoomFactor,
|
||||
maxResolution,
|
||||
minResolution,
|
||||
smooth,
|
||||
!constrainOnlyCenter && extent,
|
||||
showFullExtent
|
||||
);
|
||||
} else {
|
||||
resolutionConstraint = createMinMaxResolution(maxResolution, minResolution, smooth,
|
||||
!constrainOnlyCenter && extent, showFullExtent);
|
||||
resolutionConstraint = createMinMaxResolution(
|
||||
maxResolution,
|
||||
minResolution,
|
||||
smooth,
|
||||
!constrainOnlyCenter && extent,
|
||||
showFullExtent
|
||||
);
|
||||
}
|
||||
}
|
||||
return {constraint: resolutionConstraint, maxResolution: maxResolution,
|
||||
minResolution: minResolution, minZoom: minZoom, zoomFactor: zoomFactor};
|
||||
return {
|
||||
constraint: resolutionConstraint,
|
||||
maxResolution: maxResolution,
|
||||
minResolution: minResolution,
|
||||
minZoom: minZoom,
|
||||
zoomFactor: zoomFactor,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {ViewOptions} options View options.
|
||||
* @return {import("./rotationconstraint.js").Type} Rotation constraint.
|
||||
*/
|
||||
export function createRotationConstraint(options) {
|
||||
const enableRotation = options.enableRotation !== undefined ?
|
||||
options.enableRotation : true;
|
||||
const enableRotation =
|
||||
options.enableRotation !== undefined ? options.enableRotation : true;
|
||||
if (enableRotation) {
|
||||
const constrainRotation = options.constrainRotation;
|
||||
if (constrainRotation === undefined || constrainRotation === true) {
|
||||
@@ -1737,7 +1916,6 @@ export function createRotationConstraint(options) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if an animation involves no view change.
|
||||
* @param {Animation} animation The animation.
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
*/
|
||||
export default {
|
||||
ANIMATING: 0,
|
||||
INTERACTING: 1
|
||||
INTERACTING: 1,
|
||||
};
|
||||
|
||||
@@ -8,5 +8,5 @@
|
||||
export default {
|
||||
CENTER: 'center',
|
||||
RESOLUTION: 'resolution',
|
||||
ROTATION: 'rotation'
|
||||
ROTATION: 'rotation',
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/array
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Performs a binary search on the provided sorted list and returns the index of the item if found. If it can't be found it'll return -1.
|
||||
* https://github.com/darkskyapp/binary-search
|
||||
@@ -22,13 +21,14 @@ export function binarySearch(haystack, needle, opt_comparator) {
|
||||
while (low < high) {
|
||||
/* Note that "(low + high) >>> 1" may overflow, and results in a typecast
|
||||
* to double (which gives the wrong results). */
|
||||
mid = low + (high - low >> 1);
|
||||
mid = low + ((high - low) >> 1);
|
||||
cmp = +comparator(haystack[mid], needle);
|
||||
|
||||
if (cmp < 0.0) { /* Too low. */
|
||||
if (cmp < 0.0) {
|
||||
/* Too low. */
|
||||
low = mid + 1;
|
||||
|
||||
} else { /* Key found or too high */
|
||||
} else {
|
||||
/* Key found or too high */
|
||||
high = mid;
|
||||
found = !cmp;
|
||||
}
|
||||
@@ -38,7 +38,6 @@ export function binarySearch(haystack, needle, opt_comparator) {
|
||||
return found ? low : ~low;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare function for array sort that is safe for numbers.
|
||||
* @param {*} a The first object to be compared.
|
||||
@@ -50,7 +49,6 @@ export function numberSafeCompareFunction(a, b) {
|
||||
return a > b ? 1 : a < b ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether the array contains the given object.
|
||||
* @param {Array<*>} arr The array to test for the presence of the element.
|
||||
@@ -61,7 +59,6 @@ export function includes(arr, obj) {
|
||||
return arr.indexOf(obj) >= 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} arr Array.
|
||||
* @param {number} target Target.
|
||||
@@ -107,7 +104,6 @@ export function linearFindNearest(arr, target, direction) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<*>} arr Array.
|
||||
* @param {number} begin Begin index.
|
||||
@@ -123,7 +119,6 @@ export function reverseSubArray(arr, begin, end) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<VALUE>} arr The array to modify.
|
||||
* @param {!Array<VALUE>|VALUE} data The elements or arrays of elements to add to arr.
|
||||
@@ -137,7 +132,6 @@ export function extend(arr, data) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<VALUE>} arr The array to modify.
|
||||
* @param {VALUE} obj The element to remove.
|
||||
@@ -153,7 +147,6 @@ export function remove(arr, obj) {
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<VALUE>} arr The array to search in.
|
||||
* @param {function(VALUE, number, ?) : boolean} func The function to compare.
|
||||
@@ -173,7 +166,6 @@ export function find(arr, func) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array|Uint8ClampedArray} arr1 The first array to compare.
|
||||
* @param {Array|Uint8ClampedArray} arr2 The second array to compare.
|
||||
@@ -192,7 +184,6 @@ export function equals(arr1, arr2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sort the passed array such that the relative order of equal elements is preverved.
|
||||
* See https://en.wikipedia.org/wiki/Sorting_algorithm#Stability for details.
|
||||
@@ -207,7 +198,7 @@ export function stableSort(arr, compareFnc) {
|
||||
for (i = 0; i < length; i++) {
|
||||
tmp[i] = {index: i, value: arr[i]};
|
||||
}
|
||||
tmp.sort(function(a, b) {
|
||||
tmp.sort(function (a, b) {
|
||||
return compareFnc(a.value, b.value) || a.index - b.index;
|
||||
});
|
||||
for (i = 0; i < arr.length; i++) {
|
||||
@@ -215,7 +206,6 @@ export function stableSort(arr, compareFnc) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<*>} arr The array to search in.
|
||||
* @param {Function} func Comparison function.
|
||||
@@ -223,14 +213,13 @@ export function stableSort(arr, compareFnc) {
|
||||
*/
|
||||
export function findIndex(arr, func) {
|
||||
let index;
|
||||
const found = !arr.every(function(el, idx) {
|
||||
const found = !arr.every(function (el, idx) {
|
||||
index = idx;
|
||||
return !func(el, idx, arr);
|
||||
});
|
||||
return found ? index : -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<*>} arr The array to test.
|
||||
* @param {Function=} opt_func Comparison function.
|
||||
@@ -239,11 +228,11 @@ export function findIndex(arr, func) {
|
||||
*/
|
||||
export function isSorted(arr, opt_func, opt_strict) {
|
||||
const compare = opt_func || numberSafeCompareFunction;
|
||||
return arr.every(function(currentVal, index) {
|
||||
return arr.every(function (currentVal, index) {
|
||||
if (index === 0) {
|
||||
return true;
|
||||
}
|
||||
const res = compare(arr[index - 1], currentVal);
|
||||
return !(res > 0 || opt_strict && res === 0);
|
||||
return !(res > 0 || (opt_strict && res === 0));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
*/
|
||||
import {clamp} from './math.js';
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function((import("./coordinate.js").Coordinate|undefined), number, import("./size.js").Size, boolean=): (import("./coordinate.js").Coordinate|undefined)} Type
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {boolean} onlyCenter If true, the constraint will only apply to the view center.
|
||||
@@ -25,7 +23,7 @@ export function createExtent(extent, onlyCenter, smooth) {
|
||||
* @param {boolean=} opt_isMoving True if an interaction or animation is in progress.
|
||||
* @return {import("./coordinate.js").Coordinate|undefined} Center.
|
||||
*/
|
||||
function(center, resolution, size, opt_isMoving) {
|
||||
function (center, resolution, size, opt_isMoving) {
|
||||
if (center) {
|
||||
const viewWidth = onlyCenter ? 0 : size[0] * resolution;
|
||||
const viewHeight = onlyCenter ? 0 : size[1] * resolution;
|
||||
@@ -51,9 +49,11 @@ export function createExtent(extent, onlyCenter, smooth) {
|
||||
|
||||
// during an interaction, allow some overscroll
|
||||
if (opt_isMoving && smooth) {
|
||||
x += -ratio * Math.log(1 + Math.max(0, minX - center[0]) / ratio) +
|
||||
x +=
|
||||
-ratio * Math.log(1 + Math.max(0, minX - center[0]) / ratio) +
|
||||
ratio * Math.log(1 + Math.max(0, center[0] - maxX) / ratio);
|
||||
y += -ratio * Math.log(1 + Math.max(0, minY - center[1]) / ratio) +
|
||||
y +=
|
||||
-ratio * Math.log(1 + Math.max(0, minY - center[1]) / ratio) +
|
||||
ratio * Math.log(1 + Math.max(0, center[1] - maxY) / ratio);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,6 @@ export function createExtent(extent, onlyCenter, smooth) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("./coordinate.js").Coordinate=} center Center.
|
||||
* @return {import("./coordinate.js").Coordinate|undefined} Center.
|
||||
|
||||
103
src/ol/color.js
103
src/ol/color.js
@@ -4,7 +4,6 @@
|
||||
import {assert} from './asserts.js';
|
||||
import {clamp} from './math.js';
|
||||
|
||||
|
||||
/**
|
||||
* A color represented as a short array [red, green, blue, alpha].
|
||||
* red, green, and blue should be integers in the range 0..255 inclusive.
|
||||
@@ -14,7 +13,6 @@ import {clamp} from './math.js';
|
||||
* @api
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* This RegExp matches # followed by 3, 4, 6, or 8 hex digits.
|
||||
* @const
|
||||
@@ -23,7 +21,6 @@ import {clamp} from './math.js';
|
||||
*/
|
||||
const HEX_COLOR_RE_ = /^#([a-f0-9]{3}|[a-f0-9]{4}(?:[a-f0-9]{2}){0,2})$/i;
|
||||
|
||||
|
||||
/**
|
||||
* Regular expression for matching potential named color style strings.
|
||||
* @const
|
||||
@@ -32,7 +29,6 @@ const HEX_COLOR_RE_ = /^#([a-f0-9]{3}|[a-f0-9]{4}(?:[a-f0-9]{2}){0,2})$/i;
|
||||
*/
|
||||
const NAMED_COLOR_RE_ = /^([a-z]*)$|^hsla?\(.*\)$/i;
|
||||
|
||||
|
||||
/**
|
||||
* Return the color as an rgba string.
|
||||
* @param {Color|string} color Color.
|
||||
@@ -65,62 +61,58 @@ function fromNamed(color) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} s String.
|
||||
* @return {Color} Color.
|
||||
*/
|
||||
export const fromString = (
|
||||
function() {
|
||||
export const fromString = (function () {
|
||||
// We maintain a small cache of parsed strings. To provide cheap LRU-like
|
||||
// semantics, whenever the cache grows too large we simply delete an
|
||||
// arbitrary 25% of the entries.
|
||||
|
||||
// We maintain a small cache of parsed strings. To provide cheap LRU-like
|
||||
// semantics, whenever the cache grows too large we simply delete an
|
||||
// arbitrary 25% of the entries.
|
||||
/**
|
||||
* @const
|
||||
* @type {number}
|
||||
*/
|
||||
const MAX_CACHE_SIZE = 1024;
|
||||
|
||||
/**
|
||||
* @type {Object<string, Color>}
|
||||
*/
|
||||
const cache = {};
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
let cacheSize = 0;
|
||||
|
||||
return (
|
||||
/**
|
||||
* @const
|
||||
* @type {number}
|
||||
* @param {string} s String.
|
||||
* @return {Color} Color.
|
||||
*/
|
||||
const MAX_CACHE_SIZE = 1024;
|
||||
|
||||
/**
|
||||
* @type {Object<string, Color>}
|
||||
*/
|
||||
const cache = {};
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
let cacheSize = 0;
|
||||
|
||||
return (
|
||||
/**
|
||||
* @param {string} s String.
|
||||
* @return {Color} Color.
|
||||
*/
|
||||
function(s) {
|
||||
let color;
|
||||
if (cache.hasOwnProperty(s)) {
|
||||
color = cache[s];
|
||||
} else {
|
||||
if (cacheSize >= MAX_CACHE_SIZE) {
|
||||
let i = 0;
|
||||
for (const key in cache) {
|
||||
if ((i++ & 3) === 0) {
|
||||
delete cache[key];
|
||||
--cacheSize;
|
||||
}
|
||||
function (s) {
|
||||
let color;
|
||||
if (cache.hasOwnProperty(s)) {
|
||||
color = cache[s];
|
||||
} else {
|
||||
if (cacheSize >= MAX_CACHE_SIZE) {
|
||||
let i = 0;
|
||||
for (const key in cache) {
|
||||
if ((i++ & 3) === 0) {
|
||||
delete cache[key];
|
||||
--cacheSize;
|
||||
}
|
||||
}
|
||||
color = fromStringInternal_(s);
|
||||
cache[s] = color;
|
||||
++cacheSize;
|
||||
}
|
||||
return color;
|
||||
color = fromStringInternal_(s);
|
||||
cache[s] = color;
|
||||
++cacheSize;
|
||||
}
|
||||
);
|
||||
|
||||
})();
|
||||
return color;
|
||||
}
|
||||
);
|
||||
})();
|
||||
|
||||
/**
|
||||
* Return the color as an array. This function maintains a cache of calculated
|
||||
@@ -149,7 +141,8 @@ function fromStringInternal_(s) {
|
||||
s = fromNamed(s);
|
||||
}
|
||||
|
||||
if (HEX_COLOR_RE_.exec(s)) { // hex
|
||||
if (HEX_COLOR_RE_.exec(s)) {
|
||||
// hex
|
||||
const n = s.length - 1; // number of hex digits
|
||||
let d; // number of digits per channel
|
||||
if (n <= 4) {
|
||||
@@ -175,10 +168,12 @@ function fromStringInternal_(s) {
|
||||
}
|
||||
}
|
||||
color = [r, g, b, a / 255];
|
||||
} else if (s.indexOf('rgba(') == 0) { // rgba()
|
||||
} else if (s.indexOf('rgba(') == 0) {
|
||||
// rgba()
|
||||
color = s.slice(5, -1).split(',').map(Number);
|
||||
normalize(color);
|
||||
} else if (s.indexOf('rgb(') == 0) { // rgb()
|
||||
} else if (s.indexOf('rgb(') == 0) {
|
||||
// rgb()
|
||||
color = s.slice(4, -1).split(',').map(Number);
|
||||
color.push(1);
|
||||
normalize(color);
|
||||
@@ -188,7 +183,6 @@ function fromStringInternal_(s) {
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO this function is only used in the test, we probably shouldn't export it
|
||||
* @param {Color} color Color.
|
||||
@@ -202,7 +196,6 @@ export function normalize(color) {
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Color} color Color.
|
||||
* @return {string} String.
|
||||
@@ -232,5 +225,7 @@ export function isStringColor(s) {
|
||||
if (NAMED_COLOR_RE_.test(s)) {
|
||||
s = fromNamed(s);
|
||||
}
|
||||
return HEX_COLOR_RE_.test(s) || s.indexOf('rgba(') === 0 || s.indexOf('rgb(') === 0;
|
||||
return (
|
||||
HEX_COLOR_RE_.test(s) || s.indexOf('rgba(') === 0 || s.indexOf('rgb(') === 0
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import {toString} from './color.js';
|
||||
|
||||
|
||||
/**
|
||||
* A type accepted by CanvasRenderingContext2D.fillStyle
|
||||
* or CanvasRenderingContext2D.strokeStyle.
|
||||
@@ -16,7 +15,6 @@ import {toString} from './color.js';
|
||||
* @api
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("./color.js").Color|ColorLike} color Color.
|
||||
* @return {ColorLike} The color as an {@link ol/colorlike~ColorLike}.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* @module ol/control
|
||||
*/
|
||||
import Collection from './Collection.js';
|
||||
import Attribution from './control/Attribution.js';
|
||||
import Collection from './Collection.js';
|
||||
import Rotate from './control/Rotate.js';
|
||||
import Zoom from './control/Zoom.js';
|
||||
|
||||
@@ -33,7 +33,6 @@ export {default as ZoomToExtent} from './control/ZoomToExtent.js';
|
||||
* @api
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Set of controls included in maps by default. Unless configured otherwise,
|
||||
* this returns a collection containing an instance of each of the following
|
||||
@@ -49,7 +48,6 @@ export {default as ZoomToExtent} from './control/ZoomToExtent.js';
|
||||
* @api
|
||||
*/
|
||||
export function defaults(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
const controls = new Collection();
|
||||
@@ -64,8 +62,8 @@ export function defaults(opt_options) {
|
||||
controls.push(new Rotate(options.rotateOptions));
|
||||
}
|
||||
|
||||
const attributionControl = options.attribution !== undefined ?
|
||||
options.attribution : true;
|
||||
const attributionControl =
|
||||
options.attribution !== undefined ? options.attribution : true;
|
||||
if (attributionControl) {
|
||||
controls.push(new Attribution(options.attributionOptions));
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
/**
|
||||
* @module ol/control/Attribution
|
||||
*/
|
||||
import {equals} from '../array.js';
|
||||
import Control from './Control.js';
|
||||
import {CLASS_CONTROL, CLASS_UNSELECTABLE, CLASS_COLLAPSED} from '../css.js';
|
||||
import {removeChildren, replaceNode} from '../dom.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {CLASS_COLLAPSED, CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js';
|
||||
import {equals} from '../array.js';
|
||||
import {inView} from '../layer/Layer.js';
|
||||
|
||||
import {removeChildren, replaceNode} from '../dom.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
@@ -32,7 +31,6 @@ import {inView} from '../layer/Layer.js';
|
||||
* callback.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Control to show all the attributions associated with the layer sources
|
||||
@@ -43,18 +41,16 @@ import {inView} from '../layer/Layer.js';
|
||||
* @api
|
||||
*/
|
||||
class Attribution extends Control {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Attribution options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super({
|
||||
element: document.createElement('div'),
|
||||
render: options.render || render,
|
||||
target: options.target
|
||||
target: options.target,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -67,7 +63,8 @@ class Attribution extends Control {
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.collapsed_ = options.collapsed !== undefined ? options.collapsed : true;
|
||||
this.collapsed_ =
|
||||
options.collapsed !== undefined ? options.collapsed : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -79,18 +76,21 @@ class Attribution extends Control {
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.collapsible_ = options.collapsible !== undefined ?
|
||||
options.collapsible : true;
|
||||
this.collapsible_ =
|
||||
options.collapsible !== undefined ? options.collapsible : true;
|
||||
|
||||
if (!this.collapsible_) {
|
||||
this.collapsed_ = false;
|
||||
}
|
||||
|
||||
const className = options.className !== undefined ? options.className : 'ol-attribution';
|
||||
const className =
|
||||
options.className !== undefined ? options.className : 'ol-attribution';
|
||||
|
||||
const tipLabel = options.tipLabel !== undefined ? options.tipLabel : 'Attributions';
|
||||
const tipLabel =
|
||||
options.tipLabel !== undefined ? options.tipLabel : 'Attributions';
|
||||
|
||||
const collapseLabel = options.collapseLabel !== undefined ? options.collapseLabel : '\u00BB';
|
||||
const collapseLabel =
|
||||
options.collapseLabel !== undefined ? options.collapseLabel : '\u00BB';
|
||||
|
||||
if (typeof collapseLabel === 'string') {
|
||||
/**
|
||||
@@ -116,19 +116,27 @@ class Attribution extends Control {
|
||||
this.label_ = label;
|
||||
}
|
||||
|
||||
|
||||
const activeLabel = (this.collapsible_ && !this.collapsed_) ?
|
||||
this.collapseLabel_ : this.label_;
|
||||
const activeLabel =
|
||||
this.collapsible_ && !this.collapsed_ ? this.collapseLabel_ : this.label_;
|
||||
const button = document.createElement('button');
|
||||
button.setAttribute('type', 'button');
|
||||
button.title = tipLabel;
|
||||
button.appendChild(activeLabel);
|
||||
|
||||
button.addEventListener(EventType.CLICK, this.handleClick_.bind(this), false);
|
||||
button.addEventListener(
|
||||
EventType.CLICK,
|
||||
this.handleClick_.bind(this),
|
||||
false
|
||||
);
|
||||
|
||||
const cssClasses = className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL +
|
||||
(this.collapsed_ && this.collapsible_ ? ' ' + CLASS_COLLAPSED : '') +
|
||||
(this.collapsible_ ? '' : ' ol-uncollapsible');
|
||||
const cssClasses =
|
||||
className +
|
||||
' ' +
|
||||
CLASS_UNSELECTABLE +
|
||||
' ' +
|
||||
CLASS_CONTROL +
|
||||
(this.collapsed_ && this.collapsible_ ? ' ' + CLASS_COLLAPSED : '') +
|
||||
(this.collapsible_ ? '' : ' ol-uncollapsible');
|
||||
const element = this.element;
|
||||
element.className = cssClasses;
|
||||
element.appendChild(this.ulElement_);
|
||||
@@ -146,7 +154,6 @@ class Attribution extends Control {
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.renderedVisible_ = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +197,10 @@ class Attribution extends Control {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!this.overrideCollapsible_ && source.getAttributionsCollapsible() === false) {
|
||||
if (
|
||||
!this.overrideCollapsible_ &&
|
||||
source.getAttributionsCollapsible() === false
|
||||
) {
|
||||
this.setCollapsible(false);
|
||||
}
|
||||
|
||||
@@ -320,7 +330,6 @@ class Attribution extends Control {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the attribution element.
|
||||
* @param {import("../MapEvent.js").default} mapEvent Map event.
|
||||
@@ -330,5 +339,4 @@ export function render(mapEvent) {
|
||||
this.updateElement_(mapEvent.frameState);
|
||||
}
|
||||
|
||||
|
||||
export default Attribution;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
/**
|
||||
* @module ol/control/Control
|
||||
*/
|
||||
import {VOID} from '../functions.js';
|
||||
import MapEventType from '../MapEventType.js';
|
||||
import BaseObject from '../Object.js';
|
||||
import {removeNode} from '../dom.js';
|
||||
import MapEventType from '../MapEventType.js';
|
||||
import {VOID} from '../functions.js';
|
||||
import {listen, unlistenByKey} from '../events.js';
|
||||
|
||||
import {removeNode} from '../dom.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
@@ -20,7 +19,6 @@ import {listen, unlistenByKey} from '../events.js';
|
||||
* the control to be rendered outside of the map's viewport.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A control is a visible widget with a DOM element in a fixed position on the
|
||||
@@ -46,12 +44,10 @@ import {listen, unlistenByKey} from '../events.js';
|
||||
* @api
|
||||
*/
|
||||
class Control extends BaseObject {
|
||||
|
||||
/**
|
||||
* @param {Options} options Control options.
|
||||
*/
|
||||
constructor(options) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -87,7 +83,6 @@ class Control extends BaseObject {
|
||||
if (options.target) {
|
||||
this.setTarget(options.target);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,12 +119,14 @@ class Control extends BaseObject {
|
||||
this.listenerKeys.length = 0;
|
||||
this.map_ = map;
|
||||
if (this.map_) {
|
||||
const target = this.target_ ?
|
||||
this.target_ : map.getOverlayContainerStopEvent();
|
||||
const target = this.target_
|
||||
? this.target_
|
||||
: map.getOverlayContainerStopEvent();
|
||||
target.appendChild(this.element);
|
||||
if (this.render !== VOID) {
|
||||
this.listenerKeys.push(listen(map,
|
||||
MapEventType.POSTRENDER, this.render, this));
|
||||
this.listenerKeys.push(
|
||||
listen(map, MapEventType.POSTRENDER, this.render, this)
|
||||
);
|
||||
}
|
||||
map.render();
|
||||
}
|
||||
@@ -155,11 +152,9 @@ class Control extends BaseObject {
|
||||
* @api
|
||||
*/
|
||||
setTarget(target) {
|
||||
this.target_ = typeof target === 'string' ?
|
||||
document.getElementById(target) :
|
||||
target;
|
||||
this.target_ =
|
||||
typeof target === 'string' ? document.getElementById(target) : target;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Control;
|
||||
|
||||
@@ -2,19 +2,21 @@
|
||||
* @module ol/control/FullScreen
|
||||
*/
|
||||
import Control from './Control.js';
|
||||
import {CLASS_CONTROL, CLASS_UNSELECTABLE, CLASS_UNSUPPORTED} from '../css.js';
|
||||
import {replaceNode} from '../dom.js';
|
||||
import {listen} from '../events.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {CLASS_CONTROL, CLASS_UNSELECTABLE, CLASS_UNSUPPORTED} from '../css.js';
|
||||
import {listen} from '../events.js';
|
||||
import {replaceNode} from '../dom.js';
|
||||
|
||||
const events = ['fullscreenchange', 'webkitfullscreenchange', 'MSFullscreenChange'];
|
||||
|
||||
const events = [
|
||||
'fullscreenchange',
|
||||
'webkitfullscreenchange',
|
||||
'MSFullscreenChange',
|
||||
];
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
const FullScreenEventType = {
|
||||
|
||||
/**
|
||||
* Triggered after the map entered fullscreen.
|
||||
* @event FullScreenEventType#enterfullscreen
|
||||
@@ -27,11 +29,9 @@ const FullScreenEventType = {
|
||||
* @event FullScreenEventType#leavefullscreen
|
||||
* @api
|
||||
*/
|
||||
LEAVEFULLSCREEN: 'leavefullscreen'
|
||||
|
||||
LEAVEFULLSCREEN: 'leavefullscreen',
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {string} [className='ol-full-screen'] CSS class name.
|
||||
@@ -49,7 +49,6 @@ const FullScreenEventType = {
|
||||
* be displayed fullscreen.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Provides a button that when clicked fills up the full screen with the map.
|
||||
@@ -66,25 +65,23 @@ const FullScreenEventType = {
|
||||
* @api
|
||||
*/
|
||||
class FullScreen extends Control {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super({
|
||||
element: document.createElement('div'),
|
||||
target: options.target
|
||||
target: options.target,
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.cssClassName_ = options.className !== undefined ? options.className :
|
||||
'ol-full-screen';
|
||||
this.cssClassName_ =
|
||||
options.className !== undefined ? options.className : 'ol-full-screen';
|
||||
|
||||
const label = options.label !== undefined ? options.label : '\u2922';
|
||||
|
||||
@@ -92,17 +89,20 @@ class FullScreen extends Control {
|
||||
* @private
|
||||
* @type {Text}
|
||||
*/
|
||||
this.labelNode_ = typeof label === 'string' ?
|
||||
document.createTextNode(label) : label;
|
||||
this.labelNode_ =
|
||||
typeof label === 'string' ? document.createTextNode(label) : label;
|
||||
|
||||
const labelActive = options.labelActive !== undefined ? options.labelActive : '\u00d7';
|
||||
const labelActive =
|
||||
options.labelActive !== undefined ? options.labelActive : '\u00d7';
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Text}
|
||||
*/
|
||||
this.labelActiveNode_ = typeof labelActive === 'string' ?
|
||||
document.createTextNode(labelActive) : labelActive;
|
||||
this.labelActiveNode_ =
|
||||
typeof labelActive === 'string'
|
||||
? document.createTextNode(labelActive)
|
||||
: labelActive;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -116,11 +116,20 @@ class FullScreen extends Control {
|
||||
this.button_.title = tipLabel;
|
||||
this.button_.appendChild(this.labelNode_);
|
||||
|
||||
this.button_.addEventListener(EventType.CLICK, this.handleClick_.bind(this), false);
|
||||
this.button_.addEventListener(
|
||||
EventType.CLICK,
|
||||
this.handleClick_.bind(this),
|
||||
false
|
||||
);
|
||||
|
||||
const cssClasses = this.cssClassName_ + ' ' + CLASS_UNSELECTABLE +
|
||||
' ' + CLASS_CONTROL + ' ' +
|
||||
(!isFullScreenSupported() ? CLASS_UNSUPPORTED : '');
|
||||
const cssClasses =
|
||||
this.cssClassName_ +
|
||||
' ' +
|
||||
CLASS_UNSELECTABLE +
|
||||
' ' +
|
||||
CLASS_CONTROL +
|
||||
' ' +
|
||||
(!isFullScreenSupported() ? CLASS_UNSUPPORTED : '');
|
||||
const element = this.element;
|
||||
element.className = cssClasses;
|
||||
element.appendChild(this.button_);
|
||||
@@ -136,7 +145,6 @@ class FullScreen extends Control {
|
||||
* @type {HTMLElement|string|undefined}
|
||||
*/
|
||||
this.source_ = options.source;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,15 +172,15 @@ class FullScreen extends Control {
|
||||
} else {
|
||||
let element;
|
||||
if (this.source_) {
|
||||
element = typeof this.source_ === 'string' ?
|
||||
document.getElementById(this.source_) :
|
||||
this.source_;
|
||||
element =
|
||||
typeof this.source_ === 'string'
|
||||
? document.getElementById(this.source_)
|
||||
: this.source_;
|
||||
} else {
|
||||
element = map.getTargetElement();
|
||||
}
|
||||
if (this.keys_) {
|
||||
requestFullScreenWithKeys(element);
|
||||
|
||||
} else {
|
||||
requestFullScreen(element);
|
||||
}
|
||||
@@ -224,13 +232,13 @@ class FullScreen extends Control {
|
||||
if (map) {
|
||||
for (let i = 0, ii = events.length; i < ii; ++i) {
|
||||
this.listenerKeys.push(
|
||||
listen(document, events[i], this.handleFullScreenChange_, this));
|
||||
listen(document, events[i], this.handleFullScreenChange_, this)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Fullscreen is supported by the current platform.
|
||||
*/
|
||||
@@ -248,7 +256,9 @@ function isFullScreenSupported() {
|
||||
*/
|
||||
function isFullScreen() {
|
||||
return !!(
|
||||
document.webkitIsFullScreen || document.msFullscreenElement || document.fullscreenElement
|
||||
document.webkitIsFullScreen ||
|
||||
document.msFullscreenElement ||
|
||||
document.fullscreenElement
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,16 @@
|
||||
*/
|
||||
|
||||
import 'elm-pep';
|
||||
import {listen} from '../events.js';
|
||||
import Control from './Control.js';
|
||||
import EventType from '../pointer/EventType.js';
|
||||
import {getChangeEventType} from '../Object.js';
|
||||
import Control from './Control.js';
|
||||
import {getTransformFromProjections, identityTransform, get as getProjection, getUserProjection} from '../proj.js';
|
||||
|
||||
import {
|
||||
get as getProjection,
|
||||
getTransformFromProjections,
|
||||
getUserProjection,
|
||||
identityTransform,
|
||||
} from '../proj.js';
|
||||
import {listen} from '../events.js';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
@@ -20,7 +24,6 @@ const PROJECTION = 'projection';
|
||||
*/
|
||||
const COORDINATE_FORMAT = 'coordinateFormat';
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {string} [className='ol-mouse-position'] CSS class name.
|
||||
@@ -38,7 +41,6 @@ const COORDINATE_FORMAT = 'coordinateFormat';
|
||||
* string `''`).
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A control to show the 2D coordinates of the mouse cursor. By default, these
|
||||
@@ -52,24 +54,26 @@ const COORDINATE_FORMAT = 'coordinateFormat';
|
||||
* @api
|
||||
*/
|
||||
class MousePosition extends Control {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Mouse position options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
const element = document.createElement('div');
|
||||
element.className = options.className !== undefined ? options.className : 'ol-mouse-position';
|
||||
element.className =
|
||||
options.className !== undefined ? options.className : 'ol-mouse-position';
|
||||
|
||||
super({
|
||||
element: element,
|
||||
render: options.render || render,
|
||||
target: options.target
|
||||
target: options.target,
|
||||
});
|
||||
|
||||
this.addEventListener(getChangeEventType(PROJECTION), this.handleProjectionChanged_);
|
||||
this.addEventListener(
|
||||
getChangeEventType(PROJECTION),
|
||||
this.handleProjectionChanged_
|
||||
);
|
||||
|
||||
if (options.coordinateFormat) {
|
||||
this.setCoordinateFormat(options.coordinateFormat);
|
||||
@@ -82,7 +86,8 @@ class MousePosition extends Control {
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.undefinedHTML_ = options.undefinedHTML !== undefined ? options.undefinedHTML : ' ';
|
||||
this.undefinedHTML_ =
|
||||
options.undefinedHTML !== undefined ? options.undefinedHTML : ' ';
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -107,7 +112,6 @@ class MousePosition extends Control {
|
||||
* @type {?import("../proj.js").TransformFunction}
|
||||
*/
|
||||
this.transform_ = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,9 +130,9 @@ class MousePosition extends Control {
|
||||
* @api
|
||||
*/
|
||||
getCoordinateFormat() {
|
||||
return (
|
||||
/** @type {import("../coordinate.js").CoordinateFormat|undefined} */ (this.get(COORDINATE_FORMAT))
|
||||
);
|
||||
return /** @type {import("../coordinate.js").CoordinateFormat|undefined} */ (this.get(
|
||||
COORDINATE_FORMAT
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,9 +143,9 @@ class MousePosition extends Control {
|
||||
* @api
|
||||
*/
|
||||
getProjection() {
|
||||
return (
|
||||
/** @type {import("../proj/Projection.js").default|undefined} */ (this.get(PROJECTION))
|
||||
);
|
||||
return /** @type {import("../proj/Projection.js").default|undefined} */ (this.get(
|
||||
PROJECTION
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +220,9 @@ class MousePosition extends Control {
|
||||
const projection = this.getProjection();
|
||||
if (projection) {
|
||||
this.transform_ = getTransformFromProjections(
|
||||
this.mapProjection_, projection);
|
||||
this.mapProjection_,
|
||||
projection
|
||||
);
|
||||
} else {
|
||||
this.transform_ = identityTransform;
|
||||
}
|
||||
@@ -227,7 +233,9 @@ class MousePosition extends Control {
|
||||
const userProjection = getUserProjection();
|
||||
if (userProjection) {
|
||||
this.transform_ = getTransformFromProjections(
|
||||
this.mapProjection_, userProjection);
|
||||
this.mapProjection_,
|
||||
userProjection
|
||||
);
|
||||
}
|
||||
this.transform_(coordinate, coordinate);
|
||||
const coordinateFormat = this.getCoordinateFormat();
|
||||
@@ -245,7 +253,6 @@ class MousePosition extends Control {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the projection. Rendering of the coordinates is done in
|
||||
* `handleMouseMove` and `handleMouseUp`.
|
||||
@@ -264,5 +271,4 @@ export function render(mapEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default MousePosition;
|
||||
|
||||
@@ -1,24 +1,29 @@
|
||||
/**
|
||||
* @module ol/control/OverviewMap
|
||||
*/
|
||||
import PluggableMap from '../PluggableMap.js';
|
||||
import CompositeMapRenderer from '../renderer/Composite.js';
|
||||
import Control from './Control.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import MapEventType from '../MapEventType.js';
|
||||
import MapProperty from '../MapProperty.js';
|
||||
import {getChangeEventType} from '../Object.js';
|
||||
import ObjectEventType from '../ObjectEventType.js';
|
||||
import Overlay from '../Overlay.js';
|
||||
import OverlayPositioning from '../OverlayPositioning.js';
|
||||
import ViewProperty from '../ViewProperty.js';
|
||||
import Control from './Control.js';
|
||||
import {fromExtent as polygonFromExtent} from '../geom/Polygon.js';
|
||||
import {CLASS_CONTROL, CLASS_UNSELECTABLE, CLASS_COLLAPSED} from '../css.js';
|
||||
import {replaceNode} from '../dom.js';
|
||||
import {listen, listenOnce} from '../events.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {containsExtent, equals as equalsExtent, getBottomRight, getTopLeft, scaleFromCenter} from '../extent.js';
|
||||
import PluggableMap from '../PluggableMap.js';
|
||||
import View from '../View.js';
|
||||
|
||||
import ViewProperty from '../ViewProperty.js';
|
||||
import {CLASS_COLLAPSED, CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js';
|
||||
import {
|
||||
containsExtent,
|
||||
equals as equalsExtent,
|
||||
getBottomRight,
|
||||
getTopLeft,
|
||||
scaleFromCenter,
|
||||
} from '../extent.js';
|
||||
import {getChangeEventType} from '../Object.js';
|
||||
import {listen, listenOnce} from '../events.js';
|
||||
import {fromExtent as polygonFromExtent} from '../geom/Polygon.js';
|
||||
import {replaceNode} from '../dom.js';
|
||||
|
||||
/**
|
||||
* Maximum width and/or height extent ratio that determines when the overview
|
||||
@@ -27,7 +32,6 @@ import View from '../View.js';
|
||||
*/
|
||||
const MAX_RATIO = 0.75;
|
||||
|
||||
|
||||
/**
|
||||
* Minimum width and/or height extent ratio that determines when the overview
|
||||
* map should be zoomed in.
|
||||
@@ -35,14 +39,12 @@ const MAX_RATIO = 0.75;
|
||||
*/
|
||||
const MIN_RATIO = 0.1;
|
||||
|
||||
|
||||
class ControlledMap extends PluggableMap {
|
||||
createRenderer() {
|
||||
return new CompositeMapRenderer(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {string} [className='ol-overviewmap'] CSS class name.
|
||||
@@ -64,7 +66,6 @@ class ControlledMap extends PluggableMap {
|
||||
* a default view with the same projection as the main map will be used.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Create a new control with a map acting as an overview map for another
|
||||
* defined map.
|
||||
@@ -72,18 +73,16 @@ class ControlledMap extends PluggableMap {
|
||||
* @api
|
||||
*/
|
||||
class OverviewMap extends Control {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options OverviewMap options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super({
|
||||
element: document.createElement('div'),
|
||||
render: options.render || render,
|
||||
target: options.target
|
||||
target: options.target,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -95,14 +94,15 @@ class OverviewMap extends Control {
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.collapsed_ = options.collapsed !== undefined ? options.collapsed : true;
|
||||
this.collapsed_ =
|
||||
options.collapsed !== undefined ? options.collapsed : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.collapsible_ = options.collapsible !== undefined ?
|
||||
options.collapsible : true;
|
||||
this.collapsible_ =
|
||||
options.collapsible !== undefined ? options.collapsible : true;
|
||||
|
||||
if (!this.collapsible_) {
|
||||
this.collapsed_ = false;
|
||||
@@ -112,8 +112,8 @@ class OverviewMap extends Control {
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.rotateWithView_ = options.rotateWithView !== undefined ?
|
||||
options.rotateWithView : false;
|
||||
this.rotateWithView_ =
|
||||
options.rotateWithView !== undefined ? options.rotateWithView : false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -121,11 +121,14 @@ class OverviewMap extends Control {
|
||||
*/
|
||||
this.viewExtent_ = undefined;
|
||||
|
||||
const className = options.className !== undefined ? options.className : 'ol-overviewmap';
|
||||
const className =
|
||||
options.className !== undefined ? options.className : 'ol-overviewmap';
|
||||
|
||||
const tipLabel = options.tipLabel !== undefined ? options.tipLabel : 'Overview map';
|
||||
const tipLabel =
|
||||
options.tipLabel !== undefined ? options.tipLabel : 'Overview map';
|
||||
|
||||
const collapseLabel = options.collapseLabel !== undefined ? options.collapseLabel : '\u00AB';
|
||||
const collapseLabel =
|
||||
options.collapseLabel !== undefined ? options.collapseLabel : '\u00AB';
|
||||
|
||||
if (typeof collapseLabel === 'string') {
|
||||
/**
|
||||
@@ -140,7 +143,6 @@ class OverviewMap extends Control {
|
||||
|
||||
const label = options.label !== undefined ? options.label : '\u00BB';
|
||||
|
||||
|
||||
if (typeof label === 'string') {
|
||||
/**
|
||||
* @private
|
||||
@@ -152,14 +154,18 @@ class OverviewMap extends Control {
|
||||
this.label_ = label;
|
||||
}
|
||||
|
||||
const activeLabel = (this.collapsible_ && !this.collapsed_) ?
|
||||
this.collapseLabel_ : this.label_;
|
||||
const activeLabel =
|
||||
this.collapsible_ && !this.collapsed_ ? this.collapseLabel_ : this.label_;
|
||||
const button = document.createElement('button');
|
||||
button.setAttribute('type', 'button');
|
||||
button.title = tipLabel;
|
||||
button.appendChild(activeLabel);
|
||||
|
||||
button.addEventListener(EventType.CLICK, this.handleClick_.bind(this), false);
|
||||
button.addEventListener(
|
||||
EventType.CLICK,
|
||||
this.handleClick_.bind(this),
|
||||
false
|
||||
);
|
||||
|
||||
/**
|
||||
* @type {HTMLElement}
|
||||
@@ -180,12 +186,12 @@ class OverviewMap extends Control {
|
||||
* @private
|
||||
*/
|
||||
this.ovmap_ = new ControlledMap({
|
||||
view: options.view
|
||||
view: options.view,
|
||||
});
|
||||
const ovmap = this.ovmap_;
|
||||
|
||||
if (options.layers) {
|
||||
options.layers.forEach(function(layer) {
|
||||
options.layers.forEach(function (layer) {
|
||||
ovmap.addLayer(layer);
|
||||
});
|
||||
}
|
||||
@@ -201,13 +207,18 @@ class OverviewMap extends Control {
|
||||
this.boxOverlay_ = new Overlay({
|
||||
position: [0, 0],
|
||||
positioning: OverlayPositioning.CENTER_CENTER,
|
||||
element: box
|
||||
element: box,
|
||||
});
|
||||
this.ovmap_.addOverlay(this.boxOverlay_);
|
||||
|
||||
const cssClasses = className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL +
|
||||
(this.collapsed_ && this.collapsible_ ? ' ' + CLASS_COLLAPSED : '') +
|
||||
(this.collapsible_ ? '' : ' ol-uncollapsible');
|
||||
const cssClasses =
|
||||
className +
|
||||
' ' +
|
||||
CLASS_UNSELECTABLE +
|
||||
' ' +
|
||||
CLASS_CONTROL +
|
||||
(this.collapsed_ && this.collapsible_ ? ' ' + CLASS_COLLAPSED : '') +
|
||||
(this.collapsible_ ? '' : ' ol-uncollapsible');
|
||||
const element = this.element;
|
||||
element.className = cssClasses;
|
||||
element.appendChild(this.ovmapDiv_);
|
||||
@@ -222,21 +233,23 @@ class OverviewMap extends Control {
|
||||
|
||||
/* Functions definition */
|
||||
|
||||
const computeDesiredMousePosition = function(mousePosition) {
|
||||
const computeDesiredMousePosition = function (mousePosition) {
|
||||
return {
|
||||
clientX: mousePosition.clientX,
|
||||
clientY: mousePosition.clientY
|
||||
clientY: mousePosition.clientY,
|
||||
};
|
||||
};
|
||||
|
||||
const move = function(event) {
|
||||
const move = function (event) {
|
||||
const position = /** @type {?} */ (computeDesiredMousePosition(event));
|
||||
const coordinates = ovmap.getEventCoordinateInternal(/** @type {Event} */ (position));
|
||||
const coordinates = ovmap.getEventCoordinateInternal(
|
||||
/** @type {Event} */ (position)
|
||||
);
|
||||
|
||||
overlay.setPosition(coordinates);
|
||||
};
|
||||
|
||||
const endMoving = function(event) {
|
||||
const endMoving = function (event) {
|
||||
const coordinates = ovmap.getEventCoordinateInternal(event);
|
||||
|
||||
scope.getMap().getView().setCenterInternal(coordinates);
|
||||
@@ -247,11 +260,10 @@ class OverviewMap extends Control {
|
||||
|
||||
/* Binding */
|
||||
|
||||
overlayBox.addEventListener('mousedown', function() {
|
||||
overlayBox.addEventListener('mousedown', function () {
|
||||
window.addEventListener('mousemove', move);
|
||||
window.addEventListener('mouseup', endMoving);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,9 +289,14 @@ class OverviewMap extends Control {
|
||||
|
||||
if (map) {
|
||||
this.ovmap_.setTarget(this.ovmapDiv_);
|
||||
this.listenerKeys.push(listen(
|
||||
map, ObjectEventType.PROPERTYCHANGE,
|
||||
this.handleMapPropertyChange_, this));
|
||||
this.listenerKeys.push(
|
||||
listen(
|
||||
map,
|
||||
ObjectEventType.PROPERTYCHANGE,
|
||||
this.handleMapPropertyChange_,
|
||||
this
|
||||
)
|
||||
);
|
||||
|
||||
const view = map.getView();
|
||||
if (view) {
|
||||
@@ -317,12 +334,15 @@ class OverviewMap extends Control {
|
||||
if (!this.view_) {
|
||||
// Unless an explicit view definition was given, derive default from whatever main map uses.
|
||||
const newView = new View({
|
||||
projection: view.getProjection()
|
||||
projection: view.getProjection(),
|
||||
});
|
||||
this.ovmap_.setView(newView);
|
||||
}
|
||||
|
||||
view.addEventListener(getChangeEventType(ViewProperty.ROTATION), this.boundHandleRotationChanged_);
|
||||
view.addEventListener(
|
||||
getChangeEventType(ViewProperty.ROTATION),
|
||||
this.boundHandleRotationChanged_
|
||||
);
|
||||
// Sync once with the new view
|
||||
this.handleRotationChanged_();
|
||||
}
|
||||
@@ -333,7 +353,10 @@ class OverviewMap extends Control {
|
||||
* @private
|
||||
*/
|
||||
unbindView_(view) {
|
||||
view.removeEventListener(getChangeEventType(ViewProperty.ROTATION), this.boundHandleRotationChanged_);
|
||||
view.removeEventListener(
|
||||
getChangeEventType(ViewProperty.ROTATION),
|
||||
this.boundHandleRotationChanged_
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -381,10 +404,12 @@ class OverviewMap extends Control {
|
||||
const ovview = ovmap.getView();
|
||||
const ovextent = ovview.calculateExtentInternal(ovmapSize);
|
||||
|
||||
const topLeftPixel =
|
||||
ovmap.getPixelFromCoordinateInternal(getTopLeft(extent));
|
||||
const bottomRightPixel =
|
||||
ovmap.getPixelFromCoordinateInternal(getBottomRight(extent));
|
||||
const topLeftPixel = ovmap.getPixelFromCoordinateInternal(
|
||||
getTopLeft(extent)
|
||||
);
|
||||
const bottomRightPixel = ovmap.getPixelFromCoordinateInternal(
|
||||
getBottomRight(extent)
|
||||
);
|
||||
|
||||
const boxWidth = Math.abs(topLeftPixel[0] - bottomRightPixel[0]);
|
||||
const boxHeight = Math.abs(topLeftPixel[1] - bottomRightPixel[1]);
|
||||
@@ -392,10 +417,12 @@ class OverviewMap extends Control {
|
||||
const ovmapWidth = ovmapSize[0];
|
||||
const ovmapHeight = ovmapSize[1];
|
||||
|
||||
if (boxWidth < ovmapWidth * MIN_RATIO ||
|
||||
boxHeight < ovmapHeight * MIN_RATIO ||
|
||||
boxWidth > ovmapWidth * MAX_RATIO ||
|
||||
boxHeight > ovmapHeight * MAX_RATIO) {
|
||||
if (
|
||||
boxWidth < ovmapWidth * MIN_RATIO ||
|
||||
boxHeight < ovmapHeight * MIN_RATIO ||
|
||||
boxWidth > ovmapWidth * MAX_RATIO ||
|
||||
boxHeight > ovmapHeight * MAX_RATIO
|
||||
) {
|
||||
this.resetExtent_();
|
||||
} else if (!containsExtent(ovextent, extent)) {
|
||||
this.recenter_();
|
||||
@@ -425,8 +452,7 @@ class OverviewMap extends Control {
|
||||
// get how many times the current map overview could hold different
|
||||
// box sizes using the min and max ratio, pick the step in the middle used
|
||||
// to calculate the extent from the main map to set it to the overview map,
|
||||
const steps = Math.log(
|
||||
MAX_RATIO / MIN_RATIO) / Math.LN2;
|
||||
const steps = Math.log(MAX_RATIO / MIN_RATIO) / Math.LN2;
|
||||
const ratio = 1 / (Math.pow(2, steps / 2) * MIN_RATIO);
|
||||
scaleFromCenter(extent, ratio);
|
||||
ovview.fitInternal(polygonFromExtent(extent));
|
||||
@@ -473,8 +499,8 @@ class OverviewMap extends Control {
|
||||
const center = view.getCenterInternal();
|
||||
const resolution = view.getResolution();
|
||||
const ovresolution = ovview.getResolution();
|
||||
const width = mapSize[0] * resolution / ovresolution;
|
||||
const height = mapSize[1] * resolution / ovresolution;
|
||||
const width = (mapSize[0] * resolution) / ovresolution;
|
||||
const height = (mapSize[1] * resolution) / ovresolution;
|
||||
|
||||
// set position using center coordinates
|
||||
overlay.setPosition(center);
|
||||
@@ -520,11 +546,14 @@ class OverviewMap extends Control {
|
||||
}
|
||||
ovmap.updateSize();
|
||||
this.resetExtent_();
|
||||
listenOnce(ovmap, MapEventType.POSTRENDER,
|
||||
function(event) {
|
||||
listenOnce(
|
||||
ovmap,
|
||||
MapEventType.POSTRENDER,
|
||||
function (event) {
|
||||
this.updateBox_();
|
||||
},
|
||||
this);
|
||||
this
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -617,7 +646,6 @@ class OverviewMap extends Control {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the overview map element.
|
||||
* @param {import("../MapEvent.js").default} mapEvent Map event.
|
||||
@@ -628,5 +656,4 @@ export function render(mapEvent) {
|
||||
this.updateBox_();
|
||||
}
|
||||
|
||||
|
||||
export default OverviewMap;
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
* @module ol/control/Rotate
|
||||
*/
|
||||
import Control from './Control.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {CLASS_CONTROL, CLASS_HIDDEN, CLASS_UNSELECTABLE} from '../css.js';
|
||||
import {easeOut} from '../easing.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
@@ -23,7 +22,6 @@ import EventType from '../events/EventType.js';
|
||||
* rendered outside of the map's viewport.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A button control to reset rotation to 0.
|
||||
@@ -33,21 +31,20 @@ import EventType from '../events/EventType.js';
|
||||
* @api
|
||||
*/
|
||||
class Rotate extends Control {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Rotate options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super({
|
||||
element: document.createElement('div'),
|
||||
render: options.render || render,
|
||||
target: options.target
|
||||
target: options.target,
|
||||
});
|
||||
|
||||
const className = options.className !== undefined ? options.className : 'ol-rotate';
|
||||
const className =
|
||||
options.className !== undefined ? options.className : 'ol-rotate';
|
||||
|
||||
const label = options.label !== undefined ? options.label : '\u21E7';
|
||||
|
||||
@@ -74,9 +71,14 @@ class Rotate extends Control {
|
||||
button.title = tipLabel;
|
||||
button.appendChild(this.label_);
|
||||
|
||||
button.addEventListener(EventType.CLICK, this.handleClick_.bind(this), false);
|
||||
button.addEventListener(
|
||||
EventType.CLICK,
|
||||
this.handleClick_.bind(this),
|
||||
false
|
||||
);
|
||||
|
||||
const cssClasses = className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL;
|
||||
const cssClasses =
|
||||
className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL;
|
||||
const element = this.element;
|
||||
element.className = cssClasses;
|
||||
element.appendChild(button);
|
||||
@@ -104,7 +106,6 @@ class Rotate extends Control {
|
||||
if (this.autoHide_) {
|
||||
this.element.classList.add(CLASS_HIDDEN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +138,7 @@ class Rotate extends Control {
|
||||
view.animate({
|
||||
rotation: 0,
|
||||
duration: this.duration_,
|
||||
easing: easeOut
|
||||
easing: easeOut,
|
||||
});
|
||||
} else {
|
||||
view.setRotation(0);
|
||||
@@ -146,7 +147,6 @@ class Rotate extends Control {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the rotate control element.
|
||||
* @param {import("../MapEvent.js").default} mapEvent Map event.
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
/**
|
||||
* @module ol/control/ScaleLine
|
||||
*/
|
||||
import {getChangeEventType} from '../Object.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import Control from './Control.js';
|
||||
import {CLASS_UNSELECTABLE} from '../css.js';
|
||||
import {getPointResolution, METERS_PER_UNIT} from '../proj.js';
|
||||
import ProjUnits from '../proj/Units.js';
|
||||
|
||||
import {CLASS_UNSELECTABLE} from '../css.js';
|
||||
import {METERS_PER_UNIT, getPointResolution} from '../proj.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {getChangeEventType} from '../Object.js';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
@@ -24,10 +23,9 @@ export const Units = {
|
||||
IMPERIAL: 'imperial',
|
||||
NAUTICAL: 'nautical',
|
||||
METRIC: 'metric',
|
||||
US: 'us'
|
||||
US: 'us',
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Array<number>}
|
||||
@@ -40,7 +38,6 @@ const LEADING_DIGITS = [1, 2, 5];
|
||||
*/
|
||||
const DEFAULT_DPI = 25.4 / 0.28;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {string} [className='ol-scale-line'] CSS Class name.
|
||||
@@ -60,7 +57,6 @@ const DEFAULT_DPI = 25.4 / 0.28;
|
||||
* when `bar` is `true`. If undefined the OGC default screen pixel size of 0.28mm will be assumed.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A control displaying rough y-axis distances, calculated for the center of the
|
||||
@@ -76,21 +72,23 @@ const DEFAULT_DPI = 25.4 / 0.28;
|
||||
* @api
|
||||
*/
|
||||
class ScaleLine extends Control {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Scale line options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
const className = options.className !== undefined ? options.className :
|
||||
options.bar ? 'ol-scale-bar' : 'ol-scale-line';
|
||||
const className =
|
||||
options.className !== undefined
|
||||
? options.className
|
||||
: options.bar
|
||||
? 'ol-scale-bar'
|
||||
: 'ol-scale-line';
|
||||
|
||||
super({
|
||||
element: document.createElement('div'),
|
||||
render: options.render || render,
|
||||
target: options.target
|
||||
target: options.target,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -133,7 +131,10 @@ class ScaleLine extends Control {
|
||||
*/
|
||||
this.renderedHTML_ = '';
|
||||
|
||||
this.addEventListener(getChangeEventType(UNITS_PROP), this.handleUnitsChanged_);
|
||||
this.addEventListener(
|
||||
getChangeEventType(UNITS_PROP),
|
||||
this.handleUnitsChanged_
|
||||
);
|
||||
|
||||
this.setUnits(options.units || Units.METRIC);
|
||||
|
||||
@@ -160,7 +161,6 @@ class ScaleLine extends Control {
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.dpi_ = options.dpi || undefined;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,13 +217,17 @@ class ScaleLine extends Control {
|
||||
const center = viewState.center;
|
||||
const projection = viewState.projection;
|
||||
const units = this.getUnits();
|
||||
const pointResolutionUnits = units == Units.DEGREES ?
|
||||
ProjUnits.DEGREES :
|
||||
ProjUnits.METERS;
|
||||
let pointResolution =
|
||||
getPointResolution(projection, viewState.resolution, center, pointResolutionUnits);
|
||||
const pointResolutionUnits =
|
||||
units == Units.DEGREES ? ProjUnits.DEGREES : ProjUnits.METERS;
|
||||
let pointResolution = getPointResolution(
|
||||
projection,
|
||||
viewState.resolution,
|
||||
center,
|
||||
pointResolutionUnits
|
||||
);
|
||||
|
||||
const minWidth = this.minWidth_ * (this.dpi_ || DEFAULT_DPI) / DEFAULT_DPI;
|
||||
const minWidth =
|
||||
(this.minWidth_ * (this.dpi_ || DEFAULT_DPI)) / DEFAULT_DPI;
|
||||
|
||||
let nominalCount = minWidth * pointResolution;
|
||||
let suffix = '';
|
||||
@@ -281,8 +285,7 @@ class ScaleLine extends Control {
|
||||
assert(false, 33); // Invalid units
|
||||
}
|
||||
|
||||
let i = 3 * Math.floor(
|
||||
Math.log(minWidth * pointResolution) / Math.log(10));
|
||||
let i = 3 * Math.floor(Math.log(minWidth * pointResolution) / Math.log(10));
|
||||
let count, width, decimalCount;
|
||||
while (true) {
|
||||
decimalCount = Math.floor(i / 3);
|
||||
@@ -319,7 +322,6 @@ class ScaleLine extends Control {
|
||||
this.element.style.display = '';
|
||||
this.renderedVisible_ = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,7 +332,8 @@ class ScaleLine extends Control {
|
||||
* @returns {string} The stringified HTML of the scalebar.
|
||||
*/
|
||||
createScaleBar(width, scale, suffix) {
|
||||
const mapScale = '1 : ' + Math.round(this.getScaleForResolution()).toLocaleString();
|
||||
const mapScale =
|
||||
'1 : ' + Math.round(this.getScaleForResolution()).toLocaleString();
|
||||
const scaleSteps = [];
|
||||
const stepWidth = width / this.scaleBarSteps_;
|
||||
let backgroundColor = '#ffffff';
|
||||
@@ -342,22 +345,27 @@ class ScaleLine extends Control {
|
||||
scaleSteps.push(
|
||||
'<div>' +
|
||||
'<div ' +
|
||||
'class="ol-scale-singlebar" ' +
|
||||
'style=' +
|
||||
'"width: ' + stepWidth + 'px;' +
|
||||
'background-color: ' + backgroundColor + ';"' +
|
||||
'class="ol-scale-singlebar" ' +
|
||||
'style=' +
|
||||
'"width: ' +
|
||||
stepWidth +
|
||||
'px;' +
|
||||
'background-color: ' +
|
||||
backgroundColor +
|
||||
';"' +
|
||||
'>' +
|
||||
'</div>' +
|
||||
this.createMarker('relative', i) +
|
||||
/*render text every second step, except when only 2 steps */
|
||||
(i % 2 === 0 || this.scaleBarSteps_ === 2 ?
|
||||
this.createStepText(i, width, false, scale, suffix) :
|
||||
''
|
||||
) +
|
||||
'</div>'
|
||||
(i % 2 === 0 || this.scaleBarSteps_ === 2
|
||||
? this.createStepText(i, width, false, scale, suffix)
|
||||
: '') +
|
||||
'</div>'
|
||||
);
|
||||
if (i === this.scaleBarSteps_ - 1) {
|
||||
{/*render text at the end */}
|
||||
{
|
||||
/*render text at the end */
|
||||
}
|
||||
scaleSteps.push(this.createStepText(i + 1, width, true, scale, suffix));
|
||||
}
|
||||
// switch colors of steps between black and white
|
||||
@@ -370,19 +378,23 @@ class ScaleLine extends Control {
|
||||
|
||||
let scaleBarText;
|
||||
if (this.scaleBarText_) {
|
||||
scaleBarText = '<div ' +
|
||||
'class="ol-scale-text" ' +
|
||||
'style="width: ' + width + 'px;">' +
|
||||
mapScale +
|
||||
'</div>';
|
||||
scaleBarText =
|
||||
'<div ' +
|
||||
'class="ol-scale-text" ' +
|
||||
'style="width: ' +
|
||||
width +
|
||||
'px;">' +
|
||||
mapScale +
|
||||
'</div>';
|
||||
} else {
|
||||
scaleBarText = '';
|
||||
}
|
||||
const container = '<div ' +
|
||||
const container =
|
||||
'<div ' +
|
||||
'style="display: flex;">' +
|
||||
scaleBarText +
|
||||
scaleSteps.join('') +
|
||||
'</div>';
|
||||
'</div>';
|
||||
return container;
|
||||
}
|
||||
|
||||
@@ -394,11 +406,17 @@ class ScaleLine extends Control {
|
||||
*/
|
||||
createMarker(position, i) {
|
||||
const top = position === 'absolute' ? 3 : -10;
|
||||
return '<div ' +
|
||||
'class="ol-scale-step-marker" ' +
|
||||
'style="position: ' + position + ';' +
|
||||
'top: ' + top + 'px;"' +
|
||||
'></div>';
|
||||
return (
|
||||
'<div ' +
|
||||
'class="ol-scale-step-marker" ' +
|
||||
'style="position: ' +
|
||||
position +
|
||||
';' +
|
||||
'top: ' +
|
||||
top +
|
||||
'px;"' +
|
||||
'></div>'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,20 +429,31 @@ class ScaleLine extends Control {
|
||||
* @returns {string} The stringified div containing the step text
|
||||
*/
|
||||
createStepText(i, width, isLast, scale, suffix) {
|
||||
const length = i === 0 ? 0 : Math.round((scale / this.scaleBarSteps_ * i) * 100) / 100;
|
||||
const length =
|
||||
i === 0 ? 0 : Math.round((scale / this.scaleBarSteps_) * i * 100) / 100;
|
||||
const lengthString = length + (i === 0 ? '' : ' ' + suffix);
|
||||
const margin = i === 0 ? -3 : width / this.scaleBarSteps_ * -1;
|
||||
const minWidth = i === 0 ? 0 : width / this.scaleBarSteps_ * 2;
|
||||
return '<div ' +
|
||||
const margin = i === 0 ? -3 : (width / this.scaleBarSteps_) * -1;
|
||||
const minWidth = i === 0 ? 0 : (width / this.scaleBarSteps_) * 2;
|
||||
return (
|
||||
'<div ' +
|
||||
'class="ol-scale-step-text" ' +
|
||||
'style="' +
|
||||
'margin-left: ' + margin + 'px;' +
|
||||
'text-align: ' + (i === 0 ? 'left' : 'center') + '; ' +
|
||||
'min-width: ' + minWidth + 'px;' +
|
||||
'left: ' + (isLast ? width + 'px' : 'unset') + ';"' +
|
||||
'margin-left: ' +
|
||||
margin +
|
||||
'px;' +
|
||||
'text-align: ' +
|
||||
(i === 0 ? 'left' : 'center') +
|
||||
'; ' +
|
||||
'min-width: ' +
|
||||
minWidth +
|
||||
'px;' +
|
||||
'left: ' +
|
||||
(isLast ? width + 'px' : 'unset') +
|
||||
';"' +
|
||||
'>' +
|
||||
lengthString +
|
||||
'</div>';
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -459,5 +488,4 @@ export function render(mapEvent) {
|
||||
this.updateElement_();
|
||||
}
|
||||
|
||||
|
||||
export default ScaleLine;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
/**
|
||||
* @module ol/control/Zoom
|
||||
*/
|
||||
import EventType from '../events/EventType.js';
|
||||
import Control from './Control.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js';
|
||||
import {easeOut} from '../easing.js';
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {number} [duration=250] Animation duration in milliseconds.
|
||||
@@ -22,7 +21,6 @@ import {easeOut} from '../easing.js';
|
||||
* rendered outside of the map's viewport.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A control with 2 buttons, one for zoom in and one for zoom out.
|
||||
@@ -32,52 +30,68 @@ import {easeOut} from '../easing.js';
|
||||
* @api
|
||||
*/
|
||||
class Zoom extends Control {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Zoom options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super({
|
||||
element: document.createElement('div'),
|
||||
target: options.target
|
||||
target: options.target,
|
||||
});
|
||||
|
||||
const className = options.className !== undefined ? options.className : 'ol-zoom';
|
||||
const className =
|
||||
options.className !== undefined ? options.className : 'ol-zoom';
|
||||
|
||||
const delta = options.delta !== undefined ? options.delta : 1;
|
||||
|
||||
const zoomInLabel = options.zoomInLabel !== undefined ? options.zoomInLabel : '+';
|
||||
const zoomOutLabel = options.zoomOutLabel !== undefined ? options.zoomOutLabel : '\u2212';
|
||||
const zoomInLabel =
|
||||
options.zoomInLabel !== undefined ? options.zoomInLabel : '+';
|
||||
const zoomOutLabel =
|
||||
options.zoomOutLabel !== undefined ? options.zoomOutLabel : '\u2212';
|
||||
|
||||
const zoomInTipLabel = options.zoomInTipLabel !== undefined ?
|
||||
options.zoomInTipLabel : 'Zoom in';
|
||||
const zoomOutTipLabel = options.zoomOutTipLabel !== undefined ?
|
||||
options.zoomOutTipLabel : 'Zoom out';
|
||||
const zoomInTipLabel =
|
||||
options.zoomInTipLabel !== undefined ? options.zoomInTipLabel : 'Zoom in';
|
||||
const zoomOutTipLabel =
|
||||
options.zoomOutTipLabel !== undefined
|
||||
? options.zoomOutTipLabel
|
||||
: 'Zoom out';
|
||||
|
||||
const inElement = document.createElement('button');
|
||||
inElement.className = className + '-in';
|
||||
inElement.setAttribute('type', 'button');
|
||||
inElement.title = zoomInTipLabel;
|
||||
inElement.appendChild(
|
||||
typeof zoomInLabel === 'string' ? document.createTextNode(zoomInLabel) : zoomInLabel
|
||||
typeof zoomInLabel === 'string'
|
||||
? document.createTextNode(zoomInLabel)
|
||||
: zoomInLabel
|
||||
);
|
||||
|
||||
inElement.addEventListener(EventType.CLICK, this.handleClick_.bind(this, delta), false);
|
||||
inElement.addEventListener(
|
||||
EventType.CLICK,
|
||||
this.handleClick_.bind(this, delta),
|
||||
false
|
||||
);
|
||||
|
||||
const outElement = document.createElement('button');
|
||||
outElement.className = className + '-out';
|
||||
outElement.setAttribute('type', 'button');
|
||||
outElement.title = zoomOutTipLabel;
|
||||
outElement.appendChild(
|
||||
typeof zoomOutLabel === 'string' ? document.createTextNode(zoomOutLabel) : zoomOutLabel
|
||||
typeof zoomOutLabel === 'string'
|
||||
? document.createTextNode(zoomOutLabel)
|
||||
: zoomOutLabel
|
||||
);
|
||||
|
||||
outElement.addEventListener(EventType.CLICK, this.handleClick_.bind(this, -delta), false);
|
||||
outElement.addEventListener(
|
||||
EventType.CLICK,
|
||||
this.handleClick_.bind(this, -delta),
|
||||
false
|
||||
);
|
||||
|
||||
const cssClasses = className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL;
|
||||
const cssClasses =
|
||||
className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL;
|
||||
const element = this.element;
|
||||
element.className = cssClasses;
|
||||
element.appendChild(inElement);
|
||||
@@ -88,7 +102,6 @@ class Zoom extends Control {
|
||||
* @private
|
||||
*/
|
||||
this.duration_ = options.duration !== undefined ? options.duration : 250;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +136,7 @@ class Zoom extends Control {
|
||||
view.animate({
|
||||
zoom: newZoom,
|
||||
duration: this.duration_,
|
||||
easing: easeOut
|
||||
easing: easeOut,
|
||||
});
|
||||
} else {
|
||||
view.setZoom(newZoom);
|
||||
@@ -132,5 +145,4 @@ class Zoom extends Control {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Zoom;
|
||||
|
||||
@@ -4,14 +4,13 @@
|
||||
|
||||
import 'elm-pep';
|
||||
import Control from './Control.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import PointerEventType from '../pointer/EventType.js';
|
||||
import {CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js';
|
||||
import {clamp} from '../math.js';
|
||||
import {easeOut} from '../easing.js';
|
||||
import {listen, unlistenByKey} from '../events.js';
|
||||
import {stopPropagation} from '../events/Event.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {clamp} from '../math.js';
|
||||
import PointerEventType from '../pointer/EventType.js';
|
||||
|
||||
|
||||
/**
|
||||
* The enum for available directions.
|
||||
@@ -20,10 +19,9 @@ import PointerEventType from '../pointer/EventType.js';
|
||||
*/
|
||||
const Direction = {
|
||||
VERTICAL: 0,
|
||||
HORIZONTAL: 1
|
||||
HORIZONTAL: 1,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {string} [className='ol-zoomslider'] CSS class name.
|
||||
@@ -32,7 +30,6 @@ const Direction = {
|
||||
* should be re-rendered. This is called in a `requestAnimationFrame` callback.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A slider type of control for zooming.
|
||||
@@ -44,23 +41,21 @@ const Direction = {
|
||||
* @api
|
||||
*/
|
||||
class ZoomSlider extends Control {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Zoom slider options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super({
|
||||
element: document.createElement('div'),
|
||||
render: options.render || render
|
||||
render: options.render || render,
|
||||
});
|
||||
|
||||
/**
|
||||
* @type {!Array.<import("../events.js").EventsKey>}
|
||||
* @private
|
||||
*/
|
||||
* @type {!Array.<import("../events.js").EventsKey>}
|
||||
* @private
|
||||
*/
|
||||
this.dragListenerKeys_ = [];
|
||||
|
||||
/**
|
||||
@@ -131,19 +126,37 @@ class ZoomSlider extends Control {
|
||||
*/
|
||||
this.duration_ = options.duration !== undefined ? options.duration : 200;
|
||||
|
||||
const className = options.className !== undefined ? options.className : 'ol-zoomslider';
|
||||
const className =
|
||||
options.className !== undefined ? options.className : 'ol-zoomslider';
|
||||
const thumbElement = document.createElement('button');
|
||||
thumbElement.setAttribute('type', 'button');
|
||||
thumbElement.className = className + '-thumb ' + CLASS_UNSELECTABLE;
|
||||
const containerElement = this.element;
|
||||
containerElement.className = className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL;
|
||||
containerElement.className =
|
||||
className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL;
|
||||
containerElement.appendChild(thumbElement);
|
||||
|
||||
containerElement.addEventListener(PointerEventType.POINTERDOWN, this.handleDraggerStart_.bind(this), false);
|
||||
containerElement.addEventListener(PointerEventType.POINTERMOVE, this.handleDraggerDrag_.bind(this), false);
|
||||
containerElement.addEventListener(PointerEventType.POINTERUP, this.handleDraggerEnd_.bind(this), false);
|
||||
containerElement.addEventListener(
|
||||
PointerEventType.POINTERDOWN,
|
||||
this.handleDraggerStart_.bind(this),
|
||||
false
|
||||
);
|
||||
containerElement.addEventListener(
|
||||
PointerEventType.POINTERMOVE,
|
||||
this.handleDraggerDrag_.bind(this),
|
||||
false
|
||||
);
|
||||
containerElement.addEventListener(
|
||||
PointerEventType.POINTERUP,
|
||||
this.handleDraggerEnd_.bind(this),
|
||||
false
|
||||
);
|
||||
|
||||
containerElement.addEventListener(EventType.CLICK, this.handleContainerClick_.bind(this), false);
|
||||
containerElement.addEventListener(
|
||||
EventType.CLICK,
|
||||
this.handleContainerClick_.bind(this),
|
||||
false
|
||||
);
|
||||
thumbElement.addEventListener(EventType.CLICK, stopPropagation, false);
|
||||
}
|
||||
|
||||
@@ -171,17 +184,20 @@ class ZoomSlider extends Control {
|
||||
initSlider_() {
|
||||
const container = this.element;
|
||||
const containerSize = {
|
||||
width: container.offsetWidth, height: container.offsetHeight
|
||||
width: container.offsetWidth,
|
||||
height: container.offsetHeight,
|
||||
};
|
||||
|
||||
const thumb = /** @type {HTMLElement} */ (container.firstElementChild);
|
||||
const computedStyle = getComputedStyle(thumb);
|
||||
const thumbWidth = thumb.offsetWidth +
|
||||
parseFloat(computedStyle['marginRight']) +
|
||||
parseFloat(computedStyle['marginLeft']);
|
||||
const thumbHeight = thumb.offsetHeight +
|
||||
parseFloat(computedStyle['marginTop']) +
|
||||
parseFloat(computedStyle['marginBottom']);
|
||||
const thumbWidth =
|
||||
thumb.offsetWidth +
|
||||
parseFloat(computedStyle['marginRight']) +
|
||||
parseFloat(computedStyle['marginLeft']);
|
||||
const thumbHeight =
|
||||
thumb.offsetHeight +
|
||||
parseFloat(computedStyle['marginTop']) +
|
||||
parseFloat(computedStyle['marginBottom']);
|
||||
this.thumbSize_ = [thumbWidth, thumbHeight];
|
||||
|
||||
if (containerSize.width > containerSize.height) {
|
||||
@@ -203,7 +219,8 @@ class ZoomSlider extends Control {
|
||||
|
||||
const relativePosition = this.getRelativePosition_(
|
||||
event.offsetX - this.thumbSize_[0] / 2,
|
||||
event.offsetY - this.thumbSize_[1] / 2);
|
||||
event.offsetY - this.thumbSize_[1] / 2
|
||||
);
|
||||
|
||||
const resolution = this.getResolutionForPosition_(relativePosition);
|
||||
const zoom = view.getConstrainedZoom(view.getZoomForResolution(resolution));
|
||||
@@ -211,7 +228,7 @@ class ZoomSlider extends Control {
|
||||
view.animateInternal({
|
||||
zoom: zoom,
|
||||
duration: this.duration_,
|
||||
easing: easeOut
|
||||
easing: easeOut,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -222,7 +239,8 @@ class ZoomSlider extends Control {
|
||||
*/
|
||||
handleDraggerStart_(event) {
|
||||
if (!this.dragging_ && event.target === this.element.firstElementChild) {
|
||||
const element = /** @type {HTMLElement} */ (this.element.firstElementChild);
|
||||
const element = /** @type {HTMLElement} */ (this.element
|
||||
.firstElementChild);
|
||||
this.getMap().getView().beginInteraction();
|
||||
this.startX_ = event.clientX - parseFloat(element.style.left);
|
||||
this.startY_ = event.clientY - parseFloat(element.style.top);
|
||||
@@ -250,7 +268,9 @@ class ZoomSlider extends Control {
|
||||
const deltaX = event.clientX - this.startX_;
|
||||
const deltaY = event.clientY - this.startY_;
|
||||
const relativePosition = this.getRelativePosition_(deltaX, deltaY);
|
||||
this.currentResolution_ = this.getResolutionForPosition_(relativePosition);
|
||||
this.currentResolution_ = this.getResolutionForPosition_(
|
||||
relativePosition
|
||||
);
|
||||
this.getMap().getView().setResolution(this.currentResolution_);
|
||||
}
|
||||
}
|
||||
@@ -338,7 +358,6 @@ class ZoomSlider extends Control {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the zoomslider element.
|
||||
* @param {import("../MapEvent.js").default} mapEvent Map event.
|
||||
@@ -356,5 +375,4 @@ export function render(mapEvent) {
|
||||
this.setThumbPosition_(res);
|
||||
}
|
||||
|
||||
|
||||
export default ZoomSlider;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
/**
|
||||
* @module ol/control/ZoomToExtent
|
||||
*/
|
||||
import EventType from '../events/EventType.js';
|
||||
import {fromExtent as polygonFromExtent} from '../geom/Polygon.js';
|
||||
import Control from './Control.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js';
|
||||
|
||||
import {fromExtent as polygonFromExtent} from '../geom/Polygon.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
@@ -19,7 +18,6 @@ import {CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js';
|
||||
* extent of the view projection is used.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A button control which, when pressed, changes the map view to a specific
|
||||
@@ -28,7 +26,6 @@ import {CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js';
|
||||
* @api
|
||||
*/
|
||||
class ZoomToExtent extends Control {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
@@ -37,7 +34,7 @@ class ZoomToExtent extends Control {
|
||||
|
||||
super({
|
||||
element: document.createElement('div'),
|
||||
target: options.target
|
||||
target: options.target,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -46,10 +43,12 @@ class ZoomToExtent extends Control {
|
||||
*/
|
||||
this.extent = options.extent ? options.extent : null;
|
||||
|
||||
const className = options.className !== undefined ? options.className : 'ol-zoom-extent';
|
||||
const className =
|
||||
options.className !== undefined ? options.className : 'ol-zoom-extent';
|
||||
|
||||
const label = options.label !== undefined ? options.label : 'E';
|
||||
const tipLabel = options.tipLabel !== undefined ? options.tipLabel : 'Fit to extent';
|
||||
const tipLabel =
|
||||
options.tipLabel !== undefined ? options.tipLabel : 'Fit to extent';
|
||||
const button = document.createElement('button');
|
||||
button.setAttribute('type', 'button');
|
||||
button.title = tipLabel;
|
||||
@@ -57,9 +56,14 @@ class ZoomToExtent extends Control {
|
||||
typeof label === 'string' ? document.createTextNode(label) : label
|
||||
);
|
||||
|
||||
button.addEventListener(EventType.CLICK, this.handleClick_.bind(this), false);
|
||||
button.addEventListener(
|
||||
EventType.CLICK,
|
||||
this.handleClick_.bind(this),
|
||||
false
|
||||
);
|
||||
|
||||
const cssClasses = className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL;
|
||||
const cssClasses =
|
||||
className + ' ' + CLASS_UNSELECTABLE + ' ' + CLASS_CONTROL;
|
||||
const element = this.element;
|
||||
element.className = cssClasses;
|
||||
element.appendChild(button);
|
||||
@@ -80,7 +84,9 @@ class ZoomToExtent extends Control {
|
||||
handleZoomToExtent() {
|
||||
const map = this.getMap();
|
||||
const view = map.getView();
|
||||
const extent = !this.extent ? view.getProjection().getExtent() : this.extent;
|
||||
const extent = !this.extent
|
||||
? view.getProjection().getExtent()
|
||||
: this.extent;
|
||||
view.fitInternal(polygonFromExtent(extent));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* @module ol/coordinate
|
||||
*/
|
||||
import {getWidth} from './extent.js';
|
||||
import {modulo} from './math.js';
|
||||
import {padNumber} from './string.js';
|
||||
import {getWidth} from './extent.js';
|
||||
|
||||
|
||||
/**
|
||||
* An array of numbers representing an xy coordinate. Example: `[16, 48]`.
|
||||
@@ -12,7 +11,6 @@ import {getWidth} from './extent.js';
|
||||
* @api
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* A function that takes a {@link module:ol/coordinate~Coordinate} and
|
||||
* transforms it into a `{string}`.
|
||||
@@ -21,7 +19,6 @@ import {getWidth} from './extent.js';
|
||||
* @api
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Add `delta` to `coordinate`. `coordinate` is modified in place and returned
|
||||
* by the function.
|
||||
@@ -46,7 +43,6 @@ export function add(coordinate, delta) {
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the point closest to the passed coordinate on the passed circle.
|
||||
*
|
||||
@@ -69,13 +65,12 @@ export function closestOnCircle(coordinate, circle) {
|
||||
}
|
||||
const d = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
const x = x0 + r * dx / d;
|
||||
const y = y0 + r * dy / d;
|
||||
const x = x0 + (r * dx) / d;
|
||||
const y = y0 + (r * dy) / d;
|
||||
|
||||
return [x, y];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the point closest to the passed coordinate on the passed segment.
|
||||
* This is the foot of the perpendicular of the coordinate to the segment when
|
||||
@@ -99,8 +94,10 @@ export function closestOnSegment(coordinate, segment) {
|
||||
const y2 = end[1];
|
||||
const dx = x2 - x1;
|
||||
const dy = y2 - y1;
|
||||
const along = (dx === 0 && dy === 0) ? 0 :
|
||||
((dx * (x0 - x1)) + (dy * (y0 - y1))) / ((dx * dx + dy * dy) || 0);
|
||||
const along =
|
||||
dx === 0 && dy === 0
|
||||
? 0
|
||||
: (dx * (x0 - x1) + dy * (y0 - y1)) / (dx * dx + dy * dy || 0);
|
||||
let x, y;
|
||||
if (along <= 0) {
|
||||
x = x1;
|
||||
@@ -115,7 +112,6 @@ export function closestOnSegment(coordinate, segment) {
|
||||
return [x, y];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a {@link module:ol/coordinate~CoordinateFormat} function that can be
|
||||
* used to format
|
||||
@@ -150,13 +146,12 @@ export function createStringXY(opt_fractionDigits) {
|
||||
* @param {Coordinate} coordinate Coordinate.
|
||||
* @return {string} String XY.
|
||||
*/
|
||||
function(coordinate) {
|
||||
function (coordinate) {
|
||||
return toStringXY(coordinate, opt_fractionDigits);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} hemispheres Hemispheres.
|
||||
* @param {number} degrees Degrees.
|
||||
@@ -172,7 +167,7 @@ export function degreesToStringHDMS(hemispheres, degrees, opt_fractionDigits) {
|
||||
|
||||
let deg = Math.floor(x / 3600);
|
||||
let min = Math.floor((x - deg * 3600) / 60);
|
||||
let sec = x - (deg * 3600) - (min * 60);
|
||||
let sec = x - deg * 3600 - min * 60;
|
||||
sec = Math.ceil(sec * precision) / precision;
|
||||
|
||||
if (sec >= 60) {
|
||||
@@ -185,12 +180,19 @@ export function degreesToStringHDMS(hemispheres, degrees, opt_fractionDigits) {
|
||||
deg += 1;
|
||||
}
|
||||
|
||||
return deg + '\u00b0 ' + padNumber(min, 2) + '\u2032 ' +
|
||||
padNumber(sec, 2, dflPrecision) + '\u2033' +
|
||||
(normalizedDegrees == 0 ? '' : ' ' + hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0));
|
||||
return (
|
||||
deg +
|
||||
'\u00b0 ' +
|
||||
padNumber(min, 2) +
|
||||
'\u2032 ' +
|
||||
padNumber(sec, 2, dflPrecision) +
|
||||
'\u2033' +
|
||||
(normalizedDegrees == 0
|
||||
? ''
|
||||
: ' ' + hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transforms the given {@link module:ol/coordinate~Coordinate} to a string
|
||||
* using the given string template. The strings `{x}` and `{y}` in the template
|
||||
@@ -232,7 +234,6 @@ export function format(coordinate, template, opt_fractionDigits) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Coordinate} coordinate1 First coordinate.
|
||||
* @param {Coordinate} coordinate2 Second coordinate.
|
||||
@@ -249,7 +250,6 @@ export function equals(coordinate1, coordinate2) {
|
||||
return equals;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rotate `coordinate` by `angle`. `coordinate` is modified in place and
|
||||
* returned by the function.
|
||||
@@ -278,7 +278,6 @@ export function rotate(coordinate, angle) {
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scale `coordinate` by `scale`. `coordinate` is modified in place and returned
|
||||
* by the function.
|
||||
@@ -302,7 +301,6 @@ export function scale(coordinate, scale) {
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Coordinate} coord1 First coordinate.
|
||||
* @param {Coordinate} coord2 Second coordinate.
|
||||
@@ -314,7 +312,6 @@ export function squaredDistance(coord1, coord2) {
|
||||
return dx * dx + dy * dy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Coordinate} coord1 First coordinate.
|
||||
* @param {Coordinate} coord2 Second coordinate.
|
||||
@@ -324,7 +321,6 @@ export function distance(coord1, coord2) {
|
||||
return Math.sqrt(squaredDistance(coord1, coord2));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the squared distance from a coordinate to a line segment.
|
||||
*
|
||||
@@ -334,11 +330,9 @@ export function distance(coord1, coord2) {
|
||||
* @return {number} Squared distance from the point to the line segment.
|
||||
*/
|
||||
export function squaredDistanceToSegment(coordinate, segment) {
|
||||
return squaredDistance(coordinate,
|
||||
closestOnSegment(coordinate, segment));
|
||||
return squaredDistance(coordinate, closestOnSegment(coordinate, segment));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format a geographic coordinate with the hemisphere, degrees, minutes, and
|
||||
* seconds.
|
||||
@@ -367,14 +361,16 @@ export function squaredDistanceToSegment(coordinate, segment) {
|
||||
*/
|
||||
export function toStringHDMS(coordinate, opt_fractionDigits) {
|
||||
if (coordinate) {
|
||||
return degreesToStringHDMS('NS', coordinate[1], opt_fractionDigits) + ' ' +
|
||||
degreesToStringHDMS('EW', coordinate[0], opt_fractionDigits);
|
||||
return (
|
||||
degreesToStringHDMS('NS', coordinate[1], opt_fractionDigits) +
|
||||
' ' +
|
||||
degreesToStringHDMS('EW', coordinate[0], opt_fractionDigits)
|
||||
);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format a coordinate as a comma delimited string.
|
||||
*
|
||||
@@ -404,7 +400,6 @@ export function toStringXY(coordinate, opt_fractionDigits) {
|
||||
return format(coordinate, '{x}, {y}', opt_fractionDigits);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Modifies the provided coordinate in-place to be within the real world
|
||||
* extent. The lower projection extent boundary is inclusive, the upper one
|
||||
@@ -416,10 +411,16 @@ export function toStringXY(coordinate, opt_fractionDigits) {
|
||||
*/
|
||||
export function wrapX(coordinate, projection) {
|
||||
const projectionExtent = projection.getExtent();
|
||||
if (projection.canWrapX() && (coordinate[0] < projectionExtent[0] || coordinate[0] >= projectionExtent[2])) {
|
||||
if (
|
||||
projection.canWrapX() &&
|
||||
(coordinate[0] < projectionExtent[0] ||
|
||||
coordinate[0] >= projectionExtent[2])
|
||||
) {
|
||||
const worldWidth = getWidth(projectionExtent);
|
||||
const worldsAway = Math.floor((coordinate[0] - projectionExtent[0]) / worldWidth);
|
||||
coordinate[0] -= (worldsAway * worldWidth);
|
||||
const worldsAway = Math.floor(
|
||||
(coordinate[0] - projectionExtent[0]) / worldWidth
|
||||
);
|
||||
coordinate[0] -= worldsAway * worldWidth;
|
||||
}
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* @property {Array<string>} families
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* The CSS class for hidden feature.
|
||||
*
|
||||
@@ -22,7 +21,6 @@
|
||||
*/
|
||||
export const CLASS_HIDDEN = 'ol-hidden';
|
||||
|
||||
|
||||
/**
|
||||
* The CSS class that we'll give the DOM elements to have them selectable.
|
||||
*
|
||||
@@ -31,7 +29,6 @@ export const CLASS_HIDDEN = 'ol-hidden';
|
||||
*/
|
||||
export const CLASS_SELECTABLE = 'ol-selectable';
|
||||
|
||||
|
||||
/**
|
||||
* The CSS class that we'll give the DOM elements to have them unselectable.
|
||||
*
|
||||
@@ -40,7 +37,6 @@ export const CLASS_SELECTABLE = 'ol-selectable';
|
||||
*/
|
||||
export const CLASS_UNSELECTABLE = 'ol-unselectable';
|
||||
|
||||
|
||||
/**
|
||||
* The CSS class for unsupported feature.
|
||||
*
|
||||
@@ -49,7 +45,6 @@ export const CLASS_UNSELECTABLE = 'ol-unselectable';
|
||||
*/
|
||||
export const CLASS_UNSUPPORTED = 'ol-unsupported';
|
||||
|
||||
|
||||
/**
|
||||
* The CSS class for controls.
|
||||
*
|
||||
@@ -58,7 +53,6 @@ export const CLASS_UNSUPPORTED = 'ol-unsupported';
|
||||
*/
|
||||
export const CLASS_CONTROL = 'ol-control';
|
||||
|
||||
|
||||
/**
|
||||
* The CSS class that we'll give the DOM elements that are collapsed, i.e.
|
||||
* to those elements which usually can be expanded.
|
||||
@@ -72,22 +66,25 @@ export const CLASS_COLLAPSED = 'ol-collapsed';
|
||||
* From http://stackoverflow.com/questions/10135697/regex-to-parse-any-css-font
|
||||
* @type {RegExp}
|
||||
*/
|
||||
const fontRegEx = new RegExp([
|
||||
'^\\s*(?=(?:(?:[-a-z]+\\s*){0,2}(italic|oblique))?)',
|
||||
'(?=(?:(?:[-a-z]+\\s*){0,2}(small-caps))?)',
|
||||
'(?=(?:(?:[-a-z]+\\s*){0,2}(bold(?:er)?|lighter|[1-9]00 ))?)',
|
||||
'(?:(?:normal|\\1|\\2|\\3)\\s*){0,3}((?:xx?-)?',
|
||||
'(?:small|large)|medium|smaller|larger|[\\.\\d]+(?:\\%|in|[cem]m|ex|p[ctx]))',
|
||||
'(?:\\s*\\/\\s*(normal|[\\.\\d]+(?:\\%|in|[cem]m|ex|p[ctx])?))',
|
||||
'?\\s*([-,\\"\\\'\\sa-z]+?)\\s*$'
|
||||
].join(''), 'i');
|
||||
const fontRegEx = new RegExp(
|
||||
[
|
||||
'^\\s*(?=(?:(?:[-a-z]+\\s*){0,2}(italic|oblique))?)',
|
||||
'(?=(?:(?:[-a-z]+\\s*){0,2}(small-caps))?)',
|
||||
'(?=(?:(?:[-a-z]+\\s*){0,2}(bold(?:er)?|lighter|[1-9]00 ))?)',
|
||||
'(?:(?:normal|\\1|\\2|\\3)\\s*){0,3}((?:xx?-)?',
|
||||
'(?:small|large)|medium|smaller|larger|[\\.\\d]+(?:\\%|in|[cem]m|ex|p[ctx]))',
|
||||
'(?:\\s*\\/\\s*(normal|[\\.\\d]+(?:\\%|in|[cem]m|ex|p[ctx])?))',
|
||||
'?\\s*([-,\\"\\\'\\sa-z]+?)\\s*$',
|
||||
].join(''),
|
||||
'i'
|
||||
);
|
||||
const fontRegExMatchIndex = [
|
||||
'style',
|
||||
'variant',
|
||||
'weight',
|
||||
'size',
|
||||
'lineHeight',
|
||||
'family'
|
||||
'family',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -96,7 +93,7 @@ const fontRegExMatchIndex = [
|
||||
* @param {string} fontSpec The CSS font property.
|
||||
* @return {FontParameters} The font parameters (or null if the input spec is invalid).
|
||||
*/
|
||||
export const getFontParameters = function(fontSpec) {
|
||||
export const getFontParameters = function (fontSpec) {
|
||||
const match = fontSpec.match(fontRegEx);
|
||||
if (!match) {
|
||||
return null;
|
||||
@@ -106,7 +103,7 @@ export const getFontParameters = function(fontSpec) {
|
||||
size: '1.2em',
|
||||
style: 'normal',
|
||||
weight: 'normal',
|
||||
variant: 'normal'
|
||||
variant: 'normal',
|
||||
});
|
||||
for (let i = 0, ii = fontRegExMatchIndex.length; i < ii; ++i) {
|
||||
const value = match[i + 1];
|
||||
|
||||
@@ -4,7 +4,6 @@ import {WORKER_OFFSCREEN_CANVAS} from './has.js';
|
||||
* @module ol/dom
|
||||
*/
|
||||
|
||||
|
||||
//FIXME Move this function to the canvas module
|
||||
/**
|
||||
* Create an html canvas element and returns its 2d context.
|
||||
@@ -14,11 +13,12 @@ import {WORKER_OFFSCREEN_CANVAS} from './has.js';
|
||||
* @return {CanvasRenderingContext2D} The context.
|
||||
*/
|
||||
export function createCanvasContext2D(opt_width, opt_height, opt_canvasPool) {
|
||||
const canvas = opt_canvasPool && opt_canvasPool.length ?
|
||||
opt_canvasPool.shift() :
|
||||
WORKER_OFFSCREEN_CANVAS ?
|
||||
new OffscreenCanvas(opt_width || 300, opt_height || 300) :
|
||||
document.createElement('canvas');
|
||||
const canvas =
|
||||
opt_canvasPool && opt_canvasPool.length
|
||||
? opt_canvasPool.shift()
|
||||
: WORKER_OFFSCREEN_CANVAS
|
||||
? new OffscreenCanvas(opt_width || 300, opt_height || 300)
|
||||
: document.createElement('canvas');
|
||||
if (opt_width) {
|
||||
canvas.width = opt_width;
|
||||
}
|
||||
@@ -29,7 +29,6 @@ export function createCanvasContext2D(opt_width, opt_height, opt_canvasPool) {
|
||||
return /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current computed width for the given element including margin,
|
||||
* padding and border.
|
||||
@@ -45,7 +44,6 @@ export function outerWidth(element) {
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current computed height for the given element including margin,
|
||||
* padding and border.
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/easing
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Start slow and speed up.
|
||||
* @param {number} t Input between 0 and 1.
|
||||
@@ -13,7 +12,6 @@ export function easeIn(t) {
|
||||
return Math.pow(t, 3);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start fast and slow down.
|
||||
* @param {number} t Input between 0 and 1.
|
||||
@@ -24,7 +22,6 @@ export function easeOut(t) {
|
||||
return 1 - easeIn(1 - t);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start slow, speed up, and then slow down again.
|
||||
* @param {number} t Input between 0 and 1.
|
||||
@@ -35,7 +32,6 @@ export function inAndOut(t) {
|
||||
return 3 * t * t - 2 * t * t * t;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Maintain a constant speed over time.
|
||||
* @param {number} t Input between 0 and 1.
|
||||
@@ -46,7 +42,6 @@ export function linear(t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start slow, speed up, and at the very end slow down again. This has the
|
||||
* same general behavior as {@link module:ol/easing~inAndOut}, but the final
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import {clear} from './obj.js';
|
||||
|
||||
|
||||
/**
|
||||
* Key to use with {@link module:ol/Observable~Observable#unByKey}.
|
||||
* @typedef {Object} EventsKey
|
||||
@@ -51,7 +50,7 @@ export function listen(target, type, listener, opt_this, opt_once) {
|
||||
}
|
||||
if (opt_once) {
|
||||
const originalListener = listener;
|
||||
listener = function() {
|
||||
listener = function () {
|
||||
target.removeEventListener(type, listener);
|
||||
originalListener.apply(this, arguments);
|
||||
};
|
||||
@@ -59,13 +58,12 @@ export function listen(target, type, listener, opt_this, opt_once) {
|
||||
const eventsKey = {
|
||||
target: target,
|
||||
type: type,
|
||||
listener: listener
|
||||
listener: listener,
|
||||
};
|
||||
target.addEventListener(type, listener);
|
||||
return eventsKey;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registers a one-off event listener on an event target. Inspired by
|
||||
* https://google.github.io/closure-library/api/source/closure/goog/events/events.js.src.html
|
||||
@@ -90,7 +88,6 @@ export function listenOnce(target, type, listener, opt_this) {
|
||||
return listen(target, type, listener, opt_this, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unregisters event listeners on an event target. Inspired by
|
||||
* https://google.github.io/closure-library/api/source/closure/goog/events/events.js.src.html
|
||||
|
||||
@@ -13,12 +13,10 @@
|
||||
* {@link module:ol/events/Target~Target}.
|
||||
*/
|
||||
class BaseEvent {
|
||||
|
||||
/**
|
||||
* @param {string} type Type.
|
||||
*/
|
||||
constructor(type) {
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
@@ -54,10 +52,8 @@ class BaseEvent {
|
||||
stopPropagation() {
|
||||
this.propagationStopped = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Event|import("./Event.js").default} evt Event
|
||||
*/
|
||||
@@ -65,7 +61,6 @@ export function stopPropagation(evt) {
|
||||
evt.stopPropagation();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Event|import("./Event.js").default} evt Event
|
||||
*/
|
||||
|
||||
@@ -35,5 +35,5 @@ export default {
|
||||
LOAD: 'load',
|
||||
RESIZE: 'resize',
|
||||
TOUCHMOVE: 'touchmove',
|
||||
WHEEL: 'wheel'
|
||||
WHEEL: 'wheel',
|
||||
};
|
||||
|
||||
@@ -10,5 +10,5 @@ export default {
|
||||
LEFT: 37,
|
||||
UP: 38,
|
||||
RIGHT: 39,
|
||||
DOWN: 40
|
||||
DOWN: 40,
|
||||
};
|
||||
|
||||
@@ -2,16 +2,14 @@
|
||||
* @module ol/events/Target
|
||||
*/
|
||||
import Disposable from '../Disposable.js';
|
||||
import {VOID} from '../functions.js';
|
||||
import Event from './Event.js';
|
||||
import {VOID} from '../functions.js';
|
||||
import {clear} from '../obj.js';
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {EventTarget|Target} EventTargetLike
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A simplified implementation of the W3C DOM Level 2 EventTarget interface.
|
||||
@@ -28,12 +26,10 @@ import {clear} from '../obj.js';
|
||||
* returns false.
|
||||
*/
|
||||
class Target extends Disposable {
|
||||
|
||||
/**
|
||||
* @param {*=} opt_target Default event target for dispatched events.
|
||||
*/
|
||||
constructor(opt_target) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -59,7 +55,6 @@ class Target extends Disposable {
|
||||
* @type {!Object<string, Array<import("../events.js").Listener>>}
|
||||
*/
|
||||
this.listeners_ = {};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,9 +102,13 @@ class Target extends Disposable {
|
||||
++this.dispatching_[type];
|
||||
for (let i = 0, ii = listeners.length; i < ii; ++i) {
|
||||
if ('handleEvent' in listeners[i]) {
|
||||
propagate = /** @type {import("../events.js").ListenerObject} */ (listeners[i]).handleEvent(evt);
|
||||
propagate = /** @type {import("../events.js").ListenerObject} */ (listeners[
|
||||
i
|
||||
]).handleEvent(evt);
|
||||
} else {
|
||||
propagate = /** @type {import("../events.js").ListenerFunction} */ (listeners[i]).call(this, evt);
|
||||
propagate = /** @type {import("../events.js").ListenerFunction} */ (listeners[
|
||||
i
|
||||
]).call(this, evt);
|
||||
}
|
||||
if (propagate === false || evt.propagationStopped) {
|
||||
propagate = false;
|
||||
@@ -153,9 +152,9 @@ class Target extends Disposable {
|
||||
* @return {boolean} Has listeners.
|
||||
*/
|
||||
hasListener(opt_type) {
|
||||
return opt_type ?
|
||||
opt_type in this.listeners_ :
|
||||
Object.keys(this.listeners_).length > 0;
|
||||
return opt_type
|
||||
? opt_type in this.listeners_
|
||||
: Object.keys(this.listeners_).length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,5 +181,4 @@ class Target extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Target;
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
* @module ol/events/condition
|
||||
*/
|
||||
import MapBrowserEventType from '../MapBrowserEventType.js';
|
||||
import {FALSE, TRUE} from '../functions.js';
|
||||
import {MAC, WEBKIT} from '../has.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {TRUE, FALSE} from '../functions.js';
|
||||
import {WEBKIT, MAC} from '../has.js';
|
||||
|
||||
|
||||
/**
|
||||
* A function that takes an {@link module:ol/MapBrowserEvent} and returns a
|
||||
@@ -14,7 +13,6 @@ import {WEBKIT, MAC} from '../has.js';
|
||||
* @typedef {function(this: ?, import("../MapBrowserEvent.js").default): boolean} Condition
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if only the alt-key is pressed, `false` otherwise (e.g. when
|
||||
* additionally the shift-key is pressed).
|
||||
@@ -23,15 +21,15 @@ import {WEBKIT, MAC} from '../has.js';
|
||||
* @return {boolean} True if only the alt key is pressed.
|
||||
* @api
|
||||
*/
|
||||
export const altKeyOnly = function(mapBrowserEvent) {
|
||||
export const altKeyOnly = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return (
|
||||
originalEvent.altKey &&
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
!originalEvent.shiftKey);
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
!originalEvent.shiftKey
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if only the alt-key and shift-key is pressed, `false` otherwise
|
||||
* (e.g. when additionally the platform-modifier-key is pressed).
|
||||
@@ -40,15 +38,15 @@ export const altKeyOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if only the alt and shift keys are pressed.
|
||||
* @api
|
||||
*/
|
||||
export const altShiftKeysOnly = function(mapBrowserEvent) {
|
||||
export const altShiftKeysOnly = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return (
|
||||
originalEvent.altKey &&
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
originalEvent.shiftKey);
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
originalEvent.shiftKey
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the map has the focus. This condition requires a map target
|
||||
* element with a `tabindex` attribute, e.g. `<div id="map" tabindex="1">`.
|
||||
@@ -57,11 +55,10 @@ export const altShiftKeysOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} The map has the focus.
|
||||
* @api
|
||||
*/
|
||||
export const focus = function(event) {
|
||||
export const focus = function (event) {
|
||||
return event.target.getTargetElement().contains(document.activeElement);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return always true.
|
||||
*
|
||||
@@ -71,7 +68,6 @@ export const focus = function(event) {
|
||||
*/
|
||||
export const always = TRUE;
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the event is a `click` event, `false` otherwise.
|
||||
*
|
||||
@@ -79,11 +75,10 @@ export const always = TRUE;
|
||||
* @return {boolean} True if the event is a map `click` event.
|
||||
* @api
|
||||
*/
|
||||
export const click = function(mapBrowserEvent) {
|
||||
export const click = function (mapBrowserEvent) {
|
||||
return mapBrowserEvent.type == MapBrowserEventType.CLICK;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the event has an "action"-producing mouse button.
|
||||
*
|
||||
@@ -93,13 +88,11 @@ export const click = function(mapBrowserEvent) {
|
||||
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Map browser event.
|
||||
* @return {boolean} The result.
|
||||
*/
|
||||
export const mouseActionButton = function(mapBrowserEvent) {
|
||||
export const mouseActionButton = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {MouseEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return originalEvent.button == 0 &&
|
||||
!(WEBKIT && MAC && originalEvent.ctrlKey);
|
||||
return originalEvent.button == 0 && !(WEBKIT && MAC && originalEvent.ctrlKey);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return always false.
|
||||
*
|
||||
@@ -109,7 +102,6 @@ export const mouseActionButton = function(mapBrowserEvent) {
|
||||
*/
|
||||
export const never = FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the browser event is a `pointermove` event, `false`
|
||||
* otherwise.
|
||||
@@ -118,11 +110,10 @@ export const never = FALSE;
|
||||
* @return {boolean} True if the browser event is a `pointermove` event.
|
||||
* @api
|
||||
*/
|
||||
export const pointerMove = function(mapBrowserEvent) {
|
||||
export const pointerMove = function (mapBrowserEvent) {
|
||||
return mapBrowserEvent.type == 'pointermove';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the event is a map `singleclick` event, `false` otherwise.
|
||||
*
|
||||
@@ -130,11 +121,10 @@ export const pointerMove = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event is a map `singleclick` event.
|
||||
* @api
|
||||
*/
|
||||
export const singleClick = function(mapBrowserEvent) {
|
||||
export const singleClick = function (mapBrowserEvent) {
|
||||
return mapBrowserEvent.type == MapBrowserEventType.SINGLECLICK;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the event is a map `dblclick` event, `false` otherwise.
|
||||
*
|
||||
@@ -142,11 +132,10 @@ export const singleClick = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event is a map `dblclick` event.
|
||||
* @api
|
||||
*/
|
||||
export const doubleClick = function(mapBrowserEvent) {
|
||||
export const doubleClick = function (mapBrowserEvent) {
|
||||
return mapBrowserEvent.type == MapBrowserEventType.DBLCLICK;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if no modifier key (alt-, shift- or platform-modifier-key) is
|
||||
* pressed.
|
||||
@@ -155,15 +144,15 @@ export const doubleClick = function(mapBrowserEvent) {
|
||||
* @return {boolean} True only if there no modifier keys are pressed.
|
||||
* @api
|
||||
*/
|
||||
export const noModifierKeys = function(mapBrowserEvent) {
|
||||
export const noModifierKeys = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return (
|
||||
!originalEvent.altKey &&
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
!originalEvent.shiftKey);
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
!originalEvent.shiftKey
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if only the platform-modifier-key (the meta-key on Mac,
|
||||
* ctrl-key otherwise) is pressed, `false` otherwise (e.g. when additionally
|
||||
@@ -173,14 +162,15 @@ export const noModifierKeys = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if only the platform modifier key is pressed.
|
||||
* @api
|
||||
*/
|
||||
export const platformModifierKeyOnly = function(mapBrowserEvent) {
|
||||
export const platformModifierKeyOnly = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return !originalEvent.altKey &&
|
||||
return (
|
||||
!originalEvent.altKey &&
|
||||
(MAC ? originalEvent.metaKey : originalEvent.ctrlKey) &&
|
||||
!originalEvent.shiftKey;
|
||||
!originalEvent.shiftKey
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if only the shift-key is pressed, `false` otherwise (e.g. when
|
||||
* additionally the alt-key is pressed).
|
||||
@@ -189,15 +179,15 @@ export const platformModifierKeyOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if only the shift key is pressed.
|
||||
* @api
|
||||
*/
|
||||
export const shiftKeyOnly = function(mapBrowserEvent) {
|
||||
export const shiftKeyOnly = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
return (
|
||||
!originalEvent.altKey &&
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
originalEvent.shiftKey);
|
||||
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
|
||||
originalEvent.shiftKey
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the target element is not editable, i.e. not a `<input>`-,
|
||||
* `<select>`- or `<textarea>`-element, `false` otherwise.
|
||||
@@ -206,13 +196,12 @@ export const shiftKeyOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True only if the target element is not editable.
|
||||
* @api
|
||||
*/
|
||||
export const targetNotEditable = function(mapBrowserEvent) {
|
||||
export const targetNotEditable = function (mapBrowserEvent) {
|
||||
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
|
||||
const tagName = /** @type {Element} */ (originalEvent.target).tagName;
|
||||
return tagName !== 'INPUT' && tagName !== 'SELECT' && tagName !== 'TEXTAREA';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the event originates from a mouse device.
|
||||
*
|
||||
@@ -220,8 +209,9 @@ export const targetNotEditable = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event originates from a mouse device.
|
||||
* @api
|
||||
*/
|
||||
export const mouseOnly = function(mapBrowserEvent) {
|
||||
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
|
||||
export const mouseOnly = function (mapBrowserEvent) {
|
||||
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
|
||||
.pointerEvent;
|
||||
assert(pointerEvent !== undefined, 56); // mapBrowserEvent must originate from a pointer event
|
||||
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
return pointerEvent.pointerType == 'mouse';
|
||||
@@ -234,8 +224,9 @@ export const mouseOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event originates from a touchable device.
|
||||
* @api
|
||||
*/
|
||||
export const touchOnly = function(mapBrowserEvent) {
|
||||
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
|
||||
export const touchOnly = function (mapBrowserEvent) {
|
||||
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
|
||||
.pointerEvent;
|
||||
assert(pointerEvt !== undefined, 56); // mapBrowserEvent must originate from a pointer event
|
||||
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
return pointerEvt.pointerType === 'touch';
|
||||
@@ -248,8 +239,9 @@ export const touchOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event originates from a digital pen.
|
||||
* @api
|
||||
*/
|
||||
export const penOnly = function(mapBrowserEvent) {
|
||||
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
|
||||
export const penOnly = function (mapBrowserEvent) {
|
||||
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
|
||||
.pointerEvent;
|
||||
assert(pointerEvt !== undefined, 56); // mapBrowserEvent must originate from a pointer event
|
||||
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
return pointerEvt.pointerType === 'pen';
|
||||
@@ -264,8 +256,9 @@ export const penOnly = function(mapBrowserEvent) {
|
||||
* @return {boolean} True if the event originates from a primary pointer.
|
||||
* @api
|
||||
*/
|
||||
export const primaryAction = function(mapBrowserEvent) {
|
||||
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
|
||||
export const primaryAction = function (mapBrowserEvent) {
|
||||
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
|
||||
.pointerEvent;
|
||||
assert(pointerEvent !== undefined, 56); // mapBrowserEvent must originate from a pointer event
|
||||
return pointerEvent.isPrimary && pointerEvent.button === 0;
|
||||
};
|
||||
|
||||
197
src/ol/extent.js
197
src/ol/extent.js
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* @module ol/extent
|
||||
*/
|
||||
import {assert} from './asserts.js';
|
||||
import Corner from './extent/Corner.js';
|
||||
import Relationship from './extent/Relationship.js';
|
||||
|
||||
import {assert} from './asserts.js';
|
||||
|
||||
/**
|
||||
* An array of numbers representing an extent: `[minx, miny, maxx, maxy]`.
|
||||
@@ -27,7 +26,6 @@ export function boundingExtent(coordinates) {
|
||||
return extent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} xs Xs.
|
||||
* @param {Array<number>} ys Ys.
|
||||
@@ -43,7 +41,6 @@ function _boundingExtentXYs(xs, ys, opt_extent) {
|
||||
return createOrUpdate(minX, minY, maxX, maxY, opt_extent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return extent increased by the provided value.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -64,12 +61,11 @@ export function buffer(extent, value, opt_extent) {
|
||||
extent[0] - value,
|
||||
extent[1] - value,
|
||||
extent[2] + value,
|
||||
extent[3] + value
|
||||
extent[3] + value,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a clone of an extent.
|
||||
*
|
||||
@@ -89,7 +85,6 @@ export function clone(extent, opt_extent) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {number} x X.
|
||||
@@ -115,7 +110,6 @@ export function closestSquaredDistanceXY(extent, x, y) {
|
||||
return dx * dx + dy * dy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the passed coordinate is contained or on the edge of the extent.
|
||||
*
|
||||
@@ -128,7 +122,6 @@ export function containsCoordinate(extent, coordinate) {
|
||||
return containsXY(extent, coordinate[0], coordinate[1]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if one extent contains another.
|
||||
*
|
||||
@@ -142,11 +135,14 @@ export function containsCoordinate(extent, coordinate) {
|
||||
* @api
|
||||
*/
|
||||
export function containsExtent(extent1, extent2) {
|
||||
return extent1[0] <= extent2[0] && extent2[2] <= extent1[2] &&
|
||||
extent1[1] <= extent2[1] && extent2[3] <= extent1[3];
|
||||
return (
|
||||
extent1[0] <= extent2[0] &&
|
||||
extent2[2] <= extent1[2] &&
|
||||
extent1[1] <= extent2[1] &&
|
||||
extent2[3] <= extent1[3]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the passed coordinate is contained or on the edge of the extent.
|
||||
*
|
||||
@@ -160,7 +156,6 @@ export function containsXY(extent, x, y) {
|
||||
return extent[0] <= x && x <= extent[2] && extent[1] <= y && y <= extent[3];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the relationship between a coordinate and extent.
|
||||
* @param {Extent} extent The extent.
|
||||
@@ -192,7 +187,6 @@ export function coordinateRelationship(extent, coordinate) {
|
||||
return relationship;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an empty extent.
|
||||
* @return {Extent} Empty extent.
|
||||
@@ -202,7 +196,6 @@ export function createEmpty() {
|
||||
return [Infinity, Infinity, -Infinity, -Infinity];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new extent or update the provided extent.
|
||||
* @param {number} minX Minimum X.
|
||||
@@ -224,18 +217,15 @@ export function createOrUpdate(minX, minY, maxX, maxY, opt_extent) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new empty extent or make the provided one empty.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function createOrUpdateEmpty(opt_extent) {
|
||||
return createOrUpdate(
|
||||
Infinity, Infinity, -Infinity, -Infinity, opt_extent);
|
||||
return createOrUpdate(Infinity, Infinity, -Infinity, -Infinity, opt_extent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("./coordinate.js").Coordinate} coordinate Coordinate.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
@@ -247,7 +237,6 @@ export function createOrUpdateFromCoordinate(coordinate, opt_extent) {
|
||||
return createOrUpdate(x, y, x, y, opt_extent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<import("./coordinate.js").Coordinate>} coordinates Coordinates.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
@@ -258,7 +247,6 @@ export function createOrUpdateFromCoordinates(coordinates, opt_extent) {
|
||||
return extendCoordinates(extent, coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -267,7 +255,13 @@ export function createOrUpdateFromCoordinates(coordinates, opt_extent) {
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function createOrUpdateFromFlatCoordinates(flatCoordinates, offset, end, stride, opt_extent) {
|
||||
export function createOrUpdateFromFlatCoordinates(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
opt_extent
|
||||
) {
|
||||
const extent = createOrUpdateEmpty(opt_extent);
|
||||
return extendFlatCoordinates(extent, flatCoordinates, offset, end, stride);
|
||||
}
|
||||
@@ -282,7 +276,6 @@ export function createOrUpdateFromRings(rings, opt_extent) {
|
||||
return extendRings(extent, rings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if two extents are equivalent.
|
||||
* @param {Extent} extent1 Extent 1.
|
||||
@@ -291,8 +284,12 @@ export function createOrUpdateFromRings(rings, opt_extent) {
|
||||
* @api
|
||||
*/
|
||||
export function equals(extent1, extent2) {
|
||||
return extent1[0] == extent2[0] && extent1[2] == extent2[2] &&
|
||||
extent1[1] == extent2[1] && extent1[3] == extent2[3];
|
||||
return (
|
||||
extent1[0] == extent2[0] &&
|
||||
extent1[2] == extent2[2] &&
|
||||
extent1[1] == extent2[1] &&
|
||||
extent1[3] == extent2[3]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,11 +300,14 @@ export function equals(extent1, extent2) {
|
||||
* @return {boolean} The two extents differ by less than the tolerance.
|
||||
*/
|
||||
export function approximatelyEquals(extent1, extent2, tolerance) {
|
||||
return Math.abs(extent1[0] - extent2[0]) < tolerance && Math.abs(extent1[2] - extent2[2]) < tolerance &&
|
||||
Math.abs(extent1[1] - extent2[1]) < tolerance && Math.abs(extent1[3] - extent2[3]) < tolerance;
|
||||
return (
|
||||
Math.abs(extent1[0] - extent2[0]) < tolerance &&
|
||||
Math.abs(extent1[2] - extent2[2]) < tolerance &&
|
||||
Math.abs(extent1[1] - extent2[1]) < tolerance &&
|
||||
Math.abs(extent1[3] - extent2[3]) < tolerance
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Modify an extent to include another extent.
|
||||
* @param {Extent} extent1 The extent to be modified.
|
||||
@@ -331,7 +331,6 @@ export function extend(extent1, extent2) {
|
||||
return extent1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {import("./coordinate.js").Coordinate} coordinate Coordinate.
|
||||
@@ -351,7 +350,6 @@ export function extendCoordinate(extent, coordinate) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {Array<import("./coordinate.js").Coordinate>} coordinates Coordinates.
|
||||
@@ -364,7 +362,6 @@ export function extendCoordinates(extent, coordinates) {
|
||||
return extent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
@@ -373,14 +370,19 @@ export function extendCoordinates(extent, coordinates) {
|
||||
* @param {number} stride Stride.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function extendFlatCoordinates(extent, flatCoordinates, offset, end, stride) {
|
||||
export function extendFlatCoordinates(
|
||||
extent,
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride
|
||||
) {
|
||||
for (; offset < end; offset += stride) {
|
||||
extendXY(extent, flatCoordinates[offset], flatCoordinates[offset + 1]);
|
||||
}
|
||||
return extent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {Array<Array<import("./coordinate.js").Coordinate>>} rings Rings.
|
||||
@@ -393,7 +395,6 @@ export function extendRings(extent, rings) {
|
||||
return extent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {number} x X.
|
||||
@@ -406,7 +407,6 @@ export function extendXY(extent, x, y) {
|
||||
extent[3] = Math.max(extent[3], y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function calls `callback` for each corner of the extent. If the
|
||||
* callback returns a truthy value the function returns that value
|
||||
@@ -437,7 +437,6 @@ export function forEachCorner(extent, callback) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the size of an extent.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -452,7 +451,6 @@ export function getArea(extent) {
|
||||
return area;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the bottom left coordinate of an extent.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -463,7 +461,6 @@ export function getBottomLeft(extent) {
|
||||
return [extent[0], extent[1]];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the bottom right coordinate of an extent.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -474,7 +471,6 @@ export function getBottomRight(extent) {
|
||||
return [extent[2], extent[1]];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the center coordinate of an extent.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -485,7 +481,6 @@ export function getCenter(extent) {
|
||||
return [(extent[0] + extent[2]) / 2, (extent[1] + extent[3]) / 2];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a corner coordinate of an extent.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -508,7 +503,6 @@ export function getCorner(extent, corner) {
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Extent} extent1 Extent 1.
|
||||
* @param {Extent} extent2 Extent 2.
|
||||
@@ -522,7 +516,6 @@ export function getEnlargedArea(extent1, extent2) {
|
||||
return (maxX - minX) * (maxY - minY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("./coordinate.js").Coordinate} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
@@ -531,9 +524,15 @@ export function getEnlargedArea(extent1, extent2) {
|
||||
* @param {Extent=} opt_extent Destination extent.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function getForViewAndSize(center, resolution, rotation, size, opt_extent) {
|
||||
const dx = resolution * size[0] / 2;
|
||||
const dy = resolution * size[1] / 2;
|
||||
export function getForViewAndSize(
|
||||
center,
|
||||
resolution,
|
||||
rotation,
|
||||
size,
|
||||
opt_extent
|
||||
) {
|
||||
const dx = (resolution * size[0]) / 2;
|
||||
const dy = (resolution * size[1]) / 2;
|
||||
const cosRotation = Math.cos(rotation);
|
||||
const sinRotation = Math.sin(rotation);
|
||||
const xCos = dx * cosRotation;
|
||||
@@ -551,12 +550,14 @@ export function getForViewAndSize(center, resolution, rotation, size, opt_extent
|
||||
const y2 = y + xSin + yCos;
|
||||
const y3 = y + xSin - yCos;
|
||||
return createOrUpdate(
|
||||
Math.min(x0, x1, x2, x3), Math.min(y0, y1, y2, y3),
|
||||
Math.max(x0, x1, x2, x3), Math.max(y0, y1, y2, y3),
|
||||
opt_extent);
|
||||
Math.min(x0, x1, x2, x3),
|
||||
Math.min(y0, y1, y2, y3),
|
||||
Math.max(x0, x1, x2, x3),
|
||||
Math.max(y0, y1, y2, y3),
|
||||
opt_extent
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the height of an extent.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -567,7 +568,6 @@ export function getHeight(extent) {
|
||||
return extent[3] - extent[1];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Extent} extent1 Extent 1.
|
||||
* @param {Extent} extent2 Extent 2.
|
||||
@@ -578,7 +578,6 @@ export function getIntersectionArea(extent1, extent2) {
|
||||
return getArea(intersection);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the intersection of two extents.
|
||||
* @param {Extent} extent1 Extent 1.
|
||||
@@ -616,7 +615,6 @@ export function getIntersection(extent1, extent2, opt_extent) {
|
||||
return intersection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Extent} extent Extent.
|
||||
* @return {number} Margin.
|
||||
@@ -625,7 +623,6 @@ export function getMargin(extent) {
|
||||
return getWidth(extent) + getHeight(extent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the size (width, height) of an extent.
|
||||
* @param {Extent} extent The extent.
|
||||
@@ -636,7 +633,6 @@ export function getSize(extent) {
|
||||
return [extent[2] - extent[0], extent[3] - extent[1]];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the top left coordinate of an extent.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -647,7 +643,6 @@ export function getTopLeft(extent) {
|
||||
return [extent[0], extent[3]];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the top right coordinate of an extent.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -658,7 +653,6 @@ export function getTopRight(extent) {
|
||||
return [extent[2], extent[3]];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the width of an extent.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -669,7 +663,6 @@ export function getWidth(extent) {
|
||||
return extent[2] - extent[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if one extent intersects another.
|
||||
* @param {Extent} extent1 Extent 1.
|
||||
@@ -678,13 +671,14 @@ export function getWidth(extent) {
|
||||
* @api
|
||||
*/
|
||||
export function intersects(extent1, extent2) {
|
||||
return extent1[0] <= extent2[2] &&
|
||||
extent1[2] >= extent2[0] &&
|
||||
extent1[1] <= extent2[3] &&
|
||||
extent1[3] >= extent2[1];
|
||||
return (
|
||||
extent1[0] <= extent2[2] &&
|
||||
extent1[2] >= extent2[0] &&
|
||||
extent1[1] <= extent2[3] &&
|
||||
extent1[3] >= extent2[1]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if an extent is empty.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -695,7 +689,6 @@ export function isEmpty(extent) {
|
||||
return extent[2] < extent[0] || extent[3] < extent[1];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
@@ -713,7 +706,6 @@ export function returnOrUpdate(extent, opt_extent) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {number} value Value.
|
||||
@@ -727,7 +719,6 @@ export function scaleFromCenter(extent, value) {
|
||||
extent[3] += deltaY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the segment between two coordinates intersects (crosses,
|
||||
* touches, or is contained by) the provided extent.
|
||||
@@ -740,8 +731,10 @@ export function intersectsSegment(extent, start, end) {
|
||||
let intersects = false;
|
||||
const startRel = coordinateRelationship(extent, start);
|
||||
const endRel = coordinateRelationship(extent, end);
|
||||
if (startRel === Relationship.INTERSECTING ||
|
||||
endRel === Relationship.INTERSECTING) {
|
||||
if (
|
||||
startRel === Relationship.INTERSECTING ||
|
||||
endRel === Relationship.INTERSECTING
|
||||
) {
|
||||
intersects = true;
|
||||
} else {
|
||||
const minX = extent[0];
|
||||
@@ -754,36 +747,42 @@ export function intersectsSegment(extent, start, end) {
|
||||
const endY = end[1];
|
||||
const slope = (endY - startY) / (endX - startX);
|
||||
let x, y;
|
||||
if (!!(endRel & Relationship.ABOVE) &&
|
||||
!(startRel & Relationship.ABOVE)) {
|
||||
if (!!(endRel & Relationship.ABOVE) && !(startRel & Relationship.ABOVE)) {
|
||||
// potentially intersects top
|
||||
x = endX - ((endY - maxY) / slope);
|
||||
x = endX - (endY - maxY) / slope;
|
||||
intersects = x >= minX && x <= maxX;
|
||||
}
|
||||
if (!intersects && !!(endRel & Relationship.RIGHT) &&
|
||||
!(startRel & Relationship.RIGHT)) {
|
||||
if (
|
||||
!intersects &&
|
||||
!!(endRel & Relationship.RIGHT) &&
|
||||
!(startRel & Relationship.RIGHT)
|
||||
) {
|
||||
// potentially intersects right
|
||||
y = endY - ((endX - maxX) * slope);
|
||||
y = endY - (endX - maxX) * slope;
|
||||
intersects = y >= minY && y <= maxY;
|
||||
}
|
||||
if (!intersects && !!(endRel & Relationship.BELOW) &&
|
||||
!(startRel & Relationship.BELOW)) {
|
||||
if (
|
||||
!intersects &&
|
||||
!!(endRel & Relationship.BELOW) &&
|
||||
!(startRel & Relationship.BELOW)
|
||||
) {
|
||||
// potentially intersects bottom
|
||||
x = endX - ((endY - minY) / slope);
|
||||
x = endX - (endY - minY) / slope;
|
||||
intersects = x >= minX && x <= maxX;
|
||||
}
|
||||
if (!intersects && !!(endRel & Relationship.LEFT) &&
|
||||
!(startRel & Relationship.LEFT)) {
|
||||
if (
|
||||
!intersects &&
|
||||
!!(endRel & Relationship.LEFT) &&
|
||||
!(startRel & Relationship.LEFT)
|
||||
) {
|
||||
// potentially intersects left
|
||||
y = endY - ((endX - minX) * slope);
|
||||
y = endY - (endX - minX) * slope;
|
||||
intersects = y >= minY && y <= maxY;
|
||||
}
|
||||
|
||||
}
|
||||
return intersects;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply a transform function to the extent.
|
||||
* @param {Extent} extent Extent.
|
||||
@@ -802,18 +801,26 @@ export function applyTransform(extent, transformFn, opt_extent, opt_stops) {
|
||||
const height = extent[3] - extent[1];
|
||||
for (let i = 0; i < opt_stops; ++i) {
|
||||
coordinates.push(
|
||||
extent[0] + width * i / opt_stops, extent[1],
|
||||
extent[2], extent[1] + height * i / opt_stops,
|
||||
extent[2] - width * i / opt_stops, extent[3],
|
||||
extent[0], extent[3] - height * i / opt_stops
|
||||
extent[0] + (width * i) / opt_stops,
|
||||
extent[1],
|
||||
extent[2],
|
||||
extent[1] + (height * i) / opt_stops,
|
||||
extent[2] - (width * i) / opt_stops,
|
||||
extent[3],
|
||||
extent[0],
|
||||
extent[3] - (height * i) / opt_stops
|
||||
);
|
||||
}
|
||||
} else {
|
||||
coordinates = [
|
||||
extent[0], extent[1],
|
||||
extent[2], extent[1],
|
||||
extent[2], extent[3],
|
||||
extent[0], extent[3]
|
||||
extent[0],
|
||||
extent[1],
|
||||
extent[2],
|
||||
extent[1],
|
||||
extent[2],
|
||||
extent[3],
|
||||
extent[0],
|
||||
extent[3],
|
||||
];
|
||||
}
|
||||
transformFn(coordinates, coordinates, 2);
|
||||
@@ -826,7 +833,6 @@ export function applyTransform(extent, transformFn, opt_extent, opt_stops) {
|
||||
return _boundingExtentXYs(xs, ys, opt_extent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Modifies the provided extent in-place to be within the real world
|
||||
* extent.
|
||||
@@ -838,10 +844,15 @@ export function applyTransform(extent, transformFn, opt_extent, opt_stops) {
|
||||
export function wrapX(extent, projection) {
|
||||
const projectionExtent = projection.getExtent();
|
||||
const center = getCenter(extent);
|
||||
if (projection.canWrapX() && (center[0] < projectionExtent[0] || center[0] >= projectionExtent[2])) {
|
||||
if (
|
||||
projection.canWrapX() &&
|
||||
(center[0] < projectionExtent[0] || center[0] >= projectionExtent[2])
|
||||
) {
|
||||
const worldWidth = getWidth(projectionExtent);
|
||||
const worldsAway = Math.floor((center[0] - projectionExtent[0]) / worldWidth);
|
||||
const offset = (worldsAway * worldWidth);
|
||||
const worldsAway = Math.floor(
|
||||
(center[0] - projectionExtent[0]) / worldWidth
|
||||
);
|
||||
const offset = worldsAway * worldWidth;
|
||||
extent[0] -= offset;
|
||||
extent[2] -= offset;
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ export default {
|
||||
BOTTOM_LEFT: 'bottom-left',
|
||||
BOTTOM_RIGHT: 'bottom-right',
|
||||
TOP_LEFT: 'top-left',
|
||||
TOP_RIGHT: 'top-right'
|
||||
TOP_RIGHT: 'top-right',
|
||||
};
|
||||
|
||||
@@ -12,5 +12,5 @@ export default {
|
||||
ABOVE: 2,
|
||||
RIGHT: 4,
|
||||
BELOW: 8,
|
||||
LEFT: 16
|
||||
LEFT: 16,
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* @module ol/featureloader
|
||||
*/
|
||||
import {VOID} from './functions.js';
|
||||
import FormatType from './format/FormatType.js';
|
||||
import {VOID} from './functions.js';
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -28,7 +28,6 @@ let withCredentials = false;
|
||||
* @api
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* {@link module:ol/source/Vector} sources use a function of this type to
|
||||
* get the url to load features from.
|
||||
@@ -41,7 +40,6 @@ let withCredentials = false;
|
||||
* @api
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|FeatureUrlFunction} url Feature URL service.
|
||||
* @param {import("./format/Feature.js").default} format Feature format.
|
||||
@@ -61,11 +59,13 @@ export function loadFeaturesXhr(url, format, success, failure) {
|
||||
* @param {import("./proj/Projection.js").default} projection Projection.
|
||||
* @this {import("./source/Vector").default|import("./VectorTile.js").default}
|
||||
*/
|
||||
function(extent, resolution, projection) {
|
||||
function (extent, resolution, projection) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET',
|
||||
xhr.open(
|
||||
'GET',
|
||||
typeof url === 'function' ? url(extent, resolution, projection) : url,
|
||||
true);
|
||||
true
|
||||
);
|
||||
if (format.getType() == FormatType.ARRAY_BUFFER) {
|
||||
xhr.responseType = 'arraybuffer';
|
||||
}
|
||||
@@ -74,9 +74,9 @@ export function loadFeaturesXhr(url, format, success, failure) {
|
||||
* @param {Event} event Event.
|
||||
* @private
|
||||
*/
|
||||
xhr.onload = function(event) {
|
||||
xhr.onload = function (event) {
|
||||
// status will be 0 for file:// urls
|
||||
if (!xhr.status || xhr.status >= 200 && xhr.status < 300) {
|
||||
if (!xhr.status || (xhr.status >= 200 && xhr.status < 300)) {
|
||||
const type = format.getType();
|
||||
/** @type {Document|Node|Object|string|undefined} */
|
||||
let source;
|
||||
@@ -85,17 +85,23 @@ export function loadFeaturesXhr(url, format, success, failure) {
|
||||
} else if (type == FormatType.XML) {
|
||||
source = xhr.responseXML;
|
||||
if (!source) {
|
||||
source = new DOMParser().parseFromString(xhr.responseText, 'application/xml');
|
||||
source = new DOMParser().parseFromString(
|
||||
xhr.responseText,
|
||||
'application/xml'
|
||||
);
|
||||
}
|
||||
} else if (type == FormatType.ARRAY_BUFFER) {
|
||||
source = /** @type {ArrayBuffer} */ (xhr.response);
|
||||
}
|
||||
if (source) {
|
||||
success.call(this, format.readFeatures(source, {
|
||||
extent: extent,
|
||||
featureProjection: projection
|
||||
}),
|
||||
format.readProjection(source));
|
||||
success.call(
|
||||
this,
|
||||
format.readFeatures(source, {
|
||||
extent: extent,
|
||||
featureProjection: projection,
|
||||
}),
|
||||
format.readProjection(source)
|
||||
);
|
||||
} else {
|
||||
failure.call(this);
|
||||
}
|
||||
@@ -106,7 +112,7 @@ export function loadFeaturesXhr(url, format, success, failure) {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
xhr.onerror = function() {
|
||||
xhr.onerror = function () {
|
||||
failure.call(this);
|
||||
}.bind(this);
|
||||
xhr.send();
|
||||
@@ -114,7 +120,6 @@ export function loadFeaturesXhr(url, format, success, failure) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an XHR feature loader for a `url` and `format`. The feature loader
|
||||
* loads features (with XHR), parses the features, and adds them to the
|
||||
@@ -125,19 +130,25 @@ export function loadFeaturesXhr(url, format, success, failure) {
|
||||
* @api
|
||||
*/
|
||||
export function xhr(url, format) {
|
||||
return loadFeaturesXhr(url, format,
|
||||
return loadFeaturesXhr(
|
||||
url,
|
||||
format,
|
||||
/**
|
||||
* @param {Array<import("./Feature.js").default>} features The loaded features.
|
||||
* @param {import("./proj/Projection.js").default} dataProjection Data
|
||||
* projection.
|
||||
* @this {import("./source/Vector").default|import("./VectorTile.js").default}
|
||||
*/
|
||||
function(features, dataProjection) {
|
||||
function (features, dataProjection) {
|
||||
const sourceOrTile = /** @type {?} */ (this);
|
||||
if (typeof sourceOrTile.addFeatures === 'function') {
|
||||
/** @type {import("./source/Vector").default} */ (sourceOrTile).addFeatures(features);
|
||||
/** @type {import("./source/Vector").default} */ (sourceOrTile).addFeatures(
|
||||
features
|
||||
);
|
||||
}
|
||||
}, /* FIXME handle error */ VOID);
|
||||
},
|
||||
/* FIXME handle error */ VOID
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,12 +2,9 @@
|
||||
* @module ol/format/EsriJSON
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {containsExtent} from '../extent.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
import JSONFeature from './JSONFeature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import JSONFeature from './JSONFeature.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import LinearRing from '../geom/LinearRing.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
@@ -15,10 +12,13 @@ import MultiPoint from '../geom/MultiPoint.js';
|
||||
import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {containsExtent} from '../extent.js';
|
||||
import {deflateCoordinates} from '../geom/flat/deflate.js';
|
||||
import {linearRingIsClockwise} from '../geom/flat/orient.js';
|
||||
import {isEmpty} from '../obj.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {isEmpty} from '../obj.js';
|
||||
import {linearRingIsClockwise} from '../geom/flat/orient.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* @typedef {import("arcgis-rest-api").Feature} EsriJSONFeature
|
||||
@@ -33,7 +33,6 @@ import {get as getProjection} from '../proj.js';
|
||||
* @typedef {import("arcgis-rest-api").SpatialReferenceWkid} EsriJSONSpatialReferenceWkid
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} EsriJSONMultiPolygon
|
||||
* @property {Array<Array<Array<Array<number>>>>} rings Rings for the MultiPolygon.
|
||||
@@ -42,7 +41,6 @@ import {get as getProjection} from '../proj.js';
|
||||
* @property {EsriJSONSpatialReferenceWkid} [spatialReference] The coordinate reference system.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<import("../geom/GeometryType.js").default, function(EsriJSONGeometry): import("../geom/Geometry.js").default>}
|
||||
@@ -55,7 +53,6 @@ GEOMETRY_READERS[GeometryType.MULTI_POINT] = readMultiPointGeometry;
|
||||
GEOMETRY_READERS[GeometryType.MULTI_LINE_STRING] = readMultiLineStringGeometry;
|
||||
GEOMETRY_READERS[GeometryType.MULTI_POLYGON] = readMultiPolygonGeometry;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, function(import("../geom/Geometry.js").default, import("./Feature.js").WriteOptions=): (EsriJSONGeometry)>}
|
||||
@@ -68,13 +65,11 @@ GEOMETRY_WRITERS[GeometryType.MULTI_POINT] = writeMultiPointGeometry;
|
||||
GEOMETRY_WRITERS[GeometryType.MULTI_LINE_STRING] = writeMultiLineStringGeometry;
|
||||
GEOMETRY_WRITERS[GeometryType.MULTI_POLYGON] = writeMultiPolygonGeometry;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {string} [geometryName] Geometry name to use when creating features.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for reading and writing data in the EsriJSON format.
|
||||
@@ -82,12 +77,10 @@ GEOMETRY_WRITERS[GeometryType.MULTI_POLYGON] = writeMultiPolygonGeometry;
|
||||
* @api
|
||||
*/
|
||||
class EsriJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super();
|
||||
@@ -98,7 +91,6 @@ class EsriJSON extends JSONFeature {
|
||||
* @private
|
||||
*/
|
||||
this.geometryName_ = options.geometryName;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +112,7 @@ class EsriJSON extends JSONFeature {
|
||||
feature.setProperties(esriJSONFeature.attributes, true);
|
||||
const id = esriJSONFeature.attributes[opt_idField];
|
||||
if (id !== undefined) {
|
||||
feature.setId(/** @type {number} */(id));
|
||||
feature.setId(/** @type {number} */ (id));
|
||||
}
|
||||
}
|
||||
return feature;
|
||||
@@ -140,7 +132,13 @@ class EsriJSON extends JSONFeature {
|
||||
const features = [];
|
||||
const esriJSONFeatures = esriJSONFeatureSet.features;
|
||||
for (let i = 0, ii = esriJSONFeatures.length; i < ii; ++i) {
|
||||
features.push(this.readFeatureFromObject(esriJSONFeatures[i], options, object.objectIdFieldName));
|
||||
features.push(
|
||||
this.readFeatureFromObject(
|
||||
esriJSONFeatures[i],
|
||||
options,
|
||||
object.objectIdFieldName
|
||||
)
|
||||
);
|
||||
}
|
||||
return features;
|
||||
} else {
|
||||
@@ -164,8 +162,13 @@ class EsriJSON extends JSONFeature {
|
||||
* @return {import("../proj/Projection.js").default} Projection.
|
||||
*/
|
||||
readProjectionFromObject(object) {
|
||||
if (object['spatialReference'] && object['spatialReference']['wkid'] !== undefined) {
|
||||
const spatialReference = /** @type {EsriJSONSpatialReferenceWkid} */ (object['spatialReference']);
|
||||
if (
|
||||
object['spatialReference'] &&
|
||||
object['spatialReference']['wkid'] !== undefined
|
||||
) {
|
||||
const spatialReference = /** @type {EsriJSONSpatialReferenceWkid} */ (object[
|
||||
'spatialReference'
|
||||
]);
|
||||
const crs = spatialReference.wkid;
|
||||
return getProjection('EPSG:' + crs);
|
||||
} else {
|
||||
@@ -200,8 +203,15 @@ class EsriJSON extends JSONFeature {
|
||||
if (geometry) {
|
||||
object['geometry'] = writeGeometry(geometry, opt_options);
|
||||
if (opt_options && opt_options.featureProjection) {
|
||||
object['geometry']['spatialReference'] = /** @type {EsriJSONSpatialReferenceWkid} */({
|
||||
wkid: Number(getProjection(opt_options.featureProjection).getCode().split(':').pop())
|
||||
object['geometry'][
|
||||
'spatialReference'
|
||||
] = /** @type {EsriJSONSpatialReferenceWkid} */ ({
|
||||
wkid: Number(
|
||||
getProjection(opt_options.featureProjection)
|
||||
.getCode()
|
||||
.split(':')
|
||||
.pop()
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -230,12 +240,11 @@ class EsriJSON extends JSONFeature {
|
||||
objects.push(this.writeFeatureObject(features[i], opt_options));
|
||||
}
|
||||
return {
|
||||
'features': objects
|
||||
'features': objects,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONGeometry} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
@@ -271,10 +280,13 @@ function readGeometry(object, opt_options) {
|
||||
}
|
||||
}
|
||||
const geometryReader = GEOMETRY_READERS[type];
|
||||
return transformGeometryWithOptions(geometryReader(object), false, opt_options);
|
||||
return transformGeometryWithOptions(
|
||||
geometryReader(object),
|
||||
false,
|
||||
opt_options
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines inner and outer rings.
|
||||
* Checks if any polygons in this array contain any other polygons in this
|
||||
@@ -293,8 +305,12 @@ function convertRings(rings, layout) {
|
||||
flatRing.length = 0;
|
||||
deflateCoordinates(flatRing, 0, rings[i], layout.length);
|
||||
// is this ring an outer ring? is it clockwise?
|
||||
const clockwise = linearRingIsClockwise(flatRing, 0,
|
||||
flatRing.length, layout.length);
|
||||
const clockwise = linearRingIsClockwise(
|
||||
flatRing,
|
||||
0,
|
||||
flatRing.length,
|
||||
layout.length
|
||||
);
|
||||
if (clockwise) {
|
||||
outerRings.push([rings[i]]);
|
||||
} else {
|
||||
@@ -327,7 +343,6 @@ function convertRings(rings, layout) {
|
||||
return outerRings;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONPoint} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} Point.
|
||||
@@ -335,21 +350,20 @@ function convertRings(rings, layout) {
|
||||
function readPointGeometry(object) {
|
||||
let point;
|
||||
if (object.m !== undefined && object.z !== undefined) {
|
||||
point = new Point([object.x, object.y, object.z, object.m],
|
||||
GeometryLayout.XYZM);
|
||||
point = new Point(
|
||||
[object.x, object.y, object.z, object.m],
|
||||
GeometryLayout.XYZM
|
||||
);
|
||||
} else if (object.z !== undefined) {
|
||||
point = new Point([object.x, object.y, object.z],
|
||||
GeometryLayout.XYZ);
|
||||
point = new Point([object.x, object.y, object.z], GeometryLayout.XYZ);
|
||||
} else if (object.m !== undefined) {
|
||||
point = new Point([object.x, object.y, object.m],
|
||||
GeometryLayout.XYM);
|
||||
point = new Point([object.x, object.y, object.m], GeometryLayout.XYM);
|
||||
} else {
|
||||
point = new Point([object.x, object.y]);
|
||||
}
|
||||
return point;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONPolyline} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} LineString.
|
||||
@@ -359,7 +373,6 @@ function readLineStringGeometry(object) {
|
||||
return new LineString(object.paths[0], layout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONPolyline} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} MultiLineString.
|
||||
@@ -369,7 +382,6 @@ function readMultiLineStringGeometry(object) {
|
||||
return new MultiLineString(object.paths, layout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONHasZM} object Object.
|
||||
* @return {import("../geom/GeometryLayout.js").default} The geometry layout to use.
|
||||
@@ -386,7 +398,6 @@ function getGeometryLayout(object) {
|
||||
return layout;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONMultipoint} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} MultiPoint.
|
||||
@@ -396,7 +407,6 @@ function readMultiPointGeometry(object) {
|
||||
return new MultiPoint(object.points, layout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONMultiPolygon} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} MultiPolygon.
|
||||
@@ -406,7 +416,6 @@ function readMultiPolygonGeometry(object) {
|
||||
return new MultiPolygon(object.rings, layout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONPolygon} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} Polygon.
|
||||
@@ -416,7 +425,6 @@ function readPolygonGeometry(object) {
|
||||
return new Polygon(object.rings, layout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Point.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -431,25 +439,25 @@ function writePointGeometry(geometry, opt_options) {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1],
|
||||
z: coordinates[2]
|
||||
z: coordinates[2],
|
||||
};
|
||||
} else if (layout === GeometryLayout.XYM) {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1],
|
||||
m: coordinates[2]
|
||||
m: coordinates[2],
|
||||
};
|
||||
} else if (layout === GeometryLayout.XYZM) {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1],
|
||||
z: coordinates[2],
|
||||
m: coordinates[3]
|
||||
m: coordinates[3],
|
||||
};
|
||||
} else if (layout === GeometryLayout.XY) {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1]
|
||||
y: coordinates[1],
|
||||
};
|
||||
} else {
|
||||
assert(false, 34); // Invalid geometry layout
|
||||
@@ -457,7 +465,6 @@ function writePointGeometry(geometry, opt_options) {
|
||||
return esriJSON;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/SimpleGeometry.js").default} geometry Geometry.
|
||||
* @return {Object} Object with boolean hasZ and hasM keys.
|
||||
@@ -465,14 +472,11 @@ function writePointGeometry(geometry, opt_options) {
|
||||
function getHasZM(geometry) {
|
||||
const layout = geometry.getLayout();
|
||||
return {
|
||||
hasZ: (layout === GeometryLayout.XYZ ||
|
||||
layout === GeometryLayout.XYZM),
|
||||
hasM: (layout === GeometryLayout.XYM ||
|
||||
layout === GeometryLayout.XYZM)
|
||||
hasZ: layout === GeometryLayout.XYZ || layout === GeometryLayout.XYZM,
|
||||
hasM: layout === GeometryLayout.XYM || layout === GeometryLayout.XYZM,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/LineString.js").default} lineString Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -484,12 +488,11 @@ function writeLineStringGeometry(lineString, opt_options) {
|
||||
hasZ: hasZM.hasZ,
|
||||
hasM: hasZM.hasM,
|
||||
paths: [
|
||||
/** @type {Array<EsriJSONPosition>} */ (lineString.getCoordinates())
|
||||
]
|
||||
/** @type {Array<EsriJSONPosition>} */ (lineString.getCoordinates()),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Polygon.js").default} polygon Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -501,11 +504,12 @@ function writePolygonGeometry(polygon, opt_options) {
|
||||
return {
|
||||
hasZ: hasZM.hasZ,
|
||||
hasM: hasZM.hasM,
|
||||
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (polygon.getCoordinates(false))
|
||||
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (polygon.getCoordinates(
|
||||
false
|
||||
)),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/MultiLineString.js").default} multiLineString Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -516,11 +520,10 @@ function writeMultiLineStringGeometry(multiLineString, opt_options) {
|
||||
return {
|
||||
hasZ: hasZM.hasZ,
|
||||
hasM: hasZM.hasM,
|
||||
paths: /** @type {Array<Array<EsriJSONPosition>>} */ (multiLineString.getCoordinates())
|
||||
paths: /** @type {Array<Array<EsriJSONPosition>>} */ (multiLineString.getCoordinates()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/MultiPoint.js").default} multiPoint Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -531,11 +534,10 @@ function writeMultiPointGeometry(multiPoint, opt_options) {
|
||||
return {
|
||||
hasZ: hasZM.hasZ,
|
||||
hasM: hasZM.hasM,
|
||||
points: /** @type {Array<EsriJSONPosition>} */ (multiPoint.getCoordinates())
|
||||
points: /** @type {Array<EsriJSONPosition>} */ (multiPoint.getCoordinates()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/MultiPolygon.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -553,11 +555,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
|
||||
return {
|
||||
hasZ: hasZM.hasZ,
|
||||
hasM: hasZM.hasM,
|
||||
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (output)
|
||||
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (output),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -565,8 +566,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
|
||||
*/
|
||||
function writeGeometry(geometry, opt_options) {
|
||||
const geometryWriter = GEOMETRY_WRITERS[geometry.getType()];
|
||||
return geometryWriter(transformGeometryWithOptions(geometry, true, opt_options), opt_options);
|
||||
return geometryWriter(
|
||||
transformGeometryWithOptions(geometry, true, opt_options),
|
||||
opt_options
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export default EsriJSON;
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
/**
|
||||
* @module ol/format/Feature
|
||||
*/
|
||||
import {assign} from '../obj.js';
|
||||
import {abstract} from '../util.js';
|
||||
import {get as getProjection, equivalent as equivalentProjection, transformExtent} from '../proj.js';
|
||||
import Units from '../proj/Units.js';
|
||||
|
||||
import {abstract} from '../util.js';
|
||||
import {assign} from '../obj.js';
|
||||
import {
|
||||
equivalent as equivalentProjection,
|
||||
get as getProjection,
|
||||
transformExtent,
|
||||
} from '../proj.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} ReadOptions
|
||||
@@ -23,7 +26,6 @@ import Units from '../proj/Units.js';
|
||||
* `dataProjection`.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} WriteOptions
|
||||
* @property {import("../proj.js").ProjectionLike} [dataProjection] Projection of the data we are writing.
|
||||
@@ -49,7 +51,6 @@ import Units from '../proj/Units.js';
|
||||
* Default is no rounding.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Abstract base class; normally only used for creating subclasses and not
|
||||
@@ -64,7 +65,6 @@ import Units from '../proj/Units.js';
|
||||
*/
|
||||
class FeatureFormat {
|
||||
constructor() {
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {import("../proj/Projection.js").default}
|
||||
@@ -76,7 +76,6 @@ class FeatureFormat {
|
||||
* @type {import("../proj/Projection.js").default}
|
||||
*/
|
||||
this.defaultFeatureProjection = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,16 +88,20 @@ class FeatureFormat {
|
||||
getReadOptions(source, opt_options) {
|
||||
let options;
|
||||
if (opt_options) {
|
||||
let dataProjection = opt_options.dataProjection ?
|
||||
getProjection(opt_options.dataProjection) : this.readProjection(source);
|
||||
if (opt_options.extent &&
|
||||
dataProjection && dataProjection.getUnits() === Units.TILE_PIXELS) {
|
||||
let dataProjection = opt_options.dataProjection
|
||||
? getProjection(opt_options.dataProjection)
|
||||
: this.readProjection(source);
|
||||
if (
|
||||
opt_options.extent &&
|
||||
dataProjection &&
|
||||
dataProjection.getUnits() === Units.TILE_PIXELS
|
||||
) {
|
||||
dataProjection = getProjection(dataProjection);
|
||||
dataProjection.setWorldExtent(opt_options.extent);
|
||||
}
|
||||
options = {
|
||||
dataProjection: dataProjection,
|
||||
featureProjection: opt_options.featureProjection
|
||||
featureProjection: opt_options.featureProjection,
|
||||
};
|
||||
}
|
||||
return this.adaptOptions(options);
|
||||
@@ -114,10 +117,13 @@ class FeatureFormat {
|
||||
* Updated options.
|
||||
*/
|
||||
adaptOptions(options) {
|
||||
return assign({
|
||||
dataProjection: this.dataProjection,
|
||||
featureProjection: this.defaultFeatureProjection
|
||||
}, options);
|
||||
return assign(
|
||||
{
|
||||
dataProjection: this.dataProjection,
|
||||
featureProjection: this.defaultFeatureProjection,
|
||||
},
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,25 +227,41 @@ export default FeatureFormat;
|
||||
* @return {import("../geom/Geometry.js").default} Transformed geometry.
|
||||
*/
|
||||
export function transformGeometryWithOptions(geometry, write, opt_options) {
|
||||
const featureProjection = opt_options ? getProjection(opt_options.featureProjection) : null;
|
||||
const dataProjection = opt_options ? getProjection(opt_options.dataProjection) : null;
|
||||
const featureProjection = opt_options
|
||||
? getProjection(opt_options.featureProjection)
|
||||
: null;
|
||||
const dataProjection = opt_options
|
||||
? getProjection(opt_options.dataProjection)
|
||||
: null;
|
||||
|
||||
let transformed;
|
||||
if (featureProjection && dataProjection && !equivalentProjection(featureProjection, dataProjection)) {
|
||||
if (
|
||||
featureProjection &&
|
||||
dataProjection &&
|
||||
!equivalentProjection(featureProjection, dataProjection)
|
||||
) {
|
||||
transformed = (write ? geometry.clone() : geometry).transform(
|
||||
write ? featureProjection : dataProjection,
|
||||
write ? dataProjection : featureProjection);
|
||||
write ? dataProjection : featureProjection
|
||||
);
|
||||
} else {
|
||||
transformed = geometry;
|
||||
}
|
||||
if (write && opt_options && /** @type {WriteOptions} */ (opt_options).decimals !== undefined) {
|
||||
const power = Math.pow(10, /** @type {WriteOptions} */ (opt_options).decimals);
|
||||
if (
|
||||
write &&
|
||||
opt_options &&
|
||||
/** @type {WriteOptions} */ (opt_options).decimals !== undefined
|
||||
) {
|
||||
const power = Math.pow(
|
||||
10,
|
||||
/** @type {WriteOptions} */ (opt_options).decimals
|
||||
);
|
||||
// if decimals option on write, round each coordinate appropriately
|
||||
/**
|
||||
* @param {Array<number>} coordinates Coordinates.
|
||||
* @return {Array<number>} Transformed coordinates.
|
||||
*/
|
||||
const transform = function(coordinates) {
|
||||
const transform = function (coordinates) {
|
||||
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
coordinates[i] = Math.round(coordinates[i] * power) / power;
|
||||
}
|
||||
@@ -253,17 +275,24 @@ export function transformGeometryWithOptions(geometry, write, opt_options) {
|
||||
return transformed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../extent.js").Extent} extent Extent.
|
||||
* @param {ReadOptions=} opt_options Read options.
|
||||
* @return {import("../extent.js").Extent} Transformed extent.
|
||||
*/
|
||||
export function transformExtentWithOptions(extent, opt_options) {
|
||||
const featureProjection = opt_options ? getProjection(opt_options.featureProjection) : null;
|
||||
const dataProjection = opt_options ? getProjection(opt_options.dataProjection) : null;
|
||||
const featureProjection = opt_options
|
||||
? getProjection(opt_options.featureProjection)
|
||||
: null;
|
||||
const dataProjection = opt_options
|
||||
? getProjection(opt_options.dataProjection)
|
||||
: null;
|
||||
|
||||
if (featureProjection && dataProjection && !equivalentProjection(featureProjection, dataProjection)) {
|
||||
if (
|
||||
featureProjection &&
|
||||
dataProjection &&
|
||||
!equivalentProjection(featureProjection, dataProjection)
|
||||
) {
|
||||
return transformExtent(extent, dataProjection, featureProjection);
|
||||
} else {
|
||||
return extent;
|
||||
|
||||
@@ -9,5 +9,5 @@ export default {
|
||||
ARRAY_BUFFER: 'arraybuffer',
|
||||
JSON: 'json',
|
||||
TEXT: 'text',
|
||||
XML: 'xml'
|
||||
XML: 'xml',
|
||||
};
|
||||
|
||||
@@ -15,7 +15,6 @@ import GML3 from './GML3.js';
|
||||
*/
|
||||
const GML = GML3;
|
||||
|
||||
|
||||
/**
|
||||
* Encode an array of features in GML 3.1.1 Simple Features.
|
||||
*
|
||||
@@ -27,7 +26,6 @@ const GML = GML3;
|
||||
*/
|
||||
GML.prototype.writeFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* Encode an array of features in the GML 3.1.1 format as an XML node.
|
||||
*
|
||||
|
||||
@@ -1,22 +1,33 @@
|
||||
/**
|
||||
* @module ol/format/GML2
|
||||
*/
|
||||
import {createOrUpdate} from '../extent.js';
|
||||
import {transformExtentWithOptions, transformGeometryWithOptions} from './Feature.js';
|
||||
import GMLBase, {GMLNS} from './GMLBase.js';
|
||||
import {writeStringTextNode} from './xsd.js';
|
||||
import {
|
||||
OBJECT_PROPERTY_NODE_FACTORY,
|
||||
createElementNS,
|
||||
getAllTextContent,
|
||||
makeArrayPusher,
|
||||
makeChildAppender,
|
||||
makeReplacer,
|
||||
makeSimpleNodeFactory,
|
||||
pushParseAndPop,
|
||||
pushSerializeAndPop,
|
||||
} from '../xml.js';
|
||||
import {assign} from '../obj.js';
|
||||
import {createOrUpdate} from '../extent.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {createElementNS, getAllTextContent, makeArrayPusher, makeChildAppender,
|
||||
makeReplacer, makeSimpleNodeFactory, OBJECT_PROPERTY_NODE_FACTORY, pushParseAndPop, pushSerializeAndPop} from '../xml.js';
|
||||
|
||||
import {
|
||||
transformExtentWithOptions,
|
||||
transformGeometryWithOptions,
|
||||
} from './Feature.js';
|
||||
import {writeStringTextNode} from './xsd.js';
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
const schemaLocation = GMLNS + ' http://schemas.opengis.net/gml/2.1.2/feature.xsd';
|
||||
|
||||
const schemaLocation =
|
||||
GMLNS + ' http://schemas.opengis.net/gml/2.1.2/feature.xsd';
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -26,10 +37,9 @@ const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
|
||||
'MultiLineString': 'lineStringMember',
|
||||
'MultiCurve': 'curveMember',
|
||||
'MultiPolygon': 'polygonMember',
|
||||
'MultiSurface': 'surfaceMember'
|
||||
'MultiSurface': 'surfaceMember',
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for reading and writing data in the GML format,
|
||||
@@ -38,26 +48,26 @@ const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
|
||||
* @api
|
||||
*/
|
||||
class GML2 extends GMLBase {
|
||||
|
||||
/**
|
||||
* @param {import("./GMLBase.js").Options=} opt_options Optional configuration object.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = /** @type {import("./GMLBase.js").Options} */
|
||||
(opt_options ? opt_options : {});
|
||||
const options =
|
||||
/** @type {import("./GMLBase.js").Options} */
|
||||
(opt_options ? opt_options : {});
|
||||
|
||||
super(options);
|
||||
|
||||
this.FEATURE_COLLECTION_PARSERS[GMLNS][
|
||||
'featureMember'] =
|
||||
makeArrayPusher(this.readFeaturesInternal);
|
||||
this.FEATURE_COLLECTION_PARSERS[GMLNS]['featureMember'] = makeArrayPusher(
|
||||
this.readFeaturesInternal
|
||||
);
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.schemaLocation = options.schemaLocation ?
|
||||
options.schemaLocation : schemaLocation;
|
||||
|
||||
this.schemaLocation = options.schemaLocation
|
||||
? options.schemaLocation
|
||||
: schemaLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +93,7 @@ class GML2 extends GMLBase {
|
||||
const coords = coordsGroups[i].split(/,+/);
|
||||
const x = parseFloat(coords[0]);
|
||||
const y = parseFloat(coords[1]);
|
||||
const z = (coords.length === 3) ? parseFloat(coords[2]) : 0;
|
||||
const z = coords.length === 3 ? parseFloat(coords[2]) : 0;
|
||||
if (axisOrientation.substr(0, 2) === 'en') {
|
||||
flatCoordinates.push(x, y, z);
|
||||
} else {
|
||||
@@ -101,11 +111,19 @@ class GML2 extends GMLBase {
|
||||
*/
|
||||
readBox_(node, objectStack) {
|
||||
/** @type {Array<number>} */
|
||||
const flatCoordinates = pushParseAndPop([null],
|
||||
this.BOX_PARSERS_, node, objectStack, this);
|
||||
return createOrUpdate(flatCoordinates[1][0],
|
||||
flatCoordinates[1][1], flatCoordinates[1][3],
|
||||
flatCoordinates[1][4]);
|
||||
const flatCoordinates = pushParseAndPop(
|
||||
[null],
|
||||
this.BOX_PARSERS_,
|
||||
node,
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
return createOrUpdate(
|
||||
flatCoordinates[1][0],
|
||||
flatCoordinates[1][1],
|
||||
flatCoordinates[1][3],
|
||||
flatCoordinates[1][4]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,11 +133,17 @@ class GML2 extends GMLBase {
|
||||
*/
|
||||
innerBoundaryIsParser_(node, objectStack) {
|
||||
/** @type {Array<number>|undefined} */
|
||||
const flatLinearRing = pushParseAndPop(undefined,
|
||||
this.RING_PARSERS, node, objectStack, this);
|
||||
const flatLinearRing = pushParseAndPop(
|
||||
undefined,
|
||||
this.RING_PARSERS,
|
||||
node,
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
if (flatLinearRing) {
|
||||
const flatLinearRings = /** @type {Array<Array<number>>} */
|
||||
(objectStack[objectStack.length - 1]);
|
||||
const flatLinearRings =
|
||||
/** @type {Array<Array<number>>} */
|
||||
(objectStack[objectStack.length - 1]);
|
||||
flatLinearRings.push(flatLinearRing);
|
||||
}
|
||||
}
|
||||
@@ -131,11 +155,17 @@ class GML2 extends GMLBase {
|
||||
*/
|
||||
outerBoundaryIsParser_(node, objectStack) {
|
||||
/** @type {Array<number>|undefined} */
|
||||
const flatLinearRing = pushParseAndPop(undefined,
|
||||
this.RING_PARSERS, node, objectStack, this);
|
||||
const flatLinearRing = pushParseAndPop(
|
||||
undefined,
|
||||
this.RING_PARSERS,
|
||||
node,
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
if (flatLinearRing) {
|
||||
const flatLinearRings = /** @type {Array<Array<number>>} */
|
||||
(objectStack[objectStack.length - 1]);
|
||||
const flatLinearRings =
|
||||
/** @type {Array<Array<number>>} */
|
||||
(objectStack[objectStack.length - 1]);
|
||||
flatLinearRings[0] = flatLinearRing;
|
||||
}
|
||||
}
|
||||
@@ -166,8 +196,7 @@ class GML2 extends GMLBase {
|
||||
} else {
|
||||
nodeName = 'Envelope';
|
||||
}
|
||||
return createElementNS('http://www.opengis.net/gml',
|
||||
nodeName);
|
||||
return createElementNS('http://www.opengis.net/gml', nodeName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,25 +224,36 @@ class GML2 extends GMLBase {
|
||||
if (value !== null) {
|
||||
keys.push(key);
|
||||
values.push(value);
|
||||
if (key == geometryName || typeof /** @type {?} */ (value).getSimplifiedGeometry === 'function') {
|
||||
if (
|
||||
key == geometryName ||
|
||||
typeof (/** @type {?} */ (value).getSimplifiedGeometry) === 'function'
|
||||
) {
|
||||
if (!(key in context.serializers[featureNS])) {
|
||||
context.serializers[featureNS][key] = makeChildAppender(
|
||||
this.writeGeometryElement, this);
|
||||
this.writeGeometryElement,
|
||||
this
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (!(key in context.serializers[featureNS])) {
|
||||
context.serializers[featureNS][key] = makeChildAppender(writeStringTextNode);
|
||||
context.serializers[featureNS][key] = makeChildAppender(
|
||||
writeStringTextNode
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const item = assign({}, context);
|
||||
item.node = node;
|
||||
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */
|
||||
(item), context.serializers,
|
||||
pushSerializeAndPop(
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
(item),
|
||||
context.serializers,
|
||||
makeSimpleNodeFactory(undefined, featureNS),
|
||||
values,
|
||||
objectStack, keys);
|
||||
objectStack,
|
||||
keys
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,16 +268,17 @@ class GML2 extends GMLBase {
|
||||
if (node.nodeName !== 'LineStringSegment' && srsName) {
|
||||
node.setAttribute('srsName', srsName);
|
||||
}
|
||||
if (node.nodeName === 'LineString' ||
|
||||
node.nodeName === 'LineStringSegment') {
|
||||
if (
|
||||
node.nodeName === 'LineString' ||
|
||||
node.nodeName === 'LineStringSegment'
|
||||
) {
|
||||
const coordinates = this.createCoordinatesNode_(node.namespaceURI);
|
||||
node.appendChild(coordinates);
|
||||
this.writeCoordinates_(coordinates, geometry, objectStack);
|
||||
} else if (node.nodeName === 'Curve') {
|
||||
const segments = createElementNS(node.namespaceURI, 'segments');
|
||||
node.appendChild(segments);
|
||||
this.writeCurveSegments_(segments,
|
||||
geometry, objectStack);
|
||||
this.writeCurveSegments_(segments, geometry, objectStack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,10 +311,15 @@ class GML2 extends GMLBase {
|
||||
node.setAttribute('srsName', srsName);
|
||||
}
|
||||
const lines = geometry.getLineStrings();
|
||||
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, curve: curve},
|
||||
pushSerializeAndPop(
|
||||
{node: node, hasZ: hasZ, srsName: srsName, curve: curve},
|
||||
this.LINESTRINGORCURVEMEMBER_SERIALIZERS_,
|
||||
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines,
|
||||
objectStack, undefined, this);
|
||||
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_,
|
||||
lines,
|
||||
objectStack,
|
||||
undefined,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,19 +328,34 @@ class GML2 extends GMLBase {
|
||||
* @param {Array<*>} objectStack Node stack.
|
||||
*/
|
||||
writeGeometryElement(node, geometry, objectStack) {
|
||||
const context = /** @type {import("./Feature.js").WriteOptions} */ (objectStack[objectStack.length - 1]);
|
||||
const context = /** @type {import("./Feature.js").WriteOptions} */ (objectStack[
|
||||
objectStack.length - 1
|
||||
]);
|
||||
const item = assign({}, context);
|
||||
item['node'] = node;
|
||||
let value;
|
||||
if (Array.isArray(geometry)) {
|
||||
value = transformExtentWithOptions(/** @type {import("../extent.js").Extent} */ (geometry), context);
|
||||
value = transformExtentWithOptions(
|
||||
/** @type {import("../extent.js").Extent} */ (geometry),
|
||||
context
|
||||
);
|
||||
} else {
|
||||
value = transformGeometryWithOptions(/** @type {import("../geom/Geometry.js").default} */ (geometry), true, context);
|
||||
value = transformGeometryWithOptions(
|
||||
/** @type {import("../geom/Geometry.js").default} */ (geometry),
|
||||
true,
|
||||
context
|
||||
);
|
||||
}
|
||||
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */
|
||||
(item), this.GEOMETRY_SERIALIZERS_,
|
||||
this.GEOMETRY_NODE_FACTORY_, [value],
|
||||
objectStack, undefined, this);
|
||||
pushSerializeAndPop(
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
(item),
|
||||
this.GEOMETRY_SERIALIZERS_,
|
||||
this.GEOMETRY_NODE_FACTORY_,
|
||||
[value],
|
||||
objectStack,
|
||||
undefined,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,12 +424,15 @@ class GML2 extends GMLBase {
|
||||
{node: node, hasZ: hasZ, srsName: srsName},
|
||||
this.RING_SERIALIZERS_,
|
||||
this.RING_NODE_FACTORY_,
|
||||
rings, objectStack, undefined, this);
|
||||
rings,
|
||||
objectStack,
|
||||
undefined,
|
||||
this
|
||||
);
|
||||
} else if (node.nodeName === 'Surface') {
|
||||
const patches = createElementNS(node.namespaceURI, 'patches');
|
||||
node.appendChild(patches);
|
||||
this.writeSurfacePatches_(
|
||||
patches, geometry, objectStack);
|
||||
this.writeSurfacePatches_(patches, geometry, objectStack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,8 +450,10 @@ class GML2 extends GMLBase {
|
||||
if (exteriorWritten === undefined) {
|
||||
context['exteriorWritten'] = true;
|
||||
}
|
||||
return createElementNS(parentNode.namespaceURI,
|
||||
exteriorWritten !== undefined ? 'innerBoundaryIs' : 'outerBoundaryIs');
|
||||
return createElementNS(
|
||||
parentNode.namespaceURI,
|
||||
exteriorWritten !== undefined ? 'innerBoundaryIs' : 'outerBoundaryIs'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -426,9 +492,10 @@ class GML2 extends GMLBase {
|
||||
if (opt_srsName) {
|
||||
axisOrientation = getProjection(opt_srsName).getAxisOrientation();
|
||||
}
|
||||
let coords = ((axisOrientation.substr(0, 2) === 'en') ?
|
||||
point[0] + ',' + point[1] :
|
||||
point[1] + ',' + point[0]);
|
||||
let coords =
|
||||
axisOrientation.substr(0, 2) === 'en'
|
||||
? point[0] + ',' + point[1]
|
||||
: point[1] + ',' + point[0];
|
||||
if (opt_hasZ) {
|
||||
// For newly created points, Z can be undefined.
|
||||
const z = point[2] || 0;
|
||||
@@ -472,10 +539,15 @@ class GML2 extends GMLBase {
|
||||
node.setAttribute('srsName', srsName);
|
||||
}
|
||||
const points = geometry.getPoints();
|
||||
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName},
|
||||
pushSerializeAndPop(
|
||||
{node: node, hasZ: hasZ, srsName: srsName},
|
||||
this.POINTMEMBER_SERIALIZERS_,
|
||||
makeSimpleNodeFactory('pointMember'), points,
|
||||
objectStack, undefined, this);
|
||||
makeSimpleNodeFactory('pointMember'),
|
||||
points,
|
||||
objectStack,
|
||||
undefined,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -522,10 +594,15 @@ class GML2 extends GMLBase {
|
||||
node.setAttribute('srsName', srsName);
|
||||
}
|
||||
const polygons = geometry.getPolygons();
|
||||
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, surface: surface},
|
||||
pushSerializeAndPop(
|
||||
{node: node, hasZ: hasZ, srsName: srsName, surface: surface},
|
||||
this.SURFACEORPOLYGONMEMBER_SERIALIZERS_,
|
||||
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons,
|
||||
objectStack, undefined, this);
|
||||
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_,
|
||||
polygons,
|
||||
objectStack,
|
||||
undefined,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -535,8 +612,7 @@ class GML2 extends GMLBase {
|
||||
* @private
|
||||
*/
|
||||
writeSurfaceOrPolygonMember_(node, polygon, objectStack) {
|
||||
const child = this.GEOMETRY_NODE_FACTORY_(
|
||||
polygon, objectStack);
|
||||
const child = this.GEOMETRY_NODE_FACTORY_(polygon, objectStack);
|
||||
if (child) {
|
||||
node.appendChild(child);
|
||||
this.writeSurfaceOrPolygon_(child, polygon, objectStack);
|
||||
@@ -557,11 +633,16 @@ class GML2 extends GMLBase {
|
||||
}
|
||||
const keys = ['lowerCorner', 'upperCorner'];
|
||||
const values = [extent[0] + ' ' + extent[1], extent[2] + ' ' + extent[3]];
|
||||
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */
|
||||
({node: node}), this.ENVELOPE_SERIALIZERS_,
|
||||
pushSerializeAndPop(
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
({node: node}),
|
||||
this.ENVELOPE_SERIALIZERS_,
|
||||
OBJECT_PROPERTY_NODE_FACTORY,
|
||||
values,
|
||||
objectStack, keys, this);
|
||||
objectStack,
|
||||
keys,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -574,8 +655,10 @@ class GML2 extends GMLBase {
|
||||
*/
|
||||
MULTIGEOMETRY_MEMBER_NODE_FACTORY_(value, objectStack, opt_nodeName) {
|
||||
const parentNode = objectStack[objectStack.length - 1].node;
|
||||
return createElementNS('http://www.opengis.net/gml',
|
||||
MULTIGEOMETRY_TO_MEMBER_NODENAME[parentNode.nodeName]);
|
||||
return createElementNS(
|
||||
'http://www.opengis.net/gml',
|
||||
MULTIGEOMETRY_TO_MEMBER_NODENAME[parentNode.nodeName]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,8 +669,8 @@ class GML2 extends GMLBase {
|
||||
*/
|
||||
GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'coordinates': makeReplacer(GML2.prototype.readFlatCoordinates_)
|
||||
}
|
||||
'coordinates': makeReplacer(GML2.prototype.readFlatCoordinates_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -598,8 +681,8 @@ GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
|
||||
GML2.prototype.FLAT_LINEAR_RINGS_PARSERS = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'innerBoundaryIs': GML2.prototype.innerBoundaryIsParser_,
|
||||
'outerBoundaryIs': GML2.prototype.outerBoundaryIsParser_
|
||||
}
|
||||
'outerBoundaryIs': GML2.prototype.outerBoundaryIsParser_,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -609,9 +692,8 @@ GML2.prototype.FLAT_LINEAR_RINGS_PARSERS = {
|
||||
*/
|
||||
GML2.prototype.BOX_PARSERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'coordinates': makeArrayPusher(
|
||||
GML2.prototype.readFlatCoordinates_)
|
||||
}
|
||||
'coordinates': makeArrayPusher(GML2.prototype.readFlatCoordinates_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -622,19 +704,14 @@ GML2.prototype.BOX_PARSERS_ = {
|
||||
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),
|
||||
'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_)
|
||||
}
|
||||
'MultiPolygon': makeReplacer(GMLBase.prototype.readMultiPolygon),
|
||||
'Box': makeReplacer(GML2.prototype.readBox_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -644,30 +721,27 @@ GML2.prototype.GEOMETRY_PARSERS = {
|
||||
*/
|
||||
GML2.prototype.GEOMETRY_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'Curve': makeChildAppender(
|
||||
GML2.prototype.writeCurveOrLineString_),
|
||||
'Curve': makeChildAppender(GML2.prototype.writeCurveOrLineString_),
|
||||
'MultiCurve': makeChildAppender(
|
||||
GML2.prototype.writeMultiCurveOrLineString_),
|
||||
GML2.prototype.writeMultiCurveOrLineString_
|
||||
),
|
||||
'Point': makeChildAppender(GML2.prototype.writePoint_),
|
||||
'MultiPoint': makeChildAppender(
|
||||
GML2.prototype.writeMultiPoint_),
|
||||
'LineString': makeChildAppender(
|
||||
GML2.prototype.writeCurveOrLineString_),
|
||||
'MultiPoint': makeChildAppender(GML2.prototype.writeMultiPoint_),
|
||||
'LineString': makeChildAppender(GML2.prototype.writeCurveOrLineString_),
|
||||
'MultiLineString': makeChildAppender(
|
||||
GML2.prototype.writeMultiCurveOrLineString_),
|
||||
'LinearRing': makeChildAppender(
|
||||
GML2.prototype.writeLinearRing_),
|
||||
'Polygon': makeChildAppender(
|
||||
GML2.prototype.writeSurfaceOrPolygon_),
|
||||
GML2.prototype.writeMultiCurveOrLineString_
|
||||
),
|
||||
'LinearRing': makeChildAppender(GML2.prototype.writeLinearRing_),
|
||||
'Polygon': makeChildAppender(GML2.prototype.writeSurfaceOrPolygon_),
|
||||
'MultiPolygon': makeChildAppender(
|
||||
GML2.prototype.writeMultiSurfaceOrPolygon_),
|
||||
'Surface': makeChildAppender(
|
||||
GML2.prototype.writeSurfaceOrPolygon_),
|
||||
GML2.prototype.writeMultiSurfaceOrPolygon_
|
||||
),
|
||||
'Surface': makeChildAppender(GML2.prototype.writeSurfaceOrPolygon_),
|
||||
'MultiSurface': makeChildAppender(
|
||||
GML2.prototype.writeMultiSurfaceOrPolygon_),
|
||||
'Envelope': makeChildAppender(
|
||||
GML2.prototype.writeEnvelope)
|
||||
}
|
||||
GML2.prototype.writeMultiSurfaceOrPolygon_
|
||||
),
|
||||
'Envelope': makeChildAppender(GML2.prototype.writeEnvelope),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -677,10 +751,12 @@ GML2.prototype.GEOMETRY_SERIALIZERS_ = {
|
||||
GML2.prototype.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'lineStringMember': makeChildAppender(
|
||||
GML2.prototype.writeLineStringOrCurveMember_),
|
||||
GML2.prototype.writeLineStringOrCurveMember_
|
||||
),
|
||||
'curveMember': makeChildAppender(
|
||||
GML2.prototype.writeLineStringOrCurveMember_)
|
||||
}
|
||||
GML2.prototype.writeLineStringOrCurveMember_
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -690,8 +766,8 @@ GML2.prototype.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
|
||||
GML2.prototype.RING_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'outerBoundaryIs': makeChildAppender(GML2.prototype.writeRing_),
|
||||
'innerBoundaryIs': makeChildAppender(GML2.prototype.writeRing_)
|
||||
}
|
||||
'innerBoundaryIs': makeChildAppender(GML2.prototype.writeRing_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -700,9 +776,8 @@ GML2.prototype.RING_SERIALIZERS_ = {
|
||||
*/
|
||||
GML2.prototype.POINTMEMBER_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'pointMember': makeChildAppender(
|
||||
GML2.prototype.writePointMember_)
|
||||
}
|
||||
'pointMember': makeChildAppender(GML2.prototype.writePointMember_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -713,10 +788,12 @@ GML2.prototype.POINTMEMBER_SERIALIZERS_ = {
|
||||
GML2.prototype.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'surfaceMember': makeChildAppender(
|
||||
GML2.prototype.writeSurfaceOrPolygonMember_),
|
||||
GML2.prototype.writeSurfaceOrPolygonMember_
|
||||
),
|
||||
'polygonMember': makeChildAppender(
|
||||
GML2.prototype.writeSurfaceOrPolygonMember_)
|
||||
}
|
||||
GML2.prototype.writeSurfaceOrPolygonMember_
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -726,8 +803,8 @@ GML2.prototype.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
|
||||
GML2.prototype.ENVELOPE_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'lowerCorner': makeChildAppender(writeStringTextNode),
|
||||
'upperCorner': makeChildAppender(writeStringTextNode)
|
||||
}
|
||||
'upperCorner': makeChildAppender(writeStringTextNode),
|
||||
},
|
||||
};
|
||||
|
||||
export default GML2;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import GML3 from './GML3.js';
|
||||
import GMLBase from './GMLBase.js';
|
||||
import {makeArrayPusher, makeReplacer, makeChildAppender} from '../xml.js';
|
||||
import {makeArrayPusher, makeChildAppender, makeReplacer} from '../xml.js';
|
||||
import {writeStringTextNode} from '../format/xsd.js';
|
||||
|
||||
/**
|
||||
@@ -12,21 +12,22 @@ import {writeStringTextNode} from '../format/xsd.js';
|
||||
* @api
|
||||
*/
|
||||
class GML32 extends GML3 {
|
||||
|
||||
/**
|
||||
* @param {import("./GMLBase.js").Options=} opt_options Optional configuration object.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = /** @type {import("./GMLBase.js").Options} */ (opt_options ? opt_options : {});
|
||||
const options = /** @type {import("./GMLBase.js").Options} */ (opt_options
|
||||
? opt_options
|
||||
: {});
|
||||
|
||||
super(options);
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.schemaLocation = options.schemaLocation ?
|
||||
options.schemaLocation : this.namespace + ' http://schemas.opengis.net/gml/3.2.1/gml.xsd';
|
||||
|
||||
this.schemaLocation = options.schemaLocation
|
||||
? options.schemaLocation
|
||||
: this.namespace + ' http://schemas.opengis.net/gml/3.2.1/gml.xsd';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +41,8 @@ GML32.prototype.namespace = 'http://www.opengis.net/gml/3.2';
|
||||
GML32.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'pos': makeReplacer(GML3.prototype.readFlatPos_),
|
||||
'posList': makeReplacer(GML3.prototype.readFlatPosList_)
|
||||
}
|
||||
'posList': makeReplacer(GML3.prototype.readFlatPosList_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -52,8 +53,8 @@ GML32.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
|
||||
GML32.prototype.FLAT_LINEAR_RINGS_PARSERS = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'interior': GML3.prototype.interiorParser_,
|
||||
'exterior': GML3.prototype.exteriorParser_
|
||||
}
|
||||
'exterior': GML3.prototype.exteriorParser_,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -64,25 +65,18 @@ GML32.prototype.FLAT_LINEAR_RINGS_PARSERS = {
|
||||
GML32.prototype.GEOMETRY_PARSERS = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'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),
|
||||
'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),
|
||||
'MultiPolygon': makeReplacer(GMLBase.prototype.readMultiPolygon),
|
||||
'Surface': makeReplacer(GML32.prototype.readSurface_),
|
||||
'MultiSurface': makeReplacer(
|
||||
GML3.prototype.readMultiSurface_),
|
||||
'MultiSurface': makeReplacer(GML3.prototype.readMultiSurface_),
|
||||
'Curve': makeReplacer(GML32.prototype.readCurve_),
|
||||
'MultiCurve': makeReplacer(
|
||||
GML3.prototype.readMultiCurve_),
|
||||
'Envelope': makeReplacer(GML32.prototype.readEnvelope_)
|
||||
}
|
||||
'MultiCurve': makeReplacer(GML3.prototype.readMultiCurve_),
|
||||
'Envelope': makeReplacer(GML32.prototype.readEnvelope_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -92,11 +86,9 @@ GML32.prototype.GEOMETRY_PARSERS = {
|
||||
*/
|
||||
GML32.prototype.MULTICURVE_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'curveMember': makeArrayPusher(
|
||||
GML3.prototype.curveMemberParser_),
|
||||
'curveMembers': makeArrayPusher(
|
||||
GML3.prototype.curveMemberParser_)
|
||||
}
|
||||
'curveMember': makeArrayPusher(GML3.prototype.curveMemberParser_),
|
||||
'curveMembers': makeArrayPusher(GML3.prototype.curveMemberParser_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -106,11 +98,9 @@ GML32.prototype.MULTICURVE_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.MULTISURFACE_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'surfaceMember': makeArrayPusher(
|
||||
GML3.prototype.surfaceMemberParser_),
|
||||
'surfaceMembers': makeArrayPusher(
|
||||
GML3.prototype.surfaceMemberParser_)
|
||||
}
|
||||
'surfaceMember': makeArrayPusher(GML3.prototype.surfaceMemberParser_),
|
||||
'surfaceMembers': makeArrayPusher(GML3.prototype.surfaceMemberParser_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -120,10 +110,9 @@ GML32.prototype.MULTISURFACE_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.CURVEMEMBER_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'LineString': makeArrayPusher(
|
||||
GMLBase.prototype.readLineString),
|
||||
'Curve': makeArrayPusher(GML3.prototype.readCurve_)
|
||||
}
|
||||
'LineString': makeArrayPusher(GMLBase.prototype.readLineString),
|
||||
'Curve': makeArrayPusher(GML3.prototype.readCurve_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -134,8 +123,8 @@ GML32.prototype.CURVEMEMBER_PARSERS_ = {
|
||||
GML32.prototype.SURFACEMEMBER_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'Polygon': makeArrayPusher(GMLBase.prototype.readPolygon),
|
||||
'Surface': makeArrayPusher(GML3.prototype.readSurface_)
|
||||
}
|
||||
'Surface': makeArrayPusher(GML3.prototype.readSurface_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -145,8 +134,8 @@ GML32.prototype.SURFACEMEMBER_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.SURFACE_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'patches': makeReplacer(GML3.prototype.readPatch_)
|
||||
}
|
||||
'patches': makeReplacer(GML3.prototype.readPatch_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -156,8 +145,8 @@ GML32.prototype.SURFACE_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.CURVE_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'segments': makeReplacer(GML3.prototype.readSegment_)
|
||||
}
|
||||
'segments': makeReplacer(GML3.prototype.readSegment_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -167,11 +156,9 @@ GML32.prototype.CURVE_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.ENVELOPE_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'lowerCorner': makeArrayPusher(
|
||||
GML3.prototype.readFlatPosList_),
|
||||
'upperCorner': makeArrayPusher(
|
||||
GML3.prototype.readFlatPosList_)
|
||||
}
|
||||
'lowerCorner': makeArrayPusher(GML3.prototype.readFlatPosList_),
|
||||
'upperCorner': makeArrayPusher(GML3.prototype.readFlatPosList_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -181,9 +168,8 @@ GML32.prototype.ENVELOPE_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.PATCHES_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'PolygonPatch': makeReplacer(
|
||||
GML3.prototype.readPolygonPatch_)
|
||||
}
|
||||
'PolygonPatch': makeReplacer(GML3.prototype.readPolygonPatch_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -193,9 +179,8 @@ GML32.prototype.PATCHES_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.SEGMENTS_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'LineStringSegment': makeReplacer(
|
||||
GML3.prototype.readLineStringSegment_)
|
||||
}
|
||||
'LineStringSegment': makeReplacer(GML3.prototype.readLineStringSegment_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -205,11 +190,9 @@ GML32.prototype.SEGMENTS_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.MULTIPOINT_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'pointMember': makeArrayPusher(
|
||||
GMLBase.prototype.pointMemberParser_),
|
||||
'pointMembers': makeArrayPusher(
|
||||
GMLBase.prototype.pointMemberParser_)
|
||||
}
|
||||
'pointMember': makeArrayPusher(GMLBase.prototype.pointMemberParser_),
|
||||
'pointMembers': makeArrayPusher(GMLBase.prototype.pointMemberParser_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -220,10 +203,12 @@ GML32.prototype.MULTIPOINT_PARSERS_ = {
|
||||
GML32.prototype.MULTILINESTRING_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'lineStringMember': makeArrayPusher(
|
||||
GMLBase.prototype.lineStringMemberParser_),
|
||||
GMLBase.prototype.lineStringMemberParser_
|
||||
),
|
||||
'lineStringMembers': makeArrayPusher(
|
||||
GMLBase.prototype.lineStringMemberParser_)
|
||||
}
|
||||
GMLBase.prototype.lineStringMemberParser_
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -233,11 +218,9 @@ GML32.prototype.MULTILINESTRING_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.MULTIPOLYGON_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'polygonMember': makeArrayPusher(
|
||||
GMLBase.prototype.polygonMemberParser_),
|
||||
'polygonMembers': makeArrayPusher(
|
||||
GMLBase.prototype.polygonMemberParser_)
|
||||
}
|
||||
'polygonMember': makeArrayPusher(GMLBase.prototype.polygonMemberParser_),
|
||||
'polygonMembers': makeArrayPusher(GMLBase.prototype.polygonMemberParser_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -247,9 +230,8 @@ GML32.prototype.MULTIPOLYGON_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.POINTMEMBER_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'Point': makeArrayPusher(
|
||||
GMLBase.prototype.readFlatCoordinatesFromNode_)
|
||||
}
|
||||
'Point': makeArrayPusher(GMLBase.prototype.readFlatCoordinatesFromNode_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -259,9 +241,8 @@ GML32.prototype.POINTMEMBER_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.LINESTRINGMEMBER_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'LineString': makeArrayPusher(
|
||||
GMLBase.prototype.readLineString)
|
||||
}
|
||||
'LineString': makeArrayPusher(GMLBase.prototype.readLineString),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -271,9 +252,8 @@ GML32.prototype.LINESTRINGMEMBER_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.POLYGONMEMBER_PARSERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'Polygon': makeArrayPusher(
|
||||
GMLBase.prototype.readPolygon)
|
||||
}
|
||||
'Polygon': makeArrayPusher(GMLBase.prototype.readPolygon),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -283,9 +263,8 @@ GML32.prototype.POLYGONMEMBER_PARSERS_ = {
|
||||
*/
|
||||
GML32.prototype.RING_PARSERS = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'LinearRing': makeReplacer(
|
||||
GMLBase.prototype.readFlatLinearRing_)
|
||||
}
|
||||
'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing_),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -295,11 +274,10 @@ GML32.prototype.RING_PARSERS = {
|
||||
GML32.prototype.RING_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'exterior': makeChildAppender(GML3.prototype.writeRing_),
|
||||
'interior': makeChildAppender(GML3.prototype.writeRing_)
|
||||
}
|
||||
'interior': makeChildAppender(GML3.prototype.writeRing_),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
* @private
|
||||
@@ -307,11 +285,10 @@ GML32.prototype.RING_SERIALIZERS_ = {
|
||||
GML32.prototype.ENVELOPE_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'lowerCorner': makeChildAppender(writeStringTextNode),
|
||||
'upperCorner': makeChildAppender(writeStringTextNode)
|
||||
}
|
||||
'upperCorner': makeChildAppender(writeStringTextNode),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
* @private
|
||||
@@ -319,25 +296,24 @@ GML32.prototype.ENVELOPE_SERIALIZERS_ = {
|
||||
GML32.prototype.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'surfaceMember': makeChildAppender(
|
||||
GML3.prototype.writeSurfaceOrPolygonMember_),
|
||||
GML3.prototype.writeSurfaceOrPolygonMember_
|
||||
),
|
||||
'polygonMember': makeChildAppender(
|
||||
GML3.prototype.writeSurfaceOrPolygonMember_)
|
||||
}
|
||||
GML3.prototype.writeSurfaceOrPolygonMember_
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
* @private
|
||||
*/
|
||||
GML32.prototype.POINTMEMBER_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'pointMember': makeChildAppender(
|
||||
GML3.prototype.writePointMember_)
|
||||
}
|
||||
'pointMember': makeChildAppender(GML3.prototype.writePointMember_),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
* @private
|
||||
@@ -345,10 +321,12 @@ GML32.prototype.POINTMEMBER_SERIALIZERS_ = {
|
||||
GML32.prototype.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'lineStringMember': makeChildAppender(
|
||||
GML3.prototype.writeLineStringOrCurveMember_),
|
||||
GML3.prototype.writeLineStringOrCurveMember_
|
||||
),
|
||||
'curveMember': makeChildAppender(
|
||||
GML3.prototype.writeLineStringOrCurveMember_)
|
||||
}
|
||||
GML3.prototype.writeLineStringOrCurveMember_
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -357,30 +335,27 @@ GML32.prototype.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
|
||||
*/
|
||||
GML32.prototype.GEOMETRY_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'Curve': makeChildAppender(
|
||||
GML3.prototype.writeCurveOrLineString_),
|
||||
'Curve': makeChildAppender(GML3.prototype.writeCurveOrLineString_),
|
||||
'MultiCurve': makeChildAppender(
|
||||
GML3.prototype.writeMultiCurveOrLineString_),
|
||||
GML3.prototype.writeMultiCurveOrLineString_
|
||||
),
|
||||
'Point': makeChildAppender(GML32.prototype.writePoint_),
|
||||
'MultiPoint': makeChildAppender(
|
||||
GML3.prototype.writeMultiPoint_),
|
||||
'LineString': makeChildAppender(
|
||||
GML3.prototype.writeCurveOrLineString_),
|
||||
'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_),
|
||||
GML3.prototype.writeMultiCurveOrLineString_
|
||||
),
|
||||
'LinearRing': makeChildAppender(GML3.prototype.writeLinearRing_),
|
||||
'Polygon': makeChildAppender(GML3.prototype.writeSurfaceOrPolygon_),
|
||||
'MultiPolygon': makeChildAppender(
|
||||
GML3.prototype.writeMultiSurfaceOrPolygon_),
|
||||
'Surface': makeChildAppender(
|
||||
GML3.prototype.writeSurfaceOrPolygon_),
|
||||
GML3.prototype.writeMultiSurfaceOrPolygon_
|
||||
),
|
||||
'Surface': makeChildAppender(GML3.prototype.writeSurfaceOrPolygon_),
|
||||
'MultiSurface': makeChildAppender(
|
||||
GML3.prototype.writeMultiSurfaceOrPolygon_),
|
||||
'Envelope': makeChildAppender(
|
||||
GML3.prototype.writeEnvelope)
|
||||
}
|
||||
GML3.prototype.writeMultiSurfaceOrPolygon_
|
||||
),
|
||||
'Envelope': makeChildAppender(GML3.prototype.writeEnvelope),
|
||||
},
|
||||
};
|
||||
|
||||
export default GML32;
|
||||
|
||||
@@ -4,10 +4,7 @@
|
||||
// FIXME Envelopes should not be treated as geometries! readEnvelope_ is part
|
||||
// of GEOMETRY_PARSERS_ and methods using GEOMETRY_PARSERS_ do not expect
|
||||
// envelopes/extents, only geometries!
|
||||
import {extend} from '../array.js';
|
||||
import Feature from '../Feature.js';
|
||||
import {transformGeometryWithOptions, transformExtentWithOptions} from './Feature.js';
|
||||
import XMLFeature from './XMLFeature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import LinearRing from '../geom/LinearRing.js';
|
||||
@@ -16,10 +13,22 @@ import MultiPoint from '../geom/MultiPoint.js';
|
||||
import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import XMLFeature from './XMLFeature.js';
|
||||
import {assign} from '../obj.js';
|
||||
import {extend} from '../array.js';
|
||||
import {
|
||||
getAllTextContent,
|
||||
getAttributeNS,
|
||||
makeArrayPusher,
|
||||
makeReplacer,
|
||||
parseNode,
|
||||
pushParseAndPop,
|
||||
} from '../xml.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {getAllTextContent, getAttributeNS, makeArrayPusher, makeReplacer, parseNode, pushParseAndPop} from '../xml.js';
|
||||
|
||||
import {
|
||||
transformExtentWithOptions,
|
||||
transformGeometryWithOptions,
|
||||
} from './Feature.js';
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -27,7 +36,6 @@ import {getAllTextContent, getAttributeNS, makeArrayPusher, makeReplacer, parseN
|
||||
*/
|
||||
export const GMLNS = 'http://www.opengis.net/gml';
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression that matches if a string only contains whitespace
|
||||
* characters. It will e.g. match `''`, `' '`, `'\n'` etc. The non-breaking
|
||||
@@ -41,7 +49,6 @@ export const GMLNS = 'http://www.opengis.net/gml';
|
||||
*/
|
||||
const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {Object<string, string>|string} [featureNS] Feature
|
||||
@@ -74,7 +81,6 @@ const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
|
||||
* @property {boolean} [hasZ=false] If coordinates have a Z value.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Abstract base class; normally only used for creating subclasses and not
|
||||
@@ -86,7 +92,6 @@ const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
|
||||
* @abstract
|
||||
*/
|
||||
class GMLBase extends XMLFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Optional configuration object.
|
||||
*/
|
||||
@@ -125,7 +130,7 @@ class GMLBase extends XMLFeature {
|
||||
this.FEATURE_COLLECTION_PARSERS = {};
|
||||
this.FEATURE_COLLECTION_PARSERS[this.namespace] = {
|
||||
'featureMember': makeArrayPusher(this.readFeaturesInternal),
|
||||
'featureMembers': makeReplacer(this.readFeaturesInternal)
|
||||
'featureMembers': makeReplacer(this.readFeaturesInternal),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -138,9 +143,13 @@ class GMLBase extends XMLFeature {
|
||||
const localName = node.localName;
|
||||
let features = null;
|
||||
if (localName == 'FeatureCollection') {
|
||||
features = pushParseAndPop([],
|
||||
this.FEATURE_COLLECTION_PARSERS, node,
|
||||
objectStack, this);
|
||||
features = pushParseAndPop(
|
||||
[],
|
||||
this.FEATURE_COLLECTION_PARSERS,
|
||||
node,
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
} else if (localName == 'featureMembers' || localName == 'featureMember') {
|
||||
const context = objectStack[0];
|
||||
let featureType = context['featureType'];
|
||||
@@ -148,7 +157,7 @@ class GMLBase extends XMLFeature {
|
||||
const prefix = 'p';
|
||||
const defaultPrefix = 'p0';
|
||||
if (!featureType && node.childNodes) {
|
||||
featureType = [], featureNS = {};
|
||||
(featureType = []), (featureNS = {});
|
||||
for (let i = 0, ii = node.childNodes.length; i < ii; ++i) {
|
||||
const child = node.childNodes[i];
|
||||
if (child.nodeType === 1) {
|
||||
@@ -185,18 +194,22 @@ class GMLBase extends XMLFeature {
|
||||
}
|
||||
/** @type {Object<string, Object<string, import("../xml.js").Parser>>} */
|
||||
const parsersNS = {};
|
||||
const featureTypes = Array.isArray(featureType) ? featureType : [featureType];
|
||||
const featureTypes = Array.isArray(featureType)
|
||||
? featureType
|
||||
: [featureType];
|
||||
for (const p in featureNS) {
|
||||
/** @type {Object<string, import("../xml.js").Parser>} */
|
||||
const parsers = {};
|
||||
for (let i = 0, ii = featureTypes.length; i < ii; ++i) {
|
||||
const featurePrefix = featureTypes[i].indexOf(':') === -1 ?
|
||||
defaultPrefix : featureTypes[i].split(':')[0];
|
||||
const featurePrefix =
|
||||
featureTypes[i].indexOf(':') === -1
|
||||
? defaultPrefix
|
||||
: featureTypes[i].split(':')[0];
|
||||
if (featurePrefix === p) {
|
||||
parsers[featureTypes[i].split(':').pop()] =
|
||||
(localName == 'featureMembers') ?
|
||||
makeArrayPusher(this.readFeatureElement, this) :
|
||||
makeReplacer(this.readFeatureElement, this);
|
||||
localName == 'featureMembers'
|
||||
? makeArrayPusher(this.readFeatureElement, this)
|
||||
: makeReplacer(this.readFeatureElement, this);
|
||||
}
|
||||
}
|
||||
parsersNS[featureNS[p]] = parsers;
|
||||
@@ -221,13 +234,28 @@ class GMLBase extends XMLFeature {
|
||||
readGeometryElement(node, objectStack) {
|
||||
const context = /** @type {Object} */ (objectStack[0]);
|
||||
context['srsName'] = node.firstElementChild.getAttribute('srsName');
|
||||
context['srsDimension'] = node.firstElementChild.getAttribute('srsDimension');
|
||||
const geometry = pushParseAndPop(null, this.GEOMETRY_PARSERS, node, objectStack, this);
|
||||
context['srsDimension'] = node.firstElementChild.getAttribute(
|
||||
'srsDimension'
|
||||
);
|
||||
const geometry = pushParseAndPop(
|
||||
null,
|
||||
this.GEOMETRY_PARSERS,
|
||||
node,
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
if (geometry) {
|
||||
if (Array.isArray(geometry)) {
|
||||
return transformExtentWithOptions(/** @type {import("../extent.js").Extent} */ (geometry), context);
|
||||
return transformExtentWithOptions(
|
||||
/** @type {import("../extent.js").Extent} */ (geometry),
|
||||
context
|
||||
);
|
||||
} else {
|
||||
return transformGeometryWithOptions(/** @type {import("../geom/Geometry.js").default} */ (geometry), false, context);
|
||||
return transformGeometryWithOptions(
|
||||
/** @type {import("../geom/Geometry.js").default} */ (geometry),
|
||||
false,
|
||||
context
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return undefined;
|
||||
@@ -247,8 +275,11 @@ class GMLBase extends XMLFeature {
|
||||
let value;
|
||||
const localName = n.localName;
|
||||
// first, check if it is simple attribute
|
||||
if (n.childNodes.length === 0
|
||||
|| (n.childNodes.length === 1 && (n.firstChild.nodeType === 3 || n.firstChild.nodeType === 4))) {
|
||||
if (
|
||||
n.childNodes.length === 0 ||
|
||||
(n.childNodes.length === 1 &&
|
||||
(n.firstChild.nodeType === 3 || n.firstChild.nodeType === 4))
|
||||
) {
|
||||
value = getAllTextContent(n, false);
|
||||
if (ONLY_WHITESPACE_RE.test(value)) {
|
||||
value = undefined;
|
||||
@@ -258,7 +289,8 @@ class GMLBase extends XMLFeature {
|
||||
//if feature, try it as a geometry
|
||||
value = this.readGeometryElement(n, objectStack);
|
||||
}
|
||||
if (!value) { //if not a geometry or not a feature, treat it as a complex attribute
|
||||
if (!value) {
|
||||
//if not a geometry or not a feature, treat it as a complex attribute
|
||||
value = this.readFeatureElementInternal(n, objectStack, false);
|
||||
} else if (localName !== 'boundedBy') {
|
||||
// boundedBy is an extent and must not be considered as a geometry
|
||||
@@ -291,8 +323,8 @@ class GMLBase extends XMLFeature {
|
||||
if (geometryName) {
|
||||
feature.setGeometryName(geometryName);
|
||||
}
|
||||
const fid = node.getAttribute('fid') ||
|
||||
getAttributeNS(node, this.namespace, 'id');
|
||||
const fid =
|
||||
node.getAttribute('fid') || getAttributeNS(node, this.namespace, 'id');
|
||||
if (fid) {
|
||||
feature.setId(fid);
|
||||
}
|
||||
@@ -300,7 +332,6 @@ class GMLBase extends XMLFeature {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -316,7 +347,10 @@ class GMLBase extends XMLFeature {
|
||||
* @return {Point|undefined} Point.
|
||||
*/
|
||||
readPoint(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
if (flatCoordinates) {
|
||||
return new Point(flatCoordinates, GeometryLayout.XYZ);
|
||||
}
|
||||
@@ -329,8 +363,13 @@ class GMLBase extends XMLFeature {
|
||||
*/
|
||||
readMultiPoint(node, objectStack) {
|
||||
/** @type {Array<Array<number>>} */
|
||||
const coordinates = pushParseAndPop([],
|
||||
this.MULTIPOINT_PARSERS_, node, objectStack, this);
|
||||
const coordinates = pushParseAndPop(
|
||||
[],
|
||||
this.MULTIPOINT_PARSERS_,
|
||||
node,
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
if (coordinates) {
|
||||
return new MultiPoint(coordinates);
|
||||
} else {
|
||||
@@ -345,8 +384,13 @@ class GMLBase extends XMLFeature {
|
||||
*/
|
||||
readMultiLineString(node, objectStack) {
|
||||
/** @type {Array<LineString>} */
|
||||
const lineStrings = pushParseAndPop([],
|
||||
this.MULTILINESTRING_PARSERS_, node, objectStack, this);
|
||||
const lineStrings = pushParseAndPop(
|
||||
[],
|
||||
this.MULTILINESTRING_PARSERS_,
|
||||
node,
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
if (lineStrings) {
|
||||
return new MultiLineString(lineStrings);
|
||||
}
|
||||
@@ -359,7 +403,13 @@ class GMLBase extends XMLFeature {
|
||||
*/
|
||||
readMultiPolygon(node, objectStack) {
|
||||
/** @type {Array<Polygon>} */
|
||||
const polygons = pushParseAndPop([], this.MULTIPOLYGON_PARSERS_, node, objectStack, this);
|
||||
const polygons = pushParseAndPop(
|
||||
[],
|
||||
this.MULTIPOLYGON_PARSERS_,
|
||||
node,
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
if (polygons) {
|
||||
return new MultiPolygon(polygons);
|
||||
}
|
||||
@@ -398,7 +448,10 @@ class GMLBase extends XMLFeature {
|
||||
* @return {LineString|undefined} LineString.
|
||||
*/
|
||||
readLineString(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
if (flatCoordinates) {
|
||||
const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ);
|
||||
return lineString;
|
||||
@@ -414,9 +467,13 @@ class GMLBase extends XMLFeature {
|
||||
* @return {Array<number>|undefined} LinearRing flat coordinates.
|
||||
*/
|
||||
readFlatLinearRing_(node, objectStack) {
|
||||
const ring = pushParseAndPop(null,
|
||||
this.GEOMETRY_FLAT_COORDINATES_PARSERS, node,
|
||||
objectStack, this);
|
||||
const ring = pushParseAndPop(
|
||||
null,
|
||||
this.GEOMETRY_FLAT_COORDINATES_PARSERS,
|
||||
node,
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
if (ring) {
|
||||
return ring;
|
||||
} else {
|
||||
@@ -430,7 +487,10 @@ class GMLBase extends XMLFeature {
|
||||
* @return {LinearRing|undefined} LinearRing.
|
||||
*/
|
||||
readLinearRing(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
if (flatCoordinates) {
|
||||
return new LinearRing(flatCoordinates, GeometryLayout.XYZ);
|
||||
}
|
||||
@@ -443,8 +503,13 @@ class GMLBase extends XMLFeature {
|
||||
*/
|
||||
readPolygon(node, objectStack) {
|
||||
/** @type {Array<Array<number>>} */
|
||||
const flatLinearRings = pushParseAndPop([null],
|
||||
this.FLAT_LINEAR_RINGS_PARSERS, node, objectStack, this);
|
||||
const flatLinearRings = pushParseAndPop(
|
||||
[null],
|
||||
this.FLAT_LINEAR_RINGS_PARSERS,
|
||||
node,
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
if (flatLinearRings && flatLinearRings[0]) {
|
||||
const flatCoordinates = flatLinearRings[0];
|
||||
const ends = [flatCoordinates.length];
|
||||
@@ -466,7 +531,13 @@ class GMLBase extends XMLFeature {
|
||||
* @return {Array<number>} Flat coordinates.
|
||||
*/
|
||||
readFlatCoordinatesFromNode_(node, objectStack) {
|
||||
return pushParseAndPop(null, this.GEOMETRY_FLAT_COORDINATES_PARSERS, node, objectStack, this);
|
||||
return pushParseAndPop(
|
||||
null,
|
||||
this.GEOMETRY_FLAT_COORDINATES_PARSERS,
|
||||
node,
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -477,8 +548,9 @@ class GMLBase extends XMLFeature {
|
||||
*/
|
||||
//@ts-ignore
|
||||
readGeometryFromNode(node, opt_options) {
|
||||
const geometry = this.readGeometryElement(node,
|
||||
[this.getReadOptions(node, opt_options ? opt_options : {})]);
|
||||
const geometry = this.readGeometryElement(node, [
|
||||
this.getReadOptions(node, opt_options ? opt_options : {}),
|
||||
]);
|
||||
return geometry ? geometry : null;
|
||||
}
|
||||
|
||||
@@ -490,7 +562,7 @@ class GMLBase extends XMLFeature {
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
const options = {
|
||||
featureType: this.featureType,
|
||||
featureNS: this.featureNS
|
||||
featureNS: this.featureNS,
|
||||
};
|
||||
if (opt_options) {
|
||||
assign(options, this.getReadOptions(node, opt_options));
|
||||
@@ -504,44 +576,43 @@ class GMLBase extends XMLFeature {
|
||||
* @return {import("../proj/Projection.js").default} Projection.
|
||||
*/
|
||||
readProjectionFromNode(node) {
|
||||
return getProjection(this.srsName ? this.srsName : node.firstElementChild.getAttribute('srsName'));
|
||||
return getProjection(
|
||||
this.srsName
|
||||
? this.srsName
|
||||
: node.firstElementChild.getAttribute('srsName')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GMLBase.prototype.namespace = GMLNS;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
* @protected
|
||||
*/
|
||||
GMLBase.prototype.FLAT_LINEAR_RINGS_PARSERS = {
|
||||
'http://www.opengis.net/gml': {}
|
||||
'http://www.opengis.net/gml': {},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
* @protected
|
||||
*/
|
||||
GMLBase.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
|
||||
'http://www.opengis.net/gml': {}
|
||||
'http://www.opengis.net/gml': {},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
* @protected
|
||||
*/
|
||||
GMLBase.prototype.GEOMETRY_PARSERS = {
|
||||
'http://www.opengis.net/gml': {}
|
||||
'http://www.opengis.net/gml': {},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
@@ -550,11 +621,10 @@ GMLBase.prototype.GEOMETRY_PARSERS = {
|
||||
GMLBase.prototype.MULTIPOINT_PARSERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'pointMember': makeArrayPusher(GMLBase.prototype.pointMemberParser_),
|
||||
'pointMembers': makeArrayPusher(GMLBase.prototype.pointMemberParser_)
|
||||
}
|
||||
'pointMembers': makeArrayPusher(GMLBase.prototype.pointMemberParser_),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
@@ -562,12 +632,15 @@ GMLBase.prototype.MULTIPOINT_PARSERS_ = {
|
||||
*/
|
||||
GMLBase.prototype.MULTILINESTRING_PARSERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'lineStringMember': makeArrayPusher(GMLBase.prototype.lineStringMemberParser_),
|
||||
'lineStringMembers': makeArrayPusher(GMLBase.prototype.lineStringMemberParser_)
|
||||
}
|
||||
'lineStringMember': makeArrayPusher(
|
||||
GMLBase.prototype.lineStringMemberParser_
|
||||
),
|
||||
'lineStringMembers': makeArrayPusher(
|
||||
GMLBase.prototype.lineStringMemberParser_
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
@@ -576,11 +649,10 @@ GMLBase.prototype.MULTILINESTRING_PARSERS_ = {
|
||||
GMLBase.prototype.MULTIPOLYGON_PARSERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'polygonMember': makeArrayPusher(GMLBase.prototype.polygonMemberParser_),
|
||||
'polygonMembers': makeArrayPusher(GMLBase.prototype.polygonMemberParser_)
|
||||
}
|
||||
'polygonMembers': makeArrayPusher(GMLBase.prototype.polygonMemberParser_),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
@@ -588,11 +660,10 @@ GMLBase.prototype.MULTIPOLYGON_PARSERS_ = {
|
||||
*/
|
||||
GMLBase.prototype.POINTMEMBER_PARSERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'Point': makeArrayPusher(GMLBase.prototype.readFlatCoordinatesFromNode_)
|
||||
}
|
||||
'Point': makeArrayPusher(GMLBase.prototype.readFlatCoordinatesFromNode_),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
@@ -600,11 +671,10 @@ GMLBase.prototype.POINTMEMBER_PARSERS_ = {
|
||||
*/
|
||||
GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'LineString': makeArrayPusher(GMLBase.prototype.readLineString)
|
||||
}
|
||||
'LineString': makeArrayPusher(GMLBase.prototype.readLineString),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
@@ -612,11 +682,10 @@ GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = {
|
||||
*/
|
||||
GMLBase.prototype.POLYGONMEMBER_PARSERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'Polygon': makeArrayPusher(GMLBase.prototype.readPolygon)
|
||||
}
|
||||
'Polygon': makeArrayPusher(GMLBase.prototype.readPolygon),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
@@ -624,8 +693,8 @@ GMLBase.prototype.POLYGONMEMBER_PARSERS_ = {
|
||||
*/
|
||||
GMLBase.prototype.RING_PARSERS = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing_)
|
||||
}
|
||||
'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing_),
|
||||
},
|
||||
};
|
||||
|
||||
export default GMLBase;
|
||||
|
||||
@@ -2,21 +2,40 @@
|
||||
* @module ol/format/GPX
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import {includes} from '../array.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
import XMLFeature from './XMLFeature.js';
|
||||
import {readString, readDecimal, readNonNegativeInteger, readDateTime, writeStringTextNode, writeNonNegativeIntegerTextNode, writeDecimalTextNode, writeDateTimeTextNode} from './xsd.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import XMLFeature from './XMLFeature.js';
|
||||
import {
|
||||
OBJECT_PROPERTY_NODE_FACTORY,
|
||||
XML_SCHEMA_INSTANCE_URI,
|
||||
createElementNS,
|
||||
makeArrayPusher,
|
||||
makeArraySerializer,
|
||||
makeChildAppender,
|
||||
makeObjectPropertySetter,
|
||||
makeSequence,
|
||||
makeSimpleNodeFactory,
|
||||
makeStructureNS,
|
||||
parseNode,
|
||||
pushParseAndPop,
|
||||
pushSerializeAndPop,
|
||||
} from '../xml.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {createElementNS, makeArrayPusher, makeArraySerializer, makeChildAppender,
|
||||
makeObjectPropertySetter, makeSequence, makeSimpleNodeFactory, makeStructureNS,
|
||||
OBJECT_PROPERTY_NODE_FACTORY, parseNode, pushParseAndPop, pushSerializeAndPop,
|
||||
XML_SCHEMA_INSTANCE_URI} from '../xml.js';
|
||||
|
||||
import {includes} from '../array.js';
|
||||
import {
|
||||
readDateTime,
|
||||
readDecimal,
|
||||
readNonNegativeInteger,
|
||||
readString,
|
||||
writeDateTimeTextNode,
|
||||
writeDecimalTextNode,
|
||||
writeNonNegativeIntegerTextNode,
|
||||
writeStringTextNode,
|
||||
} from './xsd.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -25,17 +44,16 @@ import {createElementNS, makeArrayPusher, makeArraySerializer, makeChildAppender
|
||||
const NAMESPACE_URIS = [
|
||||
null,
|
||||
'http://www.topografix.com/GPX/1/0',
|
||||
'http://www.topografix.com/GPX/1/1'
|
||||
'http://www.topografix.com/GPX/1/1',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
const SCHEMA_LOCATION = 'http://www.topografix.com/GPX/1/1 ' +
|
||||
'http://www.topografix.com/GPX/1/1/gpx.xsd';
|
||||
|
||||
const SCHEMA_LOCATION =
|
||||
'http://www.topografix.com/GPX/1/1 ' +
|
||||
'http://www.topografix.com/GPX/1/1/gpx.xsd';
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -44,47 +62,40 @@ const SCHEMA_LOCATION = 'http://www.topografix.com/GPX/1/1 ' +
|
||||
const FEATURE_READER = {
|
||||
'rte': readRte,
|
||||
'trk': readTrk,
|
||||
'wpt': readWpt
|
||||
'wpt': readWpt,
|
||||
};
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const GPX_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'rte': makeArrayPusher(readRte),
|
||||
'trk': makeArrayPusher(readTrk),
|
||||
'wpt': makeArrayPusher(readWpt),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const GPX_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'rte': makeArrayPusher(readRte),
|
||||
'trk': makeArrayPusher(readTrk),
|
||||
'wpt': makeArrayPusher(readWpt)
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const LINK_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'text': makeObjectPropertySetter(readString, 'linkText'),
|
||||
'type': makeObjectPropertySetter(readString, 'linkType')
|
||||
});
|
||||
|
||||
const LINK_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'text': makeObjectPropertySetter(readString, 'linkText'),
|
||||
'type': makeObjectPropertySetter(readString, 'linkType'),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const GPX_SERIALIZERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'rte': makeChildAppender(writeRte),
|
||||
'trk': makeChildAppender(writeTrk),
|
||||
'wpt': makeChildAppender(writeWpt)
|
||||
});
|
||||
|
||||
const GPX_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'rte': makeChildAppender(writeRte),
|
||||
'trk': makeChildAppender(writeTrk),
|
||||
'wpt': makeChildAppender(writeWpt),
|
||||
});
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
@@ -119,7 +130,6 @@ const GPX_SERIALIZERS = makeStructureNS(
|
||||
* @api
|
||||
*/
|
||||
class GPX extends XMLFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
@@ -128,7 +138,6 @@ class GPX extends XMLFeature {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
|
||||
/**
|
||||
* @type {import("../proj/Projection.js").default}
|
||||
*/
|
||||
@@ -172,7 +181,9 @@ class GPX extends XMLFeature {
|
||||
if (!featureReader) {
|
||||
return null;
|
||||
}
|
||||
const feature = featureReader(node, [this.getReadOptions(node, opt_options)]);
|
||||
const feature = featureReader(node, [
|
||||
this.getReadOptions(node, opt_options),
|
||||
]);
|
||||
if (!feature) {
|
||||
return null;
|
||||
}
|
||||
@@ -191,8 +202,9 @@ class GPX extends XMLFeature {
|
||||
}
|
||||
if (node.localName == 'gpx') {
|
||||
/** @type {Array<Feature>} */
|
||||
const features = pushParseAndPop([], GPX_PARSERS,
|
||||
node, [this.getReadOptions(node, opt_options)]);
|
||||
const features = pushParseAndPop([], GPX_PARSERS, node, [
|
||||
this.getReadOptions(node, opt_options),
|
||||
]);
|
||||
if (features) {
|
||||
this.handleReadExtensions_(features);
|
||||
return features;
|
||||
@@ -219,118 +231,115 @@ class GPX extends XMLFeature {
|
||||
const gpx = createElementNS('http://www.topografix.com/GPX/1/1', 'gpx');
|
||||
const xmlnsUri = 'http://www.w3.org/2000/xmlns/';
|
||||
gpx.setAttributeNS(xmlnsUri, 'xmlns:xsi', XML_SCHEMA_INSTANCE_URI);
|
||||
gpx.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', SCHEMA_LOCATION);
|
||||
gpx.setAttributeNS(
|
||||
XML_SCHEMA_INSTANCE_URI,
|
||||
'xsi:schemaLocation',
|
||||
SCHEMA_LOCATION
|
||||
);
|
||||
gpx.setAttribute('version', '1.1');
|
||||
gpx.setAttribute('creator', 'OpenLayers');
|
||||
|
||||
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */
|
||||
({node: gpx}), GPX_SERIALIZERS, GPX_NODE_FACTORY, features, [opt_options]);
|
||||
pushSerializeAndPop(
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
({node: gpx}),
|
||||
GPX_SERIALIZERS,
|
||||
GPX_NODE_FACTORY,
|
||||
features,
|
||||
[opt_options]
|
||||
);
|
||||
return gpx;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const RTE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'name': makeObjectPropertySetter(readString),
|
||||
'cmt': makeObjectPropertySetter(readString),
|
||||
'desc': makeObjectPropertySetter(readString),
|
||||
'src': makeObjectPropertySetter(readString),
|
||||
'link': parseLink,
|
||||
'number': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'extensions': parseExtensions,
|
||||
'type': makeObjectPropertySetter(readString),
|
||||
'rtept': parseRtePt,
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const RTE_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'name': makeObjectPropertySetter(readString),
|
||||
'cmt': makeObjectPropertySetter(readString),
|
||||
'desc': makeObjectPropertySetter(readString),
|
||||
'src': makeObjectPropertySetter(readString),
|
||||
'link': parseLink,
|
||||
'number': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'extensions': parseExtensions,
|
||||
'type': makeObjectPropertySetter(readString),
|
||||
'rtept': parseRtePt
|
||||
});
|
||||
|
||||
const RTEPT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'ele': makeObjectPropertySetter(readDecimal),
|
||||
'time': makeObjectPropertySetter(readDateTime),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const RTEPT_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'ele': makeObjectPropertySetter(readDecimal),
|
||||
'time': makeObjectPropertySetter(readDateTime)
|
||||
});
|
||||
|
||||
const TRK_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'name': makeObjectPropertySetter(readString),
|
||||
'cmt': makeObjectPropertySetter(readString),
|
||||
'desc': makeObjectPropertySetter(readString),
|
||||
'src': makeObjectPropertySetter(readString),
|
||||
'link': parseLink,
|
||||
'number': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'type': makeObjectPropertySetter(readString),
|
||||
'extensions': parseExtensions,
|
||||
'trkseg': parseTrkSeg,
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const TRK_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'name': makeObjectPropertySetter(readString),
|
||||
'cmt': makeObjectPropertySetter(readString),
|
||||
'desc': makeObjectPropertySetter(readString),
|
||||
'src': makeObjectPropertySetter(readString),
|
||||
'link': parseLink,
|
||||
'number': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'type': makeObjectPropertySetter(readString),
|
||||
'extensions': parseExtensions,
|
||||
'trkseg': parseTrkSeg
|
||||
});
|
||||
|
||||
const TRKSEG_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'trkpt': parseTrkPt,
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const TRKSEG_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'trkpt': parseTrkPt
|
||||
});
|
||||
|
||||
const TRKPT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'ele': makeObjectPropertySetter(readDecimal),
|
||||
'time': makeObjectPropertySetter(readDateTime),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const TRKPT_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'ele': makeObjectPropertySetter(readDecimal),
|
||||
'time': makeObjectPropertySetter(readDateTime)
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const WPT_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'ele': makeObjectPropertySetter(readDecimal),
|
||||
'time': makeObjectPropertySetter(readDateTime),
|
||||
'magvar': makeObjectPropertySetter(readDecimal),
|
||||
'geoidheight': makeObjectPropertySetter(readDecimal),
|
||||
'name': makeObjectPropertySetter(readString),
|
||||
'cmt': makeObjectPropertySetter(readString),
|
||||
'desc': makeObjectPropertySetter(readString),
|
||||
'src': makeObjectPropertySetter(readString),
|
||||
'link': parseLink,
|
||||
'sym': makeObjectPropertySetter(readString),
|
||||
'type': makeObjectPropertySetter(readString),
|
||||
'fix': makeObjectPropertySetter(readString),
|
||||
'sat': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'hdop': makeObjectPropertySetter(readDecimal),
|
||||
'vdop': makeObjectPropertySetter(readDecimal),
|
||||
'pdop': makeObjectPropertySetter(readDecimal),
|
||||
'ageofdgpsdata': makeObjectPropertySetter(readDecimal),
|
||||
'dgpsid': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'extensions': parseExtensions
|
||||
});
|
||||
|
||||
const WPT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'ele': makeObjectPropertySetter(readDecimal),
|
||||
'time': makeObjectPropertySetter(readDateTime),
|
||||
'magvar': makeObjectPropertySetter(readDecimal),
|
||||
'geoidheight': makeObjectPropertySetter(readDecimal),
|
||||
'name': makeObjectPropertySetter(readString),
|
||||
'cmt': makeObjectPropertySetter(readString),
|
||||
'desc': makeObjectPropertySetter(readString),
|
||||
'src': makeObjectPropertySetter(readString),
|
||||
'link': parseLink,
|
||||
'sym': makeObjectPropertySetter(readString),
|
||||
'type': makeObjectPropertySetter(readString),
|
||||
'fix': makeObjectPropertySetter(readString),
|
||||
'sat': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'hdop': makeObjectPropertySetter(readDecimal),
|
||||
'vdop': makeObjectPropertySetter(readDecimal),
|
||||
'pdop': makeObjectPropertySetter(readDecimal),
|
||||
'ageofdgpsdata': makeObjectPropertySetter(readDecimal),
|
||||
'dgpsid': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'extensions': parseExtensions,
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -338,87 +347,86 @@ const WPT_PARSERS = makeStructureNS(
|
||||
*/
|
||||
const LINK_SEQUENCE = ['text', 'type'];
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const LINK_SERIALIZERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'text': makeChildAppender(writeStringTextNode),
|
||||
'type': makeChildAppender(writeStringTextNode)
|
||||
});
|
||||
|
||||
const LINK_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'text': makeChildAppender(writeStringTextNode),
|
||||
'type': makeChildAppender(writeStringTextNode),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Array<string>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const RTE_SEQUENCE = makeStructureNS(
|
||||
NAMESPACE_URIS, [
|
||||
'name', 'cmt', 'desc', 'src', 'link', 'number', 'type', 'rtept'
|
||||
]);
|
||||
|
||||
const RTE_SEQUENCE = makeStructureNS(NAMESPACE_URIS, [
|
||||
'name',
|
||||
'cmt',
|
||||
'desc',
|
||||
'src',
|
||||
'link',
|
||||
'number',
|
||||
'type',
|
||||
'rtept',
|
||||
]);
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const RTE_SERIALIZERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'name': makeChildAppender(writeStringTextNode),
|
||||
'cmt': makeChildAppender(writeStringTextNode),
|
||||
'desc': makeChildAppender(writeStringTextNode),
|
||||
'src': makeChildAppender(writeStringTextNode),
|
||||
'link': makeChildAppender(writeLink),
|
||||
'number': makeChildAppender(writeNonNegativeIntegerTextNode),
|
||||
'type': makeChildAppender(writeStringTextNode),
|
||||
'rtept': makeArraySerializer(makeChildAppender(writeWptType))
|
||||
});
|
||||
|
||||
const RTE_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'name': makeChildAppender(writeStringTextNode),
|
||||
'cmt': makeChildAppender(writeStringTextNode),
|
||||
'desc': makeChildAppender(writeStringTextNode),
|
||||
'src': makeChildAppender(writeStringTextNode),
|
||||
'link': makeChildAppender(writeLink),
|
||||
'number': makeChildAppender(writeNonNegativeIntegerTextNode),
|
||||
'type': makeChildAppender(writeStringTextNode),
|
||||
'rtept': makeArraySerializer(makeChildAppender(writeWptType)),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Array<string>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const RTEPT_TYPE_SEQUENCE = makeStructureNS(
|
||||
NAMESPACE_URIS, [
|
||||
'ele', 'time'
|
||||
]);
|
||||
|
||||
const RTEPT_TYPE_SEQUENCE = makeStructureNS(NAMESPACE_URIS, ['ele', 'time']);
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Array<string>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const TRK_SEQUENCE = makeStructureNS(
|
||||
NAMESPACE_URIS, [
|
||||
'name', 'cmt', 'desc', 'src', 'link', 'number', 'type', 'trkseg'
|
||||
]);
|
||||
|
||||
const TRK_SEQUENCE = makeStructureNS(NAMESPACE_URIS, [
|
||||
'name',
|
||||
'cmt',
|
||||
'desc',
|
||||
'src',
|
||||
'link',
|
||||
'number',
|
||||
'type',
|
||||
'trkseg',
|
||||
]);
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const TRK_SERIALIZERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'name': makeChildAppender(writeStringTextNode),
|
||||
'cmt': makeChildAppender(writeStringTextNode),
|
||||
'desc': makeChildAppender(writeStringTextNode),
|
||||
'src': makeChildAppender(writeStringTextNode),
|
||||
'link': makeChildAppender(writeLink),
|
||||
'number': makeChildAppender(writeNonNegativeIntegerTextNode),
|
||||
'type': makeChildAppender(writeStringTextNode),
|
||||
'trkseg': makeArraySerializer(makeChildAppender(writeTrkSeg))
|
||||
});
|
||||
|
||||
const TRK_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'name': makeChildAppender(writeStringTextNode),
|
||||
'cmt': makeChildAppender(writeStringTextNode),
|
||||
'desc': makeChildAppender(writeStringTextNode),
|
||||
'src': makeChildAppender(writeStringTextNode),
|
||||
'link': makeChildAppender(writeLink),
|
||||
'number': makeChildAppender(writeNonNegativeIntegerTextNode),
|
||||
'type': makeChildAppender(writeStringTextNode),
|
||||
'trkseg': makeArraySerializer(makeChildAppender(writeTrkSeg)),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -426,58 +434,66 @@ const TRK_SERIALIZERS = makeStructureNS(
|
||||
*/
|
||||
const TRKSEG_NODE_FACTORY = makeSimpleNodeFactory('trkpt');
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const TRKSEG_SERIALIZERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'trkpt': makeChildAppender(writeWptType)
|
||||
});
|
||||
|
||||
const TRKSEG_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'trkpt': makeChildAppender(writeWptType),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Array<string>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const WPT_TYPE_SEQUENCE = makeStructureNS(
|
||||
NAMESPACE_URIS, [
|
||||
'ele', 'time', 'magvar', 'geoidheight', 'name', 'cmt', 'desc', 'src',
|
||||
'link', 'sym', 'type', 'fix', 'sat', 'hdop', 'vdop', 'pdop',
|
||||
'ageofdgpsdata', 'dgpsid'
|
||||
]);
|
||||
|
||||
const WPT_TYPE_SEQUENCE = makeStructureNS(NAMESPACE_URIS, [
|
||||
'ele',
|
||||
'time',
|
||||
'magvar',
|
||||
'geoidheight',
|
||||
'name',
|
||||
'cmt',
|
||||
'desc',
|
||||
'src',
|
||||
'link',
|
||||
'sym',
|
||||
'type',
|
||||
'fix',
|
||||
'sat',
|
||||
'hdop',
|
||||
'vdop',
|
||||
'pdop',
|
||||
'ageofdgpsdata',
|
||||
'dgpsid',
|
||||
]);
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const WPT_TYPE_SERIALIZERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'ele': makeChildAppender(writeDecimalTextNode),
|
||||
'time': makeChildAppender(writeDateTimeTextNode),
|
||||
'magvar': makeChildAppender(writeDecimalTextNode),
|
||||
'geoidheight': makeChildAppender(writeDecimalTextNode),
|
||||
'name': makeChildAppender(writeStringTextNode),
|
||||
'cmt': makeChildAppender(writeStringTextNode),
|
||||
'desc': makeChildAppender(writeStringTextNode),
|
||||
'src': makeChildAppender(writeStringTextNode),
|
||||
'link': makeChildAppender(writeLink),
|
||||
'sym': makeChildAppender(writeStringTextNode),
|
||||
'type': makeChildAppender(writeStringTextNode),
|
||||
'fix': makeChildAppender(writeStringTextNode),
|
||||
'sat': makeChildAppender(writeNonNegativeIntegerTextNode),
|
||||
'hdop': makeChildAppender(writeDecimalTextNode),
|
||||
'vdop': makeChildAppender(writeDecimalTextNode),
|
||||
'pdop': makeChildAppender(writeDecimalTextNode),
|
||||
'ageofdgpsdata': makeChildAppender(writeDecimalTextNode),
|
||||
'dgpsid': makeChildAppender(writeNonNegativeIntegerTextNode)
|
||||
});
|
||||
|
||||
const WPT_TYPE_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'ele': makeChildAppender(writeDecimalTextNode),
|
||||
'time': makeChildAppender(writeDateTimeTextNode),
|
||||
'magvar': makeChildAppender(writeDecimalTextNode),
|
||||
'geoidheight': makeChildAppender(writeDecimalTextNode),
|
||||
'name': makeChildAppender(writeStringTextNode),
|
||||
'cmt': makeChildAppender(writeStringTextNode),
|
||||
'desc': makeChildAppender(writeStringTextNode),
|
||||
'src': makeChildAppender(writeStringTextNode),
|
||||
'link': makeChildAppender(writeLink),
|
||||
'sym': makeChildAppender(writeStringTextNode),
|
||||
'type': makeChildAppender(writeStringTextNode),
|
||||
'fix': makeChildAppender(writeStringTextNode),
|
||||
'sat': makeChildAppender(writeNonNegativeIntegerTextNode),
|
||||
'hdop': makeChildAppender(writeDecimalTextNode),
|
||||
'vdop': makeChildAppender(writeDecimalTextNode),
|
||||
'pdop': makeChildAppender(writeDecimalTextNode),
|
||||
'ageofdgpsdata': makeChildAppender(writeDecimalTextNode),
|
||||
'dgpsid': makeChildAppender(writeNonNegativeIntegerTextNode),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -486,10 +502,9 @@ const WPT_TYPE_SERIALIZERS = makeStructureNS(
|
||||
const GEOMETRY_TYPE_TO_NODENAME = {
|
||||
'Point': 'wpt',
|
||||
'LineString': 'rte',
|
||||
'MultiLineString': 'trk'
|
||||
'MultiLineString': 'trk',
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {*} value Value.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -507,7 +522,6 @@ function GPX_NODE_FACTORY(value, objectStack, opt_nodeName) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {LayoutOptions} layoutOptions Layout options.
|
||||
@@ -518,7 +532,8 @@ function GPX_NODE_FACTORY(value, objectStack, opt_nodeName) {
|
||||
function appendCoordinate(flatCoordinates, layoutOptions, node, values) {
|
||||
flatCoordinates.push(
|
||||
parseFloat(node.getAttribute('lon')),
|
||||
parseFloat(node.getAttribute('lat')));
|
||||
parseFloat(node.getAttribute('lat'))
|
||||
);
|
||||
if ('ele' in values) {
|
||||
flatCoordinates.push(/** @type {number} */ (values['ele']));
|
||||
delete values['ele'];
|
||||
@@ -536,7 +551,6 @@ function appendCoordinate(flatCoordinates, layoutOptions, node, values) {
|
||||
return flatCoordinates;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Choose GeometryLayout based on flags in layoutOptions and adjust flatCoordinates
|
||||
* and ends arrays by shrinking them accordingly (removing unused zero entries).
|
||||
@@ -570,17 +584,16 @@ function applyLayoutOptions(layoutOptions, flatCoordinates, ends) {
|
||||
flatCoordinates[i * stride + 2] = flatCoordinates[i * 4 + 3];
|
||||
}
|
||||
}
|
||||
flatCoordinates.length = flatCoordinates.length / 4 * stride;
|
||||
flatCoordinates.length = (flatCoordinates.length / 4) * stride;
|
||||
if (ends) {
|
||||
for (let i = 0, ii = ends.length; i < ii; i++) {
|
||||
ends[i] = ends[i] / 4 * stride;
|
||||
ends[i] = (ends[i] / 4) * stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -594,7 +607,6 @@ function parseLink(node, objectStack) {
|
||||
parseNode(LINK_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -604,7 +616,6 @@ function parseExtensions(node, objectStack) {
|
||||
values['extensionsNode_'] = node;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -612,14 +623,19 @@ function parseExtensions(node, objectStack) {
|
||||
function parseRtePt(node, objectStack) {
|
||||
const values = pushParseAndPop({}, RTEPT_PARSERS, node, objectStack);
|
||||
if (values) {
|
||||
const rteValues = /** @type {!Object} */ (objectStack[objectStack.length - 1]);
|
||||
const flatCoordinates = /** @type {Array<number>} */ (rteValues['flatCoordinates']);
|
||||
const layoutOptions = /** @type {LayoutOptions} */ (rteValues['layoutOptions']);
|
||||
const rteValues = /** @type {!Object} */ (objectStack[
|
||||
objectStack.length - 1
|
||||
]);
|
||||
const flatCoordinates = /** @type {Array<number>} */ (rteValues[
|
||||
'flatCoordinates'
|
||||
]);
|
||||
const layoutOptions = /** @type {LayoutOptions} */ (rteValues[
|
||||
'layoutOptions'
|
||||
]);
|
||||
appendCoordinate(flatCoordinates, layoutOptions, node, values);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -627,14 +643,19 @@ function parseRtePt(node, objectStack) {
|
||||
function parseTrkPt(node, objectStack) {
|
||||
const values = pushParseAndPop({}, TRKPT_PARSERS, node, objectStack);
|
||||
if (values) {
|
||||
const trkValues = /** @type {!Object} */ (objectStack[objectStack.length - 1]);
|
||||
const flatCoordinates = /** @type {Array<number>} */ (trkValues['flatCoordinates']);
|
||||
const layoutOptions = /** @type {LayoutOptions} */ (trkValues['layoutOptions']);
|
||||
const trkValues = /** @type {!Object} */ (objectStack[
|
||||
objectStack.length - 1
|
||||
]);
|
||||
const flatCoordinates = /** @type {Array<number>} */ (trkValues[
|
||||
'flatCoordinates'
|
||||
]);
|
||||
const layoutOptions = /** @type {LayoutOptions} */ (trkValues[
|
||||
'layoutOptions'
|
||||
]);
|
||||
appendCoordinate(flatCoordinates, layoutOptions, node, values);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -642,13 +663,13 @@ function parseTrkPt(node, objectStack) {
|
||||
function parseTrkSeg(node, objectStack) {
|
||||
const values = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
||||
parseNode(TRKSEG_PARSERS, node, objectStack);
|
||||
const flatCoordinates = /** @type {Array<number>} */
|
||||
(values['flatCoordinates']);
|
||||
const flatCoordinates =
|
||||
/** @type {Array<number>} */
|
||||
(values['flatCoordinates']);
|
||||
const ends = /** @type {Array<number>} */ (values['ends']);
|
||||
ends.push(flatCoordinates.length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -656,15 +677,21 @@ function parseTrkSeg(node, objectStack) {
|
||||
*/
|
||||
function readRte(node, objectStack) {
|
||||
const options = /** @type {import("./Feature.js").ReadOptions} */ (objectStack[0]);
|
||||
const values = pushParseAndPop({
|
||||
'flatCoordinates': [],
|
||||
'layoutOptions': {}
|
||||
}, RTE_PARSERS, node, objectStack);
|
||||
const values = pushParseAndPop(
|
||||
{
|
||||
'flatCoordinates': [],
|
||||
'layoutOptions': {},
|
||||
},
|
||||
RTE_PARSERS,
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
if (!values) {
|
||||
return undefined;
|
||||
}
|
||||
const flatCoordinates = /** @type {Array<number>} */
|
||||
(values['flatCoordinates']);
|
||||
const flatCoordinates =
|
||||
/** @type {Array<number>} */
|
||||
(values['flatCoordinates']);
|
||||
delete values['flatCoordinates'];
|
||||
const layoutOptions = /** @type {LayoutOptions} */ (values['layoutOptions']);
|
||||
delete values['layoutOptions'];
|
||||
@@ -676,7 +703,6 @@ function readRte(node, objectStack) {
|
||||
return feature;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -684,16 +710,22 @@ function readRte(node, objectStack) {
|
||||
*/
|
||||
function readTrk(node, objectStack) {
|
||||
const options = /** @type {import("./Feature.js").ReadOptions} */ (objectStack[0]);
|
||||
const values = pushParseAndPop({
|
||||
'flatCoordinates': [],
|
||||
'ends': [],
|
||||
'layoutOptions': {}
|
||||
}, TRK_PARSERS, node, objectStack);
|
||||
const values = pushParseAndPop(
|
||||
{
|
||||
'flatCoordinates': [],
|
||||
'ends': [],
|
||||
'layoutOptions': {},
|
||||
},
|
||||
TRK_PARSERS,
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
if (!values) {
|
||||
return undefined;
|
||||
}
|
||||
const flatCoordinates = /** @type {Array<number>} */
|
||||
(values['flatCoordinates']);
|
||||
const flatCoordinates =
|
||||
/** @type {Array<number>} */
|
||||
(values['flatCoordinates']);
|
||||
delete values['flatCoordinates'];
|
||||
const ends = /** @type {Array<number>} */ (values['ends']);
|
||||
delete values['ends'];
|
||||
@@ -707,7 +739,6 @@ function readTrk(node, objectStack) {
|
||||
return feature;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -729,7 +760,6 @@ function readWpt(node, objectStack) {
|
||||
return feature;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {string} value Value for the link's `href` attribute.
|
||||
@@ -739,16 +769,17 @@ function writeLink(node, value, objectStack) {
|
||||
node.setAttribute('href', value);
|
||||
const context = objectStack[objectStack.length - 1];
|
||||
const properties = context['properties'];
|
||||
const link = [
|
||||
properties['linkText'],
|
||||
properties['linkType']
|
||||
];
|
||||
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */ ({node: node}),
|
||||
LINK_SERIALIZERS, OBJECT_PROPERTY_NODE_FACTORY,
|
||||
link, objectStack, LINK_SEQUENCE);
|
||||
const link = [properties['linkText'], properties['linkType']];
|
||||
pushSerializeAndPop(
|
||||
/** @type {import("../xml.js").NodeStackItem} */ ({node: node}),
|
||||
LINK_SERIALIZERS,
|
||||
OBJECT_PROPERTY_NODE_FACTORY,
|
||||
link,
|
||||
objectStack,
|
||||
LINK_SEQUENCE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
|
||||
@@ -768,7 +799,7 @@ function writeWptType(node, coordinate, objectStack) {
|
||||
if (coordinate[3] !== 0) {
|
||||
properties['time'] = coordinate[3];
|
||||
}
|
||||
// fall through
|
||||
// fall through
|
||||
case GeometryLayout.XYZ:
|
||||
if (coordinate[2] !== 0) {
|
||||
properties['ele'] = coordinate[2];
|
||||
@@ -780,19 +811,24 @@ function writeWptType(node, coordinate, objectStack) {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// pass
|
||||
// pass
|
||||
}
|
||||
const orderedKeys = (node.nodeName == 'rtept') ?
|
||||
RTEPT_TYPE_SEQUENCE[namespaceURI] :
|
||||
WPT_TYPE_SEQUENCE[namespaceURI];
|
||||
const orderedKeys =
|
||||
node.nodeName == 'rtept'
|
||||
? RTEPT_TYPE_SEQUENCE[namespaceURI]
|
||||
: WPT_TYPE_SEQUENCE[namespaceURI];
|
||||
const values = makeSequence(properties, orderedKeys);
|
||||
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */
|
||||
pushSerializeAndPop(
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
({node: node, 'properties': properties}),
|
||||
WPT_TYPE_SERIALIZERS, OBJECT_PROPERTY_NODE_FACTORY,
|
||||
values, objectStack, orderedKeys);
|
||||
WPT_TYPE_SERIALIZERS,
|
||||
OBJECT_PROPERTY_NODE_FACTORY,
|
||||
values,
|
||||
objectStack,
|
||||
orderedKeys
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Feature} feature Feature.
|
||||
@@ -805,19 +841,27 @@ function writeRte(node, feature, objectStack) {
|
||||
context['properties'] = properties;
|
||||
const geometry = feature.getGeometry();
|
||||
if (geometry.getType() == GeometryType.LINE_STRING) {
|
||||
const lineString = /** @type {LineString} */ (transformGeometryWithOptions(geometry, true, options));
|
||||
const lineString = /** @type {LineString} */ (transformGeometryWithOptions(
|
||||
geometry,
|
||||
true,
|
||||
options
|
||||
));
|
||||
context['geometryLayout'] = lineString.getLayout();
|
||||
properties['rtept'] = lineString.getCoordinates();
|
||||
}
|
||||
const parentNode = objectStack[objectStack.length - 1].node;
|
||||
const orderedKeys = RTE_SEQUENCE[parentNode.namespaceURI];
|
||||
const values = makeSequence(properties, orderedKeys);
|
||||
pushSerializeAndPop(context,
|
||||
RTE_SERIALIZERS, OBJECT_PROPERTY_NODE_FACTORY,
|
||||
values, objectStack, orderedKeys);
|
||||
pushSerializeAndPop(
|
||||
context,
|
||||
RTE_SERIALIZERS,
|
||||
OBJECT_PROPERTY_NODE_FACTORY,
|
||||
values,
|
||||
objectStack,
|
||||
orderedKeys
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Feature} feature Feature.
|
||||
@@ -831,18 +875,26 @@ function writeTrk(node, feature, objectStack) {
|
||||
context['properties'] = properties;
|
||||
const geometry = feature.getGeometry();
|
||||
if (geometry.getType() == GeometryType.MULTI_LINE_STRING) {
|
||||
const multiLineString = /** @type {MultiLineString} */ (transformGeometryWithOptions(geometry, true, options));
|
||||
const multiLineString = /** @type {MultiLineString} */ (transformGeometryWithOptions(
|
||||
geometry,
|
||||
true,
|
||||
options
|
||||
));
|
||||
properties['trkseg'] = multiLineString.getLineStrings();
|
||||
}
|
||||
const parentNode = objectStack[objectStack.length - 1].node;
|
||||
const orderedKeys = TRK_SEQUENCE[parentNode.namespaceURI];
|
||||
const values = makeSequence(properties, orderedKeys);
|
||||
pushSerializeAndPop(context,
|
||||
TRK_SERIALIZERS, OBJECT_PROPERTY_NODE_FACTORY,
|
||||
values, objectStack, orderedKeys);
|
||||
pushSerializeAndPop(
|
||||
context,
|
||||
TRK_SERIALIZERS,
|
||||
OBJECT_PROPERTY_NODE_FACTORY,
|
||||
values,
|
||||
objectStack,
|
||||
orderedKeys
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {LineString} lineString LineString.
|
||||
@@ -853,12 +905,15 @@ function writeTrkSeg(node, lineString, objectStack) {
|
||||
const context = {node: node};
|
||||
context['geometryLayout'] = lineString.getLayout();
|
||||
context['properties'] = {};
|
||||
pushSerializeAndPop(context,
|
||||
TRKSEG_SERIALIZERS, TRKSEG_NODE_FACTORY,
|
||||
lineString.getCoordinates(), objectStack);
|
||||
pushSerializeAndPop(
|
||||
context,
|
||||
TRKSEG_SERIALIZERS,
|
||||
TRKSEG_NODE_FACTORY,
|
||||
lineString.getCoordinates(),
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Feature} feature Feature.
|
||||
@@ -870,11 +925,14 @@ function writeWpt(node, feature, objectStack) {
|
||||
context['properties'] = feature.getProperties();
|
||||
const geometry = feature.getGeometry();
|
||||
if (geometry.getType() == GeometryType.POINT) {
|
||||
const point = /** @type {Point} */ (transformGeometryWithOptions(geometry, true, options));
|
||||
const point = /** @type {Point} */ (transformGeometryWithOptions(
|
||||
geometry,
|
||||
true,
|
||||
options
|
||||
));
|
||||
context['geometryLayout'] = point.getLayout();
|
||||
writeWptType(node, point.getCoordinates(), objectStack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default GPX;
|
||||
|
||||
@@ -2,20 +2,20 @@
|
||||
* @module ol/format/GeoJSON
|
||||
*/
|
||||
|
||||
import {assert} from '../asserts.js';
|
||||
import Feature from '../Feature.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
import JSONFeature from './JSONFeature.js';
|
||||
import GeometryCollection from '../geom/GeometryCollection.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import JSONFeature from './JSONFeature.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
import MultiPoint from '../geom/MultiPoint.js';
|
||||
import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {assign, isEmpty} from '../obj.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* @typedef {import("geojson").GeoJSON} GeoJSONObject
|
||||
@@ -31,7 +31,6 @@ import GeometryType from '../geom/GeometryType.js';
|
||||
* @typedef {import("geojson").GeometryCollection} GeoJSONGeometryCollection
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {import("../proj.js").ProjectionLike} [dataProjection='EPSG:4326'] Default data projection.
|
||||
@@ -44,20 +43,17 @@ import GeometryType from '../geom/GeometryType.js';
|
||||
* and a `geometryName` is provided, the `geometryName` will take precedence.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for reading and writing data in the GeoJSON format.
|
||||
*
|
||||
* @api
|
||||
* @api
|
||||
*/
|
||||
class GeoJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super();
|
||||
@@ -66,8 +62,8 @@ class GeoJSON extends JSONFeature {
|
||||
* @type {import("../proj/Projection.js").default}
|
||||
*/
|
||||
this.dataProjection = getProjection(
|
||||
options.dataProjection ?
|
||||
options.dataProjection : 'EPSG:4326');
|
||||
options.dataProjection ? options.dataProjection : 'EPSG:4326'
|
||||
);
|
||||
|
||||
if (options.featureProjection) {
|
||||
this.defaultFeatureProjection = getProjection(options.featureProjection);
|
||||
@@ -86,7 +82,6 @@ class GeoJSON extends JSONFeature {
|
||||
* @private
|
||||
*/
|
||||
this.extractGeometryName_ = options.extractGeometryName;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +101,7 @@ class GeoJSON extends JSONFeature {
|
||||
geoJSONFeature = {
|
||||
'type': 'Feature',
|
||||
'geometry': /** @type {GeoJSONGeometry} */ (object),
|
||||
'properties': null
|
||||
'properties': null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -114,7 +109,10 @@ class GeoJSON extends JSONFeature {
|
||||
const feature = new Feature();
|
||||
if (this.geometryName_) {
|
||||
feature.setGeometryName(this.geometryName_);
|
||||
} else if (this.extractGeometryName_ && 'geometry_name' in geoJSONFeature !== undefined) {
|
||||
} else if (
|
||||
this.extractGeometryName_ &&
|
||||
'geometry_name' in geoJSONFeature !== undefined
|
||||
) {
|
||||
feature.setGeometryName(geoJSONFeature['geometry_name']);
|
||||
}
|
||||
feature.setGeometry(geometry);
|
||||
@@ -144,7 +142,9 @@ class GeoJSON extends JSONFeature {
|
||||
features = [];
|
||||
const geoJSONFeatures = geoJSONFeatureCollection['features'];
|
||||
for (let i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
|
||||
features.push(this.readFeatureFromObject(geoJSONFeatures[i], opt_options));
|
||||
features.push(
|
||||
this.readFeatureFromObject(geoJSONFeatures[i], opt_options)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
features = [this.readFeatureFromObject(object, opt_options)];
|
||||
@@ -181,9 +181,7 @@ class GeoJSON extends JSONFeature {
|
||||
} else {
|
||||
projection = this.dataProjection;
|
||||
}
|
||||
return (
|
||||
/** @type {import("../proj/Projection.js").default} */ (projection)
|
||||
);
|
||||
return /** @type {import("../proj/Projection.js").default} */ (projection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,7 +199,7 @@ class GeoJSON extends JSONFeature {
|
||||
const object = {
|
||||
'type': 'Feature',
|
||||
geometry: null,
|
||||
properties: null
|
||||
properties: null,
|
||||
};
|
||||
|
||||
const id = feature.getId();
|
||||
@@ -238,7 +236,7 @@ class GeoJSON extends JSONFeature {
|
||||
}
|
||||
return {
|
||||
type: 'FeatureCollection',
|
||||
features: objects
|
||||
features: objects,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -255,7 +253,6 @@ class GeoJSON extends JSONFeature {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry|GeoJSONGeometryCollection} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
@@ -276,7 +273,9 @@ function readGeometry(object, opt_options) {
|
||||
break;
|
||||
}
|
||||
case GeometryType.LINE_STRING: {
|
||||
geometry = readLineStringGeometry(/** @type {GeoJSONLineString} */ (object));
|
||||
geometry = readLineStringGeometry(
|
||||
/** @type {GeoJSONLineString} */ (object)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case GeometryType.POLYGON: {
|
||||
@@ -284,19 +283,27 @@ function readGeometry(object, opt_options) {
|
||||
break;
|
||||
}
|
||||
case GeometryType.MULTI_POINT: {
|
||||
geometry = readMultiPointGeometry(/** @type {GeoJSONMultiPoint} */ (object));
|
||||
geometry = readMultiPointGeometry(
|
||||
/** @type {GeoJSONMultiPoint} */ (object)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case GeometryType.MULTI_LINE_STRING: {
|
||||
geometry = readMultiLineStringGeometry(/** @type {GeoJSONMultiLineString} */ (object));
|
||||
geometry = readMultiLineStringGeometry(
|
||||
/** @type {GeoJSONMultiLineString} */ (object)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case GeometryType.MULTI_POLYGON: {
|
||||
geometry = readMultiPolygonGeometry(/** @type {GeoJSONMultiPolygon} */ (object));
|
||||
geometry = readMultiPolygonGeometry(
|
||||
/** @type {GeoJSONMultiPolygon} */ (object)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case GeometryType.GEOMETRY_COLLECTION: {
|
||||
geometry = readGeometryCollectionGeometry(/** @type {GeoJSONGeometryCollection} */ (object));
|
||||
geometry = readGeometryCollectionGeometry(
|
||||
/** @type {GeoJSONGeometryCollection} */ (object)
|
||||
);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -306,7 +313,6 @@ function readGeometry(object, opt_options) {
|
||||
return transformGeometryWithOptions(geometry, false, opt_options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometryCollection} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
@@ -318,13 +324,13 @@ function readGeometryCollectionGeometry(object, opt_options) {
|
||||
* @param {GeoJSONGeometry} geometry Geometry.
|
||||
* @return {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
*/
|
||||
function(geometry) {
|
||||
function (geometry) {
|
||||
return readGeometry(geometry, opt_options);
|
||||
});
|
||||
}
|
||||
);
|
||||
return new GeometryCollection(geometries);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONPoint} object Object.
|
||||
* @return {Point} Point.
|
||||
@@ -333,7 +339,6 @@ function readPointGeometry(object) {
|
||||
return new Point(object['coordinates']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONLineString} object Object.
|
||||
* @return {LineString} LineString.
|
||||
@@ -342,7 +347,6 @@ function readLineStringGeometry(object) {
|
||||
return new LineString(object['coordinates']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONMultiLineString} object Object.
|
||||
* @return {MultiLineString} MultiLineString.
|
||||
@@ -351,7 +355,6 @@ function readMultiLineStringGeometry(object) {
|
||||
return new MultiLineString(object['coordinates']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONMultiPoint} object Object.
|
||||
* @return {MultiPoint} MultiPoint.
|
||||
@@ -360,7 +363,6 @@ function readMultiPointGeometry(object) {
|
||||
return new MultiPoint(object['coordinates']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONMultiPolygon} object Object.
|
||||
* @return {MultiPolygon} MultiPolygon.
|
||||
@@ -369,7 +371,6 @@ function readMultiPolygonGeometry(object) {
|
||||
return new MultiPolygon(object['coordinates']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONPolygon} object Object.
|
||||
* @return {Polygon} Polygon.
|
||||
@@ -378,7 +379,6 @@ function readPolygonGeometry(object) {
|
||||
return new Polygon(object['coordinates']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -392,37 +392,58 @@ function writeGeometry(geometry, opt_options) {
|
||||
let geoJSON;
|
||||
switch (type) {
|
||||
case GeometryType.POINT: {
|
||||
geoJSON = writePointGeometry(/** @type {Point} */ (geometry), opt_options);
|
||||
geoJSON = writePointGeometry(
|
||||
/** @type {Point} */ (geometry),
|
||||
opt_options
|
||||
);
|
||||
break;
|
||||
}
|
||||
case GeometryType.LINE_STRING: {
|
||||
geoJSON = writeLineStringGeometry(/** @type {LineString} */ (geometry), opt_options);
|
||||
geoJSON = writeLineStringGeometry(
|
||||
/** @type {LineString} */ (geometry),
|
||||
opt_options
|
||||
);
|
||||
break;
|
||||
}
|
||||
case GeometryType.POLYGON: {
|
||||
geoJSON = writePolygonGeometry(/** @type {Polygon} */ (geometry), opt_options);
|
||||
geoJSON = writePolygonGeometry(
|
||||
/** @type {Polygon} */ (geometry),
|
||||
opt_options
|
||||
);
|
||||
break;
|
||||
}
|
||||
case GeometryType.MULTI_POINT: {
|
||||
geoJSON = writeMultiPointGeometry(/** @type {MultiPoint} */ (geometry), opt_options);
|
||||
geoJSON = writeMultiPointGeometry(
|
||||
/** @type {MultiPoint} */ (geometry),
|
||||
opt_options
|
||||
);
|
||||
break;
|
||||
}
|
||||
case GeometryType.MULTI_LINE_STRING: {
|
||||
geoJSON = writeMultiLineStringGeometry(/** @type {MultiLineString} */ (geometry), opt_options);
|
||||
geoJSON = writeMultiLineStringGeometry(
|
||||
/** @type {MultiLineString} */ (geometry),
|
||||
opt_options
|
||||
);
|
||||
break;
|
||||
}
|
||||
case GeometryType.MULTI_POLYGON: {
|
||||
geoJSON = writeMultiPolygonGeometry(/** @type {MultiPolygon} */ (geometry), opt_options);
|
||||
geoJSON = writeMultiPolygonGeometry(
|
||||
/** @type {MultiPolygon} */ (geometry),
|
||||
opt_options
|
||||
);
|
||||
break;
|
||||
}
|
||||
case GeometryType.GEOMETRY_COLLECTION: {
|
||||
geoJSON = writeGeometryCollectionGeometry(/** @type {GeometryCollection} */ (geometry), opt_options);
|
||||
geoJSON = writeGeometryCollectionGeometry(
|
||||
/** @type {GeometryCollection} */ (geometry),
|
||||
opt_options
|
||||
);
|
||||
break;
|
||||
}
|
||||
case GeometryType.CIRCLE: {
|
||||
geoJSON = {
|
||||
type: 'GeometryCollection',
|
||||
geometries: []
|
||||
geometries: [],
|
||||
};
|
||||
break;
|
||||
}
|
||||
@@ -433,25 +454,23 @@ function writeGeometry(geometry, opt_options) {
|
||||
return geoJSON;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeometryCollection} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
|
||||
*/
|
||||
function writeGeometryCollectionGeometry(geometry, opt_options) {
|
||||
const geometries = geometry.getGeometriesArray().map(function(geometry) {
|
||||
const geometries = geometry.getGeometriesArray().map(function (geometry) {
|
||||
const options = assign({}, opt_options);
|
||||
delete options.featureProjection;
|
||||
return writeGeometry(geometry, options);
|
||||
});
|
||||
return {
|
||||
type: 'GeometryCollection',
|
||||
geometries: geometries
|
||||
geometries: geometries,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {LineString} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -460,11 +479,10 @@ function writeGeometryCollectionGeometry(geometry, opt_options) {
|
||||
function writeLineStringGeometry(geometry, opt_options) {
|
||||
return {
|
||||
type: 'LineString',
|
||||
coordinates: geometry.getCoordinates()
|
||||
coordinates: geometry.getCoordinates(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {MultiLineString} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -473,11 +491,10 @@ function writeLineStringGeometry(geometry, opt_options) {
|
||||
function writeMultiLineStringGeometry(geometry, opt_options) {
|
||||
return {
|
||||
type: 'MultiLineString',
|
||||
coordinates: geometry.getCoordinates()
|
||||
coordinates: geometry.getCoordinates(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {MultiPoint} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -486,11 +503,10 @@ function writeMultiLineStringGeometry(geometry, opt_options) {
|
||||
function writeMultiPointGeometry(geometry, opt_options) {
|
||||
return {
|
||||
type: 'MultiPoint',
|
||||
coordinates: geometry.getCoordinates()
|
||||
coordinates: geometry.getCoordinates(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {MultiPolygon} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -503,11 +519,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
|
||||
}
|
||||
return {
|
||||
type: 'MultiPolygon',
|
||||
coordinates: geometry.getCoordinates(right)
|
||||
coordinates: geometry.getCoordinates(right),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Point} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -516,11 +531,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
|
||||
function writePointGeometry(geometry, opt_options) {
|
||||
return {
|
||||
type: 'Point',
|
||||
coordinates: geometry.getCoordinates()
|
||||
coordinates: geometry.getCoordinates(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Polygon} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -533,9 +547,8 @@ function writePolygonGeometry(geometry, opt_options) {
|
||||
}
|
||||
return {
|
||||
type: 'Polygon',
|
||||
coordinates: geometry.getCoordinates(right)
|
||||
coordinates: geometry.getCoordinates(right),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export default GeoJSON;
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
* @module ol/format/IGC
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
import TextFeature from './TextFeature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import TextFeature from './TextFeature.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* IGC altitude/z. One of 'barometric', 'gps', 'none'.
|
||||
@@ -15,16 +15,14 @@ import {get as getProjection} from '../proj.js';
|
||||
const IGCZ = {
|
||||
BAROMETRIC: 'barometric',
|
||||
GPS: 'gps',
|
||||
NONE: 'none'
|
||||
NONE: 'none',
|
||||
};
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {RegExp}
|
||||
*/
|
||||
const B_RECORD_RE =
|
||||
/^B(\d{2})(\d{2})(\d{2})(\d{2})(\d{5})([NS])(\d{3})(\d{5})([EW])([AV])(\d{5})(\d{5})/;
|
||||
|
||||
const B_RECORD_RE = /^B(\d{2})(\d{2})(\d{2})(\d{2})(\d{5})([NS])(\d{3})(\d{5})([EW])([AV])(\d{5})(\d{5})/;
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -32,14 +30,12 @@ const B_RECORD_RE =
|
||||
*/
|
||||
const H_RECORD_RE = /^H.([A-Z]{3}).*?:(.*)/;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {RegExp}
|
||||
*/
|
||||
const HFDTE_RECORD_RE = /^HFDTE(\d{2})(\d{2})(\d{2})/;
|
||||
|
||||
|
||||
/**
|
||||
* A regular expression matching the newline characters `\r\n`, `\r` and `\n`.
|
||||
*
|
||||
@@ -48,14 +44,12 @@ const HFDTE_RECORD_RE = /^HFDTE(\d{2})(\d{2})(\d{2})/;
|
||||
*/
|
||||
const NEWLINE_RE = /\r\n|\r|\n/;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {IGCZ|string} [altitudeMode='none'] Altitude mode. Possible
|
||||
* values are `'barometric'`, `'gps'`, and `'none'`.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for `*.igc` flight recording files.
|
||||
@@ -67,7 +61,6 @@ const NEWLINE_RE = /\r\n|\r|\n/;
|
||||
* @api
|
||||
*/
|
||||
class IGC extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
@@ -85,7 +78,9 @@ class IGC extends TextFeature {
|
||||
* @private
|
||||
* @type {IGCZ}
|
||||
*/
|
||||
this.altitudeMode_ = options.altitudeMode ? options.altitudeMode : IGCZ.NONE;
|
||||
this.altitudeMode_ = options.altitudeMode
|
||||
? options.altitudeMode
|
||||
: IGCZ.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,9 +154,12 @@ class IGC extends TextFeature {
|
||||
if (flatCoordinates.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const layout = altitudeMode == IGCZ.NONE ? GeometryLayout.XYM : GeometryLayout.XYZM;
|
||||
const layout =
|
||||
altitudeMode == IGCZ.NONE ? GeometryLayout.XYM : GeometryLayout.XYZM;
|
||||
const lineString = new LineString(flatCoordinates, layout);
|
||||
const feature = new Feature(transformGeometryWithOptions(lineString, false, opt_options));
|
||||
const feature = new Feature(
|
||||
transformGeometryWithOptions(lineString, false, opt_options)
|
||||
);
|
||||
feature.setProperties(properties, true);
|
||||
return feature;
|
||||
}
|
||||
@@ -180,7 +178,6 @@ class IGC extends TextFeature {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default IGC;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
import {assert} from '../asserts.js';
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} PreferredOptions
|
||||
* @property {string} [format] Preferred image format. Will be used if the image information
|
||||
@@ -51,7 +50,7 @@ import {assert} from '../asserts.js';
|
||||
const Versions = {
|
||||
VERSION1: 'version1',
|
||||
VERSION2: 'version2',
|
||||
VERSION3: 'version3'
|
||||
VERSION3: 'version3',
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -65,67 +64,96 @@ IIIF_PROFILE_VALUES[Versions.VERSION1] = {
|
||||
'level0': {
|
||||
supports: [],
|
||||
formats: [],
|
||||
qualities: ['native']
|
||||
qualities: ['native'],
|
||||
},
|
||||
'level1': {
|
||||
supports: ['regionByPx', 'sizeByW', 'sizeByH', 'sizeByPct'],
|
||||
formats: ['jpg'],
|
||||
qualities: ['native']
|
||||
qualities: ['native'],
|
||||
},
|
||||
'level2': {
|
||||
supports: ['regionByPx', 'regionByPct', 'sizeByW', 'sizeByH', 'sizeByPct',
|
||||
'sizeByConfinedWh', 'sizeByWh'],
|
||||
supports: [
|
||||
'regionByPx',
|
||||
'regionByPct',
|
||||
'sizeByW',
|
||||
'sizeByH',
|
||||
'sizeByPct',
|
||||
'sizeByConfinedWh',
|
||||
'sizeByWh',
|
||||
],
|
||||
formats: ['jpg', 'png'],
|
||||
qualities: ['native', 'color', 'grey', 'bitonal']
|
||||
}
|
||||
qualities: ['native', 'color', 'grey', 'bitonal'],
|
||||
},
|
||||
};
|
||||
IIIF_PROFILE_VALUES[Versions.VERSION2] = {
|
||||
'level0': {
|
||||
supports: [],
|
||||
formats: ['jpg'],
|
||||
qualities: ['default']
|
||||
qualities: ['default'],
|
||||
},
|
||||
'level1': {
|
||||
supports: ['regionByPx', 'sizeByW', 'sizeByH', 'sizeByPct'],
|
||||
formats: ['jpg'],
|
||||
qualities: ['default']
|
||||
qualities: ['default'],
|
||||
},
|
||||
'level2': {
|
||||
supports: ['regionByPx', 'regionByPct', 'sizeByW', 'sizeByH', 'sizeByPct',
|
||||
'sizeByConfinedWh', 'sizeByDistortedWh', 'sizeByWh'],
|
||||
supports: [
|
||||
'regionByPx',
|
||||
'regionByPct',
|
||||
'sizeByW',
|
||||
'sizeByH',
|
||||
'sizeByPct',
|
||||
'sizeByConfinedWh',
|
||||
'sizeByDistortedWh',
|
||||
'sizeByWh',
|
||||
],
|
||||
formats: ['jpg', 'png'],
|
||||
qualities: ['default', 'bitonal']
|
||||
}
|
||||
qualities: ['default', 'bitonal'],
|
||||
},
|
||||
};
|
||||
IIIF_PROFILE_VALUES[Versions.VERSION3] = {
|
||||
'level0': {
|
||||
supports: [],
|
||||
formats: ['jpg'],
|
||||
qualities: ['default']
|
||||
qualities: ['default'],
|
||||
},
|
||||
'level1': {
|
||||
supports: ['regionByPx', 'regionSquare', 'sizeByW', 'sizeByH', 'sizeByWh'],
|
||||
formats: ['jpg'],
|
||||
qualities: ['default']
|
||||
qualities: ['default'],
|
||||
},
|
||||
'level2': {
|
||||
supports: ['regionByPx', 'regionSquare', 'regionByPct',
|
||||
'sizeByW', 'sizeByH', 'sizeByPct', 'sizeByConfinedWh', 'sizeByWh'],
|
||||
supports: [
|
||||
'regionByPx',
|
||||
'regionSquare',
|
||||
'regionByPct',
|
||||
'sizeByW',
|
||||
'sizeByH',
|
||||
'sizeByPct',
|
||||
'sizeByConfinedWh',
|
||||
'sizeByWh',
|
||||
],
|
||||
formats: ['jpg', 'png'],
|
||||
qualities: ['default']
|
||||
}
|
||||
qualities: ['default'],
|
||||
},
|
||||
};
|
||||
IIIF_PROFILE_VALUES['none'] = {
|
||||
'none': {
|
||||
supports: [],
|
||||
formats: [],
|
||||
qualities: []
|
||||
}
|
||||
qualities: [],
|
||||
},
|
||||
};
|
||||
|
||||
const COMPLIANCE_VERSION1 = new RegExp('^https?\:\/\/library\.stanford\.edu\/iiif\/image-api\/(1\.1\/)?compliance\.html#level[0-2]$');
|
||||
const COMPLIANCE_VERSION2 = new RegExp('^https?\:\/\/iiif\.io\/api\/image\/2\/level[0-2](\.json)?$');
|
||||
const COMPLIANCE_VERSION3 = new RegExp('(^https?\:\/\/iiif\.io\/api\/image\/3\/level[0-2](\.json)?$)|(^level[0-2]$)');
|
||||
const COMPLIANCE_VERSION1 = new RegExp(
|
||||
'^https?://library.stanford.edu/iiif/image-api/(1.1/)?compliance.html#level[0-2]$'
|
||||
);
|
||||
const COMPLIANCE_VERSION2 = new RegExp(
|
||||
'^https?://iiif.io/api/image/2/level[0-2](.json)?$'
|
||||
);
|
||||
const COMPLIANCE_VERSION3 = new RegExp(
|
||||
'(^https?://iiif.io/api/image/3/level[0-2](.json)?$)|(^level[0-2]$)'
|
||||
);
|
||||
|
||||
function generateVersion1Options(iiifInfo) {
|
||||
let levelProfile = iiifInfo.getComplianceLevelSupportedFeatures();
|
||||
@@ -134,84 +162,138 @@ function generateVersion1Options(iiifInfo) {
|
||||
levelProfile = IIIF_PROFILE_VALUES[Versions.VERSION1]['level0'];
|
||||
}
|
||||
return {
|
||||
url: iiifInfo.imageInfo['@id'] === undefined ? undefined : iiifInfo.imageInfo['@id'].replace(/\/?(info.json)?$/g, ''),
|
||||
url:
|
||||
iiifInfo.imageInfo['@id'] === undefined
|
||||
? undefined
|
||||
: iiifInfo.imageInfo['@id'].replace(/\/?(info.json)?$/g, ''),
|
||||
supports: levelProfile.supports,
|
||||
formats: [...levelProfile.formats, iiifInfo.imageInfo.formats === undefined ?
|
||||
[] : iiifInfo.imageInfo.formats
|
||||
formats: [
|
||||
...levelProfile.formats,
|
||||
iiifInfo.imageInfo.formats === undefined
|
||||
? []
|
||||
: iiifInfo.imageInfo.formats,
|
||||
],
|
||||
qualities: [...levelProfile.qualities, iiifInfo.imageInfo.qualities === undefined ?
|
||||
[] : iiifInfo.imageInfo.qualities
|
||||
qualities: [
|
||||
...levelProfile.qualities,
|
||||
iiifInfo.imageInfo.qualities === undefined
|
||||
? []
|
||||
: iiifInfo.imageInfo.qualities,
|
||||
],
|
||||
resolutions: iiifInfo.imageInfo.scale_factors,
|
||||
tileSize: iiifInfo.imageInfo.tile_width !== undefined ? (iiifInfo.imageInfo.tile_height !== undefined ?
|
||||
[iiifInfo.imageInfo.tile_width, iiifInfo.imageInfo.tile_height] : [iiifInfo.imageInfo.tile_width, iiifInfo.imageInfo.tile_width]) :
|
||||
(iiifInfo.imageInfo.tile_height != undefined ? [iiifInfo.imageInfo.tile_height, iiifInfo.imageInfo.tile_height] : undefined)
|
||||
tileSize:
|
||||
iiifInfo.imageInfo.tile_width !== undefined
|
||||
? iiifInfo.imageInfo.tile_height !== undefined
|
||||
? [iiifInfo.imageInfo.tile_width, iiifInfo.imageInfo.tile_height]
|
||||
: [iiifInfo.imageInfo.tile_width, iiifInfo.imageInfo.tile_width]
|
||||
: iiifInfo.imageInfo.tile_height != undefined
|
||||
? [iiifInfo.imageInfo.tile_height, iiifInfo.imageInfo.tile_height]
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function generateVersion2Options(iiifInfo) {
|
||||
const levelProfile = iiifInfo.getComplianceLevelSupportedFeatures(),
|
||||
additionalProfile = Array.isArray(iiifInfo.imageInfo.profile) && iiifInfo.imageInfo.profile.length > 1,
|
||||
profileSupports = additionalProfile && iiifInfo.imageInfo.profile[1].supports ? iiifInfo.imageInfo.profile[1].supports : [],
|
||||
profileFormats = additionalProfile && iiifInfo.imageInfo.profile[1].formats ? iiifInfo.imageInfo.profile[1].formats : [],
|
||||
profileQualities = additionalProfile && iiifInfo.imageInfo.profile[1].qualities ? iiifInfo.imageInfo.profile[1].qualities : [];
|
||||
additionalProfile =
|
||||
Array.isArray(iiifInfo.imageInfo.profile) &&
|
||||
iiifInfo.imageInfo.profile.length > 1,
|
||||
profileSupports =
|
||||
additionalProfile && iiifInfo.imageInfo.profile[1].supports
|
||||
? iiifInfo.imageInfo.profile[1].supports
|
||||
: [],
|
||||
profileFormats =
|
||||
additionalProfile && iiifInfo.imageInfo.profile[1].formats
|
||||
? iiifInfo.imageInfo.profile[1].formats
|
||||
: [],
|
||||
profileQualities =
|
||||
additionalProfile && iiifInfo.imageInfo.profile[1].qualities
|
||||
? iiifInfo.imageInfo.profile[1].qualities
|
||||
: [];
|
||||
return {
|
||||
url: iiifInfo.imageInfo['@id'].replace(/\/?(info.json)?$/g, ''),
|
||||
sizes: iiifInfo.imageInfo.sizes === undefined ? undefined : iiifInfo.imageInfo.sizes.map(function(size) {
|
||||
return [size.width, size.height];
|
||||
}),
|
||||
tileSize: iiifInfo.imageInfo.tiles === undefined ? undefined : [
|
||||
iiifInfo.imageInfo.tiles.map(function(tile) {
|
||||
return tile.width;
|
||||
})[0],
|
||||
iiifInfo.imageInfo.tiles.map(function(tile) {
|
||||
return tile.height === undefined ? tile.width : tile.height;
|
||||
})[0]
|
||||
],
|
||||
resolutions: iiifInfo.imageInfo.tiles === undefined ? undefined :
|
||||
iiifInfo.imageInfo.tiles.map(function(tile) {
|
||||
return tile.scaleFactors;
|
||||
})[0],
|
||||
sizes:
|
||||
iiifInfo.imageInfo.sizes === undefined
|
||||
? undefined
|
||||
: iiifInfo.imageInfo.sizes.map(function (size) {
|
||||
return [size.width, size.height];
|
||||
}),
|
||||
tileSize:
|
||||
iiifInfo.imageInfo.tiles === undefined
|
||||
? undefined
|
||||
: [
|
||||
iiifInfo.imageInfo.tiles.map(function (tile) {
|
||||
return tile.width;
|
||||
})[0],
|
||||
iiifInfo.imageInfo.tiles.map(function (tile) {
|
||||
return tile.height === undefined ? tile.width : tile.height;
|
||||
})[0],
|
||||
],
|
||||
resolutions:
|
||||
iiifInfo.imageInfo.tiles === undefined
|
||||
? undefined
|
||||
: iiifInfo.imageInfo.tiles.map(function (tile) {
|
||||
return tile.scaleFactors;
|
||||
})[0],
|
||||
supports: [...levelProfile.supports, ...profileSupports],
|
||||
formats: [...levelProfile.formats, ...profileFormats],
|
||||
qualities: [...levelProfile.qualities, ...profileQualities]
|
||||
qualities: [...levelProfile.qualities, ...profileQualities],
|
||||
};
|
||||
}
|
||||
|
||||
function generateVersion3Options(iiifInfo) {
|
||||
const levelProfile = iiifInfo.getComplianceLevelSupportedFeatures(),
|
||||
formats = iiifInfo.imageInfo.extraFormats === undefined ? levelProfile.formats :
|
||||
[...levelProfile.formats, ...iiifInfo.imageInfo.extraFormats],
|
||||
preferredFormat = iiifInfo.imageInfo.preferredFormats !== undefined && Array.isArray(iiifInfo.imageInfo.preferredFormats) &&
|
||||
iiifInfo.imageInfo.preferredFormats.length > 0 ?
|
||||
iiifInfo.imageInfo.preferredFormats.filter(function(format) {
|
||||
return ['jpg', 'png', 'gif'].includes(format);
|
||||
}).reduce(function(acc, format) {
|
||||
return acc === undefined && formats.includes(format) ? format : acc;
|
||||
}, undefined) : undefined;
|
||||
formats =
|
||||
iiifInfo.imageInfo.extraFormats === undefined
|
||||
? levelProfile.formats
|
||||
: [...levelProfile.formats, ...iiifInfo.imageInfo.extraFormats],
|
||||
preferredFormat =
|
||||
iiifInfo.imageInfo.preferredFormats !== undefined &&
|
||||
Array.isArray(iiifInfo.imageInfo.preferredFormats) &&
|
||||
iiifInfo.imageInfo.preferredFormats.length > 0
|
||||
? iiifInfo.imageInfo.preferredFormats
|
||||
.filter(function (format) {
|
||||
return ['jpg', 'png', 'gif'].includes(format);
|
||||
})
|
||||
.reduce(function (acc, format) {
|
||||
return acc === undefined && formats.includes(format)
|
||||
? format
|
||||
: acc;
|
||||
}, undefined)
|
||||
: undefined;
|
||||
return {
|
||||
url: iiifInfo.imageInfo['id'],
|
||||
sizes: iiifInfo.imageInfo.sizes === undefined ? undefined : iiifInfo.imageInfo.sizes.map(function(size) {
|
||||
return [size.width, size.height];
|
||||
}),
|
||||
tileSize: iiifInfo.imageInfo.tiles === undefined ? undefined : [
|
||||
iiifInfo.imageInfo.tiles.map(function(tile) {
|
||||
return tile.width;
|
||||
})[0],
|
||||
iiifInfo.imageInfo.tiles.map(function(tile) {
|
||||
return tile.height;
|
||||
})[0]
|
||||
],
|
||||
resolutions: iiifInfo.imageInfo.tiles === undefined ? undefined :
|
||||
iiifInfo.imageInfo.tiles.map(function(tile) {
|
||||
return tile.scaleFactors;
|
||||
})[0],
|
||||
supports: iiifInfo.imageInfo.extraFeatures === undefined ? levelProfile.supports :
|
||||
[...levelProfile.supports, ...iiifInfo.imageInfo.extraFeatures],
|
||||
sizes:
|
||||
iiifInfo.imageInfo.sizes === undefined
|
||||
? undefined
|
||||
: iiifInfo.imageInfo.sizes.map(function (size) {
|
||||
return [size.width, size.height];
|
||||
}),
|
||||
tileSize:
|
||||
iiifInfo.imageInfo.tiles === undefined
|
||||
? undefined
|
||||
: [
|
||||
iiifInfo.imageInfo.tiles.map(function (tile) {
|
||||
return tile.width;
|
||||
})[0],
|
||||
iiifInfo.imageInfo.tiles.map(function (tile) {
|
||||
return tile.height;
|
||||
})[0],
|
||||
],
|
||||
resolutions:
|
||||
iiifInfo.imageInfo.tiles === undefined
|
||||
? undefined
|
||||
: iiifInfo.imageInfo.tiles.map(function (tile) {
|
||||
return tile.scaleFactors;
|
||||
})[0],
|
||||
supports:
|
||||
iiifInfo.imageInfo.extraFeatures === undefined
|
||||
? levelProfile.supports
|
||||
: [...levelProfile.supports, ...iiifInfo.imageInfo.extraFeatures],
|
||||
formats: formats,
|
||||
qualities: iiifInfo.imageInfo.extraQualities === undefined ? levelProfile.qualities :
|
||||
[...levelProfile.qualities, ...iiifInfo.imageInfo.extraQualities],
|
||||
preferredFormat: preferredFormat
|
||||
qualities:
|
||||
iiifInfo.imageInfo.extraQualities === undefined
|
||||
? levelProfile.qualities
|
||||
: [...levelProfile.qualities, ...iiifInfo.imageInfo.extraQualities],
|
||||
preferredFormat: preferredFormat,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -228,7 +310,6 @@ versionFunctions[Versions.VERSION3] = generateVersion3Options;
|
||||
* @api
|
||||
*/
|
||||
class IIIFInfo {
|
||||
|
||||
/**
|
||||
* @param {string|ImageInformationResponse} imageInfo
|
||||
* Deserialized image information JSON response object or JSON response as string
|
||||
@@ -273,7 +354,10 @@ class IIIFInfo {
|
||||
return Versions.VERSION3;
|
||||
case 'ol-no-context':
|
||||
// Image API 1.0 has no '@context'
|
||||
if (this.getComplianceLevelEntryFromProfile(Versions.VERSION1) && this.imageInfo.identifier) {
|
||||
if (
|
||||
this.getComplianceLevelEntryFromProfile(Versions.VERSION1) &&
|
||||
this.imageInfo.identifier
|
||||
) {
|
||||
return Versions.VERSION1;
|
||||
}
|
||||
break;
|
||||
@@ -307,11 +391,18 @@ class IIIFInfo {
|
||||
}
|
||||
break;
|
||||
case Versions.VERSION2:
|
||||
if (typeof this.imageInfo.profile === 'string' && COMPLIANCE_VERSION2.test(this.imageInfo.profile)) {
|
||||
if (
|
||||
typeof this.imageInfo.profile === 'string' &&
|
||||
COMPLIANCE_VERSION2.test(this.imageInfo.profile)
|
||||
) {
|
||||
return this.imageInfo.profile;
|
||||
}
|
||||
if (Array.isArray(this.imageInfo.profile) && this.imageInfo.profile.length > 0
|
||||
&& typeof this.imageInfo.profile[0] === 'string' && COMPLIANCE_VERSION2.test(this.imageInfo.profile[0])) {
|
||||
if (
|
||||
Array.isArray(this.imageInfo.profile) &&
|
||||
this.imageInfo.profile.length > 0 &&
|
||||
typeof this.imageInfo.profile[0] === 'string' &&
|
||||
COMPLIANCE_VERSION2.test(this.imageInfo.profile[0])
|
||||
) {
|
||||
return this.imageInfo.profile[0];
|
||||
}
|
||||
break;
|
||||
@@ -355,11 +446,12 @@ class IIIFInfo {
|
||||
*/
|
||||
getTileSourceOptions(opt_preferredOptions) {
|
||||
const options = opt_preferredOptions || {},
|
||||
version = this.getImageApiVersion();
|
||||
version = this.getImageApiVersion();
|
||||
if (version === undefined) {
|
||||
return;
|
||||
}
|
||||
const imageOptions = version === undefined ? undefined : versionFunctions[version](this);
|
||||
const imageOptions =
|
||||
version === undefined ? undefined : versionFunctions[version](this);
|
||||
if (imageOptions === undefined) {
|
||||
return;
|
||||
}
|
||||
@@ -368,18 +460,28 @@ class IIIFInfo {
|
||||
version: version,
|
||||
size: [this.imageInfo.width, this.imageInfo.height],
|
||||
sizes: imageOptions.sizes,
|
||||
format: options.format !== undefined && imageOptions.formats.includes(options.format) ? options.format :
|
||||
imageOptions.preferredFormat !== undefined ? imageOptions.preferredFormat : 'jpg',
|
||||
format:
|
||||
options.format !== undefined &&
|
||||
imageOptions.formats.includes(options.format)
|
||||
? options.format
|
||||
: imageOptions.preferredFormat !== undefined
|
||||
? imageOptions.preferredFormat
|
||||
: 'jpg',
|
||||
supports: imageOptions.supports,
|
||||
quality: options.quality && imageOptions.qualities.includes(options.quality) ?
|
||||
options.quality : imageOptions.qualities.includes('native') ? 'native' : 'default',
|
||||
resolutions: Array.isArray(imageOptions.resolutions) ? imageOptions.resolutions.sort(function(a, b) {
|
||||
return b - a;
|
||||
}) : undefined,
|
||||
tileSize: imageOptions.tileSize
|
||||
quality:
|
||||
options.quality && imageOptions.qualities.includes(options.quality)
|
||||
? options.quality
|
||||
: imageOptions.qualities.includes('native')
|
||||
? 'native'
|
||||
: 'default',
|
||||
resolutions: Array.isArray(imageOptions.resolutions)
|
||||
? imageOptions.resolutions.sort(function (a, b) {
|
||||
return b - a;
|
||||
})
|
||||
: undefined,
|
||||
tileSize: imageOptions.tileSize,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default IIIFInfo;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* @module ol/format/JSONFeature
|
||||
*/
|
||||
import {abstract} from '../util.js';
|
||||
import FeatureFormat from './Feature.js';
|
||||
import FormatType from './FormatType.js';
|
||||
import {abstract} from '../util.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -36,7 +36,9 @@ class JSONFeature extends FeatureFormat {
|
||||
*/
|
||||
readFeature(source, opt_options) {
|
||||
return this.readFeatureFromObject(
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
getObject(source),
|
||||
this.getReadOptions(source, opt_options)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +52,9 @@ class JSONFeature extends FeatureFormat {
|
||||
*/
|
||||
readFeatures(source, opt_options) {
|
||||
return this.readFeaturesFromObject(
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
getObject(source),
|
||||
this.getReadOptions(source, opt_options)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +89,9 @@ class JSONFeature extends FeatureFormat {
|
||||
*/
|
||||
readGeometry(source, opt_options) {
|
||||
return this.readGeometryFromObject(
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
getObject(source),
|
||||
this.getReadOptions(source, opt_options)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,7 +193,6 @@ class JSONFeature extends FeatureFormat {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @return {Object} Object.
|
||||
@@ -203,5 +208,4 @@ function getObject(source) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default JSONFeature;
|
||||
|
||||
1727
src/ol/format/KML.js
1727
src/ol/format/KML.js
File diff suppressed because it is too large
Load Diff
@@ -3,8 +3,6 @@
|
||||
*/
|
||||
//FIXME Implement projection handling
|
||||
|
||||
import {assert} from '../asserts.js';
|
||||
import PBF from 'pbf';
|
||||
import FeatureFormat, {transformGeometryWithOptions} from './Feature.js';
|
||||
import FormatType from './FormatType.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
@@ -13,14 +11,15 @@ import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
import MultiPoint from '../geom/MultiPoint.js';
|
||||
import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
import PBF from 'pbf';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import {linearRingIsClockwise} from '../geom/flat/orient.js';
|
||||
import Projection from '../proj/Projection.js';
|
||||
import Units from '../proj/Units.js';
|
||||
import RenderFeature from '../render/Feature.js';
|
||||
import Units from '../proj/Units.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {get} from '../proj.js';
|
||||
|
||||
import {linearRingIsClockwise} from '../geom/flat/orient.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
@@ -35,7 +34,6 @@ import {get} from '../proj.js';
|
||||
* layers.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for reading data in the Mapbox MVT format.
|
||||
@@ -44,7 +42,6 @@ import {get} from '../proj.js';
|
||||
* @api
|
||||
*/
|
||||
class MVT extends FeatureFormat {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
@@ -58,14 +55,16 @@ class MVT extends FeatureFormat {
|
||||
*/
|
||||
this.dataProjection = new Projection({
|
||||
code: '',
|
||||
units: Units.TILE_PIXELS
|
||||
units: Units.TILE_PIXELS,
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../Feature.js").FeatureClass}
|
||||
*/
|
||||
this.featureClass_ = options.featureClass ? options.featureClass : RenderFeature;
|
||||
this.featureClass_ = options.featureClass
|
||||
? options.featureClass
|
||||
: RenderFeature;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -90,7 +89,6 @@ class MVT extends FeatureFormat {
|
||||
* @type {string}
|
||||
*/
|
||||
this.idProperty_ = options.idProperty;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +124,8 @@ class MVT extends FeatureFormat {
|
||||
x += pbf.readSVarint();
|
||||
y += pbf.readSVarint();
|
||||
|
||||
if (cmd === 1) { // moveTo
|
||||
if (cmd === 1) {
|
||||
// moveTo
|
||||
if (coordsLen > currentEnd) {
|
||||
ends.push(coordsLen);
|
||||
currentEnd = coordsLen;
|
||||
@@ -135,16 +134,15 @@ class MVT extends FeatureFormat {
|
||||
|
||||
flatCoordinates.push(x, y);
|
||||
coordsLen += 2;
|
||||
|
||||
} else if (cmd === 7) {
|
||||
|
||||
if (coordsLen > currentEnd) {
|
||||
// close polygon
|
||||
flatCoordinates.push(
|
||||
flatCoordinates[currentEnd], flatCoordinates[currentEnd + 1]);
|
||||
flatCoordinates[currentEnd],
|
||||
flatCoordinates[currentEnd + 1]
|
||||
);
|
||||
coordsLen += 2;
|
||||
}
|
||||
|
||||
} else {
|
||||
assert(false, 59); // Invalid command found in the PBF
|
||||
}
|
||||
@@ -154,7 +152,6 @@ class MVT extends FeatureFormat {
|
||||
ends.push(coordsLen);
|
||||
currentEnd = coordsLen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +187,13 @@ class MVT extends FeatureFormat {
|
||||
const geometryType = getGeometryType(type, ends.length);
|
||||
|
||||
if (this.featureClass_ === RenderFeature) {
|
||||
feature = new this.featureClass_(geometryType, flatCoordinates, ends, values, id);
|
||||
feature = new this.featureClass_(
|
||||
geometryType,
|
||||
flatCoordinates,
|
||||
ends,
|
||||
values,
|
||||
id
|
||||
);
|
||||
feature.transform(options.dataProjection, options.featureProjection);
|
||||
} else {
|
||||
let geom;
|
||||
@@ -212,14 +215,21 @@ class MVT extends FeatureFormat {
|
||||
geom = new Polygon(flatCoordinates, GeometryLayout.XY, ends);
|
||||
}
|
||||
} else {
|
||||
geom = geometryType === GeometryType.POINT ? new Point(flatCoordinates, GeometryLayout.XY) :
|
||||
geometryType === GeometryType.LINE_STRING ? new LineString(flatCoordinates, GeometryLayout.XY) :
|
||||
geometryType === GeometryType.POLYGON ? new Polygon(flatCoordinates, GeometryLayout.XY, ends) :
|
||||
geometryType === GeometryType.MULTI_POINT ? new MultiPoint(flatCoordinates, GeometryLayout.XY) :
|
||||
geometryType === GeometryType.MULTI_LINE_STRING ? new MultiLineString(flatCoordinates, GeometryLayout.XY, ends) :
|
||||
null;
|
||||
geom =
|
||||
geometryType === GeometryType.POINT
|
||||
? new Point(flatCoordinates, GeometryLayout.XY)
|
||||
: geometryType === GeometryType.LINE_STRING
|
||||
? new LineString(flatCoordinates, GeometryLayout.XY)
|
||||
: geometryType === GeometryType.POLYGON
|
||||
? new Polygon(flatCoordinates, GeometryLayout.XY, ends)
|
||||
: geometryType === GeometryType.MULTI_POINT
|
||||
? new MultiPoint(flatCoordinates, GeometryLayout.XY)
|
||||
: geometryType === GeometryType.MULTI_LINE_STRING
|
||||
? new MultiLineString(flatCoordinates, GeometryLayout.XY, ends)
|
||||
: null;
|
||||
}
|
||||
const ctor = /** @type {typeof import("../Feature.js").default} */ (this.featureClass_);
|
||||
const ctor = /** @type {typeof import("../Feature.js").default} */ (this
|
||||
.featureClass_);
|
||||
feature = new ctor();
|
||||
if (this.geometryName_) {
|
||||
feature.setGeometryName(this.geometryName_);
|
||||
@@ -250,7 +260,9 @@ class MVT extends FeatureFormat {
|
||||
*/
|
||||
readFeatures(source, opt_options) {
|
||||
const layers = this.layers_;
|
||||
const options = /** @type {import("./Feature.js").ReadOptions} */ (this.adaptOptions(opt_options));
|
||||
const options = /** @type {import("./Feature.js").ReadOptions} */ (this.adaptOptions(
|
||||
opt_options
|
||||
));
|
||||
const dataProjection = get(options.dataProjection);
|
||||
dataProjection.setWorldExtent(options.extent);
|
||||
options.dataProjection = dataProjection;
|
||||
@@ -295,10 +307,8 @@ class MVT extends FeatureFormat {
|
||||
setLayers(layers) {
|
||||
this.layers_ = layers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reader callback for parsing layers.
|
||||
* @param {number} tag The tag.
|
||||
@@ -310,7 +320,7 @@ function layersPBFReader(tag, layers, pbf) {
|
||||
const layer = {
|
||||
keys: [],
|
||||
values: [],
|
||||
features: []
|
||||
features: [],
|
||||
};
|
||||
const end = pbf.readVarint() + pbf.pos;
|
||||
pbf.readFields(layerPBFReader, layer, end);
|
||||
@@ -343,13 +353,22 @@ function layerPBFReader(tag, layer, pbf) {
|
||||
const end = pbf.readVarint() + pbf.pos;
|
||||
while (pbf.pos < end) {
|
||||
tag = pbf.readVarint() >> 3;
|
||||
value = tag === 1 ? pbf.readString() :
|
||||
tag === 2 ? pbf.readFloat() :
|
||||
tag === 3 ? pbf.readDouble() :
|
||||
tag === 4 ? pbf.readVarint64() :
|
||||
tag === 5 ? pbf.readVarint() :
|
||||
tag === 6 ? pbf.readSVarint() :
|
||||
tag === 7 ? pbf.readBoolean() : null;
|
||||
value =
|
||||
tag === 1
|
||||
? pbf.readString()
|
||||
: tag === 2
|
||||
? pbf.readFloat()
|
||||
: tag === 3
|
||||
? pbf.readDouble()
|
||||
: tag === 4
|
||||
? pbf.readVarint64()
|
||||
: tag === 5
|
||||
? pbf.readVarint()
|
||||
: tag === 6
|
||||
? pbf.readSVarint()
|
||||
: tag === 7
|
||||
? pbf.readBoolean()
|
||||
: null;
|
||||
}
|
||||
layer.values.push(value);
|
||||
}
|
||||
@@ -378,7 +397,6 @@ function featurePBFReader(tag, feature, pbf) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read a raw feature from the pbf offset stored at index `i` in the raw layer.
|
||||
* @param {PBF} pbf PBF.
|
||||
@@ -393,13 +411,12 @@ function readRawFeature(pbf, layer, i) {
|
||||
const feature = {
|
||||
layer: layer,
|
||||
type: 0,
|
||||
properties: {}
|
||||
properties: {},
|
||||
};
|
||||
pbf.readFields(featurePBFReader, feature, end);
|
||||
return feature;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} type The raw feature's geometry type
|
||||
* @param {number} numEnds Number of ends of the flat coordinates of the
|
||||
@@ -410,12 +427,11 @@ function getGeometryType(type, numEnds) {
|
||||
/** @type {GeometryType} */
|
||||
let geometryType;
|
||||
if (type === 1) {
|
||||
geometryType = numEnds === 1 ?
|
||||
GeometryType.POINT : GeometryType.MULTI_POINT;
|
||||
geometryType =
|
||||
numEnds === 1 ? GeometryType.POINT : GeometryType.MULTI_POINT;
|
||||
} else if (type === 2) {
|
||||
geometryType = numEnds === 1 ?
|
||||
GeometryType.LINE_STRING :
|
||||
GeometryType.MULTI_LINE_STRING;
|
||||
geometryType =
|
||||
numEnds === 1 ? GeometryType.LINE_STRING : GeometryType.MULTI_LINE_STRING;
|
||||
} else if (type === 3) {
|
||||
geometryType = GeometryType.POLYGON;
|
||||
// MultiPolygon not relevant for rendering - winding order determines
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
* @module ol/format/OSMXML
|
||||
*/
|
||||
// FIXME add typedef for stack state objects
|
||||
import {extend} from '../array.js';
|
||||
import Feature from '../Feature.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
import XMLFeature from './XMLFeature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import {isEmpty} from '../obj.js';
|
||||
import XMLFeature from './XMLFeature.js';
|
||||
import {extend} from '../array.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {pushParseAndPop, makeStructureNS} from '../xml.js';
|
||||
|
||||
import {isEmpty} from '../obj.js';
|
||||
import {makeStructureNS, pushParseAndPop} from '../xml.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -21,30 +20,25 @@ import {pushParseAndPop, makeStructureNS} from '../xml.js';
|
||||
*/
|
||||
const NAMESPACE_URIS = [null];
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const WAY_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'nd': readNd,
|
||||
'tag': readTag,
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const WAY_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'nd': readNd,
|
||||
'tag': readTag
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'node': readNode,
|
||||
'way': readWay
|
||||
});
|
||||
|
||||
const PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'node': readNode,
|
||||
'way': readWay,
|
||||
});
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -72,11 +66,16 @@ class OSMXML extends XMLFeature {
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
const options = this.getReadOptions(node, opt_options);
|
||||
if (node.localName == 'osm') {
|
||||
const state = pushParseAndPop({
|
||||
nodes: {},
|
||||
ways: [],
|
||||
features: []
|
||||
}, PARSERS, node, [options]);
|
||||
const state = pushParseAndPop(
|
||||
{
|
||||
nodes: {},
|
||||
ways: [],
|
||||
features: [],
|
||||
},
|
||||
PARSERS,
|
||||
node,
|
||||
[options]
|
||||
);
|
||||
// parse nodes in ways
|
||||
for (let j = 0; j < state.ways.length; j++) {
|
||||
const values = /** @type {Object} */ (state.ways[j]);
|
||||
@@ -89,7 +88,9 @@ class OSMXML extends XMLFeature {
|
||||
let geometry;
|
||||
if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) {
|
||||
// closed way
|
||||
geometry = new Polygon(flatCoordinates, GeometryLayout.XY, [flatCoordinates.length]);
|
||||
geometry = new Polygon(flatCoordinates, GeometryLayout.XY, [
|
||||
flatCoordinates.length,
|
||||
]);
|
||||
} else {
|
||||
geometry = new LineString(flatCoordinates, GeometryLayout.XY);
|
||||
}
|
||||
@@ -105,20 +106,16 @@ class OSMXML extends XMLFeature {
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const NODE_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'tag': readTag
|
||||
});
|
||||
|
||||
const NODE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'tag': readTag,
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
@@ -131,13 +128,18 @@ function readNode(node, objectStack) {
|
||||
/** @type {import("../coordinate.js").Coordinate} */
|
||||
const coordinates = [
|
||||
parseFloat(node.getAttribute('lon')),
|
||||
parseFloat(node.getAttribute('lat'))
|
||||
parseFloat(node.getAttribute('lat')),
|
||||
];
|
||||
state.nodes[id] = coordinates;
|
||||
|
||||
const values = pushParseAndPop({
|
||||
tags: {}
|
||||
}, NODE_PARSERS, node, objectStack);
|
||||
const values = pushParseAndPop(
|
||||
{
|
||||
tags: {},
|
||||
},
|
||||
NODE_PARSERS,
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
if (!isEmpty(values.tags)) {
|
||||
const geometry = new Point(coordinates);
|
||||
transformGeometryWithOptions(geometry, false, options);
|
||||
@@ -148,23 +150,26 @@ function readNode(node, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
*/
|
||||
function readWay(node, objectStack) {
|
||||
const id = node.getAttribute('id');
|
||||
const values = pushParseAndPop({
|
||||
id: id,
|
||||
ndrefs: [],
|
||||
tags: {}
|
||||
}, WAY_PARSERS, node, objectStack);
|
||||
const values = pushParseAndPop(
|
||||
{
|
||||
id: id,
|
||||
ndrefs: [],
|
||||
tags: {},
|
||||
},
|
||||
WAY_PARSERS,
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
const state = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
||||
state.ways.push(values);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -174,7 +179,6 @@ function readNd(node, objectStack) {
|
||||
values.ndrefs.push(node.getAttribute('ref'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -184,5 +188,4 @@ function readTag(node, objectStack) {
|
||||
values.tags[node.getAttribute('k')] = node.getAttribute('v');
|
||||
}
|
||||
|
||||
|
||||
export default OSMXML;
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
/**
|
||||
* @module ol/format/OWS
|
||||
*/
|
||||
import {readHref} from './XLink.js';
|
||||
import XML from './XML.js';
|
||||
import {
|
||||
makeObjectPropertyPusher,
|
||||
makeObjectPropertySetter,
|
||||
makeStructureNS,
|
||||
pushParseAndPop,
|
||||
} from '../xml.js';
|
||||
import {readHref} from './XLink.js';
|
||||
import {readString} from './xsd.js';
|
||||
import {makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pushParseAndPop} from '../xml.js';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -13,19 +17,16 @@ import {makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pus
|
||||
*/
|
||||
const NAMESPACE_URIS = [null, 'http://www.opengis.net/ows/1.1'];
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'ServiceIdentification': makeObjectPropertySetter(readServiceIdentification),
|
||||
'ServiceProvider': makeObjectPropertySetter(readServiceProvider),
|
||||
'OperationsMetadata': makeObjectPropertySetter(readOperationsMetadata)
|
||||
});
|
||||
|
||||
const PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'ServiceIdentification': makeObjectPropertySetter(readServiceIdentification),
|
||||
'ServiceProvider': makeObjectPropertySetter(readServiceProvider),
|
||||
'OperationsMetadata': makeObjectPropertySetter(readOperationsMetadata),
|
||||
});
|
||||
|
||||
class OWS extends XML {
|
||||
constructor() {
|
||||
@@ -50,175 +51,144 @@ class OWS extends XML {
|
||||
* @return {Object} Object
|
||||
*/
|
||||
readFromNode(node) {
|
||||
const owsObject = pushParseAndPop({},
|
||||
PARSERS, node, []);
|
||||
const owsObject = pushParseAndPop({}, PARSERS, node, []);
|
||||
return owsObject ? owsObject : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const ADDRESS_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'DeliveryPoint': makeObjectPropertySetter(readString),
|
||||
'City': makeObjectPropertySetter(readString),
|
||||
'AdministrativeArea': makeObjectPropertySetter(readString),
|
||||
'PostalCode': makeObjectPropertySetter(readString),
|
||||
'Country': makeObjectPropertySetter(readString),
|
||||
'ElectronicMailAddress': makeObjectPropertySetter(readString),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const ADDRESS_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'DeliveryPoint': makeObjectPropertySetter(readString),
|
||||
'City': makeObjectPropertySetter(readString),
|
||||
'AdministrativeArea': makeObjectPropertySetter(readString),
|
||||
'PostalCode': makeObjectPropertySetter(readString),
|
||||
'Country': makeObjectPropertySetter(readString),
|
||||
'ElectronicMailAddress': makeObjectPropertySetter(readString)
|
||||
});
|
||||
|
||||
const ALLOWED_VALUES_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Value': makeObjectPropertyPusher(readValue),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const ALLOWED_VALUES_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Value': makeObjectPropertyPusher(readValue)
|
||||
});
|
||||
|
||||
const CONSTRAINT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'AllowedValues': makeObjectPropertySetter(readAllowedValues),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const CONSTRAINT_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'AllowedValues': makeObjectPropertySetter(readAllowedValues)
|
||||
});
|
||||
|
||||
const CONTACT_INFO_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Phone': makeObjectPropertySetter(readPhone),
|
||||
'Address': makeObjectPropertySetter(readAddress),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const CONTACT_INFO_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Phone': makeObjectPropertySetter(readPhone),
|
||||
'Address': makeObjectPropertySetter(readAddress)
|
||||
});
|
||||
|
||||
const DCP_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'HTTP': makeObjectPropertySetter(readHttp),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const DCP_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'HTTP': makeObjectPropertySetter(readHttp)
|
||||
});
|
||||
|
||||
const HTTP_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Get': makeObjectPropertyPusher(readGet),
|
||||
'Post': undefined, // TODO
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const HTTP_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Get': makeObjectPropertyPusher(readGet),
|
||||
'Post': undefined // TODO
|
||||
});
|
||||
|
||||
const OPERATION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'DCP': makeObjectPropertySetter(readDcp),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const OPERATION_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'DCP': makeObjectPropertySetter(readDcp)
|
||||
});
|
||||
|
||||
const OPERATIONS_METADATA_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Operation': readOperation,
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const OPERATIONS_METADATA_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Operation': readOperation
|
||||
});
|
||||
|
||||
const PHONE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Voice': makeObjectPropertySetter(readString),
|
||||
'Facsimile': makeObjectPropertySetter(readString),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const PHONE_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Voice': makeObjectPropertySetter(readString),
|
||||
'Facsimile': makeObjectPropertySetter(readString)
|
||||
});
|
||||
|
||||
const REQUEST_METHOD_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Constraint': makeObjectPropertyPusher(readConstraint),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const REQUEST_METHOD_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Constraint': makeObjectPropertyPusher(readConstraint)
|
||||
});
|
||||
|
||||
const SERVICE_CONTACT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'IndividualName': makeObjectPropertySetter(readString),
|
||||
'PositionName': makeObjectPropertySetter(readString),
|
||||
'ContactInfo': makeObjectPropertySetter(readContactInfo),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const SERVICE_CONTACT_PARSERS =
|
||||
makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'IndividualName': makeObjectPropertySetter(readString),
|
||||
'PositionName': makeObjectPropertySetter(readString),
|
||||
'ContactInfo': makeObjectPropertySetter(readContactInfo)
|
||||
});
|
||||
|
||||
const SERVICE_IDENTIFICATION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Abstract': makeObjectPropertySetter(readString),
|
||||
'AccessConstraints': makeObjectPropertySetter(readString),
|
||||
'Fees': makeObjectPropertySetter(readString),
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'ServiceTypeVersion': makeObjectPropertySetter(readString),
|
||||
'ServiceType': makeObjectPropertySetter(readString),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const SERVICE_IDENTIFICATION_PARSERS =
|
||||
makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Abstract': makeObjectPropertySetter(readString),
|
||||
'AccessConstraints': makeObjectPropertySetter(readString),
|
||||
'Fees': makeObjectPropertySetter(readString),
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'ServiceTypeVersion': makeObjectPropertySetter(readString),
|
||||
'ServiceType': makeObjectPropertySetter(readString)
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const SERVICE_PROVIDER_PARSERS =
|
||||
makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'ProviderName': makeObjectPropertySetter(readString),
|
||||
'ProviderSite': makeObjectPropertySetter(readHref),
|
||||
'ServiceContact': makeObjectPropertySetter(readServiceContact)
|
||||
});
|
||||
|
||||
const SERVICE_PROVIDER_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'ProviderName': makeObjectPropertySetter(readString),
|
||||
'ProviderSite': makeObjectPropertySetter(readHref),
|
||||
'ServiceContact': makeObjectPropertySetter(readServiceContact),
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
@@ -226,22 +196,18 @@ const SERVICE_PROVIDER_PARSERS =
|
||||
* @return {Object|undefined} The address.
|
||||
*/
|
||||
function readAddress(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
ADDRESS_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, ADDRESS_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The values.
|
||||
*/
|
||||
function readAllowedValues(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
ALLOWED_VALUES_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, ALLOWED_VALUES_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -252,34 +218,27 @@ function readConstraint(node, objectStack) {
|
||||
if (!name) {
|
||||
return undefined;
|
||||
}
|
||||
return pushParseAndPop({'name': name},
|
||||
CONSTRAINT_PARSERS, node,
|
||||
objectStack);
|
||||
return pushParseAndPop({'name': name}, CONSTRAINT_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The contact info.
|
||||
*/
|
||||
function readContactInfo(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
CONTACT_INFO_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, CONTACT_INFO_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The DCP.
|
||||
*/
|
||||
function readDcp(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
DCP_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, DCP_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -290,11 +249,14 @@ function readGet(node, objectStack) {
|
||||
if (!href) {
|
||||
return undefined;
|
||||
}
|
||||
return pushParseAndPop({'href': href},
|
||||
REQUEST_METHOD_PARSERS, node, objectStack);
|
||||
return pushParseAndPop(
|
||||
{'href': href},
|
||||
REQUEST_METHOD_PARSERS,
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -304,7 +266,6 @@ function readHttp(node, objectStack) {
|
||||
return pushParseAndPop({}, HTTP_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -312,76 +273,59 @@ function readHttp(node, objectStack) {
|
||||
*/
|
||||
function readOperation(node, objectStack) {
|
||||
const name = node.getAttribute('name');
|
||||
const value = pushParseAndPop({},
|
||||
OPERATION_PARSERS, node, objectStack);
|
||||
const value = pushParseAndPop({}, OPERATION_PARSERS, node, objectStack);
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
const object = /** @type {Object} */
|
||||
(objectStack[objectStack.length - 1]);
|
||||
const object = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
||||
object[name] = value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The operations metadata.
|
||||
*/
|
||||
function readOperationsMetadata(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
OPERATIONS_METADATA_PARSERS, node,
|
||||
objectStack);
|
||||
return pushParseAndPop({}, OPERATIONS_METADATA_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The phone.
|
||||
*/
|
||||
function readPhone(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
PHONE_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, PHONE_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The service identification.
|
||||
*/
|
||||
function readServiceIdentification(node, objectStack) {
|
||||
return pushParseAndPop(
|
||||
{}, SERVICE_IDENTIFICATION_PARSERS, node,
|
||||
objectStack);
|
||||
return pushParseAndPop({}, SERVICE_IDENTIFICATION_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The service contact.
|
||||
*/
|
||||
function readServiceContact(node, objectStack) {
|
||||
return pushParseAndPop(
|
||||
{}, SERVICE_CONTACT_PARSERS, node,
|
||||
objectStack);
|
||||
return pushParseAndPop({}, SERVICE_CONTACT_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The service provider.
|
||||
*/
|
||||
function readServiceProvider(node, objectStack) {
|
||||
return pushParseAndPop(
|
||||
{}, SERVICE_PROVIDER_PARSERS, node,
|
||||
objectStack);
|
||||
return pushParseAndPop({}, SERVICE_PROVIDER_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -391,5 +335,4 @@ function readValue(node, objectStack) {
|
||||
return readString(node);
|
||||
}
|
||||
|
||||
|
||||
export default OWS;
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
/**
|
||||
* @module ol/format/Polyline
|
||||
*/
|
||||
import {assert} from '../asserts.js';
|
||||
import Feature from '../Feature.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
import TextFeature from './TextFeature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import {getStrideForLayout} from '../geom/SimpleGeometry.js';
|
||||
import TextFeature from './TextFeature.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {flipXY} from '../geom/flat/flip.js';
|
||||
import {inflateCoordinates} from '../geom/flat/inflate.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
|
||||
import {getStrideForLayout} from '../geom/SimpleGeometry.js';
|
||||
import {inflateCoordinates} from '../geom/flat/inflate.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
@@ -20,7 +19,6 @@ import {get as getProjection} from '../proj.js';
|
||||
* feature geometries created by the format reader.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for reading and writing data in the Encoded
|
||||
@@ -36,7 +34,6 @@ import {get as getProjection} from '../proj.js';
|
||||
* @api
|
||||
*/
|
||||
class Polyline extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Optional configuration object.
|
||||
*/
|
||||
@@ -45,7 +42,6 @@ class Polyline extends TextFeature {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
|
||||
/**
|
||||
* @type {import("../proj/Projection.js").default}
|
||||
*/
|
||||
@@ -61,8 +57,9 @@ class Polyline extends TextFeature {
|
||||
* @private
|
||||
* @type {GeometryLayout}
|
||||
*/
|
||||
this.geometryLayout_ = options.geometryLayout ?
|
||||
options.geometryLayout : GeometryLayout.XY;
|
||||
this.geometryLayout_ = options.geometryLayout
|
||||
? options.geometryLayout
|
||||
: GeometryLayout.XY;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,10 +94,19 @@ class Polyline extends TextFeature {
|
||||
const stride = getStrideForLayout(this.geometryLayout_);
|
||||
const flatCoordinates = decodeDeltas(text, stride, this.factor_);
|
||||
flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
|
||||
const coordinates = inflateCoordinates(flatCoordinates, 0, flatCoordinates.length, stride);
|
||||
const coordinates = inflateCoordinates(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
stride
|
||||
);
|
||||
const lineString = new LineString(coordinates, this.geometryLayout_);
|
||||
|
||||
return transformGeometryWithOptions(lineString, false, this.adaptOptions(opt_options));
|
||||
return transformGeometryWithOptions(
|
||||
lineString,
|
||||
false,
|
||||
this.adaptOptions(opt_options)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,8 +142,13 @@ class Polyline extends TextFeature {
|
||||
* @return {string} Text.
|
||||
*/
|
||||
writeGeometryText(geometry, opt_options) {
|
||||
geometry = /** @type {LineString} */
|
||||
(transformGeometryWithOptions(geometry, true, this.adaptOptions(opt_options)));
|
||||
geometry =
|
||||
/** @type {LineString} */
|
||||
(transformGeometryWithOptions(
|
||||
geometry,
|
||||
true,
|
||||
this.adaptOptions(opt_options)
|
||||
));
|
||||
const flatCoordinates = geometry.getFlatCoordinates();
|
||||
const stride = geometry.getStride();
|
||||
flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
|
||||
@@ -145,7 +156,6 @@ class Polyline extends TextFeature {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of n-dimensional points and return an encoded string
|
||||
*
|
||||
@@ -168,7 +178,7 @@ export function encodeDeltas(numbers, stride, opt_factor) {
|
||||
lastNumbers[d] = 0;
|
||||
}
|
||||
|
||||
for (let i = 0, ii = numbers.length; i < ii;) {
|
||||
for (let i = 0, ii = numbers.length; i < ii; ) {
|
||||
for (d = 0; d < stride; ++d, ++i) {
|
||||
const num = numbers[i];
|
||||
const delta = num - lastNumbers[d];
|
||||
@@ -181,7 +191,6 @@ export function encodeDeltas(numbers, stride, opt_factor) {
|
||||
return encodeFloats(numbers, factor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of n-dimensional points from an encoded string
|
||||
*
|
||||
@@ -205,7 +214,7 @@ export function decodeDeltas(encoded, stride, opt_factor) {
|
||||
|
||||
const numbers = decodeFloats(encoded, factor);
|
||||
|
||||
for (let i = 0, ii = numbers.length; i < ii;) {
|
||||
for (let i = 0, ii = numbers.length; i < ii; ) {
|
||||
for (d = 0; d < stride; ++d, ++i) {
|
||||
lastNumbers[d] += numbers[i];
|
||||
|
||||
@@ -216,7 +225,6 @@ export function decodeDeltas(encoded, stride, opt_factor) {
|
||||
return numbers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of floating point numbers and return an encoded string
|
||||
*
|
||||
@@ -238,7 +246,6 @@ export function encodeFloats(numbers, opt_factor) {
|
||||
return encodeSignedIntegers(numbers);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of floating point numbers from an encoded string
|
||||
*
|
||||
@@ -257,7 +264,6 @@ export function decodeFloats(encoded, opt_factor) {
|
||||
return numbers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of signed integers and return an encoded string
|
||||
*
|
||||
@@ -269,12 +275,11 @@ export function decodeFloats(encoded, opt_factor) {
|
||||
export function encodeSignedIntegers(numbers) {
|
||||
for (let i = 0, ii = numbers.length; i < ii; ++i) {
|
||||
const num = numbers[i];
|
||||
numbers[i] = (num < 0) ? ~(num << 1) : (num << 1);
|
||||
numbers[i] = num < 0 ? ~(num << 1) : num << 1;
|
||||
}
|
||||
return encodeUnsignedIntegers(numbers);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of signed integers from an encoded string
|
||||
*
|
||||
@@ -285,12 +290,11 @@ export function decodeSignedIntegers(encoded) {
|
||||
const numbers = decodeUnsignedIntegers(encoded);
|
||||
for (let i = 0, ii = numbers.length; i < ii; ++i) {
|
||||
const num = numbers[i];
|
||||
numbers[i] = (num & 1) ? ~(num >> 1) : (num >> 1);
|
||||
numbers[i] = num & 1 ? ~(num >> 1) : num >> 1;
|
||||
}
|
||||
return numbers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of unsigned integers and return an encoded string
|
||||
*
|
||||
@@ -305,7 +309,6 @@ export function encodeUnsignedIntegers(numbers) {
|
||||
return encoded;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of unsigned integers from an encoded string
|
||||
*
|
||||
@@ -330,7 +333,6 @@ export function decodeUnsignedIntegers(encoded) {
|
||||
return numbers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode one single unsigned integer and return an encoded string
|
||||
*
|
||||
@@ -338,7 +340,8 @@ export function decodeUnsignedIntegers(encoded) {
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
export function encodeUnsignedInteger(num) {
|
||||
let value, encoded = '';
|
||||
let value,
|
||||
encoded = '';
|
||||
while (num >= 0x20) {
|
||||
value = (0x20 | (num & 0x1f)) + 63;
|
||||
encoded += String.fromCharCode(value);
|
||||
@@ -349,5 +352,4 @@ export function encodeUnsignedInteger(num) {
|
||||
return encoded;
|
||||
}
|
||||
|
||||
|
||||
export default Polyline;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* @module ol/format/TextFeature
|
||||
*/
|
||||
import {abstract} from '../util.js';
|
||||
import FeatureFormat from '../format/Feature.js';
|
||||
import FormatType from '../format/FormatType.js';
|
||||
import {abstract} from '../util.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -34,7 +34,10 @@ class TextFeature extends FeatureFormat {
|
||||
* @api
|
||||
*/
|
||||
readFeature(source, opt_options) {
|
||||
return this.readFeatureFromText(getText(source), this.adaptOptions(opt_options));
|
||||
return this.readFeatureFromText(
|
||||
getText(source),
|
||||
this.adaptOptions(opt_options)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +60,10 @@ class TextFeature extends FeatureFormat {
|
||||
* @api
|
||||
*/
|
||||
readFeatures(source, opt_options) {
|
||||
return this.readFeaturesFromText(getText(source), this.adaptOptions(opt_options));
|
||||
return this.readFeaturesFromText(
|
||||
getText(source),
|
||||
this.adaptOptions(opt_options)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +86,10 @@ class TextFeature extends FeatureFormat {
|
||||
* @api
|
||||
*/
|
||||
readGeometry(source, opt_options) {
|
||||
return this.readGeometryFromText(getText(source), this.adaptOptions(opt_options));
|
||||
return this.readGeometryFromText(
|
||||
getText(source),
|
||||
this.adaptOptions(opt_options)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,7 +193,6 @@ class TextFeature extends FeatureFormat {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @return {string} Text.
|
||||
@@ -197,5 +205,4 @@ function getText(source) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default TextFeature;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/format/TopoJSON
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
import JSONFeature from './JSONFeature.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
@@ -11,6 +10,7 @@ import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* @typedef {import("topojson-specification").Topology} TopoJSONTopology
|
||||
@@ -48,7 +48,6 @@ import {get as getProjection} from '../proj.js';
|
||||
* be read from all children.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for reading data in the TopoJSON format.
|
||||
@@ -56,7 +55,6 @@ import {get as getProjection} from '../proj.js';
|
||||
* @api
|
||||
*/
|
||||
class TopoJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
@@ -81,9 +79,8 @@ class TopoJSON extends JSONFeature {
|
||||
* @type {import("../proj/Projection.js").default}
|
||||
*/
|
||||
this.dataProjection = getProjection(
|
||||
options.dataProjection ?
|
||||
options.dataProjection : 'EPSG:4326');
|
||||
|
||||
options.dataProjection ? options.dataProjection : 'EPSG:4326'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +92,9 @@ class TopoJSON extends JSONFeature {
|
||||
readFeaturesFromObject(object, opt_options) {
|
||||
if (object.type == 'Topology') {
|
||||
const topoJSONTopology = /** @type {TopoJSONTopology} */ (object);
|
||||
let transform, scale = null, translate = null;
|
||||
let transform,
|
||||
scale = null,
|
||||
translate = null;
|
||||
if (topoJSONTopology['transform']) {
|
||||
transform = topoJSONTopology['transform'];
|
||||
scale = transform['scale'];
|
||||
@@ -115,13 +114,36 @@ class TopoJSON extends JSONFeature {
|
||||
continue;
|
||||
}
|
||||
if (topoJSONFeatures[objectName].type === 'GeometryCollection') {
|
||||
feature = /** @type {TopoJSONGeometryCollection} */ (topoJSONFeatures[objectName]);
|
||||
features.push.apply(features, readFeaturesFromGeometryCollection(
|
||||
feature, arcs, scale, translate, property, objectName, opt_options));
|
||||
feature = /** @type {TopoJSONGeometryCollection} */ (topoJSONFeatures[
|
||||
objectName
|
||||
]);
|
||||
features.push.apply(
|
||||
features,
|
||||
readFeaturesFromGeometryCollection(
|
||||
feature,
|
||||
arcs,
|
||||
scale,
|
||||
translate,
|
||||
property,
|
||||
objectName,
|
||||
opt_options
|
||||
)
|
||||
);
|
||||
} else {
|
||||
feature = /** @type {TopoJSONGeometry} */ (topoJSONFeatures[objectName]);
|
||||
features.push(readFeatureFromGeometry(
|
||||
feature, arcs, scale, translate, property, objectName, opt_options));
|
||||
feature = /** @type {TopoJSONGeometry} */ (topoJSONFeatures[
|
||||
objectName
|
||||
]);
|
||||
features.push(
|
||||
readFeatureFromGeometry(
|
||||
feature,
|
||||
arcs,
|
||||
scale,
|
||||
translate,
|
||||
property,
|
||||
objectName,
|
||||
opt_options
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
return features;
|
||||
@@ -138,10 +160,8 @@ class TopoJSON extends JSONFeature {
|
||||
readProjectionFromObject(object) {
|
||||
return this.dataProjection;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, function(TopoJSONGeometry, Array, ...Array=): import("../geom/Geometry.js").default>}
|
||||
@@ -152,10 +172,9 @@ const GEOMETRY_READERS = {
|
||||
'Polygon': readPolygonGeometry,
|
||||
'MultiPoint': readMultiPointGeometry,
|
||||
'MultiLineString': readMultiLineStringGeometry,
|
||||
'MultiPolygon': readMultiPolygonGeometry
|
||||
'MultiPolygon': readMultiPolygonGeometry,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Concatenate arcs into a coordinate array.
|
||||
* @param {Array<number>} indices Indices of arcs to concatenate. Negative
|
||||
@@ -190,7 +209,6 @@ function concatenateArcs(indices, arcs) {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a point from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -207,7 +225,6 @@ function readPointGeometry(object, scale, translate) {
|
||||
return new Point(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a multi-point from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -226,7 +243,6 @@ function readMultiPointGeometry(object, scale, translate) {
|
||||
return new MultiPoint(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a linestring from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -239,7 +255,6 @@ function readLineStringGeometry(object, arcs) {
|
||||
return new LineString(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a multi-linestring from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -255,7 +270,6 @@ function readMultiLineStringGeometry(object, arcs) {
|
||||
return new MultiLineString(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a polygon from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -271,7 +285,6 @@ function readPolygonGeometry(object, arcs) {
|
||||
return new Polygon(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a multi-polygon from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -294,7 +307,6 @@ function readMultiPolygonGeometry(object, arcs) {
|
||||
return new MultiPolygon(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create features from a TopoJSON GeometryCollection object.
|
||||
*
|
||||
@@ -309,17 +321,31 @@ function readMultiPolygonGeometry(object, arcs) {
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @return {Array<Feature>} Array of features.
|
||||
*/
|
||||
function readFeaturesFromGeometryCollection(collection, arcs, scale, translate, property, name, opt_options) {
|
||||
function readFeaturesFromGeometryCollection(
|
||||
collection,
|
||||
arcs,
|
||||
scale,
|
||||
translate,
|
||||
property,
|
||||
name,
|
||||
opt_options
|
||||
) {
|
||||
const geometries = collection['geometries'];
|
||||
const features = [];
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
features[i] = readFeatureFromGeometry(
|
||||
geometries[i], arcs, scale, translate, property, name, opt_options);
|
||||
geometries[i],
|
||||
arcs,
|
||||
scale,
|
||||
translate,
|
||||
property,
|
||||
name,
|
||||
opt_options
|
||||
);
|
||||
}
|
||||
return features;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a feature from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -333,17 +359,27 @@ function readFeaturesFromGeometryCollection(collection, arcs, scale, translate,
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @return {Feature} Feature.
|
||||
*/
|
||||
function readFeatureFromGeometry(object, arcs, scale, translate, property, name, opt_options) {
|
||||
function readFeatureFromGeometry(
|
||||
object,
|
||||
arcs,
|
||||
scale,
|
||||
translate,
|
||||
property,
|
||||
name,
|
||||
opt_options
|
||||
) {
|
||||
let geometry;
|
||||
const type = object.type;
|
||||
const geometryReader = GEOMETRY_READERS[type];
|
||||
if ((type === 'Point') || (type === 'MultiPoint')) {
|
||||
if (type === 'Point' || type === 'MultiPoint') {
|
||||
geometry = geometryReader(object, scale, translate);
|
||||
} else {
|
||||
geometry = geometryReader(object, arcs);
|
||||
}
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(transformGeometryWithOptions(geometry, false, opt_options));
|
||||
feature.setGeometry(
|
||||
transformGeometryWithOptions(geometry, false, opt_options)
|
||||
);
|
||||
if (object.id !== undefined) {
|
||||
feature.setId(object.id);
|
||||
}
|
||||
@@ -360,7 +396,6 @@ function readFeatureFromGeometry(object, arcs, scale, translate, property, name,
|
||||
return feature;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply a linear transform to array of arcs. The provided array of arcs is
|
||||
* modified in place.
|
||||
@@ -375,7 +410,6 @@ function transformArcs(arcs, scale, translate) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply a linear transform to an arc. The provided arc is modified in place.
|
||||
*
|
||||
@@ -396,7 +430,6 @@ function transformArc(arc, scale, translate) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply a linear transform to a vertex. The provided vertex is modified in
|
||||
* place.
|
||||
@@ -410,5 +443,4 @@ function transformVertex(vertex, scale, translate) {
|
||||
vertex[1] = vertex[1] * scale[1] + translate[1];
|
||||
}
|
||||
|
||||
|
||||
export default TopoJSON;
|
||||
|
||||
@@ -1,19 +1,32 @@
|
||||
/**
|
||||
* @module ol/format/WFS
|
||||
*/
|
||||
import {assert} from '../asserts.js';
|
||||
import GML2 from './GML2.js';
|
||||
import GML3 from './GML3.js';
|
||||
import GMLBase, {GMLNS} from './GMLBase.js';
|
||||
import {and as andFilter, bbox as bboxFilter} from './filter.js';
|
||||
import XMLFeature from './XMLFeature.js';
|
||||
import {readNonNegativeIntegerString, readNonNegativeInteger, writeStringTextNode} from './xsd.js';
|
||||
import {
|
||||
XML_SCHEMA_INSTANCE_URI,
|
||||
createElementNS,
|
||||
isDocument,
|
||||
makeArrayPusher,
|
||||
makeChildAppender,
|
||||
makeObjectPropertySetter,
|
||||
makeSimpleNodeFactory,
|
||||
parse,
|
||||
parseNode,
|
||||
pushParseAndPop,
|
||||
pushSerializeAndPop,
|
||||
} from '../xml.js';
|
||||
import {and as andFilter, bbox as bboxFilter} from './filter.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {assign} from '../obj.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {createElementNS, isDocument, makeArrayPusher, makeChildAppender,
|
||||
makeObjectPropertySetter, makeSimpleNodeFactory, parse, parseNode,
|
||||
pushParseAndPop, pushSerializeAndPop, XML_SCHEMA_INSTANCE_URI} from '../xml.js';
|
||||
|
||||
import {
|
||||
readNonNegativeInteger,
|
||||
readNonNegativeIntegerString,
|
||||
writeStringTextNode,
|
||||
} from './xsd.js';
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -22,11 +35,12 @@ import {createElementNS, isDocument, makeArrayPusher, makeChildAppender,
|
||||
const FEATURE_COLLECTION_PARSERS = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'boundedBy': makeObjectPropertySetter(
|
||||
GMLBase.prototype.readGeometryElement, 'bounds')
|
||||
}
|
||||
GMLBase.prototype.readGeometryElement,
|
||||
'bounds'
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
@@ -35,11 +49,10 @@ const TRANSACTION_SUMMARY_PARSERS = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'totalInserted': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'totalUpdated': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'totalDeleted': makeObjectPropertySetter(readNonNegativeInteger)
|
||||
}
|
||||
'totalDeleted': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
@@ -47,23 +60,22 @@ const TRANSACTION_SUMMARY_PARSERS = {
|
||||
const TRANSACTION_RESPONSE_PARSERS = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'TransactionSummary': makeObjectPropertySetter(
|
||||
readTransactionSummary, 'transactionSummary'),
|
||||
'InsertResults': makeObjectPropertySetter(
|
||||
readInsertResults, 'insertIds')
|
||||
}
|
||||
readTransactionSummary,
|
||||
'transactionSummary'
|
||||
),
|
||||
'InsertResults': makeObjectPropertySetter(readInsertResults, 'insertIds'),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
const QUERY_SERIALIZERS = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'PropertyName': makeChildAppender(writeStringTextNode)
|
||||
}
|
||||
'PropertyName': makeChildAppender(writeStringTextNode),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
@@ -73,11 +85,10 @@ const TRANSACTION_SERIALIZERS = {
|
||||
'Update': makeChildAppender(writeUpdate),
|
||||
'Delete': makeChildAppender(writeDelete),
|
||||
'Property': makeChildAppender(writeProperty),
|
||||
'Native': makeChildAppender(writeNative)
|
||||
}
|
||||
'Native': makeChildAppender(writeNative),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {Object<string, string>|string} [featureNS] The namespace URI used for features.
|
||||
@@ -86,7 +97,6 @@ const TRANSACTION_SERIALIZERS = {
|
||||
* @property {string} [schemaLocation] Optional schemaLocation to use for serialization, this will override the default.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} WriteGetFeatureOptions
|
||||
* @property {string} featureNS The namespace URI used for features.
|
||||
@@ -112,7 +122,6 @@ const TRANSACTION_SERIALIZERS = {
|
||||
* E.g. `hits` only includes the `numberOfFeatures` attribute in the response and no features.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} WriteTransactionOptions
|
||||
* @property {string} featureNS The namespace URI used for features.
|
||||
@@ -128,7 +137,6 @@ const TRANSACTION_SERIALIZERS = {
|
||||
* @property {string} [version='1.1.0'] WFS version to use for the transaction. Can be either `1.0.0` or `1.1.0`.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Number of features; bounds/extent.
|
||||
* @typedef {Object} FeatureCollectionMetadata
|
||||
@@ -136,7 +144,6 @@ const TRANSACTION_SERIALIZERS = {
|
||||
* @property {import("../extent.js").Extent} bounds
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Total deleted; total inserted; total updated; array of insert ids.
|
||||
* @typedef {Object} TransactionResponse
|
||||
@@ -146,53 +153,47 @@ const TRANSACTION_SERIALIZERS = {
|
||||
* @property {Array<string>} insertIds
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const FEATURE_PREFIX = 'feature';
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const XMLNS = 'http://www.w3.org/2000/xmlns/';
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const OGCNS = 'http://www.opengis.net/ogc';
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const WFSNS = 'http://www.opengis.net/wfs';
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const FESNS = 'http://www.opengis.net/fes';
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, string>}
|
||||
*/
|
||||
const SCHEMA_LOCATIONS = {
|
||||
'1.1.0': 'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd',
|
||||
'1.0.0': 'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd'
|
||||
'1.1.0':
|
||||
'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd',
|
||||
'1.0.0':
|
||||
'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd',
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
const DEFAULT_VERSION = '1.1.0';
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for reading and writing data in the WFS format.
|
||||
@@ -203,7 +204,6 @@ const DEFAULT_VERSION = '1.1.0';
|
||||
* @api
|
||||
*/
|
||||
class WFS extends XMLFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Optional configuration object.
|
||||
*/
|
||||
@@ -228,15 +228,15 @@ class WFS extends XMLFeature {
|
||||
* @private
|
||||
* @type {GMLBase}
|
||||
*/
|
||||
this.gmlFormat_ = options.gmlFormat ?
|
||||
options.gmlFormat : new GML3();
|
||||
this.gmlFormat_ = options.gmlFormat ? options.gmlFormat : new GML3();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.schemaLocation_ = options.schemaLocation ?
|
||||
options.schemaLocation : SCHEMA_LOCATIONS[DEFAULT_VERSION];
|
||||
this.schemaLocation_ = options.schemaLocation
|
||||
? options.schemaLocation
|
||||
: SCHEMA_LOCATIONS[DEFAULT_VERSION];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,21 +262,25 @@ class WFS extends XMLFeature {
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
const context = {
|
||||
node: node
|
||||
node: node,
|
||||
};
|
||||
assign(context, {
|
||||
'featureType': this.featureType_,
|
||||
'featureNS': this.featureNS_
|
||||
'featureNS': this.featureNS_,
|
||||
});
|
||||
|
||||
assign(context, this.getReadOptions(node, opt_options ? opt_options : {}));
|
||||
const objectStack = [context];
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS[GMLNS][
|
||||
'featureMember'] =
|
||||
makeArrayPusher(GMLBase.prototype.readFeaturesInternal);
|
||||
let features = pushParseAndPop([],
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
|
||||
objectStack, this.gmlFormat_);
|
||||
'featureMember'
|
||||
] = makeArrayPusher(GMLBase.prototype.readFeaturesInternal);
|
||||
let features = pushParseAndPop(
|
||||
[],
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS,
|
||||
node,
|
||||
objectStack,
|
||||
this.gmlFormat_
|
||||
);
|
||||
if (!features) {
|
||||
features = [];
|
||||
}
|
||||
@@ -298,9 +302,12 @@ class WFS extends XMLFeature {
|
||||
return this.readTransactionResponseFromDocument(doc);
|
||||
} else if (isDocument(source)) {
|
||||
return this.readTransactionResponseFromDocument(
|
||||
/** @type {Document} */ (source));
|
||||
/** @type {Document} */ (source)
|
||||
);
|
||||
} else {
|
||||
return this.readTransactionResponseFromNode(/** @type {Element} */ (source));
|
||||
return this.readTransactionResponseFromNode(
|
||||
/** @type {Element} */ (source)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,10 +327,12 @@ class WFS extends XMLFeature {
|
||||
return this.readFeatureCollectionMetadataFromDocument(doc);
|
||||
} else if (isDocument(source)) {
|
||||
return this.readFeatureCollectionMetadataFromDocument(
|
||||
/** @type {Document} */ (source));
|
||||
/** @type {Document} */ (source)
|
||||
);
|
||||
} else {
|
||||
return this.readFeatureCollectionMetadataFromNode(
|
||||
/** @type {Element} */ (source));
|
||||
/** @type {Element} */ (source)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +344,9 @@ class WFS extends XMLFeature {
|
||||
readFeatureCollectionMetadataFromDocument(doc) {
|
||||
for (let n = /** @type {Node} */ (doc.firstChild); n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readFeatureCollectionMetadataFromNode(/** @type {Element} */ (n));
|
||||
return this.readFeatureCollectionMetadataFromNode(
|
||||
/** @type {Element} */ (n)
|
||||
);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
@@ -349,11 +360,16 @@ class WFS extends XMLFeature {
|
||||
readFeatureCollectionMetadataFromNode(node) {
|
||||
const result = {};
|
||||
const value = readNonNegativeIntegerString(
|
||||
node.getAttribute('numberOfFeatures'));
|
||||
node.getAttribute('numberOfFeatures')
|
||||
);
|
||||
result['numberOfFeatures'] = value;
|
||||
return pushParseAndPop(
|
||||
/** @type {FeatureCollectionMetadata} */ (result),
|
||||
FEATURE_COLLECTION_PARSERS, node, [], this.gmlFormat_);
|
||||
FEATURE_COLLECTION_PARSERS,
|
||||
node,
|
||||
[],
|
||||
this.gmlFormat_
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,8 +391,11 @@ class WFS extends XMLFeature {
|
||||
*/
|
||||
readTransactionResponseFromNode(node) {
|
||||
return pushParseAndPop(
|
||||
/** @type {TransactionResponse} */({}),
|
||||
TRANSACTION_RESPONSE_PARSERS, node, []);
|
||||
/** @type {TransactionResponse} */ ({}),
|
||||
TRANSACTION_RESPONSE_PARSERS,
|
||||
node,
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,10 +434,12 @@ class WFS extends XMLFeature {
|
||||
}
|
||||
filter = options.filter;
|
||||
if (options.bbox) {
|
||||
assert(options.geometryName,
|
||||
12); // `options.geometryName` must also be provided when `options.bbox` is set
|
||||
assert(options.geometryName, 12); // `options.geometryName` must also be provided when `options.bbox` is set
|
||||
const bbox = bboxFilter(
|
||||
/** @type {string} */ (options.geometryName), options.bbox, options.srsName);
|
||||
/** @type {string} */ (options.geometryName),
|
||||
options.bbox,
|
||||
options.srsName
|
||||
);
|
||||
if (filter) {
|
||||
// if bbox and filter are both set, combine the two into a single filter
|
||||
filter = andFilter(filter, bbox);
|
||||
@@ -427,10 +448,14 @@ class WFS extends XMLFeature {
|
||||
}
|
||||
}
|
||||
}
|
||||
node.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', this.schemaLocation_);
|
||||
node.setAttributeNS(
|
||||
XML_SCHEMA_INSTANCE_URI,
|
||||
'xsi:schemaLocation',
|
||||
this.schemaLocation_
|
||||
);
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
const context = {
|
||||
node: node
|
||||
node: node,
|
||||
};
|
||||
assign(context, {
|
||||
'srsName': options.srsName,
|
||||
@@ -438,12 +463,15 @@ class WFS extends XMLFeature {
|
||||
'featurePrefix': options.featurePrefix,
|
||||
'geometryName': options.geometryName,
|
||||
'filter': filter,
|
||||
'propertyNames': options.propertyNames ? options.propertyNames : []
|
||||
'propertyNames': options.propertyNames ? options.propertyNames : [],
|
||||
});
|
||||
|
||||
assert(Array.isArray(options.featureTypes),
|
||||
11); // `options.featureTypes` should be an Array
|
||||
writeGetFeature(node, /** @type {!Array<string>} */ (options.featureTypes), [context]);
|
||||
assert(Array.isArray(options.featureTypes), 11); // `options.featureTypes` should be an Array
|
||||
writeGetFeature(
|
||||
node,
|
||||
/** @type {!Array<string>} */ (options.featureTypes),
|
||||
[context]
|
||||
);
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -474,43 +502,87 @@ class WFS extends XMLFeature {
|
||||
}
|
||||
}
|
||||
const schemaLocation = SCHEMA_LOCATIONS[version];
|
||||
node.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', schemaLocation);
|
||||
const featurePrefix = options.featurePrefix ? options.featurePrefix : FEATURE_PREFIX;
|
||||
node.setAttributeNS(
|
||||
XML_SCHEMA_INSTANCE_URI,
|
||||
'xsi:schemaLocation',
|
||||
schemaLocation
|
||||
);
|
||||
const featurePrefix = options.featurePrefix
|
||||
? options.featurePrefix
|
||||
: FEATURE_PREFIX;
|
||||
if (inserts) {
|
||||
obj = assign({node: node}, {'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName});
|
||||
obj = assign(
|
||||
{node: node},
|
||||
{
|
||||
'featureNS': options.featureNS,
|
||||
'featureType': options.featureType,
|
||||
'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion,
|
||||
'hasZ': options.hasZ,
|
||||
'srsName': options.srsName,
|
||||
}
|
||||
);
|
||||
assign(obj, baseObj);
|
||||
pushSerializeAndPop(obj,
|
||||
pushSerializeAndPop(
|
||||
obj,
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Insert'), inserts,
|
||||
objectStack);
|
||||
makeSimpleNodeFactory('Insert'),
|
||||
inserts,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
if (updates) {
|
||||
obj = assign({node: node}, {'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName});
|
||||
obj = assign(
|
||||
{node: node},
|
||||
{
|
||||
'featureNS': options.featureNS,
|
||||
'featureType': options.featureType,
|
||||
'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion,
|
||||
'hasZ': options.hasZ,
|
||||
'srsName': options.srsName,
|
||||
}
|
||||
);
|
||||
assign(obj, baseObj);
|
||||
pushSerializeAndPop(obj,
|
||||
pushSerializeAndPop(
|
||||
obj,
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Update'), updates,
|
||||
objectStack);
|
||||
makeSimpleNodeFactory('Update'),
|
||||
updates,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
if (deletes) {
|
||||
pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'srsName': options.srsName},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Delete'), deletes,
|
||||
objectStack);
|
||||
pushSerializeAndPop(
|
||||
{
|
||||
node: node,
|
||||
'featureNS': options.featureNS,
|
||||
'featureType': options.featureType,
|
||||
'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion,
|
||||
'srsName': options.srsName,
|
||||
},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Delete'),
|
||||
deletes,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
if (options.nativeElements) {
|
||||
pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'srsName': options.srsName},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Native'), options.nativeElements,
|
||||
objectStack);
|
||||
pushSerializeAndPop(
|
||||
{
|
||||
node: node,
|
||||
'featureNS': options.featureNS,
|
||||
'featureType': options.featureType,
|
||||
'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion,
|
||||
'srsName': options.srsName,
|
||||
},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Native'),
|
||||
options.nativeElements,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
@@ -533,13 +605,15 @@ class WFS extends XMLFeature {
|
||||
* @return {import("../proj/Projection.js").default} Projection.
|
||||
*/
|
||||
readProjectionFromNode(node) {
|
||||
if (node.firstElementChild &&
|
||||
node.firstElementChild.firstElementChild) {
|
||||
if (node.firstElementChild && node.firstElementChild.firstElementChild) {
|
||||
node = node.firstElementChild.firstElementChild;
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
if (!(n.childNodes.length === 0 ||
|
||||
(n.childNodes.length === 1 &&
|
||||
n.firstChild.nodeType === 3))) {
|
||||
if (
|
||||
!(
|
||||
n.childNodes.length === 0 ||
|
||||
(n.childNodes.length === 1 && n.firstChild.nodeType === 3)
|
||||
)
|
||||
) {
|
||||
const objectStack = [{}];
|
||||
this.gmlFormat_.readGeometryElement(n, objectStack);
|
||||
return getProjection(objectStack.pop().srsName);
|
||||
@@ -551,31 +625,27 @@ class WFS extends XMLFeature {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} Transaction Summary.
|
||||
*/
|
||||
function readTransactionSummary(node, objectStack) {
|
||||
return pushParseAndPop(
|
||||
{}, TRANSACTION_SUMMARY_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, TRANSACTION_SUMMARY_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
const OGC_FID_PARSERS = {
|
||||
'http://www.opengis.net/ogc': {
|
||||
'FeatureId': makeArrayPusher(function(node, objectStack) {
|
||||
'FeatureId': makeArrayPusher(function (node, objectStack) {
|
||||
return node.getAttribute('fid');
|
||||
})
|
||||
}
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -584,29 +654,25 @@ function fidParser(node, objectStack) {
|
||||
parseNode(OGC_FID_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
const INSERT_RESULTS_PARSERS = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'Feature': fidParser
|
||||
}
|
||||
'Feature': fidParser,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Array<string>|undefined} Insert results.
|
||||
*/
|
||||
function readInsertResults(node, objectStack) {
|
||||
return pushParseAndPop(
|
||||
[], INSERT_RESULTS_PARSERS, node, objectStack);
|
||||
return pushParseAndPop([], INSERT_RESULTS_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
@@ -626,7 +692,6 @@ function writeFeature(node, feature, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {number|string} fid Feature identifier.
|
||||
@@ -640,7 +705,6 @@ function writeOgcFidFilter(node, fid, objectStack) {
|
||||
node.appendChild(filter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|undefined} featurePrefix The prefix of the feature.
|
||||
* @param {string} featureType The type of the feature.
|
||||
@@ -657,7 +721,6 @@ function getTypeName(featurePrefix, featureType) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
@@ -678,7 +741,6 @@ function writeDelete(node, feature, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
@@ -702,23 +764,31 @@ function writeUpdate(node, feature, objectStack) {
|
||||
const value = feature.get(keys[i]);
|
||||
if (value !== undefined) {
|
||||
let name = keys[i];
|
||||
if (value && typeof /** @type {?} */ (value).getSimplifiedGeometry === 'function') {
|
||||
if (
|
||||
value &&
|
||||
typeof (/** @type {?} */ (value).getSimplifiedGeometry) === 'function'
|
||||
) {
|
||||
name = geometryName;
|
||||
}
|
||||
values.push({name: name, value: value});
|
||||
}
|
||||
}
|
||||
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */ (
|
||||
{'gmlVersion': context['gmlVersion'], node: node,
|
||||
'hasZ': context['hasZ'], 'srsName': context['srsName']}),
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Property'), values,
|
||||
objectStack);
|
||||
pushSerializeAndPop(
|
||||
/** @type {import("../xml.js").NodeStackItem} */ ({
|
||||
'gmlVersion': context['gmlVersion'],
|
||||
node: node,
|
||||
'hasZ': context['hasZ'],
|
||||
'srsName': context['srsName'],
|
||||
}),
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Property'),
|
||||
values,
|
||||
objectStack
|
||||
);
|
||||
writeOgcFidFilter(node, fid, objectStack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Object} pair Property name and value.
|
||||
@@ -733,13 +803,15 @@ function writeProperty(node, pair, objectStack) {
|
||||
if (pair.value !== undefined && pair.value !== null) {
|
||||
const value = createElementNS(WFSNS, 'Value');
|
||||
node.appendChild(value);
|
||||
if (pair.value && typeof /** @type {?} */ (pair.value).getSimplifiedGeometry === 'function') {
|
||||
if (
|
||||
pair.value &&
|
||||
typeof (/** @type {?} */ (pair.value).getSimplifiedGeometry) ===
|
||||
'function'
|
||||
) {
|
||||
if (gmlVersion === 2) {
|
||||
GML2.prototype.writeGeometryElement(value,
|
||||
pair.value, objectStack);
|
||||
GML2.prototype.writeGeometryElement(value, pair.value, objectStack);
|
||||
} else {
|
||||
GML3.prototype.writeGeometryElement(value,
|
||||
pair.value, objectStack);
|
||||
GML3.prototype.writeGeometryElement(value, pair.value, objectStack);
|
||||
}
|
||||
} else {
|
||||
writeStringTextNode(value, pair.value);
|
||||
@@ -747,7 +819,6 @@ function writeProperty(node, pair, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {{vendorId: string, safeToIgnore: boolean, value: string}} nativeElement The native element.
|
||||
@@ -765,13 +836,12 @@ function writeNative(node, nativeElement, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
const GETFEATURE_SERIALIZERS = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'Query': makeChildAppender(writeQuery)
|
||||
'Query': makeChildAppender(writeQuery),
|
||||
},
|
||||
'http://www.opengis.net/ogc': {
|
||||
'During': makeChildAppender(writeDuringFilter),
|
||||
@@ -790,11 +860,10 @@ const GETFEATURE_SERIALIZERS = {
|
||||
'PropertyIsGreaterThanOrEqualTo': makeChildAppender(writeComparisonFilter),
|
||||
'PropertyIsNull': makeChildAppender(writeIsNullFilter),
|
||||
'PropertyIsBetween': makeChildAppender(writeIsBetweenFilter),
|
||||
'PropertyIsLike': makeChildAppender(writeIsLikeFilter)
|
||||
}
|
||||
'PropertyIsLike': makeChildAppender(writeIsLikeFilter),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {string} featureType Feature type.
|
||||
@@ -820,12 +889,18 @@ function writeQuery(node, featureType, objectStack) {
|
||||
if (featureNS) {
|
||||
node.setAttributeNS(XMLNS, 'xmlns:' + featurePrefix, featureNS);
|
||||
}
|
||||
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign({}, context));
|
||||
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign(
|
||||
{},
|
||||
context
|
||||
));
|
||||
item.node = node;
|
||||
pushSerializeAndPop(item,
|
||||
pushSerializeAndPop(
|
||||
item,
|
||||
QUERY_SERIALIZERS,
|
||||
makeSimpleNodeFactory('PropertyName'), propertyNames,
|
||||
objectStack);
|
||||
makeSimpleNodeFactory('PropertyName'),
|
||||
propertyNames,
|
||||
objectStack
|
||||
);
|
||||
const filter = context['filter'];
|
||||
if (filter) {
|
||||
const child = createElementNS(OGCNS, 'Filter');
|
||||
@@ -834,7 +909,6 @@ function writeQuery(node, featureType, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Filter.js").default} filter Filter.
|
||||
@@ -843,13 +917,15 @@ function writeQuery(node, featureType, objectStack) {
|
||||
function writeFilterCondition(node, filter, objectStack) {
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
const item = {node: node};
|
||||
pushSerializeAndPop(item,
|
||||
pushSerializeAndPop(
|
||||
item,
|
||||
GETFEATURE_SERIALIZERS,
|
||||
makeSimpleNodeFactory(filter.getTagName()),
|
||||
[filter], objectStack);
|
||||
[filter],
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Bbox.js").default} filter Filter.
|
||||
@@ -863,7 +939,6 @@ function writeBboxFilter(node, filter, objectStack) {
|
||||
GML3.prototype.writeGeometryElement(node, filter.extent, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Contains.js").default} filter Filter.
|
||||
@@ -877,7 +952,6 @@ function writeContainsFilter(node, filter, objectStack) {
|
||||
GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Intersects.js").default} filter Filter.
|
||||
@@ -891,7 +965,6 @@ function writeIntersectsFilter(node, filter, objectStack) {
|
||||
GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Within.js").default} filter Filter.
|
||||
@@ -905,14 +978,12 @@ function writeWithinFilter(node, filter, objectStack) {
|
||||
GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/During.js").default} filter Filter.
|
||||
* @param {Array<*>} objectStack Node stack.
|
||||
*/
|
||||
function writeDuringFilter(node, filter, objectStack) {
|
||||
|
||||
const valueReference = createElementNS(FESNS, 'ValueReference');
|
||||
writeStringTextNode(valueReference, filter.propertyName);
|
||||
node.appendChild(valueReference);
|
||||
@@ -930,7 +1001,6 @@ function writeDuringFilter(node, filter, objectStack) {
|
||||
writeTimeInstant(end, filter.end);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/LogicalNary.js").default} filter Filter.
|
||||
@@ -942,14 +1012,16 @@ function writeLogicalFilter(node, filter, objectStack) {
|
||||
const conditions = filter.conditions;
|
||||
for (let i = 0, ii = conditions.length; i < ii; ++i) {
|
||||
const condition = conditions[i];
|
||||
pushSerializeAndPop(item,
|
||||
pushSerializeAndPop(
|
||||
item,
|
||||
GETFEATURE_SERIALIZERS,
|
||||
makeSimpleNodeFactory(condition.getTagName()),
|
||||
[condition], objectStack);
|
||||
[condition],
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Not.js").default} filter Filter.
|
||||
@@ -959,13 +1031,15 @@ function writeNotFilter(node, filter, objectStack) {
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
const item = {node: node};
|
||||
const condition = filter.condition;
|
||||
pushSerializeAndPop(item,
|
||||
pushSerializeAndPop(
|
||||
item,
|
||||
GETFEATURE_SERIALIZERS,
|
||||
makeSimpleNodeFactory(condition.getTagName()),
|
||||
[condition], objectStack);
|
||||
[condition],
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./filter/ComparisonBinary.js").default} filter Filter.
|
||||
@@ -979,7 +1053,6 @@ function writeComparisonFilter(node, filter, objectStack) {
|
||||
writeOgcLiteral(node, '' + filter.expression);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/IsNull.js").default} filter Filter.
|
||||
@@ -989,7 +1062,6 @@ function writeIsNullFilter(node, filter, objectStack) {
|
||||
writeOgcPropertyName(node, filter.propertyName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/IsBetween.js").default} filter Filter.
|
||||
@@ -1007,7 +1079,6 @@ function writeIsBetweenFilter(node, filter, objectStack) {
|
||||
writeOgcLiteral(upperBoundary, '' + filter.upperBoundary);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./filter/IsLike.js").default} filter Filter.
|
||||
@@ -1024,7 +1095,6 @@ function writeIsLikeFilter(node, filter, objectStack) {
|
||||
writeOgcLiteral(node, '' + filter.pattern);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} tagName Tag name.
|
||||
* @param {Node} node Node.
|
||||
@@ -1036,7 +1106,6 @@ function writeOgcExpression(tagName, node, value) {
|
||||
node.appendChild(property);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {string} value PropertyName value.
|
||||
@@ -1045,7 +1114,6 @@ function writeOgcPropertyName(node, value) {
|
||||
writeOgcExpression('PropertyName', node, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {string} value PropertyName value.
|
||||
@@ -1054,7 +1122,6 @@ function writeOgcLiteral(node, value) {
|
||||
writeOgcExpression('Literal', node, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {string} time PropertyName value.
|
||||
@@ -1068,7 +1135,6 @@ function writeTimeInstant(node, time) {
|
||||
writeStringTextNode(timePosition, time);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode filter as WFS `Filter` and return the Node.
|
||||
*
|
||||
@@ -1082,7 +1148,6 @@ export function writeFilter(filter) {
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array<string>} featureTypes Feature types.
|
||||
@@ -1090,13 +1155,18 @@ export function writeFilter(filter) {
|
||||
*/
|
||||
function writeGetFeature(node, featureTypes, objectStack) {
|
||||
const context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
||||
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign({}, context));
|
||||
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign(
|
||||
{},
|
||||
context
|
||||
));
|
||||
item.node = node;
|
||||
pushSerializeAndPop(item,
|
||||
pushSerializeAndPop(
|
||||
item,
|
||||
GETFEATURE_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Query'), featureTypes,
|
||||
objectStack);
|
||||
makeSimpleNodeFactory('Query'),
|
||||
featureTypes,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export default WFS;
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
* @module ol/format/WKT
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
import TextFeature from './TextFeature.js';
|
||||
import GeometryCollection from '../geom/GeometryCollection.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
import MultiPoint from '../geom/MultiPoint.js';
|
||||
import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
|
||||
import TextFeature from './TextFeature.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* Geometry constructors
|
||||
@@ -25,10 +24,9 @@ const GeometryConstructor = {
|
||||
'POLYGON': Polygon,
|
||||
'MULTIPOINT': MultiPoint,
|
||||
'MULTILINESTRING': MultiLineString,
|
||||
'MULTIPOLYGON': MultiPolygon
|
||||
'MULTIPOLYGON': MultiPolygon,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {boolean} [splitCollection=false] Whether to split GeometryCollections into
|
||||
@@ -48,28 +46,24 @@ const GeometryConstructor = {
|
||||
*/
|
||||
const EMPTY = 'EMPTY';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
const Z = 'Z';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
const M = 'M';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
const ZM = 'ZM';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @enum {number}
|
||||
@@ -80,7 +74,7 @@ const TokenType = {
|
||||
RIGHT_PAREN: 3,
|
||||
NUMBER: 4,
|
||||
COMMA: 5,
|
||||
EOF: 6
|
||||
EOF: 6,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -92,17 +86,14 @@ for (const type in GeometryType) {
|
||||
WKTGeometryType[type] = GeometryType[type].toUpperCase();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class to tokenize a WKT string.
|
||||
*/
|
||||
class Lexer {
|
||||
|
||||
/**
|
||||
* @param {string} wkt WKT string.
|
||||
*/
|
||||
constructor(wkt) {
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@@ -121,7 +112,7 @@ class Lexer {
|
||||
* @private
|
||||
*/
|
||||
isAlpha_(c) {
|
||||
return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z';
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +124,7 @@ class Lexer {
|
||||
*/
|
||||
isNumeric_(c, opt_decimal) {
|
||||
const decimal = opt_decimal !== undefined ? opt_decimal : false;
|
||||
return c >= '0' && c <= '9' || c == '.' && !decimal;
|
||||
return (c >= '0' && c <= '9') || (c == '.' && !decimal);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,12 +196,12 @@ class Lexer {
|
||||
c = this.nextChar_();
|
||||
} while (
|
||||
this.isNumeric_(c, decimal) ||
|
||||
// if we haven't detected a scientific number before, 'e' or 'E'
|
||||
// hint that we should continue to read
|
||||
!scientificNotation && (c == 'e' || c == 'E') ||
|
||||
// once we know that we have a scientific number, both '-' and '+'
|
||||
// are allowed
|
||||
scientificNotation && (c == '-' || c == '+')
|
||||
// if we haven't detected a scientific number before, 'e' or 'E'
|
||||
// hint that we should continue to read
|
||||
(!scientificNotation && (c == 'e' || c == 'E')) ||
|
||||
// once we know that we have a scientific number, both '-' and '+'
|
||||
// are allowed
|
||||
(scientificNotation && (c == '-' || c == '+'))
|
||||
);
|
||||
return parseFloat(this.wkt.substring(index, this.index_--));
|
||||
}
|
||||
@@ -233,12 +224,10 @@ class Lexer {
|
||||
* Class to parse the tokens from the WKT string.
|
||||
*/
|
||||
class Parser {
|
||||
|
||||
/**
|
||||
* @param {Lexer} lexer The lexer.
|
||||
*/
|
||||
constructor(lexer) {
|
||||
|
||||
/**
|
||||
* @type {Lexer}
|
||||
* @private
|
||||
@@ -518,8 +507,8 @@ class Parser {
|
||||
* @private
|
||||
*/
|
||||
isEmptyGeometry_() {
|
||||
const isEmpty = this.isTokenType(TokenType.TEXT) &&
|
||||
this.token_.value == EMPTY;
|
||||
const isEmpty =
|
||||
this.isTokenType(TokenType.TEXT) && this.token_.value == EMPTY;
|
||||
if (isEmpty) {
|
||||
this.consume_();
|
||||
}
|
||||
@@ -532,8 +521,15 @@ class Parser {
|
||||
* @private
|
||||
*/
|
||||
formatErrorMessage_() {
|
||||
return 'Unexpected `' + this.token_.value + '` at position ' +
|
||||
this.token_.position + ' in `' + this.lexer_.wkt + '`';
|
||||
return (
|
||||
'Unexpected `' +
|
||||
this.token_.value +
|
||||
'` at position ' +
|
||||
this.token_.position +
|
||||
' in `' +
|
||||
this.lexer_.wkt +
|
||||
'`'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -599,7 +595,6 @@ class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Geometry format for reading and writing data in the `WellKnownText` (WKT)
|
||||
@@ -608,7 +603,6 @@ class Parser {
|
||||
* @api
|
||||
*/
|
||||
class WKT extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
@@ -617,15 +611,13 @@ class WKT extends TextFeature {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
|
||||
/**
|
||||
* Split GeometryCollection into multiple features.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.splitCollection_ = options.splitCollection !== undefined ?
|
||||
options.splitCollection : false;
|
||||
|
||||
this.splitCollection_ =
|
||||
options.splitCollection !== undefined ? options.splitCollection : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -666,10 +658,11 @@ class WKT extends TextFeature {
|
||||
readFeaturesFromText(text, opt_options) {
|
||||
let geometries = [];
|
||||
const geometry = this.readGeometryFromText(text, opt_options);
|
||||
if (this.splitCollection_ &&
|
||||
geometry.getType() == GeometryType.GEOMETRY_COLLECTION) {
|
||||
geometries = (/** @type {GeometryCollection} */ (geometry))
|
||||
.getGeometriesArray();
|
||||
if (
|
||||
this.splitCollection_ &&
|
||||
geometry.getType() == GeometryType.GEOMETRY_COLLECTION
|
||||
) {
|
||||
geometries = /** @type {GeometryCollection} */ (geometry).getGeometriesArray();
|
||||
} else {
|
||||
geometries = [geometry];
|
||||
}
|
||||
@@ -740,7 +733,6 @@ class WKT extends TextFeature {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Point} geom Point geometry.
|
||||
* @return {string} Coordinates part of Point as WKT.
|
||||
@@ -753,7 +745,6 @@ function encodePointGeometry(geom) {
|
||||
return coordinates.join(' ');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {MultiPoint} geom MultiPoint geometry.
|
||||
* @return {string} Coordinates part of MultiPoint as WKT.
|
||||
@@ -767,7 +758,6 @@ function encodeMultiPointGeometry(geom) {
|
||||
return array.join(',');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeometryCollection} geom GeometryCollection geometry.
|
||||
* @return {string} Coordinates part of GeometryCollection as WKT.
|
||||
@@ -781,7 +771,6 @@ function encodeGeometryCollectionGeometry(geom) {
|
||||
return array.join(',');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {LineString|import("../geom/LinearRing.js").default} geom LineString geometry.
|
||||
* @return {string} Coordinates part of LineString as WKT.
|
||||
@@ -795,7 +784,6 @@ function encodeLineStringGeometry(geom) {
|
||||
return array.join(',');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {MultiLineString} geom MultiLineString geometry.
|
||||
* @return {string} Coordinates part of MultiLineString as WKT.
|
||||
@@ -809,7 +797,6 @@ function encodeMultiLineStringGeometry(geom) {
|
||||
return array.join(',');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Polygon} geom Polygon geometry.
|
||||
* @return {string} Coordinates part of Polygon as WKT.
|
||||
@@ -823,7 +810,6 @@ function encodePolygonGeometry(geom) {
|
||||
return array.join(',');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {MultiPolygon} geom MultiPolygon geometry.
|
||||
* @return {string} Coordinates part of MultiPolygon as WKT.
|
||||
@@ -853,7 +839,6 @@ function encodeGeometryLayout(geom) {
|
||||
return dimInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, function(import("../geom/Geometry.js").default): string>}
|
||||
@@ -865,10 +850,9 @@ const GeometryEncoder = {
|
||||
'MultiPoint': encodeMultiPointGeometry,
|
||||
'MultiLineString': encodeMultiLineStringGeometry,
|
||||
'MultiPolygon': encodeMultiPolygonGeometry,
|
||||
'GeometryCollection': encodeGeometryCollectionGeometry
|
||||
'GeometryCollection': encodeGeometryCollectionGeometry,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a geometry as WKT.
|
||||
* @param {!import("../geom/Geometry.js").default} geom The geometry to encode.
|
||||
@@ -879,8 +863,10 @@ function encode(geom) {
|
||||
const geometryEncoder = GeometryEncoder[type];
|
||||
const enc = geometryEncoder(geom);
|
||||
type = type.toUpperCase();
|
||||
if (typeof /** @type {?} */ (geom).getFlatCoordinates === 'function') {
|
||||
const dimInfo = encodeGeometryLayout(/** @type {import("../geom/SimpleGeometry.js").default} */ (geom));
|
||||
if (typeof (/** @type {?} */ (geom).getFlatCoordinates) === 'function') {
|
||||
const dimInfo = encodeGeometryLayout(
|
||||
/** @type {import("../geom/SimpleGeometry.js").default} */ (geom)
|
||||
);
|
||||
if (dimInfo.length > 0) {
|
||||
type += ' ' + dimInfo;
|
||||
}
|
||||
@@ -891,5 +877,4 @@ function encode(geom) {
|
||||
return type + '(' + enc + ')';
|
||||
}
|
||||
|
||||
|
||||
export default WKT;
|
||||
|
||||
@@ -1,47 +1,50 @@
|
||||
/**
|
||||
* @module ol/format/WMSCapabilities
|
||||
*/
|
||||
import {readHref} from './XLink.js';
|
||||
import XML from './XML.js';
|
||||
import {readDecimalString, readString, readNonNegativeInteger, readDecimal, readBooleanString, readNonNegativeIntegerString} from './xsd.js';
|
||||
import {makeArrayPusher, makeObjectPropertyPusher, makeObjectPropertySetter,
|
||||
makeStructureNS, pushParseAndPop} from '../xml.js';
|
||||
|
||||
import {
|
||||
makeArrayPusher,
|
||||
makeObjectPropertyPusher,
|
||||
makeObjectPropertySetter,
|
||||
makeStructureNS,
|
||||
pushParseAndPop,
|
||||
} from '../xml.js';
|
||||
import {
|
||||
readBooleanString,
|
||||
readDecimal,
|
||||
readDecimalString,
|
||||
readNonNegativeInteger,
|
||||
readNonNegativeIntegerString,
|
||||
readString,
|
||||
} from './xsd.js';
|
||||
import {readHref} from './XLink.js';
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Array<null|string>}
|
||||
*/
|
||||
const NAMESPACE_URIS = [
|
||||
null,
|
||||
'http://www.opengis.net/wms'
|
||||
];
|
||||
|
||||
const NAMESPACE_URIS = [null, 'http://www.opengis.net/wms'];
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Service': makeObjectPropertySetter(readService),
|
||||
'Capability': makeObjectPropertySetter(readCapability)
|
||||
});
|
||||
|
||||
const PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Service': makeObjectPropertySetter(readService),
|
||||
'Capability': makeObjectPropertySetter(readCapability),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const CAPABILITY_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Request': makeObjectPropertySetter(readRequest),
|
||||
'Exception': makeObjectPropertySetter(readException),
|
||||
'Layer': makeObjectPropertySetter(readCapabilityLayer)
|
||||
});
|
||||
|
||||
const CAPABILITY_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Request': makeObjectPropertySetter(readRequest),
|
||||
'Exception': makeObjectPropertySetter(readException),
|
||||
'Layer': makeObjectPropertySetter(readCapabilityLayer),
|
||||
});
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -78,231 +81,207 @@ class WMSCapabilities extends XML {
|
||||
*/
|
||||
readFromNode(node) {
|
||||
this.version = node.getAttribute('version').trim();
|
||||
const wmsCapabilityObject = pushParseAndPop({
|
||||
'version': this.version
|
||||
}, PARSERS, node, []);
|
||||
const wmsCapabilityObject = pushParseAndPop(
|
||||
{
|
||||
'version': this.version,
|
||||
},
|
||||
PARSERS,
|
||||
node,
|
||||
[]
|
||||
);
|
||||
return wmsCapabilityObject ? wmsCapabilityObject : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const SERVICE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Name': makeObjectPropertySetter(readString),
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'Abstract': makeObjectPropertySetter(readString),
|
||||
'KeywordList': makeObjectPropertySetter(readKeywordList),
|
||||
'OnlineResource': makeObjectPropertySetter(readHref),
|
||||
'ContactInformation': makeObjectPropertySetter(readContactInformation),
|
||||
'Fees': makeObjectPropertySetter(readString),
|
||||
'AccessConstraints': makeObjectPropertySetter(readString),
|
||||
'LayerLimit': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MaxWidth': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MaxHeight': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const SERVICE_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Name': makeObjectPropertySetter(readString),
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'Abstract': makeObjectPropertySetter(readString),
|
||||
'KeywordList': makeObjectPropertySetter(readKeywordList),
|
||||
'OnlineResource': makeObjectPropertySetter(readHref),
|
||||
'ContactInformation': makeObjectPropertySetter(readContactInformation),
|
||||
'Fees': makeObjectPropertySetter(readString),
|
||||
'AccessConstraints': makeObjectPropertySetter(readString),
|
||||
'LayerLimit': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MaxWidth': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MaxHeight': makeObjectPropertySetter(readNonNegativeInteger)
|
||||
});
|
||||
|
||||
const CONTACT_INFORMATION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'ContactPersonPrimary': makeObjectPropertySetter(readContactPersonPrimary),
|
||||
'ContactPosition': makeObjectPropertySetter(readString),
|
||||
'ContactAddress': makeObjectPropertySetter(readContactAddress),
|
||||
'ContactVoiceTelephone': makeObjectPropertySetter(readString),
|
||||
'ContactFacsimileTelephone': makeObjectPropertySetter(readString),
|
||||
'ContactElectronicMailAddress': makeObjectPropertySetter(readString),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const CONTACT_INFORMATION_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'ContactPersonPrimary': makeObjectPropertySetter(readContactPersonPrimary),
|
||||
'ContactPosition': makeObjectPropertySetter(readString),
|
||||
'ContactAddress': makeObjectPropertySetter(readContactAddress),
|
||||
'ContactVoiceTelephone': makeObjectPropertySetter(readString),
|
||||
'ContactFacsimileTelephone': makeObjectPropertySetter(readString),
|
||||
'ContactElectronicMailAddress': makeObjectPropertySetter(readString)
|
||||
});
|
||||
|
||||
const CONTACT_PERSON_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'ContactPerson': makeObjectPropertySetter(readString),
|
||||
'ContactOrganization': makeObjectPropertySetter(readString),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const CONTACT_PERSON_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'ContactPerson': makeObjectPropertySetter(readString),
|
||||
'ContactOrganization': makeObjectPropertySetter(readString)
|
||||
});
|
||||
|
||||
const CONTACT_ADDRESS_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'AddressType': makeObjectPropertySetter(readString),
|
||||
'Address': makeObjectPropertySetter(readString),
|
||||
'City': makeObjectPropertySetter(readString),
|
||||
'StateOrProvince': makeObjectPropertySetter(readString),
|
||||
'PostCode': makeObjectPropertySetter(readString),
|
||||
'Country': makeObjectPropertySetter(readString),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const CONTACT_ADDRESS_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'AddressType': makeObjectPropertySetter(readString),
|
||||
'Address': makeObjectPropertySetter(readString),
|
||||
'City': makeObjectPropertySetter(readString),
|
||||
'StateOrProvince': makeObjectPropertySetter(readString),
|
||||
'PostCode': makeObjectPropertySetter(readString),
|
||||
'Country': makeObjectPropertySetter(readString)
|
||||
});
|
||||
|
||||
const EXCEPTION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Format': makeArrayPusher(readString),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const EXCEPTION_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Format': makeArrayPusher(readString)
|
||||
});
|
||||
|
||||
const LAYER_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Name': makeObjectPropertySetter(readString),
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'Abstract': makeObjectPropertySetter(readString),
|
||||
'KeywordList': makeObjectPropertySetter(readKeywordList),
|
||||
'CRS': makeObjectPropertyPusher(readString),
|
||||
'EX_GeographicBoundingBox': makeObjectPropertySetter(
|
||||
readEXGeographicBoundingBox
|
||||
),
|
||||
'BoundingBox': makeObjectPropertyPusher(readBoundingBox),
|
||||
'Dimension': makeObjectPropertyPusher(readDimension),
|
||||
'Attribution': makeObjectPropertySetter(readAttribution),
|
||||
'AuthorityURL': makeObjectPropertyPusher(readAuthorityURL),
|
||||
'Identifier': makeObjectPropertyPusher(readString),
|
||||
'MetadataURL': makeObjectPropertyPusher(readMetadataURL),
|
||||
'DataURL': makeObjectPropertyPusher(readFormatOnlineresource),
|
||||
'FeatureListURL': makeObjectPropertyPusher(readFormatOnlineresource),
|
||||
'Style': makeObjectPropertyPusher(readStyle),
|
||||
'MinScaleDenominator': makeObjectPropertySetter(readDecimal),
|
||||
'MaxScaleDenominator': makeObjectPropertySetter(readDecimal),
|
||||
'Layer': makeObjectPropertyPusher(readLayer),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const LAYER_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Name': makeObjectPropertySetter(readString),
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'Abstract': makeObjectPropertySetter(readString),
|
||||
'KeywordList': makeObjectPropertySetter(readKeywordList),
|
||||
'CRS': makeObjectPropertyPusher(readString),
|
||||
'EX_GeographicBoundingBox': makeObjectPropertySetter(readEXGeographicBoundingBox),
|
||||
'BoundingBox': makeObjectPropertyPusher(readBoundingBox),
|
||||
'Dimension': makeObjectPropertyPusher(readDimension),
|
||||
'Attribution': makeObjectPropertySetter(readAttribution),
|
||||
'AuthorityURL': makeObjectPropertyPusher(readAuthorityURL),
|
||||
'Identifier': makeObjectPropertyPusher(readString),
|
||||
'MetadataURL': makeObjectPropertyPusher(readMetadataURL),
|
||||
'DataURL': makeObjectPropertyPusher(readFormatOnlineresource),
|
||||
'FeatureListURL': makeObjectPropertyPusher(readFormatOnlineresource),
|
||||
'Style': makeObjectPropertyPusher(readStyle),
|
||||
'MinScaleDenominator': makeObjectPropertySetter(readDecimal),
|
||||
'MaxScaleDenominator': makeObjectPropertySetter(readDecimal),
|
||||
'Layer': makeObjectPropertyPusher(readLayer)
|
||||
});
|
||||
|
||||
const ATTRIBUTION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'OnlineResource': makeObjectPropertySetter(readHref),
|
||||
'LogoURL': makeObjectPropertySetter(readSizedFormatOnlineresource),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const ATTRIBUTION_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'OnlineResource': makeObjectPropertySetter(readHref),
|
||||
'LogoURL': makeObjectPropertySetter(readSizedFormatOnlineresource)
|
||||
});
|
||||
|
||||
const EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'westBoundLongitude': makeObjectPropertySetter(readDecimal),
|
||||
'eastBoundLongitude': makeObjectPropertySetter(readDecimal),
|
||||
'southBoundLatitude': makeObjectPropertySetter(readDecimal),
|
||||
'northBoundLatitude': makeObjectPropertySetter(readDecimal),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS =
|
||||
makeStructureNS(NAMESPACE_URIS, {
|
||||
'westBoundLongitude': makeObjectPropertySetter(readDecimal),
|
||||
'eastBoundLongitude': makeObjectPropertySetter(readDecimal),
|
||||
'southBoundLatitude': makeObjectPropertySetter(readDecimal),
|
||||
'northBoundLatitude': makeObjectPropertySetter(readDecimal)
|
||||
});
|
||||
|
||||
const REQUEST_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'GetCapabilities': makeObjectPropertySetter(readOperationType),
|
||||
'GetMap': makeObjectPropertySetter(readOperationType),
|
||||
'GetFeatureInfo': makeObjectPropertySetter(readOperationType),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const REQUEST_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'GetCapabilities': makeObjectPropertySetter(readOperationType),
|
||||
'GetMap': makeObjectPropertySetter(readOperationType),
|
||||
'GetFeatureInfo': makeObjectPropertySetter(readOperationType)
|
||||
});
|
||||
|
||||
const OPERATIONTYPE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Format': makeObjectPropertyPusher(readString),
|
||||
'DCPType': makeObjectPropertyPusher(readDCPType),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const OPERATIONTYPE_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Format': makeObjectPropertyPusher(readString),
|
||||
'DCPType': makeObjectPropertyPusher(readDCPType)
|
||||
});
|
||||
|
||||
const DCPTYPE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'HTTP': makeObjectPropertySetter(readHTTP),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const DCPTYPE_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'HTTP': makeObjectPropertySetter(readHTTP)
|
||||
});
|
||||
|
||||
const HTTP_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Get': makeObjectPropertySetter(readFormatOnlineresource),
|
||||
'Post': makeObjectPropertySetter(readFormatOnlineresource),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const HTTP_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Get': makeObjectPropertySetter(readFormatOnlineresource),
|
||||
'Post': makeObjectPropertySetter(readFormatOnlineresource)
|
||||
});
|
||||
|
||||
const STYLE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Name': makeObjectPropertySetter(readString),
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'Abstract': makeObjectPropertySetter(readString),
|
||||
'LegendURL': makeObjectPropertyPusher(readSizedFormatOnlineresource),
|
||||
'StyleSheetURL': makeObjectPropertySetter(readFormatOnlineresource),
|
||||
'StyleURL': makeObjectPropertySetter(readFormatOnlineresource),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const STYLE_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Name': makeObjectPropertySetter(readString),
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'Abstract': makeObjectPropertySetter(readString),
|
||||
'LegendURL': makeObjectPropertyPusher(readSizedFormatOnlineresource),
|
||||
'StyleSheetURL': makeObjectPropertySetter(readFormatOnlineresource),
|
||||
'StyleURL': makeObjectPropertySetter(readFormatOnlineresource)
|
||||
});
|
||||
|
||||
const FORMAT_ONLINERESOURCE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Format': makeObjectPropertySetter(readString),
|
||||
'OnlineResource': makeObjectPropertySetter(readHref),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const FORMAT_ONLINERESOURCE_PARSERS =
|
||||
makeStructureNS(NAMESPACE_URIS, {
|
||||
'Format': makeObjectPropertySetter(readString),
|
||||
'OnlineResource': makeObjectPropertySetter(readHref)
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const KEYWORDLIST_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Keyword': makeArrayPusher(readString)
|
||||
});
|
||||
|
||||
const KEYWORDLIST_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Keyword': makeArrayPusher(readString),
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
@@ -313,7 +292,6 @@ function readAttribution(node, objectStack) {
|
||||
return pushParseAndPop({}, ATTRIBUTION_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -324,22 +302,21 @@ function readBoundingBox(node, objectStack) {
|
||||
readDecimalString(node.getAttribute('minx')),
|
||||
readDecimalString(node.getAttribute('miny')),
|
||||
readDecimalString(node.getAttribute('maxx')),
|
||||
readDecimalString(node.getAttribute('maxy'))
|
||||
readDecimalString(node.getAttribute('maxy')),
|
||||
];
|
||||
|
||||
const resolutions = [
|
||||
readDecimalString(node.getAttribute('resx')),
|
||||
readDecimalString(node.getAttribute('resy'))
|
||||
readDecimalString(node.getAttribute('resy')),
|
||||
];
|
||||
|
||||
return {
|
||||
'crs': node.getAttribute('CRS'),
|
||||
'extent': extent,
|
||||
'res': resolutions
|
||||
'res': resolutions,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -349,29 +326,40 @@ function readEXGeographicBoundingBox(node, objectStack) {
|
||||
const geographicBoundingBox = pushParseAndPop(
|
||||
{},
|
||||
EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS,
|
||||
node, objectStack);
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
if (!geographicBoundingBox) {
|
||||
return undefined;
|
||||
}
|
||||
const westBoundLongitude = /** @type {number|undefined} */
|
||||
(geographicBoundingBox['westBoundLongitude']);
|
||||
const southBoundLatitude = /** @type {number|undefined} */
|
||||
(geographicBoundingBox['southBoundLatitude']);
|
||||
const eastBoundLongitude = /** @type {number|undefined} */
|
||||
(geographicBoundingBox['eastBoundLongitude']);
|
||||
const northBoundLatitude = /** @type {number|undefined} */
|
||||
(geographicBoundingBox['northBoundLatitude']);
|
||||
if (westBoundLongitude === undefined || southBoundLatitude === undefined ||
|
||||
eastBoundLongitude === undefined || northBoundLatitude === undefined) {
|
||||
const westBoundLongitude =
|
||||
/** @type {number|undefined} */
|
||||
(geographicBoundingBox['westBoundLongitude']);
|
||||
const southBoundLatitude =
|
||||
/** @type {number|undefined} */
|
||||
(geographicBoundingBox['southBoundLatitude']);
|
||||
const eastBoundLongitude =
|
||||
/** @type {number|undefined} */
|
||||
(geographicBoundingBox['eastBoundLongitude']);
|
||||
const northBoundLatitude =
|
||||
/** @type {number|undefined} */
|
||||
(geographicBoundingBox['northBoundLatitude']);
|
||||
if (
|
||||
westBoundLongitude === undefined ||
|
||||
southBoundLatitude === undefined ||
|
||||
eastBoundLongitude === undefined ||
|
||||
northBoundLatitude === undefined
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
return [
|
||||
westBoundLongitude, southBoundLatitude,
|
||||
eastBoundLongitude, northBoundLatitude
|
||||
westBoundLongitude,
|
||||
southBoundLatitude,
|
||||
eastBoundLongitude,
|
||||
northBoundLatitude,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -381,7 +369,6 @@ function readCapability(node, objectStack) {
|
||||
return pushParseAndPop({}, CAPABILITY_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -391,7 +378,6 @@ function readService(node, objectStack) {
|
||||
return pushParseAndPop({}, SERVICE_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -401,7 +387,6 @@ function readContactInformation(node, objectStack) {
|
||||
return pushParseAndPop({}, CONTACT_INFORMATION_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -411,7 +396,6 @@ function readContactPersonPrimary(node, objectStack) {
|
||||
return pushParseAndPop({}, CONTACT_PERSON_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -421,7 +405,6 @@ function readContactAddress(node, objectStack) {
|
||||
return pushParseAndPop({}, CONTACT_ADDRESS_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -431,7 +414,6 @@ function readException(node, objectStack) {
|
||||
return pushParseAndPop([], EXCEPTION_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -441,14 +423,15 @@ function readCapabilityLayer(node, objectStack) {
|
||||
return pushParseAndPop({}, LAYER_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} Layer object.
|
||||
*/
|
||||
function readLayer(node, objectStack) {
|
||||
const parentLayerObject = /** @type {!Object<string,*>} */ (objectStack[objectStack.length - 1]);
|
||||
const parentLayerObject = /** @type {!Object<string,*>} */ (objectStack[
|
||||
objectStack.length - 1
|
||||
]);
|
||||
|
||||
const layerObject = pushParseAndPop({}, LAYER_PARSERS, node, objectStack);
|
||||
|
||||
@@ -461,8 +444,7 @@ function readLayer(node, objectStack) {
|
||||
}
|
||||
layerObject['queryable'] = queryable !== undefined ? queryable : false;
|
||||
|
||||
let cascaded = readNonNegativeIntegerString(
|
||||
node.getAttribute('cascaded'));
|
||||
let cascaded = readNonNegativeIntegerString(node.getAttribute('cascaded'));
|
||||
if (cascaded === undefined) {
|
||||
cascaded = parentLayerObject['cascaded'];
|
||||
}
|
||||
@@ -494,16 +476,22 @@ function readLayer(node, objectStack) {
|
||||
|
||||
// See 7.2.4.8
|
||||
const addKeys = ['Style', 'CRS', 'AuthorityURL'];
|
||||
addKeys.forEach(function(key) {
|
||||
addKeys.forEach(function (key) {
|
||||
if (key in parentLayerObject) {
|
||||
const childValue = layerObject[key] || [];
|
||||
layerObject[key] = childValue.concat(parentLayerObject[key]);
|
||||
}
|
||||
});
|
||||
|
||||
const replaceKeys = ['EX_GeographicBoundingBox', 'BoundingBox', 'Dimension',
|
||||
'Attribution', 'MinScaleDenominator', 'MaxScaleDenominator'];
|
||||
replaceKeys.forEach(function(key) {
|
||||
const replaceKeys = [
|
||||
'EX_GeographicBoundingBox',
|
||||
'BoundingBox',
|
||||
'Dimension',
|
||||
'Attribution',
|
||||
'MinScaleDenominator',
|
||||
'MaxScaleDenominator',
|
||||
];
|
||||
replaceKeys.forEach(function (key) {
|
||||
if (!(key in layerObject)) {
|
||||
const parentValue = parentLayerObject[key];
|
||||
layerObject[key] = parentValue;
|
||||
@@ -513,7 +501,6 @@ function readLayer(node, objectStack) {
|
||||
return layerObject;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -528,12 +515,11 @@ function readDimension(node, objectStack) {
|
||||
'multipleValues': readBooleanString(node.getAttribute('multipleValues')),
|
||||
'nearestValue': readBooleanString(node.getAttribute('nearestValue')),
|
||||
'current': readBooleanString(node.getAttribute('current')),
|
||||
'values': readString(node)
|
||||
'values': readString(node),
|
||||
};
|
||||
return dimensionObject;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -543,7 +529,6 @@ function readFormatOnlineresource(node, objectStack) {
|
||||
return pushParseAndPop({}, FORMAT_ONLINERESOURCE_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -553,7 +538,6 @@ function readRequest(node, objectStack) {
|
||||
return pushParseAndPop({}, REQUEST_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -563,7 +547,6 @@ function readDCPType(node, objectStack) {
|
||||
return pushParseAndPop({}, DCPTYPE_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -573,7 +556,6 @@ function readHTTP(node, objectStack) {
|
||||
return pushParseAndPop({}, HTTP_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -583,7 +565,6 @@ function readOperationType(node, objectStack) {
|
||||
return pushParseAndPop({}, OPERATIONTYPE_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -594,7 +575,7 @@ function readSizedFormatOnlineresource(node, objectStack) {
|
||||
if (formatOnlineresource) {
|
||||
const size = [
|
||||
readNonNegativeIntegerString(node.getAttribute('width')),
|
||||
readNonNegativeIntegerString(node.getAttribute('height'))
|
||||
readNonNegativeIntegerString(node.getAttribute('height')),
|
||||
];
|
||||
formatOnlineresource['size'] = size;
|
||||
return formatOnlineresource;
|
||||
@@ -602,7 +583,6 @@ function readSizedFormatOnlineresource(node, objectStack) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -617,7 +597,6 @@ function readAuthorityURL(node, objectStack) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -632,7 +611,6 @@ function readMetadataURL(node, objectStack) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -642,7 +620,6 @@ function readStyle(node, objectStack) {
|
||||
return pushParseAndPop({}, STYLE_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -652,5 +629,4 @@ function readKeywordList(node, objectStack) {
|
||||
return pushParseAndPop([], KEYWORDLIST_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
export default WMSCapabilities;
|
||||
|
||||
@@ -1,33 +1,29 @@
|
||||
/**
|
||||
* @module ol/format/WMSGetFeatureInfo
|
||||
*/
|
||||
import {extend, includes} from '../array.js';
|
||||
import GML2 from './GML2.js';
|
||||
import XMLFeature from './XMLFeature.js';
|
||||
import {assign} from '../obj.js';
|
||||
import {extend, includes} from '../array.js';
|
||||
import {makeArrayPusher, makeStructureNS, pushParseAndPop} from '../xml.js';
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {Array<string>} [layers] If set, only features of the given layers will be returned by the format when read.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
const featureIdentifier = '_feature';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
const layerIdentifier = '_layer';
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Format for reading WMSGetFeatureInfo format. It uses
|
||||
@@ -36,7 +32,6 @@ const layerIdentifier = '_layer';
|
||||
* @api
|
||||
*/
|
||||
class WMSGetFeatureInfo extends XMLFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
@@ -51,14 +46,12 @@ class WMSGetFeatureInfo extends XMLFeature {
|
||||
*/
|
||||
this.featureNS_ = 'http://mapserver.gis.umn.edu/mapserver';
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {GML2}
|
||||
*/
|
||||
this.gmlFormat_ = new GML2();
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<string>}
|
||||
@@ -111,8 +104,7 @@ class WMSGetFeatureInfo extends XMLFeature {
|
||||
continue;
|
||||
}
|
||||
|
||||
const featureType = layerName +
|
||||
featureIdentifier;
|
||||
const featureType = layerName + featureIdentifier;
|
||||
|
||||
context['featureType'] = featureType;
|
||||
context['featureNS'] = this.featureNS_;
|
||||
@@ -120,22 +112,35 @@ class WMSGetFeatureInfo extends XMLFeature {
|
||||
/** @type {Object<string, import("../xml.js").Parser>} */
|
||||
const parsers = {};
|
||||
parsers[featureType] = makeArrayPusher(
|
||||
this.gmlFormat_.readFeatureElement, this.gmlFormat_);
|
||||
this.gmlFormat_.readFeatureElement,
|
||||
this.gmlFormat_
|
||||
);
|
||||
const parsersNS = makeStructureNS(
|
||||
[context['featureNS'], null], parsers);
|
||||
[context['featureNS'], null],
|
||||
parsers
|
||||
);
|
||||
layerElement.setAttribute('namespaceURI', this.featureNS_);
|
||||
const layerFeatures = pushParseAndPop(
|
||||
[],
|
||||
// @ts-ignore
|
||||
[], parsersNS, layerElement, objectStack, this.gmlFormat_);
|
||||
parsersNS,
|
||||
layerElement,
|
||||
objectStack,
|
||||
this.gmlFormat_
|
||||
);
|
||||
if (layerFeatures) {
|
||||
extend(features, layerFeatures);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (localName == 'FeatureCollection') {
|
||||
const gmlFeatures = pushParseAndPop([],
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
|
||||
[{}], this.gmlFormat_);
|
||||
const gmlFeatures = pushParseAndPop(
|
||||
[],
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS,
|
||||
node,
|
||||
[{}],
|
||||
this.gmlFormat_
|
||||
);
|
||||
if (gmlFeatures) {
|
||||
features = gmlFeatures;
|
||||
}
|
||||
@@ -156,8 +161,6 @@ class WMSGetFeatureInfo extends XMLFeature {
|
||||
}
|
||||
return this.readFeatures_(node, [options]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export default WMSGetFeatureInfo;
|
||||
|
||||
@@ -1,45 +1,39 @@
|
||||
/**
|
||||
* @module ol/format/WMTSCapabilities
|
||||
*/
|
||||
import {boundingExtent} from '../extent.js';
|
||||
import OWS from './OWS.js';
|
||||
import {readHref} from './XLink.js';
|
||||
import XML from './XML.js';
|
||||
import {readString, readNonNegativeInteger, readDecimal} from './xsd.js';
|
||||
import {pushParseAndPop, makeStructureNS,
|
||||
makeObjectPropertySetter, makeObjectPropertyPusher, makeArrayPusher} from '../xml.js';
|
||||
|
||||
import {boundingExtent} from '../extent.js';
|
||||
import {
|
||||
makeArrayPusher,
|
||||
makeObjectPropertyPusher,
|
||||
makeObjectPropertySetter,
|
||||
makeStructureNS,
|
||||
pushParseAndPop,
|
||||
} from '../xml.js';
|
||||
import {readDecimal, readNonNegativeInteger, readString} from './xsd.js';
|
||||
import {readHref} from './XLink.js';
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Array<null|string>}
|
||||
*/
|
||||
const NAMESPACE_URIS = [
|
||||
null,
|
||||
'http://www.opengis.net/wmts/1.0'
|
||||
];
|
||||
|
||||
const NAMESPACE_URIS = [null, 'http://www.opengis.net/wmts/1.0'];
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Array<null|string>}
|
||||
*/
|
||||
const OWS_NAMESPACE_URIS = [
|
||||
null,
|
||||
'http://www.opengis.net/ows/1.1'
|
||||
];
|
||||
|
||||
const OWS_NAMESPACE_URIS = [null, 'http://www.opengis.net/ows/1.1'];
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Contents': makeObjectPropertySetter(readContents)
|
||||
});
|
||||
|
||||
const PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Contents': makeObjectPropertySetter(readContents),
|
||||
});
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -85,23 +79,25 @@ class WMTSCapabilities extends XML {
|
||||
return null;
|
||||
}
|
||||
WMTSCapabilityObject['version'] = version;
|
||||
WMTSCapabilityObject = pushParseAndPop(WMTSCapabilityObject, PARSERS, node, []);
|
||||
WMTSCapabilityObject = pushParseAndPop(
|
||||
WMTSCapabilityObject,
|
||||
PARSERS,
|
||||
node,
|
||||
[]
|
||||
);
|
||||
return WMTSCapabilityObject ? WMTSCapabilityObject : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const CONTENTS_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Layer': makeObjectPropertyPusher(readLayer),
|
||||
'TileMatrixSet': makeObjectPropertyPusher(readTileMatrixSet)
|
||||
});
|
||||
|
||||
const CONTENTS_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Layer': makeObjectPropertyPusher(readLayer),
|
||||
'TileMatrixSet': makeObjectPropertyPusher(readTileMatrixSet),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -109,19 +105,21 @@ const CONTENTS_PARSERS = makeStructureNS(
|
||||
*/
|
||||
// @ts-ignore
|
||||
const LAYER_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
NAMESPACE_URIS,
|
||||
{
|
||||
'Style': makeObjectPropertyPusher(readStyle),
|
||||
'Format': makeObjectPropertyPusher(readString),
|
||||
'TileMatrixSetLink': makeObjectPropertyPusher(readTileMatrixSetLink),
|
||||
'Dimension': makeObjectPropertyPusher(readDimensions),
|
||||
'ResourceURL': makeObjectPropertyPusher(readResourceUrl)
|
||||
}, makeStructureNS(OWS_NAMESPACE_URIS, {
|
||||
'ResourceURL': makeObjectPropertyPusher(readResourceUrl),
|
||||
},
|
||||
makeStructureNS(OWS_NAMESPACE_URIS, {
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'Abstract': makeObjectPropertySetter(readString),
|
||||
'WGS84BoundingBox': makeObjectPropertySetter(readWgs84BoundingBox),
|
||||
'Identifier': makeObjectPropertySetter(readString)
|
||||
}));
|
||||
|
||||
'Identifier': makeObjectPropertySetter(readString),
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -129,50 +127,47 @@ const LAYER_PARSERS = makeStructureNS(
|
||||
*/
|
||||
// @ts-ignore
|
||||
const STYLE_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'LegendURL': makeObjectPropertyPusher(readLegendUrl)
|
||||
}, makeStructureNS(OWS_NAMESPACE_URIS, {
|
||||
NAMESPACE_URIS,
|
||||
{
|
||||
'LegendURL': makeObjectPropertyPusher(readLegendUrl),
|
||||
},
|
||||
makeStructureNS(OWS_NAMESPACE_URIS, {
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'Identifier': makeObjectPropertySetter(readString)
|
||||
}));
|
||||
|
||||
'Identifier': makeObjectPropertySetter(readString),
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const TMS_LINKS_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'TileMatrixSet': makeObjectPropertySetter(readString),
|
||||
'TileMatrixSetLimits': makeObjectPropertySetter(readTileMatrixLimitsList)
|
||||
});
|
||||
const TMS_LINKS_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'TileMatrixSet': makeObjectPropertySetter(readString),
|
||||
'TileMatrixSetLimits': makeObjectPropertySetter(readTileMatrixLimitsList),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const TMS_LIMITS_LIST_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'TileMatrixLimits': makeArrayPusher(readTileMatrixLimits)
|
||||
});
|
||||
|
||||
const TMS_LIMITS_LIST_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'TileMatrixLimits': makeArrayPusher(readTileMatrixLimits),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const TMS_LIMITS_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'TileMatrix': makeObjectPropertySetter(readString),
|
||||
'MinTileRow': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MaxTileRow': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MinTileCol': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MaxTileCol': makeObjectPropertySetter(readNonNegativeInteger)
|
||||
});
|
||||
|
||||
const TMS_LIMITS_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'TileMatrix': makeObjectPropertySetter(readString),
|
||||
'MinTileRow': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MaxTileRow': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MinTileCol': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MaxTileCol': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -180,25 +175,25 @@ const TMS_LIMITS_PARSERS = makeStructureNS(
|
||||
*/
|
||||
// @ts-ignore
|
||||
const DIMENSION_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
NAMESPACE_URIS,
|
||||
{
|
||||
'Default': makeObjectPropertySetter(readString),
|
||||
'Value': makeObjectPropertyPusher(readString)
|
||||
}, makeStructureNS(OWS_NAMESPACE_URIS, {
|
||||
'Identifier': makeObjectPropertySetter(readString)
|
||||
}));
|
||||
|
||||
'Value': makeObjectPropertyPusher(readString),
|
||||
},
|
||||
makeStructureNS(OWS_NAMESPACE_URIS, {
|
||||
'Identifier': makeObjectPropertySetter(readString),
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const WGS84_BBOX_READERS = makeStructureNS(
|
||||
OWS_NAMESPACE_URIS, {
|
||||
'LowerCorner': makeArrayPusher(readCoordinates),
|
||||
'UpperCorner': makeArrayPusher(readCoordinates)
|
||||
});
|
||||
|
||||
const WGS84_BBOX_READERS = makeStructureNS(OWS_NAMESPACE_URIS, {
|
||||
'LowerCorner': makeArrayPusher(readCoordinates),
|
||||
'UpperCorner': makeArrayPusher(readCoordinates),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -206,14 +201,16 @@ const WGS84_BBOX_READERS = makeStructureNS(
|
||||
*/
|
||||
// @ts-ignore
|
||||
const TMS_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
NAMESPACE_URIS,
|
||||
{
|
||||
'WellKnownScaleSet': makeObjectPropertySetter(readString),
|
||||
'TileMatrix': makeObjectPropertyPusher(readTileMatrix)
|
||||
}, makeStructureNS(OWS_NAMESPACE_URIS, {
|
||||
'TileMatrix': makeObjectPropertyPusher(readTileMatrix),
|
||||
},
|
||||
makeStructureNS(OWS_NAMESPACE_URIS, {
|
||||
'SupportedCRS': makeObjectPropertySetter(readString),
|
||||
'Identifier': makeObjectPropertySetter(readString)
|
||||
}));
|
||||
|
||||
'Identifier': makeObjectPropertySetter(readString),
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -221,17 +218,19 @@ const TMS_PARSERS = makeStructureNS(
|
||||
*/
|
||||
// @ts-ignore
|
||||
const TM_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
NAMESPACE_URIS,
|
||||
{
|
||||
'TopLeftCorner': makeObjectPropertySetter(readCoordinates),
|
||||
'ScaleDenominator': makeObjectPropertySetter(readDecimal),
|
||||
'TileWidth': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'TileHeight': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MatrixWidth': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'MatrixHeight': makeObjectPropertySetter(readNonNegativeInteger)
|
||||
}, makeStructureNS(OWS_NAMESPACE_URIS, {
|
||||
'Identifier': makeObjectPropertySetter(readString)
|
||||
}));
|
||||
|
||||
'MatrixHeight': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
},
|
||||
makeStructureNS(OWS_NAMESPACE_URIS, {
|
||||
'Identifier': makeObjectPropertySetter(readString),
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
@@ -242,7 +241,6 @@ function readContents(node, objectStack) {
|
||||
return pushParseAndPop({}, CONTENTS_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -252,7 +250,6 @@ function readLayer(node, objectStack) {
|
||||
return pushParseAndPop({}, LAYER_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -262,7 +259,6 @@ function readTileMatrixSet(node, objectStack) {
|
||||
return pushParseAndPop({}, TMS_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -276,10 +272,8 @@ function readStyle(node, objectStack) {
|
||||
const isDefault = node.getAttribute('isDefault') === 'true';
|
||||
style['isDefault'] = isDefault;
|
||||
return style;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -289,7 +283,6 @@ function readTileMatrixSetLink(node, objectStack) {
|
||||
return pushParseAndPop({}, TMS_LINKS_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -299,7 +292,6 @@ function readDimensions(node, objectStack) {
|
||||
return pushParseAndPop({}, DIMENSION_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -322,21 +314,24 @@ function readResourceUrl(node, objectStack) {
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} WGS84 BBox object.
|
||||
*/
|
||||
function readWgs84BoundingBox(node, objectStack) {
|
||||
const coordinates = pushParseAndPop([], WGS84_BBOX_READERS, node, objectStack);
|
||||
const coordinates = pushParseAndPop(
|
||||
[],
|
||||
WGS84_BBOX_READERS,
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
if (coordinates.length != 2) {
|
||||
return undefined;
|
||||
}
|
||||
return boundingExtent(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -349,7 +344,6 @@ function readLegendUrl(node, objectStack) {
|
||||
return legend;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -368,7 +362,6 @@ function readCoordinates(node, objectStack) {
|
||||
return [x, y];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -378,7 +371,6 @@ function readTileMatrix(node, objectStack) {
|
||||
return pushParseAndPop({}, TM_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -388,7 +380,6 @@ function readTileMatrixLimitsList(node, objectStack) {
|
||||
return pushParseAndPop([], TMS_LIMITS_LIST_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -398,5 +389,4 @@ function readTileMatrixLimits(node, objectStack) {
|
||||
return pushParseAndPop({}, TMS_LIMITS_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
export default WMTSCapabilities;
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
* @module ol/format/XLink
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
const NAMESPACE_URI = 'http://www.w3.org/1999/xlink';
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @return {string|undefined} href.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* @module ol/format/XMLFeature
|
||||
*/
|
||||
import {abstract} from '../util.js';
|
||||
import {extend} from '../array.js';
|
||||
import FeatureFormat from '../format/Feature.js';
|
||||
import FormatType from '../format/FormatType.js';
|
||||
import {isDocument, parse, getXMLSerializer} from '../xml.js';
|
||||
import {abstract} from '../util.js';
|
||||
import {extend} from '../array.js';
|
||||
import {getXMLSerializer, isDocument, parse} from '../xml.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -48,9 +48,15 @@ class XMLFeature extends FeatureFormat {
|
||||
const doc = parse(source);
|
||||
return this.readFeatureFromDocument(doc, opt_options);
|
||||
} else if (isDocument(source)) {
|
||||
return this.readFeatureFromDocument(/** @type {Document} */ (source), opt_options);
|
||||
return this.readFeatureFromDocument(
|
||||
/** @type {Document} */ (source),
|
||||
opt_options
|
||||
);
|
||||
} else {
|
||||
return this.readFeatureFromNode(/** @type {Element} */ (source), opt_options);
|
||||
return this.readFeatureFromNode(
|
||||
/** @type {Element} */ (source),
|
||||
opt_options
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,9 +99,14 @@ class XMLFeature extends FeatureFormat {
|
||||
return this.readFeaturesFromDocument(doc, opt_options);
|
||||
} else if (isDocument(source)) {
|
||||
return this.readFeaturesFromDocument(
|
||||
/** @type {Document} */ (source), opt_options);
|
||||
/** @type {Document} */ (source),
|
||||
opt_options
|
||||
);
|
||||
} else {
|
||||
return this.readFeaturesFromNode(/** @type {Element} */ (source), opt_options);
|
||||
return this.readFeaturesFromNode(
|
||||
/** @type {Element} */ (source),
|
||||
opt_options
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +121,10 @@ class XMLFeature extends FeatureFormat {
|
||||
const features = [];
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
extend(features, this.readFeaturesFromNode(/** @type {Element} */ (n), opt_options));
|
||||
extend(
|
||||
features,
|
||||
this.readFeaturesFromNode(/** @type {Element} */ (n), opt_options)
|
||||
);
|
||||
}
|
||||
}
|
||||
return features;
|
||||
@@ -142,9 +156,14 @@ class XMLFeature extends FeatureFormat {
|
||||
return this.readGeometryFromDocument(doc, opt_options);
|
||||
} else if (isDocument(source)) {
|
||||
return this.readGeometryFromDocument(
|
||||
/** @type {Document} */ (source), opt_options);
|
||||
/** @type {Document} */ (source),
|
||||
opt_options
|
||||
);
|
||||
} else {
|
||||
return this.readGeometryFromNode(/** @type {Element} */ (source), opt_options);
|
||||
return this.readGeometryFromNode(
|
||||
/** @type {Element} */ (source),
|
||||
opt_options
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,5 +291,4 @@ class XMLFeature extends FeatureFormat {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default XMLFeature;
|
||||
|
||||
@@ -19,7 +19,6 @@ import NotEqualTo from './filter/NotEqualTo.js';
|
||||
import Or from './filter/Or.js';
|
||||
import Within from './filter/Within.js';
|
||||
|
||||
|
||||
/**
|
||||
* Create a logical `<And>` operator between two or more filter conditions.
|
||||
*
|
||||
@@ -29,10 +28,9 @@ import Within from './filter/Within.js';
|
||||
*/
|
||||
export function and(conditions) {
|
||||
const params = [null].concat(Array.prototype.slice.call(arguments));
|
||||
return new (Function.prototype.bind.apply(And, params));
|
||||
return new (Function.prototype.bind.apply(And, params))();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a logical `<Or>` operator between two or more filter conditions.
|
||||
*
|
||||
@@ -42,10 +40,9 @@ export function and(conditions) {
|
||||
*/
|
||||
export function or(conditions) {
|
||||
const params = [null].concat(Array.prototype.slice.call(arguments));
|
||||
return new (Function.prototype.bind.apply(Or, params));
|
||||
return new (Function.prototype.bind.apply(Or, params))();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Represents a logical `<Not>` operator for a filter condition.
|
||||
*
|
||||
@@ -57,7 +54,6 @@ export function not(condition) {
|
||||
return new Not(condition);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a `<BBOX>` operator to test whether a geometry-valued property
|
||||
* intersects a fixed bounding box
|
||||
@@ -118,7 +114,6 @@ export function within(geometryName, geometry, opt_srsName) {
|
||||
return new Within(geometryName, geometry, opt_srsName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a `<PropertyIsEqualTo>` comparison operator.
|
||||
*
|
||||
@@ -132,7 +127,6 @@ export function equalTo(propertyName, expression, opt_matchCase) {
|
||||
return new EqualTo(propertyName, expression, opt_matchCase);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a `<PropertyIsNotEqualTo>` comparison operator.
|
||||
*
|
||||
@@ -146,7 +140,6 @@ export function notEqualTo(propertyName, expression, opt_matchCase) {
|
||||
return new NotEqualTo(propertyName, expression, opt_matchCase);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a `<PropertyIsLessThan>` comparison operator.
|
||||
*
|
||||
@@ -159,7 +152,6 @@ export function lessThan(propertyName, expression) {
|
||||
return new LessThan(propertyName, expression);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a `<PropertyIsLessThanOrEqualTo>` comparison operator.
|
||||
*
|
||||
@@ -172,7 +164,6 @@ export function lessThanOrEqualTo(propertyName, expression) {
|
||||
return new LessThanOrEqualTo(propertyName, expression);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a `<PropertyIsGreaterThan>` comparison operator.
|
||||
*
|
||||
@@ -185,7 +176,6 @@ export function greaterThan(propertyName, expression) {
|
||||
return new GreaterThan(propertyName, expression);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a `<PropertyIsGreaterThanOrEqualTo>` comparison operator.
|
||||
*
|
||||
@@ -198,7 +188,6 @@ export function greaterThanOrEqualTo(propertyName, expression) {
|
||||
return new GreaterThanOrEqualTo(propertyName, expression);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a `<PropertyIsNull>` comparison operator to test whether a property value
|
||||
* is null.
|
||||
@@ -211,7 +200,6 @@ export function isNull(propertyName) {
|
||||
return new IsNull(propertyName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a `<PropertyIsBetween>` comparison operator to test whether an expression
|
||||
* value lies within a range given by a lower and upper bound (inclusive).
|
||||
@@ -226,7 +214,6 @@ export function between(propertyName, lowerBoundary, upperBoundary) {
|
||||
return new IsBetween(propertyName, lowerBoundary, upperBoundary);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Represents a `<PropertyIsLike>` comparison operator that matches a string property
|
||||
* value against a text pattern.
|
||||
@@ -243,13 +230,24 @@ export function between(propertyName, lowerBoundary, upperBoundary) {
|
||||
* @returns {!IsLike} `<PropertyIsLike>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function like(propertyName, pattern,
|
||||
opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) {
|
||||
return new IsLike(propertyName, pattern,
|
||||
opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase);
|
||||
export function like(
|
||||
propertyName,
|
||||
pattern,
|
||||
opt_wildCard,
|
||||
opt_singleChar,
|
||||
opt_escapeChar,
|
||||
opt_matchCase
|
||||
) {
|
||||
return new IsLike(
|
||||
propertyName,
|
||||
pattern,
|
||||
opt_wildCard,
|
||||
opt_singleChar,
|
||||
opt_escapeChar,
|
||||
opt_matchCase
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a `<During>` temporal operator.
|
||||
*
|
||||
|
||||
@@ -10,14 +10,12 @@ import LogicalNary from './LogicalNary.js';
|
||||
* @abstract
|
||||
*/
|
||||
class And extends LogicalNary {
|
||||
|
||||
/**
|
||||
* @param {...import("./Filter.js").default} conditions Conditions.
|
||||
*/
|
||||
constructor(conditions) {
|
||||
super('And', Array.prototype.slice.call(arguments));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default And;
|
||||
|
||||
@@ -11,7 +11,6 @@ import Filter from './Filter.js';
|
||||
* @api
|
||||
*/
|
||||
class Bbox extends Filter {
|
||||
|
||||
/**
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../../extent.js").Extent} extent Extent.
|
||||
@@ -19,7 +18,6 @@ class Bbox extends Filter {
|
||||
* on geometries when this is not provided.
|
||||
*/
|
||||
constructor(geometryName, extent, opt_srsName) {
|
||||
|
||||
super('BBOX');
|
||||
|
||||
/**
|
||||
@@ -32,7 +30,9 @@ class Bbox extends Filter {
|
||||
*/
|
||||
this.extent = extent;
|
||||
if (extent.length !== 4) {
|
||||
throw new Error('Expected an extent with four values ([minX, minY, maxX, maxY])');
|
||||
throw new Error(
|
||||
'Expected an extent with four values ([minX, minY, maxX, maxY])'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +40,6 @@ class Bbox extends Filter {
|
||||
*/
|
||||
this.srsName = opt_srsName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Bbox;
|
||||
|
||||
@@ -11,13 +11,11 @@ import Filter from './Filter.js';
|
||||
* @abstract
|
||||
*/
|
||||
class Comparison extends Filter {
|
||||
|
||||
/**
|
||||
* @param {!string} tagName The XML tag name for this filter.
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
*/
|
||||
constructor(tagName, propertyName) {
|
||||
|
||||
super(tagName);
|
||||
|
||||
/**
|
||||
@@ -25,7 +23,6 @@ class Comparison extends Filter {
|
||||
*/
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Comparison;
|
||||
|
||||
@@ -11,7 +11,6 @@ import Comparison from './Comparison.js';
|
||||
* @abstract
|
||||
*/
|
||||
class ComparisonBinary extends Comparison {
|
||||
|
||||
/**
|
||||
* @param {!string} tagName The XML tag name for this filter.
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
@@ -19,7 +18,6 @@ class ComparisonBinary extends Comparison {
|
||||
* @param {boolean=} opt_matchCase Case-sensitive?
|
||||
*/
|
||||
constructor(tagName, propertyName, expression, opt_matchCase) {
|
||||
|
||||
super(tagName, propertyName);
|
||||
|
||||
/**
|
||||
@@ -32,7 +30,6 @@ class ComparisonBinary extends Comparison {
|
||||
*/
|
||||
this.matchCase = opt_matchCase;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ComparisonBinary;
|
||||
|
||||
@@ -10,7 +10,6 @@ import Spatial from './Spatial.js';
|
||||
* @api
|
||||
*/
|
||||
class Contains extends Spatial {
|
||||
|
||||
/**
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../../geom/Geometry.js").default} geometry Geometry.
|
||||
@@ -18,11 +17,8 @@ class Contains extends Spatial {
|
||||
* set on geometries when this is not provided.
|
||||
*/
|
||||
constructor(geometryName, geometry, opt_srsName) {
|
||||
|
||||
super('Contains', geometryName, geometry, opt_srsName);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Contains;
|
||||
|
||||
@@ -9,7 +9,6 @@ import Comparison from './Comparison.js';
|
||||
* @api
|
||||
*/
|
||||
class During extends Comparison {
|
||||
|
||||
/**
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!string} begin The begin date in ISO-8601 format.
|
||||
@@ -28,7 +27,6 @@ class During extends Comparison {
|
||||
*/
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default During;
|
||||
|
||||
@@ -9,7 +9,6 @@ import ComparisonBinary from './ComparisonBinary.js';
|
||||
* @api
|
||||
*/
|
||||
class EqualTo extends ComparisonBinary {
|
||||
|
||||
/**
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!(string|number)} expression The value to compare.
|
||||
@@ -18,7 +17,6 @@ class EqualTo extends ComparisonBinary {
|
||||
constructor(propertyName, expression, opt_matchCase) {
|
||||
super('PropertyIsEqualTo', propertyName, expression, opt_matchCase);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default EqualTo;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user