Use const in more places

This commit is contained in:
Maximilian Krög
2022-08-09 00:04:31 +02:00
parent bebf2db5ae
commit 5b8d810f80
18 changed files with 108 additions and 110 deletions

View File

@@ -53,20 +53,20 @@ import {listen, unlistenByKey} from './events.js';
* import Polygon from 'ol/geom/Polygon';
* import Point from 'ol/geom/Point';
*
* var feature = new Feature({
* const feature = new Feature({
* geometry: new Polygon(polyCoords),
* labelPoint: new Point(labelCoords),
* name: 'My Polygon'
* name: 'My Polygon',
* });
*
* // get the polygon geometry
* var poly = feature.getGeometry();
* const poly = feature.getGeometry();
*
* // Render the feature as a point using the coordinates from labelPoint
* feature.setGeometryName('labelPoint');
*
* // get the point geometry
* var point = feature.getGeometry();
* const point = feature.getGeometry();
* ```
*
* @api

View File

@@ -87,7 +87,7 @@ class GeolocationError extends BaseEvent {
*
* Example:
*
* var geolocation = new Geolocation({
* const geolocation = new Geolocation({
* // take the projection to use from the map's view
* projection: view.getProjection()
* });

View File

@@ -190,17 +190,17 @@ function setLayerMapProperty(layer, map) {
* import TileLayer from 'ol/layer/Tile';
* import OSM from 'ol/source/OSM';
*
* var map = new Map({
* const map = new Map({
* view: new View({
* center: [0, 0],
* zoom: 1
* zoom: 1,
* }),
* layers: [
* new TileLayer({
* source: new OSM()
* })
* source: new OSM(),
* }),
* ],
* target: 'map'
* target: 'map',
* });
*
* The above snippet creates a map using a {@link module:ol/layer/Tile~TileLayer} to

View File

@@ -100,8 +100,9 @@ const Property = {
*
* import Overlay from 'ol/Overlay';
*
* var popup = new Overlay({
* element: document.getElementById('popup')
* // ...
* const popup = new Overlay({
* element: document.getElementById('popup'),
* });
* popup.setPosition(coordinate);
* map.addOverlay(popup);

View File

@@ -22,10 +22,10 @@ import {easeIn} from './easing.js';
* import TileState from 'ol/TileState';
*
* source.setTileLoadFunction(function(tile, src) {
* var xhr = new XMLHttpRequest();
* const xhr = new XMLHttpRequest();
* xhr.responseType = 'blob';
* xhr.addEventListener('loadend', function (evt) {
* var data = this.response;
* const data = this.response;
* if (data !== undefined) {
* tile.getImage().src = URL.createObjectURL(data);
* } else {

View File

@@ -30,7 +30,7 @@ import {removeNode} from '../dom.js';
* This is the base class for controls. You can use it for simple custom
* controls by creating the element with listeners, creating an instance:
* ```js
* var myControl = new Control({element: myElement});
* const myControl = new Control({element: myElement});
* ```
* and then adding this to the map.
*

View File

@@ -27,7 +27,7 @@ import {padNumber} from './string.js';
*
* import {add} from 'ol/coordinate';
*
* var coord = [7.85, 47.983333];
* const coord = [7.85, 47.983333];
* add(coord, [-2, 4]);
* // coord is now [5.85, 51.983333]
*
@@ -121,18 +121,18 @@ export function closestOnSegment(coordinate, segment) {
*
* import {createStringXY} from 'ol/coordinate';
*
* var coord = [7.85, 47.983333];
* var stringifyFunc = createStringXY();
* var out = stringifyFunc(coord);
* const coord = [7.85, 47.983333];
* const stringifyFunc = createStringXY();
* const out = stringifyFunc(coord);
* // out is now '8, 48'
*
* Example with explicitly specifying 2 fractional digits:
*
* import {createStringXY} from 'ol/coordinate';
*
* var coord = [7.85, 47.983333];
* var stringifyFunc = createStringXY(2);
* var out = stringifyFunc(coord);
* const coord = [7.85, 47.983333];
* const stringifyFunc = createStringXY(2);
* const out = stringifyFunc(coord);
* // out is now '7.85, 47.98'
*
* @param {number} [opt_fractionDigits] The number of digits to include
@@ -201,18 +201,18 @@ export function degreesToStringHDMS(hemispheres, degrees, opt_fractionDigits) {
*
* import {format} from 'ol/coordinate';
*
* var coord = [7.85, 47.983333];
* var template = 'Coordinate is ({x}|{y}).';
* var out = format(coord, template);
* const coord = [7.85, 47.983333];
* const template = 'Coordinate is ({x}|{y}).';
* const out = format(coord, template);
* // out is now 'Coordinate is (8|48).'
*
* Example explicitly specifying the fractional digits:
*
* import {format} from 'ol/coordinate';
*
* var coord = [7.85, 47.983333];
* var template = 'Coordinate is ({x}|{y}).';
* var out = format(coord, template, 2);
* const coord = [7.85, 47.983333];
* const template = 'Coordinate is ({x}|{y}).';
* const out = format(coord, template, 2);
* // out is now 'Coordinate is (7.85|47.98).'
*
* @param {Coordinate} coordinate Coordinate.
@@ -257,8 +257,8 @@ export function equals(coordinate1, coordinate2) {
*
* import {rotate} from 'ol/coordinate';
*
* var coord = [7.85, 47.983333];
* var rotateRadians = Math.PI / 2; // 90 degrees
* const coord = [7.85, 47.983333];
* const rotateRadians = Math.PI / 2; // 90 degrees
* rotate(coord, rotateRadians);
* // coord is now [-47.983333, 7.85]
*
@@ -285,8 +285,8 @@ export function rotate(coordinate, angle) {
*
* import {scale as scaleCoordinate} from 'ol/coordinate';
*
* var coord = [7.85, 47.983333];
* var scale = 1.2;
* const coord = [7.85, 47.983333];
* const scale = 1.2;
* scaleCoordinate(coord, scale);
* // coord is now [9.42, 57.5799996]
*
@@ -340,16 +340,16 @@ export function squaredDistanceToSegment(coordinate, segment) {
*
* import {toStringHDMS} from 'ol/coordinate';
*
* var coord = [7.85, 47.983333];
* var out = toStringHDMS(coord);
* const coord = [7.85, 47.983333];
* const out = toStringHDMS(coord);
* // out is now '47° 58 60″ N 7° 50 60″ E'
*
* Example explicitly specifying 1 fractional digit:
*
* import {toStringHDMS} from 'ol/coordinate';
*
* var coord = [7.85, 47.983333];
* var out = toStringHDMS(coord, 1);
* const coord = [7.85, 47.983333];
* const out = toStringHDMS(coord, 1);
* // out is now '47° 58 60.0″ N 7° 50 60.0″ E'
*
* @param {Coordinate} coordinate Coordinate.
@@ -377,16 +377,16 @@ export function toStringHDMS(coordinate, opt_fractionDigits) {
*
* import {toStringXY} from 'ol/coordinate';
*
* var coord = [7.85, 47.983333];
* var out = toStringXY(coord);
* const coord = [7.85, 47.983333];
* const out = toStringXY(coord);
* // out is now '8, 48'
*
* Example explicitly specifying 1 fractional digit:
*
* import {toStringXY} from 'ol/coordinate';
*
* var coord = [7.85, 47.983333];
* var out = toStringXY(coord, 1);
* const coord = [7.85, 47.983333];
* const out = toStringXY(coord, 1);
* // out is now '7.8, 48.0'
*
* @param {Coordinate} coordinate Coordinate.

View File

@@ -60,7 +60,7 @@ It's handy to have the [`src/ol/xml.js` source code](https://github.com/openlaye
The `parserNS` argument to `parse` is an `Object` whose keys are XML namespaces and whose values are `Objects` whose keys are local element names and whose values are functions. A simple example might look like this:
```js
var parserNS = {
const parserNS = {
'http://my/first/namespace': {
'elementLocalName': function(/* ... */) {
// parse an <elementLocalName> element in the http://my/first/namespace namespace

View File

@@ -113,18 +113,18 @@ class ErrorEvent extends BaseEvent {
* property (all layers must share the same vector source). See the constructor options for
* more detail.
*
* var map = new Map({
* const map = new Map({
* view: new View({
* center: [0, 0],
* zoom: 1
* zoom: 1,
* }),
* layers: [
* new MapboxVectorLayer({
* styleUrl: 'mapbox://styles/mapbox/bright-v9',
* accessToken: 'your-mapbox-access-token-here'
* })
* accessToken: 'your-mapbox-access-token-here',
* }),
* ],
* target: 'map'
* target: 'map',
* });
*
* On configuration or loading error, the layer will trigger an `'error'` event. Listeners

View File

@@ -52,12 +52,15 @@ import {getTransformFromProjections, getUserProjection} from './proj.js';
* import Fill from 'ol/style/Fill';
* import Polygon from 'ol/geom/Polygon';
*
* var canvas = document.createElement('canvas');
* var render = toContext(canvas.getContext('2d'),
* { size: [100, 100] });
* const canvas = document.createElement('canvas');
* const render = toContext(
* canvas.getContext('2d'),
* {size: [100, 100]}
* );
* render.setFillStrokeStyle(new Fill({ color: blue }));
* render.drawPolygon(
* new Polygon([[[0, 0], [100, 100], [100, 0], [0, 0]]]));
* new Polygon([[[0, 0], [100, 100], [100, 0], [0, 0]]])
* );
* ```
*
* @param {CanvasRenderingContext2D} context Canvas context.

View File

@@ -136,15 +136,15 @@ function createMinion(operation) {
*/
function createWorker(config, onMessage) {
const lib = Object.keys(config.lib || {}).map(function (name) {
return 'var ' + name + ' = ' + config.lib[name].toString() + ';';
return 'const ' + name + ' = ' + config.lib[name].toString() + ';';
});
const lines = lib.concat([
'var __minion__ = (' + createMinion.toString() + ')(',
'const __minion__ = (' + createMinion.toString() + ')(',
config.operation.toString(),
');',
'self.addEventListener("message", function(event) {',
' var buffer = __minion__(event.data);',
' const buffer = __minion__(event.data);',
' self.postMessage({buffer: buffer, meta: event.data.meta}, [buffer]);',
'});',
]);

View File

@@ -90,24 +90,24 @@ export class VectorSourceEvent extends Event {
* import {GeoJSON} from 'ol/format';
* import {bbox} from 'ol/loadingstrategy';
*
* var vectorSource = new Vector({
* const vectorSource = new Vector({
* format: new GeoJSON(),
* loader: function(extent, resolution, projection, success, failure) {
* var proj = projection.getCode();
* var url = 'https://ahocevar.com/geoserver/wfs?service=WFS&' +
* const proj = projection.getCode();
* const url = 'https://ahocevar.com/geoserver/wfs?service=WFS&' +
* 'version=1.1.0&request=GetFeature&typename=osm:water_areas&' +
* 'outputFormat=application/json&srsname=' + proj + '&' +
* 'bbox=' + extent.join(',') + ',' + proj;
* var xhr = new XMLHttpRequest();
* const xhr = new XMLHttpRequest();
* xhr.open('GET', url);
* var onError = function() {
* const onError = function() {
* vectorSource.removeLoadedExtent(extent);
* failure();
* }
* xhr.onerror = onError;
* xhr.onload = function() {
* if (xhr.status == 200) {
* var features = vectorSource.getFormat().readFeatures(xhr.responseText);
* const features = vectorSource.getFormat().readFeatures(xhr.responseText);
* vectorSource.addFeatures(features);
* success(features);
* } else {
@@ -116,7 +116,7 @@ export class VectorSourceEvent extends Event {
* }
* xhr.send();
* },
* strategy: bbox
* strategy: bbox,
* });
* ```
* @property {boolean} [overlaps=true] This source may have overlapping geometries.