Merge pull request #13888 from tschaub/object-assign

Use Object.assign
This commit is contained in:
Tim Schaub
2022-07-28 13:29:12 -06:00
committed by GitHub
46 changed files with 108 additions and 212 deletions

14
package-lock.json generated
View File

@@ -11,7 +11,7 @@
"dependencies": {
"earcut": "^2.2.3",
"geotiff": "2.0.4",
"ol-mapbox-style": "8.2.0",
"ol-mapbox-style": "8.2.1",
"pbf": "3.2.1",
"rbush": "^3.0.1"
},
@@ -7353,9 +7353,9 @@
"dev": true
},
"node_modules/ol-mapbox-style": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/ol-mapbox-style/-/ol-mapbox-style-8.2.0.tgz",
"integrity": "sha512-WyCiNUj5DiD3+MvgqXvxSf0mDUvagtlq9JQ97mHwDD1FliHt5G1333Lvqskg8psBfxijHSEWNHwqzBGnEUo1bw==",
"version": "8.2.1",
"resolved": "https://registry.npmjs.org/ol-mapbox-style/-/ol-mapbox-style-8.2.1.tgz",
"integrity": "sha512-3kBBuZC627vDL8vnUdfVbCbfkhkcZj2kXPHQcuLhC4JJEA+XkEVEtEde8x8+AZctRbHwBkSiubTPaRukgLxIRw==",
"dependencies": {
"@mapbox/mapbox-gl-style-spec": "^13.23.1",
"mapbox-to-css-font": "^2.4.1"
@@ -15844,9 +15844,9 @@
"dev": true
},
"ol-mapbox-style": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/ol-mapbox-style/-/ol-mapbox-style-8.2.0.tgz",
"integrity": "sha512-WyCiNUj5DiD3+MvgqXvxSf0mDUvagtlq9JQ97mHwDD1FliHt5G1333Lvqskg8psBfxijHSEWNHwqzBGnEUo1bw==",
"version": "8.2.1",
"resolved": "https://registry.npmjs.org/ol-mapbox-style/-/ol-mapbox-style-8.2.1.tgz",
"integrity": "sha512-3kBBuZC627vDL8vnUdfVbCbfkhkcZj2kXPHQcuLhC4JJEA+XkEVEtEde8x8+AZctRbHwBkSiubTPaRukgLxIRw==",
"requires": {
"@mapbox/mapbox-gl-style-spec": "^13.23.1",
"mapbox-to-css-font": "^2.4.1"

View File

@@ -47,7 +47,7 @@
"dependencies": {
"earcut": "^2.2.3",
"geotiff": "2.0.4",
"ol-mapbox-style": "8.2.0",
"ol-mapbox-style": "8.2.1",
"pbf": "3.2.1",
"rbush": "^3.0.1"
},

View File

@@ -3,7 +3,6 @@
*/
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';
@@ -59,7 +58,7 @@ class Map extends PluggableMap {
* @param {import("./PluggableMap.js").MapOptions} options Map options.
*/
constructor(options) {
options = assign({}, options);
options = Object.assign({}, options);
if (!options.controls) {
options.controls = defaultControls();
}

View File

@@ -4,8 +4,8 @@
import Event from './events/Event.js';
import ObjectEventType from './ObjectEventType.js';
import Observable from './Observable.js';
import {assign, isEmpty} from './obj.js';
import {getUid} from './util.js';
import {isEmpty} from './obj.js';
/**
* @classdesc
@@ -155,7 +155,7 @@ class BaseObject extends Observable {
* @api
*/
getProperties() {
return (this.values_ && assign({}, this.values_)) || {};
return (this.values_ && Object.assign({}, this.values_)) || {};
}
/**
@@ -239,7 +239,7 @@ class BaseObject extends Observable {
if (!source.values_) {
return;
}
assign(this.values_ || (this.values_ = {}), source.values_);
Object.assign(this.values_ || (this.values_ = {}), source.values_);
}
/**

View File

@@ -24,7 +24,6 @@ import {
rotate as rotateCoordinate,
} from './coordinate.js';
import {assert} from './asserts.js';
import {assign} from './obj.js';
import {none as centerNone, createExtent} from './centerconstraint.js';
import {clamp, modulo} from './math.js';
import {
@@ -325,7 +324,7 @@ class View extends BaseObject {
*/
this.un;
const options = assign({}, opt_options);
const options = Object.assign({}, opt_options);
/**
* @private
@@ -418,7 +417,7 @@ class View extends BaseObject {
* @param {ViewOptions} options View options.
*/
applyOptions_(options) {
const properties = assign({}, options);
const properties = Object.assign({}, options);
for (const key in ViewProperty) {
delete properties[key];
}
@@ -541,7 +540,7 @@ class View extends BaseObject {
// preserve rotation
options.rotation = this.getRotation();
return assign({}, options, newOptions);
return Object.assign({}, options, newOptions);
}
/**
@@ -585,14 +584,14 @@ class View extends BaseObject {
for (let i = 0; i < args.length; ++i) {
let options = arguments[i];
if (options.center) {
options = assign({}, options);
options = Object.assign({}, options);
options.center = fromUserCoordinate(
options.center,
this.getProjection()
);
}
if (options.anchor) {
options = assign({}, options);
options = Object.assign({}, options);
options.anchor = fromUserCoordinate(
options.anchor,
this.getProjection()

View File

@@ -11,10 +11,10 @@ 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 {containsExtent} from '../extent.js';
import {deflateCoordinates} from '../geom/flat/deflate.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';
@@ -274,10 +274,10 @@ function readGeometry(object, opt_options) {
const rings = convertRings(esriJSONPolygon.rings, layout);
if (rings.length === 1) {
type = 'Polygon';
object = assign({}, object, {['rings']: rings[0]});
object = Object.assign({}, object, {['rings']: rings[0]});
} else {
type = 'MultiPolygon';
object = assign({}, object, {['rings']: rings});
object = Object.assign({}, object, {['rings']: rings});
}
}
const geometryReader = GEOMETRY_READERS[type];

View File

@@ -3,7 +3,6 @@
*/
import Units from '../proj/Units.js';
import {abstract} from '../util.js';
import {assign} from '../obj.js';
import {
equivalent as equivalentProjection,
get as getProjection,
@@ -127,7 +126,7 @@ class FeatureFormat {
* Updated options.
*/
adaptOptions(options) {
return assign(
return Object.assign(
{
dataProjection: this.dataProjection,
featureProjection: this.defaultFeatureProjection,

View File

@@ -13,7 +13,6 @@ import {
pushParseAndPop,
pushSerializeAndPop,
} from '../xml.js';
import {assign} from '../obj.js';
import {createOrUpdate} from '../extent.js';
import {get as getProjection} from '../proj.js';
import {
@@ -245,7 +244,7 @@ class GML2 extends GMLBase {
}
}
}
const item = assign({}, context);
const item = Object.assign({}, context);
item.node = node;
pushSerializeAndPop(
/** @type {import("../xml.js").NodeStackItem} */
@@ -330,7 +329,7 @@ class GML2 extends GMLBase {
const context = /** @type {import("./Feature.js").WriteOptions} */ (
objectStack[objectStack.length - 1]
);
const item = assign({}, context);
const item = Object.assign({}, context);
item['node'] = node;
let value;
if (Array.isArray(geometry)) {

View File

@@ -21,7 +21,6 @@ import {
pushParseAndPop,
pushSerializeAndPop,
} from '../xml.js';
import {assign} from '../obj.js';
import {createOrUpdate} from '../extent.js';
import {extend} from '../array.js';
import {get as getProjection} from '../proj.js';
@@ -815,7 +814,7 @@ class GML3 extends GMLBase {
const context = /** @type {import("./Feature.js").WriteOptions} */ (
objectStack[objectStack.length - 1]
);
const item = assign({}, context);
const item = Object.assign({}, context);
item['node'] = node;
let value;
if (Array.isArray(geometry)) {
@@ -888,7 +887,7 @@ class GML3 extends GMLBase {
}
}
}
const item = assign({}, context);
const item = Object.assign({}, context);
item.node = node;
pushSerializeAndPop(
/** @type {import("../xml.js").NodeStackItem} */
@@ -918,7 +917,7 @@ class GML3 extends GMLBase {
this.writeFeatureElement,
this
);
const item = assign({}, context);
const item = Object.assign({}, context);
item.node = node;
pushSerializeAndPop(
/** @type {import("../xml.js").NodeStackItem} */
@@ -1001,7 +1000,7 @@ class GML3 extends GMLBase {
multiCurve: this.multiCurve_,
};
if (opt_options) {
assign(context, opt_options);
Object.assign(context, opt_options);
}
this.writeGeometryElement(geom, geometry, [context]);
return geom;
@@ -1034,7 +1033,7 @@ class GML3 extends GMLBase {
featureType: this.featureType,
};
if (opt_options) {
assign(context, opt_options);
Object.assign(context, opt_options);
}
this.writeFeatureMembers_(node, features, [context]);
return node;

View File

@@ -13,7 +13,6 @@ 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,
@@ -570,7 +569,7 @@ class GMLBase extends XMLFeature {
featureNS: this.featureNS,
};
if (opt_options) {
assign(options, this.getReadOptions(node, opt_options));
Object.assign(options, this.getReadOptions(node, opt_options));
}
const features = this.readFeaturesInternal(node, [options]);
return features || [];

View File

@@ -12,8 +12,8 @@ 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 {isEmpty} from '../obj.js';
import {transformGeometryWithOptions} from './Feature.js';
/**
@@ -476,7 +476,7 @@ function writeGeometry(geometry, opt_options) {
*/
function writeGeometryCollectionGeometry(geometry, opt_options) {
const geometries = geometry.getGeometriesArray().map(function (geometry) {
const options = assign({}, opt_options);
const options = Object.assign({}, opt_options);
delete options.featureProjection;
return writeGeometry(geometry, options);
});

View File

@@ -21,7 +21,6 @@ import {
} from '../xml.js';
import {and as andFilterFn, bbox as bboxFilterFn} from './filter.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
import {get as getProjection} from '../proj.js';
import {
readNonNegativeIntegerString,
@@ -333,12 +332,15 @@ class WFS extends XMLFeature {
const context = {
node,
};
assign(context, {
Object.assign(context, {
'featureType': this.featureType_,
'featureNS': this.featureNS_,
});
assign(context, this.getReadOptions(node, opt_options ? opt_options : {}));
Object.assign(
context,
this.getReadOptions(node, opt_options ? opt_options : {})
);
const objectStack = [context];
let featuresNS;
if (this.version_ === '2.0.0') {
@@ -511,7 +513,7 @@ class WFS extends XMLFeature {
const context = {
node,
};
assign(context, {
Object.assign(context, {
'version': this.version_,
'srsName': options.srsName,
'featureNS': options.featureNS ? options.featureNS : this.featureNS_,
@@ -530,7 +532,7 @@ class WFS extends XMLFeature {
filter
);
}
assign(context, {
Object.assign(context, {
'geometryName': options.geometryName,
'filter': filter,
});
@@ -548,7 +550,7 @@ class WFS extends XMLFeature {
options.srsName,
options.filter
);
assign(context, {
Object.assign(context, {
'geometryName': featureType.geometryName,
'filter': completeFilter,
});
@@ -686,7 +688,7 @@ function createTransactionRequest(node, baseObj, version, options) {
} else if (version === '2.0.0') {
gmlVersion = 3.2;
}
const obj = assign(
const obj = Object.assign(
{node},
{
version,
@@ -1035,7 +1037,7 @@ function writeQuery(node, featureType, objectStack) {
node.setAttributeNS(XMLNS, 'xmlns:' + featurePrefix, featureNS);
}
const item = /** @type {import("../xml.js").NodeStackItem} */ (
assign({}, context)
Object.assign({}, context)
);
item.node = node;
pushSerializeAndPop(
@@ -1062,7 +1064,7 @@ function writeFilterCondition(node, filter, objectStack) {
const context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
/** @type {import("../xml.js").NodeStackItem} */
const item = {node};
assign(item, {context});
Object.assign(item, {context});
pushSerializeAndPop(
item,
GETFEATURE_SERIALIZERS,
@@ -1167,7 +1169,7 @@ function writeLogicalFilter(node, filter, objectStack) {
const context = parent['context'];
/** @type {import("../xml.js").NodeStackItem} */
const item = {node};
assign(item, {context});
Object.assign(item, {context});
const conditions = filter.conditions;
for (let i = 0, ii = conditions.length; i < ii; ++i) {
const condition = conditions[i];
@@ -1191,7 +1193,7 @@ function writeNotFilter(node, filter, objectStack) {
const context = parent['context'];
/** @type {import("../xml.js").NodeStackItem} */
const item = {node};
assign(item, {context});
Object.assign(item, {context});
const condition = filter.condition;
pushSerializeAndPop(
item,
@@ -1332,7 +1334,7 @@ export function writeFilter(filter, opt_version) {
const context = {
node: child,
};
assign(context, {
Object.assign(context, {
'version': version,
'filter': filter,
});
@@ -1348,7 +1350,7 @@ export function writeFilter(filter, opt_version) {
function writeGetFeature(node, featureTypes, objectStack) {
const context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
const item = /** @type {import("../xml.js").NodeStackItem} */ (
assign({}, context)
Object.assign({}, context)
);
item.node = node;
pushSerializeAndPop(

View File

@@ -13,7 +13,6 @@ import Polygon from '../geom/Polygon.js';
import {get as getProjection} from '../proj.js';
import SimpleGeometry from '../geom/SimpleGeometry.js';
import {assign} from '../obj.js';
// WKB spec: https://www.ogc.org/standards/sfa
// EWKB spec: https://raw.githubusercontent.com/postgis/postgis/2.1.0/doc/ZMSgeoms.txt
@@ -423,7 +422,7 @@ class WkbWriter {
* @property {number} Z NoData value for Z
* @property {number} M NoData value for M
*/
this.nodata_ = assign({X: 0, Y: 0, Z: 0, M: 0}, opts.nodata);
this.nodata_ = Object.assign({X: 0, Y: 0, Z: 0, M: 0}, opts.nodata);
}
/**
@@ -459,7 +458,7 @@ class WkbWriter {
* @property {number} [Z] NoData value for Z
* @property {number} [M] NoData value for M
*/
const coordsObj = assign.apply(
const coordsObj = Object.assign.apply(
null,
layout.split('').map((axis, idx) => ({[axis]: coords[idx]}))
);

View File

@@ -3,7 +3,6 @@
*/
import GML2 from './GML2.js';
import XMLFeature from './XMLFeature.js';
import {assign} from '../obj.js';
import {extend} from '../array.js';
import {makeArrayPusher, makeStructureNS, pushParseAndPop} from '../xml.js';
@@ -157,7 +156,7 @@ class WMSGetFeatureInfo extends XMLFeature {
readFeaturesFromNode(node, opt_options) {
const options = {};
if (opt_options) {
assign(options, this.getReadOptions(node, opt_options));
Object.assign(options, this.getReadOptions(node, opt_options));
}
return this.readFeatures_(node, [options]);
}

View File

@@ -4,7 +4,6 @@
import EventType from '../events/EventType.js';
import Interaction from './Interaction.js';
import MapEventType from '../MapEventType.js';
import {assign} from '../obj.js';
import {listen, unlistenByKey} from '../events.js';
import {toFixed} from '../math.js';
@@ -76,7 +75,7 @@ class Link extends Interaction {
constructor(opt_options) {
super();
const options = assign(
const options = Object.assign(
{animate: true, replace: false, prefix: ''},
opt_options || {}
);
@@ -282,7 +281,7 @@ class Link extends Interaction {
if (updateView) {
if (!this.initial_ && this.animationOptions_) {
view.animate(assign(viewProperties, this.animationOptions_));
view.animate(Object.assign(viewProperties, this.animationOptions_));
} else {
if (viewProperties.center) {
view.setCenter(viewProperties.center);

View File

@@ -5,7 +5,6 @@ import BaseObject from '../Object.js';
import LayerProperty from './Property.js';
import {abstract} from '../util.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
import {clamp} from '../math.js';
/**
@@ -92,10 +91,10 @@ class BaseLayer extends BaseObject {
/**
* @type {Object<string, *>}
*/
const properties = assign({}, options);
const properties = Object.assign({}, options);
if (typeof options.properties === 'object') {
delete properties.properties;
assign(properties, options.properties);
Object.assign(properties, options.properties);
}
properties[LayerProperty.OPACITY] =

View File

@@ -3,7 +3,6 @@
*/
import Layer from './Layer.js';
import TileProperty from './TileProperty.js';
import {assign} from '../obj.js';
/***
* @template Return
@@ -66,7 +65,7 @@ class BaseTileLayer extends Layer {
constructor(opt_options) {
const options = opt_options ? opt_options : {};
const baseOptions = assign({}, options);
const baseOptions = Object.assign({}, options);
delete baseOptions.preload;
delete baseOptions.useInterimTilesOnError;

View File

@@ -3,7 +3,6 @@
*/
import Layer from './Layer.js';
import RBush from 'rbush';
import {assign} from '../obj.js';
import {
createDefaultStyle,
toFunction as toStyleFunction,
@@ -91,7 +90,7 @@ class BaseVectorLayer extends Layer {
constructor(opt_options) {
const options = opt_options ? opt_options : {};
const baseOptions = assign({}, options);
const baseOptions = Object.assign({}, options);
delete baseOptions.style;
delete baseOptions.renderBuffer;

View File

@@ -25,7 +25,6 @@ import {
isEmpty,
wrapX as wrapExtentX,
} from '../extent.js';
import {assign} from '../obj.js';
import {clamp} from '../math.js';
import {degreesToStringHDMS} from '../coordinate.js';
import {
@@ -170,7 +169,7 @@ class Graticule extends VectorLayer {
constructor(opt_options) {
const options = opt_options ? opt_options : {};
const baseOptions = assign(
const baseOptions = Object.assign(
{
updateWhileAnimating: true,
updateWhileInteracting: true,

View File

@@ -8,7 +8,7 @@ import Event from '../events/Event.js';
import EventType from '../events/EventType.js';
import ObjectEventType from '../ObjectEventType.js';
import {assert} from '../asserts.js';
import {assign, clear} from '../obj.js';
import {clear} from '../obj.js';
import {getIntersection} from '../extent.js';
import {getUid} from '../util.js';
import {listen, unlistenByKey} from '../events.js';
@@ -92,7 +92,7 @@ class LayerGroup extends BaseLayer {
*/
constructor(opt_options) {
const options = opt_options || {};
const baseOptions = /** @type {Options} */ (assign({}, options));
const baseOptions = /** @type {Options} */ (Object.assign({}, options));
delete baseOptions.layers;
let layers = options.layers;

View File

@@ -3,7 +3,6 @@
*/
import BaseVector from './BaseVector.js';
import WebGLPointsLayerRenderer from '../renderer/webgl/PointsLayer.js';
import {assign} from '../obj.js';
import {clamp} from '../math.js';
import {createCanvasContext2D} from '../dom.js';
@@ -71,7 +70,7 @@ class Heatmap extends BaseVector {
constructor(opt_options) {
const options = opt_options ? opt_options : {};
const baseOptions = assign({}, options);
const baseOptions = Object.assign({}, options);
delete baseOptions.gradient;
delete baseOptions.radius;

View File

@@ -6,7 +6,6 @@ import EventType from '../events/EventType.js';
import LayerProperty from './Property.js';
import RenderEventType from '../render/EventType.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
import {listen, unlistenByKey} from '../events.js';
/**
@@ -95,7 +94,7 @@ class Layer extends BaseLayer {
* @param {Options<SourceType>} options Layer options.
*/
constructor(options) {
const baseOptions = assign({}, options);
const baseOptions = Object.assign({}, options);
delete baseOptions.source;
super(baseOptions);

View File

@@ -3,7 +3,6 @@
*/
import BaseVectorLayer from './BaseVector.js';
import CanvasVectorImageLayerRenderer from '../renderer/canvas/VectorImageLayer.js';
import {assign} from '../obj.js';
/**
* @template {import("../source/Vector.js").default} VectorSourceType
@@ -69,7 +68,7 @@ class VectorImageLayer extends BaseVectorLayer {
constructor(opt_options) {
const options = opt_options ? opt_options : {};
const baseOptions = assign({}, options);
const baseOptions = Object.assign({}, options);
delete baseOptions.imageRatio;
super(baseOptions);

View File

@@ -6,7 +6,6 @@ import CanvasVectorTileLayerRenderer from '../renderer/canvas/VectorTileLayer.js
import TileProperty from './TileProperty.js';
import VectorTileRenderType from './VectorTileRenderType.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
/***
* @template Return
@@ -102,7 +101,7 @@ class VectorTileLayer extends BaseVectorLayer {
constructor(opt_options) {
const options = opt_options ? opt_options : {};
const baseOptions = /** @type {Object} */ (assign({}, options));
const baseOptions = /** @type {Object} */ (Object.assign({}, options));
delete baseOptions.preload;
delete baseOptions.useInterimTilesOnError;

View File

@@ -3,7 +3,6 @@
*/
import Layer from './Layer.js';
import WebGLPointsLayerRenderer from '../renderer/webgl/PointsLayer.js';
import {assign} from '../obj.js';
import {parseLiteralStyle} from '../webgl/ShaderBuilder.js';
/**
@@ -77,7 +76,7 @@ class WebGLPointsLayer extends Layer {
* @param {Options<VectorSourceType>} options Options.
*/
constructor(options) {
const baseOptions = assign({}, options);
const baseOptions = Object.assign({}, options);
super(baseOptions);
@@ -120,7 +119,7 @@ class WebGLPointsLayer extends Layer {
* @param {Object<string, number>} variables Variables to update.
*/
updateStyleVariables(variables) {
assign(this.styleVariables_, variables);
Object.assign(this.styleVariables_, variables);
this.changed();
}
}

View File

@@ -14,7 +14,6 @@ import {
getStringNumberEquivalent,
uniformNameForVariable,
} from '../style/expressions.js';
import {assign} from '../obj.js';
/**
* @typedef {import("../source/DataTile.js").default|import("../source/TileImage.js").default} SourceType
@@ -308,7 +307,7 @@ class WebGLTileLayer extends BaseTileLayer {
* @param {Options} opt_options Tile layer options.
*/
constructor(opt_options) {
const options = opt_options ? assign({}, opt_options) : {};
const options = opt_options ? Object.assign({}, opt_options) : {};
const style = options.style || {};
delete options.style;
@@ -511,7 +510,7 @@ class WebGLTileLayer extends BaseTileLayer {
* @api
*/
updateStyleVariables(variables) {
assign(this.styleVariables_, variables);
Object.assign(this.styleVariables_, variables);
this.changed();
}
}

View File

@@ -2,37 +2,6 @@
* @module ol/obj
*/
/**
* Polyfill for Object.assign(). Assigns enumerable and own properties from
* one or more source objects to a target object.
* See https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign.
*
* @param {!Object} target The target object.
* @param {...Object} var_sources The source object(s).
* @return {!Object} The modified target object.
*/
export const assign =
typeof Object.assign === 'function'
? Object.assign
: function (target, var_sources) {
if (target === undefined || target === null) {
throw new TypeError('Cannot convert undefined or null to object');
}
const output = Object(target);
for (let i = 1, ii = arguments.length; i < ii; ++i) {
const source = arguments[i];
if (source !== undefined && source !== null) {
for (const key in source) {
if (source.hasOwnProperty(key)) {
output[key] = source[key];
}
}
}
}
return output;
};
/**
* Removes all properties from an object.
* @param {Object} object The object to clear.

View File

@@ -12,7 +12,6 @@ import {
makeInverse,
toString as toTransformString,
} from '../../transform.js';
import {assign} from '../../obj.js';
import {
containsCoordinate,
containsExtent,
@@ -239,7 +238,7 @@ class CanvasImageLayerRenderer extends CanvasLayerRenderer {
const dh = img.height * transform[3];
if (!this.getLayer().getSource().getInterpolate()) {
assign(context, IMAGE_SMOOTHING_DISABLED);
Object.assign(context, IMAGE_SMOOTHING_DISABLED);
}
this.preRender(context, frameState);
@@ -262,7 +261,7 @@ class CanvasImageLayerRenderer extends CanvasLayerRenderer {
if (clipped) {
context.restore();
}
assign(context, IMAGE_SMOOTHING_ENABLED);
Object.assign(context, IMAGE_SMOOTHING_ENABLED);
if (canvasTransform !== canvas.style.transform) {
canvas.style.transform = canvasTransform;

View File

@@ -13,7 +13,6 @@ import {
makeInverse,
toString as toTransformString,
} from '../../transform.js';
import {assign} from '../../obj.js';
import {
containsCoordinate,
createEmpty,
@@ -411,7 +410,7 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer {
}
if (!tileSource.getInterpolate()) {
assign(context, IMAGE_SMOOTHING_DISABLED);
Object.assign(context, IMAGE_SMOOTHING_DISABLED);
}
this.preRender(context, frameState);
@@ -562,7 +561,7 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer {
if (layerState.extent) {
context.restore();
}
assign(context, IMAGE_SMOOTHING_ENABLED);
Object.assign(context, IMAGE_SMOOTHING_ENABLED);
if (canvasTransform !== canvas.style.transform) {
canvas.style.transform = canvasTransform;

View File

@@ -9,7 +9,6 @@ import ImageState from '../../ImageState.js';
import RBush from 'rbush';
import ViewHint from '../../ViewHint.js';
import {apply, compose, create} from '../../transform.js';
import {assign} from '../../obj.js';
import {getHeight, getWidth, isEmpty, scaleFromCenter} from '../../extent.js';
/**
@@ -109,15 +108,15 @@ class CanvasVectorImageLayerRenderer extends CanvasImageLayerRenderer {
const context = vectorRenderer.context;
const layerState = frameState.layerStatesArray[frameState.layerIndex];
context.globalAlpha = layerState.opacity;
const imageLayerState = assign({}, layerState, {opacity: 1});
const imageLayerState = Object.assign({}, layerState, {opacity: 1});
const imageFrameState =
/** @type {import("../../PluggableMap.js").FrameState} */ (
assign({}, frameState, {
Object.assign({}, frameState, {
declutterTree: new RBush(9),
extent: renderedExtent,
size: [width, height],
viewState: /** @type {import("../../View.js").State} */ (
assign({}, frameState.viewState, {
Object.assign({}, frameState.viewState, {
rotation: 0,
})
),

View File

@@ -2,7 +2,6 @@
* @module ol/reproj
*/
import {IMAGE_SMOOTHING_DISABLED} from './renderer/canvas/common.js';
import {assign} from './obj.js';
import {
containsCoordinate,
createEmpty,
@@ -227,7 +226,7 @@ export function render(
);
if (!opt_interpolate) {
assign(context, IMAGE_SMOOTHING_DISABLED);
Object.assign(context, IMAGE_SMOOTHING_DISABLED);
}
if (sources.length === 0) {
@@ -255,7 +254,7 @@ export function render(
);
if (!opt_interpolate) {
assign(stitchContext, IMAGE_SMOOTHING_DISABLED);
Object.assign(stitchContext, IMAGE_SMOOTHING_DISABLED);
}
const stitchScale = pixelRatio / sourceResolution;

View File

@@ -3,7 +3,6 @@
*/
import XYZ from './XYZ.js';
import {assign} from '../obj.js';
/**
* @typedef {Object} Options
@@ -104,7 +103,7 @@ class CartoDB extends XYZ {
* @api
*/
updateConfig(config) {
assign(this.config_, config);
Object.assign(this.config_, config);
this.initializeMap_();
}

View File

@@ -6,7 +6,6 @@ import EventType from '../events/EventType.js';
import TileEventType from './TileEventType.js';
import TileSource, {TileSourceEvent} from './Tile.js';
import TileState from '../TileState.js';
import {assign} from '../obj.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js';
import {getKeyZXY} from '../tilecoord.js';
import {getUid} from '../util.js';
@@ -197,7 +196,7 @@ class DataTileSource extends TileSource {
});
}
const options = assign(
const options = Object.assign(
{
tileCoord: [z, x, y],
loader: loader,

View File

@@ -7,7 +7,6 @@ import ImageSource, {defaultImageLoadFunction} from './Image.js';
import ImageWrapper from '../Image.js';
import {appendParams} from '../uri.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
import {containsExtent, getHeight, getWidth} from '../extent.js';
/**
@@ -172,7 +171,7 @@ class ImageArcGISRest extends ImageSource {
'FORMAT': 'PNG32',
'TRANSPARENT': true,
};
assign(params, this.params_);
Object.assign(params, this.params_);
extent = extent.slice();
const centerX = (extent[0] + extent[2]) / 2;
@@ -311,7 +310,7 @@ class ImageArcGISRest extends ImageSource {
* @api
*/
updateParams(params) {
assign(this.params_, params);
Object.assign(this.params_, params);
this.image_ = null;
this.changed();
}

View File

@@ -6,7 +6,6 @@ import EventType from '../events/EventType.js';
import ImageSource, {defaultImageLoadFunction} from './Image.js';
import ImageWrapper from '../Image.js';
import {appendParams} from '../uri.js';
import {assign} from '../obj.js';
import {
containsExtent,
getCenter,
@@ -220,7 +219,7 @@ class ImageMapGuide extends ImageSource {
* @api
*/
updateParams(params) {
assign(this.params_, params);
Object.assign(this.params_, params);
this.changed();
}
@@ -250,7 +249,7 @@ class ImageMapGuide extends ImageSource {
'SETVIEWCENTERX': center[0],
'SETVIEWCENTERY': center[1],
};
assign(baseParams, params);
Object.assign(baseParams, params);
return appendParams(baseUrl, baseParams);
}

View File

@@ -7,7 +7,6 @@ import ImageSource, {defaultImageLoadFunction} from './Image.js';
import ImageState from '../ImageState.js';
import ImageWrapper from '../Image.js';
import {IMAGE_SMOOTHING_DISABLED} from '../renderer/canvas/common.js';
import {assign} from '../obj.js';
import {createCanvasContext2D} from '../dom.js';
import {getHeight, getWidth, intersects} from '../extent.js';
import {get as getProjection} from '../proj.js';
@@ -158,7 +157,7 @@ class Static extends ImageSource {
if (targetWidth !== imageWidth || targetHeight !== imageHeight) {
const context = createCanvasContext2D(targetWidth, targetHeight);
if (!this.getInterpolate()) {
assign(context, IMAGE_SMOOTHING_DISABLED);
Object.assign(context, IMAGE_SMOOTHING_DISABLED);
}
const canvas = context.canvas;
context.drawImage(

View File

@@ -8,7 +8,6 @@ import ImageWrapper from '../Image.js';
import {DEFAULT_VERSION} from './wms.js';
import {appendParams} from '../uri.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
import {calculateSourceResolution} from '../reproj.js';
import {ceil, floor, round} from '../math.js';
import {compareVersions} from '../string.js';
@@ -206,7 +205,7 @@ class ImageWMS extends ImageSource {
'TRANSPARENT': true,
'QUERY_LAYERS': this.params_['LAYERS'],
};
assign(baseParams, this.params_, params);
Object.assign(baseParams, this.params_, params);
const x = floor((coordinate[0] - extent[0]) / resolution, DECIMALS);
const y = floor((extent[3] - coordinate[1]) / resolution, DECIMALS);
@@ -265,7 +264,7 @@ class ImageWMS extends ImageSource {
baseParams['SCALE'] = (resolution * mpu) / pixelSize;
}
assign(baseParams, params);
Object.assign(baseParams, params);
return appendParams(/** @type {string} */ (this.url_), baseParams);
}
@@ -338,7 +337,7 @@ class ImageWMS extends ImageSource {
'FORMAT': 'image/png',
'TRANSPARENT': true,
};
assign(params, this.params_);
Object.assign(params, this.params_);
this.imageSize_[0] = round(
getWidth(requestExtent) / imageResolution,
@@ -480,7 +479,7 @@ class ImageWMS extends ImageSource {
* @api
*/
updateParams(params) {
assign(this.params_, params);
Object.assign(this.params_, params);
this.updateV13_();
this.image_ = null;
this.changed();

View File

@@ -11,7 +11,6 @@ import Source from './Source.js';
import TileLayer from '../layer/Tile.js';
import TileQueue from '../TileQueue.js';
import TileSource from './Tile.js';
import {assign} from '../obj.js';
import {createCanvasContext2D} from '../dom.js';
import {create as createTransform} from '../transform.js';
import {equals, getCenter, getHeight, getWidth} from '../extent.js';
@@ -711,11 +710,11 @@ class RasterSource extends ImageSource {
*/
updateFrameState_(extent, resolution, projection) {
const frameState = /** @type {import("../PluggableMap.js").FrameState} */ (
assign({}, this.frameState_)
Object.assign({}, this.frameState_)
);
frameState.viewState = /** @type {import("../View.js").State} */ (
assign({}, frameState.viewState)
Object.assign({}, frameState.viewState)
);
const center = getCenter(extent);

View File

@@ -4,7 +4,6 @@
import TileImage from './TileImage.js';
import {appendParams} from '../uri.js';
import {assign} from '../obj.js';
import {createEmpty} from '../extent.js';
import {modulo} from '../math.js';
import {scale as scaleSize, toSize} from '../size.js';
@@ -208,7 +207,7 @@ class TileArcGISRest extends TileImage {
* @api
*/
updateParams(params) {
assign(this.params_, params);
Object.assign(this.params_, params);
this.setKey(this.getKeyForParams_());
}
@@ -246,7 +245,7 @@ class TileArcGISRest extends TileImage {
'FORMAT': 'PNG32',
'TRANSPARENT': true,
};
assign(baseParams, this.params_);
Object.assign(baseParams, this.params_);
return this.getRequestUrl_(
tileCoord,

View File

@@ -6,7 +6,6 @@ import TileImage from './TileImage.js';
import {DEFAULT_VERSION} from './wms.js';
import {appendParams} from '../uri.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
import {buffer, createEmpty} from '../extent.js';
import {buffer as bufferSize, scale as scaleSize, toSize} from '../size.js';
import {calculateSourceResolution} from '../reproj.js';
@@ -218,7 +217,7 @@ class TileWMS extends TileImage {
'TRANSPARENT': true,
'QUERY_LAYERS': this.params_['LAYERS'],
};
assign(baseParams, this.params_, params);
Object.assign(baseParams, this.params_, params);
const x = Math.floor((coordinate[0] - tileExtent[0]) / tileResolution);
const y = Math.floor((tileExtent[3] - coordinate[1]) / tileResolution);
@@ -279,7 +278,7 @@ class TileWMS extends TileImage {
baseParams['SCALE'] = (resolution * mpu) / pixelSize;
}
assign(baseParams, params);
Object.assign(baseParams, params);
return appendParams(/** @type {string} */ (this.urls[0]), baseParams);
}
@@ -407,7 +406,7 @@ class TileWMS extends TileImage {
* @api
*/
updateParams(params) {
assign(this.params_, params);
Object.assign(this.params_, params);
this.updateV13_();
this.setKey(this.getKeyForParams_());
}
@@ -462,7 +461,7 @@ class TileWMS extends TileImage {
'FORMAT': 'image/png',
'TRANSPARENT': true,
};
assign(baseParams, this.params_);
Object.assign(baseParams, this.params_);
return this.getRequestUrl_(
tileCoord,

View File

@@ -4,7 +4,6 @@
import TileImage from './TileImage.js';
import {appendParams} from '../uri.js';
import {assign} from '../obj.js';
import {containsExtent} from '../extent.js';
import {createFromCapabilitiesMatrixSet} from '../tilegrid/WMTS.js';
import {createFromTileUrlFunctions, expandUrl} from '../tileurlfunction.js';
@@ -267,7 +266,7 @@ class WMTS extends TileImage {
* @api
*/
updateDimensions(dimensions) {
assign(this.dimensions_, dimensions);
Object.assign(this.dimensions_, dimensions);
this.setKey(this.getKeyForDimensions_());
}
@@ -287,7 +286,7 @@ class WMTS extends TileImage {
};
if (requestEncoding == 'KVP') {
assign(context, {
Object.assign(context, {
'Service': 'WMTS',
'Request': 'GetTile',
'Version': this.version_,
@@ -327,7 +326,7 @@ class WMTS extends TileImage {
'TileCol': tileCoord[1],
'TileRow': tileCoord[2],
};
assign(localContext, dimensions);
Object.assign(localContext, dimensions);
let url = template;
if (requestEncoding == 'KVP') {
url = appendParams(url, localContext);

View File

@@ -3,7 +3,6 @@
*/
import TileGrid from '../tilegrid/TileGrid.js';
import {assign} from '../obj.js';
import {getJSON, resolveUrl} from '../net.js';
import {get as getProjection} from '../proj.js';
import {getIntersection as intersectExtents} from '../extent.js';
@@ -324,7 +323,7 @@ function parseTileMatrixSet(
}
}
assign(localContext, context);
Object.assign(localContext, context);
const url = tileUrlTemplate.replace(/\{(\w+?)\}/g, function (m, p) {
return localContext[p];

View File

@@ -3,7 +3,6 @@
*/
import {SAFARI_BUG_237906} from './has.js';
import {assign} from './obj.js';
/**
* Constants taken from goog.webgl
@@ -92,7 +91,7 @@ const CONTEXT_IDS = ['experimental-webgl', 'webgl', 'webkit-3d', 'moz-webgl'];
* @return {WebGLRenderingContext} WebGL rendering context.
*/
export function getContext(canvas, opt_attributes) {
const attributes = assign(
const attributes = Object.assign(
{
preserveDrawingBuffer: true,
antialias: SAFARI_BUG_237906 ? false : true, // https://bugs.webkit.org/show_bug.cgi?id=237906

View File

@@ -3,7 +3,6 @@
* @module ol/worker/webgl
*/
import {WebGLWorkerMessageType} from '../render/webgl/constants.js';
import {assign} from '../obj.js';
import {
create as createTransform,
makeInverse as makeInverseTransform,
@@ -49,7 +48,7 @@ worker.onmessage = (event) => {
}
/** @type {import('../render/webgl/constants.js').WebGLWorkerGenerateBuffersMessage} */
const message = assign(
const message = Object.assign(
{
vertexBuffer: vertexBuffer.buffer,
indexBuffer: indexBuffer.buffer,
@@ -116,7 +115,7 @@ worker.onmessage = (event) => {
const vertexBuffer = Float32Array.from(vertices);
/** @type {import('../render/webgl/constants.js').WebGLWorkerGenerateBuffersMessage} */
const message = assign(
const message = Object.assign(
{
vertexBuffer: vertexBuffer.buffer,
indexBuffer: indexBuffer.buffer,
@@ -154,7 +153,7 @@ worker.onmessage = (event) => {
const vertexBuffer = Float32Array.from(vertices);
/** @type {import('../render/webgl/constants.js').WebGLWorkerGenerateBuffersMessage} */
const message = assign(
const message = Object.assign(
{
vertexBuffer: vertexBuffer.buffer,
indexBuffer: indexBuffer.buffer,

View File

@@ -2,7 +2,6 @@ import Collection from '../../../../../src/ol/Collection.js';
import Layer from '../../../../../src/ol/layer/Layer.js';
import LayerGroup from '../../../../../src/ol/layer/Group.js';
import Source from '../../../../../src/ol/source/Source.js';
import {assign} from '../../../../../src/ol/obj.js';
import {getIntersection} from '../../../../../src/ol/extent.js';
import {getUid} from '../../../../../src/ol/util.js';
@@ -531,9 +530,9 @@ describe('ol/layer/Group', function () {
expect(layerStatesArray[0]).to.eql(layer1.getLayerState());
// layer state should match except for layer reference
const layerState = assign({}, layerStatesArray[0]);
const layerState = Object.assign({}, layerStatesArray[0]);
delete layerState.layer;
const groupState = assign({}, group.getLayerState());
const groupState = Object.assign({}, group.getLayerState());
delete groupState.layer;
expect(layerState).to.eql(groupState);
@@ -580,14 +579,14 @@ describe('ol/layer/Group', function () {
// compare layer state to group state
// layer state should match except for layer reference
let layerState = assign({}, layerStatesArray[0]);
let layerState = Object.assign({}, layerStatesArray[0]);
delete layerState.layer;
const groupState = assign({}, group.getLayerState());
const groupState = Object.assign({}, group.getLayerState());
delete groupState.layer;
expect(layerState).to.eql(groupState);
// layer state should be transformed (and we ignore layer reference)
layerState = assign({}, layerStatesArray[1]);
layerState = Object.assign({}, layerStatesArray[1]);
delete layerState.layer;
expect(layerState).to.eql({
opacity: 0.25,

View File

@@ -1,45 +1,7 @@
import expect from '../expect.js';
import {assign, clear, isEmpty} from '../../../src/ol/obj.js';
import {clear, isEmpty} from '../../../src/ol/obj.js';
describe('ol/obj.js', () => {
describe('assign()', function () {
it('is an alias for Object.assign() where available', function () {
if (typeof Object.assign === 'function') {
expect(assign).to.be(Object.assign);
}
});
it('assigns properties from a source object to a target object', function () {
const source = {
sourceProp1: 'sourceValue1',
sourceProp2: 'sourceValue2',
};
const target = {
sourceProp1: 'overridden',
targetProp1: 'targetValue1',
};
const assigned = assign(target, source);
expect(assigned).to.be(target);
expect(assigned.sourceProp1).to.be('sourceValue1');
expect(assigned.sourceProp2).to.be('sourceValue2');
expect(assigned.targetProp1).to.be('targetValue1');
});
it('throws a TypeError with `undefined` as target', function () {
expect(() => assign()).to.throwException(
/Cannot convert undefined or null to object/
);
});
it('throws a TypeError with `null` as target', function () {
expect(() => assign(null)).to.throwException(
/Cannot convert undefined or null to object/
);
});
});
describe('clear()', function () {
it('removes all properties from an object', function () {
expect(isEmpty(clear({foo: 'bar'}))).to.be(true);