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
+16 -16
View File
@@ -33,17 +33,17 @@ Below you'll find a complete working example. Create a new file, copy in the co
<h2>My Map</h2>
<div id="map" class="map"></div>
<script type="text/javascript">
var map = new ol.Map({
const map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
source: new ol.source.OSM(),
}),
],
view: new ol.View({
center: ol.proj.fromLonLat([37.41, 8.82]),
zoom: 4
})
zoom: 4,
}),
});
</script>
</body>
@@ -93,17 +93,17 @@ The map in the application is contained in a [`<div>` HTML element](https://en.w
### JavaScript to create a simple map
```js
var map = new ol.Map({
const map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
source: new ol.source.OSM(),
}),
],
view: new ol.View({
center: ol.proj.fromLonLat([37.41, 8.82]),
zoom: 4
})
zoom: 4,
}),
});
```
@@ -112,7 +112,7 @@ With this JavaScript code, a map object is created with an OSM layer zoomed on t
The following line creates an OpenLayers `Map` object. Just by itself, this does nothing since there's no layers or interaction attached to it.
```js
var map = new ol.Map({ ... });
const map = new ol.Map({ ... });
```
To attach the map object to the `<div>`, the map object takes a `target` into arguments. The value is the `id` of the `<div>`:
@@ -126,9 +126,9 @@ The `layers: [ ... ]` array is used to define the list of layers available in th
```js
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
]
source: new ol.source.OSM(),
}),
],
```
Layers in OpenLayers are defined with a type (Image, Tile or Vector) which contains a source. The source is the protocol used to get the map tiles.
@@ -138,8 +138,8 @@ The next part of the `Map` object is the `View`. The view allows to specify the
```js
view: new ol.View({
center: ol.proj.fromLonLat([37.41, 8.82]),
zoom: 4
})
zoom: 4,
}),
```
You will notice that the `center` specified is in lon/lat coordinates (EPSG:4326). Since the only layer we use is in Spherical Mercator projection (EPSG:3857), we can reproject them on the fly to be able to zoom the map on the right coordinates.
+8 -7
View File
@@ -20,7 +20,7 @@ The script below constructs a map that is rendered in the `<div>` above, using t
```js
import Map from 'ol/Map';
var map = new Map({target: 'map'});
const map = new Map({target: 'map'});
```
## View
@@ -32,7 +32,7 @@ import View from 'ol/View';
map.setView(new View({
center: [0, 0],
zoom: 2
zoom: 2,
}));
```
@@ -48,7 +48,7 @@ To get remote data for a layer, OpenLayers uses `ol/source/Source` subclasses. T
```js
import OSM from 'ol/source/OSM';
var osmSource = OSM();
const osmSource = OSM();
```
## Layer
@@ -63,7 +63,8 @@ A layer is a visual representation of data from a `source`. OpenLayers has four
```js
import TileLayer from 'ol/layer/Tile';
var osmLayer = new TileLayer({source: osmSource});
// ...
const osmLayer = new TileLayer({source: osmSource});
map.addLayer(osmLayer);
```
@@ -79,12 +80,12 @@ import TileLayer from 'ol/layer/Tile';
new Map({
layers: [
new TileLayer({source: new OSM()})
new TileLayer({source: new OSM()}),
],
view: new View({
center: [0, 0],
zoom: 2
zoom: 2,
}),
target: 'map'
target: 'map',
});
```
+9 -9
View File
@@ -16,12 +16,12 @@ import {Map, View} from 'ol';
import TileLayer from 'ol/layer/Tile';
import TileWMS from 'ol/source/TileWMS';
var map = new Map({
const map = new Map({
target: 'map',
view: new View({
projection: 'EPSG:3857', //HERE IS THE VIEW PROJECTION
center: [0, 0],
zoom: 2
zoom: 2,
}),
layers: [
new TileLayer({
@@ -29,11 +29,11 @@ var map = new Map({
projection: 'EPSG:4326', //HERE IS THE DATA SOURCE PROJECTION
url: 'https://ahocevar.com/geoserver/wms',
params: {
'LAYERS': 'ne:NE1_HR_LC_SR_W_DR'
}
})
})
]
'LAYERS': 'ne:NE1_HR_LC_SR_W_DR',
},
}),
}),
],
});
```
If a source (based on `ol/source/TileImage` or `ol/source/Image`) has a projection different from the current `ol/View`s projection then the reprojection happens automatically under the hood.
@@ -60,7 +60,7 @@ proj4.defs('EPSG:27700', '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 ' +
'+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' +
'+units=m +no_defs');
register(proj4);
var proj27700 = getProjection('EPSG:27700');
const proj27700 = getProjection('EPSG:27700');
proj27700.setExtent([0, 0, 700000, 1300000]);
```
@@ -70,7 +70,7 @@ To switch the projection used to display the map you have to set a new `ol/View`
map.setView(new View({
projection: 'EPSG:27700',
center: [400000, 650000],
zoom: 4
zoom: 4,
}));
```