Use blocked scoped variables
In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
@@ -10,22 +10,22 @@ import Fill from '../src/ol/style/Fill.js';
|
||||
import Stroke from '../src/ol/style/Stroke.js';
|
||||
import Style from '../src/ol/style/Style.js';
|
||||
|
||||
var canvas = document.createElement('canvas');
|
||||
var context = canvas.getContext('2d');
|
||||
const canvas = document.createElement('canvas');
|
||||
const context = canvas.getContext('2d');
|
||||
|
||||
// Gradient and pattern are in canvas pixel space, so we adjust for the
|
||||
// renderer's pixel ratio
|
||||
var pixelRatio = _ol_has_.DEVICE_PIXEL_RATIO;
|
||||
const pixelRatio = _ol_has_.DEVICE_PIXEL_RATIO;
|
||||
|
||||
// Generate a rainbow gradient
|
||||
function gradient(feature, resolution) {
|
||||
var extent = feature.getGeometry().getExtent();
|
||||
const extent = feature.getGeometry().getExtent();
|
||||
// Gradient starts on the left edge of each feature, and ends on the right.
|
||||
// Coordinate origin is the top-left corner of the extent of the geometry, so
|
||||
// we just divide the geometry's extent width by resolution and multiply with
|
||||
// pixelRatio to match the renderer's pixel coordinate system.
|
||||
var grad = context.createLinearGradient(0, 0,
|
||||
_ol_extent_.getWidth(extent) / resolution * pixelRatio, 0);
|
||||
const grad = context.createLinearGradient(0, 0,
|
||||
_ol_extent_.getWidth(extent) / resolution * pixelRatio, 0);
|
||||
grad.addColorStop(0, 'red');
|
||||
grad.addColorStop(1 / 6, 'orange');
|
||||
grad.addColorStop(2 / 6, 'yellow');
|
||||
@@ -37,7 +37,7 @@ function gradient(feature, resolution) {
|
||||
}
|
||||
|
||||
// Generate a canvasPattern with two circles on white background
|
||||
var pattern = (function() {
|
||||
const pattern = (function() {
|
||||
canvas.width = 11 * pixelRatio;
|
||||
canvas.height = 11 * pixelRatio;
|
||||
// white background
|
||||
@@ -57,8 +57,8 @@ var pattern = (function() {
|
||||
}());
|
||||
|
||||
// Generate style for gradient or pattern fill
|
||||
var fill = new Fill();
|
||||
var style = new Style({
|
||||
const fill = new Fill();
|
||||
const style = new Style({
|
||||
fill: fill,
|
||||
stroke: new Stroke({
|
||||
color: '#333',
|
||||
@@ -74,14 +74,14 @@ var style = new Style({
|
||||
* @param {number} resolution Resolution.
|
||||
* @return {ol.style.Style} The style to use for the feature.
|
||||
*/
|
||||
var getStackedStyle = function(feature, resolution) {
|
||||
var id = feature.getId();
|
||||
const getStackedStyle = function(feature, resolution) {
|
||||
const id = feature.getId();
|
||||
fill.setColor(id > 'J' ? gradient(feature, resolution) : pattern);
|
||||
return style;
|
||||
};
|
||||
|
||||
// Create a vector layer that makes use of the style function above…
|
||||
var vectorLayer = new VectorLayer({
|
||||
const vectorLayer = new VectorLayer({
|
||||
source: new VectorSource({
|
||||
url: 'data/geojson/countries.geojson',
|
||||
format: new GeoJSON()
|
||||
@@ -90,7 +90,7 @@ var vectorLayer = new VectorLayer({
|
||||
});
|
||||
|
||||
// … finally create a map with that layer.
|
||||
var map = new Map({
|
||||
const map = new Map({
|
||||
layers: [
|
||||
vectorLayer
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user