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:
+43
-44
@@ -30,11 +30,11 @@ import RenderFeature from '../render/Feature.js';
|
||||
* @param {olx.format.MVTOptions=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
var MVT = function(opt_options) {
|
||||
const MVT = function(opt_options) {
|
||||
|
||||
FeatureFormat.call(this);
|
||||
|
||||
var options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
/**
|
||||
* @type {ol.proj.Projection}
|
||||
@@ -89,12 +89,12 @@ inherits(MVT, FeatureFormat);
|
||||
MVT.pbfReaders_ = {
|
||||
layers: function(tag, layers, pbf) {
|
||||
if (tag === 3) {
|
||||
var layer = {
|
||||
const layer = {
|
||||
keys: [],
|
||||
values: [],
|
||||
features: []
|
||||
};
|
||||
var end = pbf.readVarint() + pbf.pos;
|
||||
const end = pbf.readVarint() + pbf.pos;
|
||||
pbf.readFields(MVT.pbfReaders_.layer, layer, end);
|
||||
layer.length = layer.features.length;
|
||||
if (layer.length) {
|
||||
@@ -114,8 +114,8 @@ MVT.pbfReaders_ = {
|
||||
} else if (tag === 3) {
|
||||
layer.keys.push(pbf.readString());
|
||||
} else if (tag === 4) {
|
||||
var value = null;
|
||||
var end = pbf.readVarint() + pbf.pos;
|
||||
let value = null;
|
||||
const end = pbf.readVarint() + pbf.pos;
|
||||
while (pbf.pos < end) {
|
||||
tag = pbf.readVarint() >> 3;
|
||||
value = tag === 1 ? pbf.readString() :
|
||||
@@ -133,10 +133,10 @@ MVT.pbfReaders_ = {
|
||||
if (tag == 1) {
|
||||
feature.id = pbf.readVarint();
|
||||
} else if (tag == 2) {
|
||||
var end = pbf.readVarint() + pbf.pos;
|
||||
const end = pbf.readVarint() + pbf.pos;
|
||||
while (pbf.pos < end) {
|
||||
var key = feature.layer.keys[pbf.readVarint()];
|
||||
var value = feature.layer.values[pbf.readVarint()];
|
||||
const key = feature.layer.keys[pbf.readVarint()];
|
||||
const value = feature.layer.values[pbf.readVarint()];
|
||||
feature.properties[key] = value;
|
||||
}
|
||||
} else if (tag == 3) {
|
||||
@@ -159,9 +159,9 @@ MVT.pbfReaders_ = {
|
||||
*/
|
||||
MVT.readRawFeature_ = function(pbf, layer, i) {
|
||||
pbf.pos = layer.features[i];
|
||||
var end = pbf.readVarint() + pbf.pos;
|
||||
const end = pbf.readVarint() + pbf.pos;
|
||||
|
||||
var feature = {
|
||||
const feature = {
|
||||
layer: layer,
|
||||
type: 0,
|
||||
properties: {}
|
||||
@@ -184,17 +184,17 @@ MVT.readRawFeature_ = function(pbf, layer, i) {
|
||||
MVT.readRawGeometry_ = function(pbf, feature, flatCoordinates, ends) {
|
||||
pbf.pos = feature.geometry;
|
||||
|
||||
var end = pbf.readVarint() + pbf.pos;
|
||||
var cmd = 1;
|
||||
var length = 0;
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
var coordsLen = 0;
|
||||
var currentEnd = 0;
|
||||
const end = pbf.readVarint() + pbf.pos;
|
||||
let cmd = 1;
|
||||
let length = 0;
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
let coordsLen = 0;
|
||||
let currentEnd = 0;
|
||||
|
||||
while (pbf.pos < end) {
|
||||
if (!length) {
|
||||
var cmdLen = pbf.readVarint();
|
||||
const cmdLen = pbf.readVarint();
|
||||
cmd = cmdLen & 0x7;
|
||||
length = cmdLen >> 3;
|
||||
}
|
||||
@@ -220,7 +220,7 @@ MVT.readRawGeometry_ = function(pbf, feature, flatCoordinates, ends) {
|
||||
if (coordsLen > currentEnd) {
|
||||
// close polygon
|
||||
flatCoordinates.push(
|
||||
flatCoordinates[currentEnd], flatCoordinates[currentEnd + 1]);
|
||||
flatCoordinates[currentEnd], flatCoordinates[currentEnd + 1]);
|
||||
coordsLen += 2;
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ MVT.readRawGeometry_ = function(pbf, feature, flatCoordinates, ends) {
|
||||
*/
|
||||
MVT.getGeometryType_ = function(type, numEnds) {
|
||||
/** @type {ol.geom.GeometryType} */
|
||||
var geometryType;
|
||||
let geometryType;
|
||||
if (type === 1) {
|
||||
geometryType = numEnds === 1 ?
|
||||
GeometryType.POINT : GeometryType.MULTI_POINT;
|
||||
@@ -271,32 +271,32 @@ MVT.getGeometryType_ = function(type, numEnds) {
|
||||
* @return {ol.Feature|ol.render.Feature} Feature.
|
||||
*/
|
||||
MVT.prototype.createFeature_ = function(pbf, rawFeature, opt_options) {
|
||||
var type = rawFeature.type;
|
||||
const type = rawFeature.type;
|
||||
if (type === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var feature;
|
||||
var id = rawFeature.id;
|
||||
var values = rawFeature.properties;
|
||||
let feature;
|
||||
const id = rawFeature.id;
|
||||
const values = rawFeature.properties;
|
||||
values[this.layerName_] = rawFeature.layer.name;
|
||||
|
||||
var flatCoordinates = [];
|
||||
var ends = [];
|
||||
const flatCoordinates = [];
|
||||
let ends = [];
|
||||
MVT.readRawGeometry_(pbf, rawFeature, flatCoordinates, ends);
|
||||
|
||||
var geometryType = MVT.getGeometryType_(type, ends.length);
|
||||
const geometryType = MVT.getGeometryType_(type, ends.length);
|
||||
|
||||
if (this.featureClass_ === RenderFeature) {
|
||||
feature = new this.featureClass_(geometryType, flatCoordinates, ends, values, id);
|
||||
} else {
|
||||
var geom;
|
||||
let geom;
|
||||
if (geometryType == GeometryType.POLYGON) {
|
||||
var endss = [];
|
||||
var offset = 0;
|
||||
var prevEndIndex = 0;
|
||||
for (var i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
const endss = [];
|
||||
let offset = 0;
|
||||
let prevEndIndex = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
if (!_ol_geom_flat_orient_.linearRingIsClockwise(flatCoordinates, offset, end, 2)) {
|
||||
endss.push(ends.slice(prevEndIndex, i));
|
||||
prevEndIndex = i;
|
||||
@@ -322,7 +322,7 @@ MVT.prototype.createFeature_ = function(pbf, rawFeature, opt_options) {
|
||||
if (this.geometryName_) {
|
||||
feature.setGeometryName(this.geometryName_);
|
||||
}
|
||||
var geometry = transformWithOptions(geom, false, this.adaptOptions(opt_options));
|
||||
const geometry = transformWithOptions(geom, false, this.adaptOptions(opt_options));
|
||||
feature.setGeometry(geometry);
|
||||
feature.setId(id);
|
||||
feature.setProperties(values);
|
||||
@@ -354,22 +354,21 @@ MVT.prototype.getType = function() {
|
||||
* @api
|
||||
*/
|
||||
MVT.prototype.readFeatures = function(source, opt_options) {
|
||||
var layers = this.layers_;
|
||||
const layers = this.layers_;
|
||||
|
||||
var pbf = new PBF(/** @type {ArrayBuffer} */ (source));
|
||||
var pbfLayers = pbf.readFields(MVT.pbfReaders_.layers, {});
|
||||
const pbf = new PBF(/** @type {ArrayBuffer} */ (source));
|
||||
const pbfLayers = pbf.readFields(MVT.pbfReaders_.layers, {});
|
||||
/** @type {Array.<ol.Feature|ol.render.Feature>} */
|
||||
var features = [];
|
||||
var pbfLayer;
|
||||
for (var name in pbfLayers) {
|
||||
const features = [];
|
||||
let pbfLayer;
|
||||
for (const name in pbfLayers) {
|
||||
if (layers && layers.indexOf(name) == -1) {
|
||||
continue;
|
||||
}
|
||||
pbfLayer = pbfLayers[name];
|
||||
|
||||
var rawFeature;
|
||||
for (var i = 0, ii = pbfLayer.length; i < ii; ++i) {
|
||||
rawFeature = MVT.readRawFeature_(pbf, pbfLayer, i);
|
||||
for (let i = 0, ii = pbfLayer.length; i < ii; ++i) {
|
||||
const rawFeature = MVT.readRawFeature_(pbf, pbfLayer, i);
|
||||
features.push(this.createFeature_(pbf, rawFeature));
|
||||
}
|
||||
this.extent_ = pbfLayer ? [0, 0, pbfLayer.extent, pbfLayer.extent] : null;
|
||||
|
||||
Reference in New Issue
Block a user