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:
Tim Schaub
2018-01-11 23:32:36 -07:00
parent 0bf2b04dee
commit ad62739a6e
684 changed files with 18120 additions and 18184 deletions

View File

@@ -13,12 +13,12 @@ import {fromLonLat, get as getProjection, toLonLat, transform} from '../../../..
describe('ol.format.GeoJSON', function() {
var format;
let format;
beforeEach(function() {
format = new GeoJSON();
});
var pointGeoJSON = {
const pointGeoJSON = {
'type': 'Feature',
'geometry': {
'type': 'Point',
@@ -29,7 +29,7 @@ describe('ol.format.GeoJSON', function() {
}
};
var nullGeometryGeoJSON = {
const nullGeometryGeoJSON = {
'type': 'Feature',
'geometry': null,
'properties': {
@@ -37,7 +37,7 @@ describe('ol.format.GeoJSON', function() {
}
};
var zeroIdGeoJSON = {
const zeroIdGeoJSON = {
'type': 'Feature',
'id': 0,
'geometry': null,
@@ -46,7 +46,7 @@ describe('ol.format.GeoJSON', function() {
}
};
var lineStringGeoJSON = {
const lineStringGeoJSON = {
'type': 'Feature',
'geometry': {
'type': 'LineString',
@@ -60,7 +60,7 @@ describe('ol.format.GeoJSON', function() {
}
};
var polygonGeoJSON = {
const polygonGeoJSON = {
'type': 'Feature',
'geometry': {
'type': 'Polygon',
@@ -74,12 +74,12 @@ describe('ol.format.GeoJSON', function() {
}
};
var featureCollectionGeoJSON = {
const featureCollectionGeoJSON = {
'type': 'FeatureCollection',
'features': [pointGeoJSON, lineStringGeoJSON, polygonGeoJSON]
};
var data = {
const data = {
'type': 'FeatureCollection',
'features': [{
'type': 'Feature',
@@ -144,37 +144,37 @@ describe('ol.format.GeoJSON', function() {
describe('#readFeature', function() {
it('can read a single point feature', function() {
var feature = format.readFeature(pointGeoJSON);
const feature = format.readFeature(pointGeoJSON);
expect(feature).to.be.an(Feature);
var geometry = feature.getGeometry();
const geometry = feature.getGeometry();
expect(geometry).to.be.an(Point);
expect(geometry.getCoordinates()).to.eql([102.0, 0.5]);
expect(feature.get('prop0')).to.be('value0');
});
it('can read a single point geometry as a feature', function() {
var feature = format.readFeature(pointGeoJSON.geometry);
const feature = format.readFeature(pointGeoJSON.geometry);
expect(feature).to.be.an(Feature);
var geometry = feature.getGeometry();
const geometry = feature.getGeometry();
expect(geometry).to.be.an(Point);
expect(geometry.getCoordinates()).to.eql([102.0, 0.5]);
});
it('can read a single line string feature', function() {
var feature = format.readFeature(lineStringGeoJSON);
const feature = format.readFeature(lineStringGeoJSON);
expect(feature).to.be.an(Feature);
var geometry = feature.getGeometry();
const geometry = feature.getGeometry();
expect(geometry).to.be.an(LineString);
expect(geometry.getCoordinates()).to.eql(
[[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]]);
[[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]]);
expect(feature.get('prop0')).to.be('value0');
expect(feature.get('prop1')).to.be(0.0);
});
it('can read a single polygon feature', function() {
var feature = format.readFeature(polygonGeoJSON);
const feature = format.readFeature(polygonGeoJSON);
expect(feature).to.be.an(Feature);
var geometry = feature.getGeometry();
const geometry = feature.getGeometry();
expect(geometry).to.be.an(Polygon);
expect(geometry.getCoordinates()).to.eql([[
[100.0, 0.0], [100.0, 1.0], [101.0, 1.0], [101.0, 0.0]
@@ -184,21 +184,21 @@ describe('ol.format.GeoJSON', function() {
});
it('can read a feature with null geometry', function() {
var feature = format.readFeature(nullGeometryGeoJSON);
const feature = format.readFeature(nullGeometryGeoJSON);
expect(feature).to.be.an(Feature);
var geometry = feature.getGeometry();
const geometry = feature.getGeometry();
expect(geometry).to.eql(null);
expect(feature.get('prop0')).to.be('value0');
});
it('can read a feature with id equal to 0', function() {
var feature = format.readFeature(zeroIdGeoJSON);
const feature = format.readFeature(zeroIdGeoJSON);
expect(feature).to.be.an(Feature);
expect(feature.getId()).to.be(0);
});
it('can read a feature collection', function() {
var features = format.readFeatures(featureCollectionGeoJSON);
const features = format.readFeatures(featureCollectionGeoJSON);
expect(features).to.have.length(3);
expect(features[0].getGeometry()).to.be.an(Point);
expect(features[1].getGeometry()).to.be.an(LineString);
@@ -206,39 +206,39 @@ describe('ol.format.GeoJSON', function() {
});
it('can read and transform a point', function() {
var feature = format.readFeatures(pointGeoJSON, {
const feature = format.readFeatures(pointGeoJSON, {
featureProjection: 'EPSG:3857'
});
expect(feature[0].getGeometry()).to.be.an(Point);
expect(feature[0].getGeometry().getCoordinates()).to.eql(
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
});
it('uses featureProjection passed to the constructor', function() {
var format = new GeoJSON({featureProjection: 'EPSG:3857'});
var feature = format.readFeatures(pointGeoJSON);
const format = new GeoJSON({featureProjection: 'EPSG:3857'});
const feature = format.readFeatures(pointGeoJSON);
expect(feature[0].getGeometry()).to.be.an(Point);
expect(feature[0].getGeometry().getCoordinates()).to.eql(
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
});
it('gives precedence to options passed to the read method', function() {
var format = new GeoJSON({featureProjection: 'EPSG:1234'});
var feature = format.readFeatures(pointGeoJSON, {
const format = new GeoJSON({featureProjection: 'EPSG:1234'});
const feature = format.readFeatures(pointGeoJSON, {
featureProjection: 'EPSG:3857'
});
expect(feature[0].getGeometry()).to.be.an(Point);
expect(feature[0].getGeometry().getCoordinates()).to.eql(
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
});
it('can read and transform a feature collection', function() {
var features = format.readFeatures(featureCollectionGeoJSON, {
const features = format.readFeatures(featureCollectionGeoJSON, {
featureProjection: 'EPSG:3857'
});
expect(features[0].getGeometry()).to.be.an(Point);
expect(features[0].getGeometry().getCoordinates()).to.eql(
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
expect(features[1].getGeometry().getCoordinates()).to.eql([
transform([102.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([103.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
@@ -254,8 +254,8 @@ describe('ol.format.GeoJSON', function() {
});
it('can create a feature with a specific geometryName', function() {
var feature = new GeoJSON({geometryName: 'the_geom'}).
readFeature(pointGeoJSON);
const feature = new GeoJSON({geometryName: 'the_geom'}).
readFeature(pointGeoJSON);
expect(feature.getGeometryName()).to.be('the_geom');
expect(feature.getGeometry()).to.be.an(Point);
});
@@ -265,56 +265,56 @@ describe('ol.format.GeoJSON', function() {
describe('#readFeatures', function() {
it('parses feature collection', function() {
var str = JSON.stringify(data);
var array = format.readFeatures(str);
const str = JSON.stringify(data);
const array = format.readFeatures(str);
expect(array.length).to.be(2);
var first = array[0];
const first = array[0];
expect(first).to.be.a(Feature);
expect(first.get('LINK_ID')).to.be(573730499);
var firstGeom = first.getGeometry();
const firstGeom = first.getGeometry();
expect(firstGeom).to.be.a(LineString);
var second = array[1];
const second = array[1];
expect(second).to.be.a(Feature);
expect(second.get('ST_NAME')).to.be('BRUNNSGATAN');
var secondGeom = second.getGeometry();
const secondGeom = second.getGeometry();
expect(secondGeom).to.be.a(LineString);
});
it('can parse a polygon geometry as an array of one feature', function() {
var features = format.readFeatures(polygonGeoJSON);
const features = format.readFeatures(polygonGeoJSON);
expect(features).to.be.an(Array);
expect(features).to.have.length(1);
var geometry = features[0].getGeometry();
const geometry = features[0].getGeometry();
expect(geometry).to.be.an(Polygon);
});
it('parses countries.geojson', function(done) {
afterLoadText('spec/ol/format/geojson/countries.geojson', function(text) {
var result = format.readFeatures(text);
const result = format.readFeatures(text);
expect(result.length).to.be(179);
var first = result[0];
const first = result[0];
expect(first).to.be.a(Feature);
expect(first.get('name')).to.be('Afghanistan');
expect(first.getId()).to.be('AFG');
var firstGeom = first.getGeometry();
const firstGeom = first.getGeometry();
expect(firstGeom).to.be.a(Polygon);
expect(_ol_extent_.equals(firstGeom.getExtent(),
[60.52843, 29.318572, 75.158028, 38.486282]))
.to.be(true);
[60.52843, 29.318572, 75.158028, 38.486282]))
.to.be(true);
var last = result[178];
const last = result[178];
expect(last).to.be.a(Feature);
expect(last.get('name')).to.be('Zimbabwe');
expect(last.getId()).to.be('ZWE');
var lastGeom = last.getGeometry();
const lastGeom = last.getGeometry();
expect(lastGeom).to.be.a(Polygon);
expect(_ol_extent_.equals(lastGeom.getExtent(),
[25.264226, -22.271612, 32.849861, -15.507787]))
.to.be(true);
[25.264226, -22.271612, 32.849861, -15.507787]))
.to.be(true);
done();
});
@@ -322,8 +322,8 @@ describe('ol.format.GeoJSON', function() {
it('generates an array of features for Feature', function() {
var format = new GeoJSON();
var json = {
const format = new GeoJSON();
const json = {
type: 'Feature',
properties: {
bam: 'baz'
@@ -333,11 +333,11 @@ describe('ol.format.GeoJSON', function() {
coordinates: [[1, 2], [3, 4]]
}
};
var features = format.readFeatures(json);
const features = format.readFeatures(json);
expect(features.length).to.be(1);
var first = features[0];
const first = features[0];
expect(first).to.be.a(Feature);
expect(first.get('bam')).to.be('baz');
expect(first.getGeometry()).to.be.a(LineString);
@@ -350,54 +350,54 @@ describe('ol.format.GeoJSON', function() {
describe('#readGeometry', function() {
it('parses point', function() {
var str = JSON.stringify({
const str = JSON.stringify({
type: 'Point',
coordinates: [10, 20]
});
var obj = format.readGeometry(str);
const obj = format.readGeometry(str);
expect(obj).to.be.a(Point);
expect(obj.getCoordinates()).to.eql([10, 20]);
expect(obj.getLayout()).to.eql('XY');
});
it('parses linestring', function() {
var str = JSON.stringify({
const str = JSON.stringify({
type: 'LineString',
coordinates: [[10, 20], [30, 40]]
});
var obj = format.readGeometry(str);
const obj = format.readGeometry(str);
expect(obj).to.be.a(LineString);
expect(obj.getCoordinates()).to.eql([[10, 20], [30, 40]]);
expect(obj.getLayout()).to.eql('XY');
});
it('parses XYZ linestring', function() {
var str = JSON.stringify({
const str = JSON.stringify({
type: 'LineString',
coordinates: [[10, 20, 1534], [30, 40, 1420]]
});
var obj = format.readGeometry(str);
const obj = format.readGeometry(str);
expect(obj).to.be.a(LineString);
expect(obj.getLayout()).to.eql('XYZ');
expect(obj.getCoordinates()).to.eql([[10, 20, 1534], [30, 40, 1420]]);
});
it('parses polygon', function() {
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
var inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]];
var inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
var str = JSON.stringify({
const outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
const inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]];
const inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
const str = JSON.stringify({
type: 'Polygon',
coordinates: [outer, inner1, inner2]
});
var obj = format.readGeometry(str);
const obj = format.readGeometry(str);
expect(obj).to.be.a(Polygon);
expect(obj.getLayout()).to.eql('XY');
var rings = obj.getLinearRings();
const rings = obj.getLinearRings();
expect(rings.length).to.be(3);
expect(rings[0]).to.be.a(LinearRing);
expect(rings[1]).to.be.a(LinearRing);
@@ -405,7 +405,7 @@ describe('ol.format.GeoJSON', function() {
});
it('parses geometry collection', function() {
var str = JSON.stringify({
const str = JSON.stringify({
type: 'GeometryCollection',
geometries: [
{type: 'Point', coordinates: [10, 20]},
@@ -413,9 +413,9 @@ describe('ol.format.GeoJSON', function() {
]
});
var geometryCollection = format.readGeometry(str);
const geometryCollection = format.readGeometry(str);
expect(geometryCollection).to.be.an(GeometryCollection);
var array = geometryCollection.getGeometries();
const array = geometryCollection.getGeometries();
expect(array.length).to.be(2);
expect(array[0]).to.be.a(Point);
expect(array[0].getLayout()).to.eql('XY');
@@ -429,7 +429,7 @@ describe('ol.format.GeoJSON', function() {
it('reads named crs from top-level object', function() {
var json = {
const json = {
type: 'FeatureCollection',
crs: {
type: 'name',
@@ -457,16 +457,16 @@ describe('ol.format.GeoJSON', function() {
}
}]
};
var features = format.readFeatures(json);
const features = format.readFeatures(json);
expect(features.length).to.be(2);
var first = features[0];
const first = features[0];
expect(first).to.be.a(Feature);
expect(first.get('foo')).to.be('bar');
expect(first.getGeometry()).to.be.a(Point);
var second = features[1];
const second = features[1];
expect(second).to.be.a(Feature);
expect(second.get('bam')).to.be('baz');
expect(second.getGeometry()).to.be.a(LineString);
@@ -477,7 +477,7 @@ describe('ol.format.GeoJSON', function() {
it('accepts null crs', function() {
var json = {
const json = {
type: 'FeatureCollection',
crs: null,
features: [{
@@ -500,16 +500,16 @@ describe('ol.format.GeoJSON', function() {
}
}]
};
var features = format.readFeatures(json);
const features = format.readFeatures(json);
expect(features.length).to.be(2);
var first = features[0];
const first = features[0];
expect(first).to.be.a(Feature);
expect(first.get('foo')).to.be('bar');
expect(first.getGeometry()).to.be.a(Point);
var second = features[1];
const second = features[1];
expect(second).to.be.a(Feature);
expect(second.get('bam')).to.be('baz');
expect(second.getGeometry()).to.be.a(LineString);
@@ -523,17 +523,17 @@ describe('ol.format.GeoJSON', function() {
describe('#writeFeatures', function() {
it('encodes feature collection', function() {
var str = JSON.stringify(data);
var array = format.readFeatures(str);
var geojson = format.writeFeaturesObject(array);
var result = format.readFeatures(geojson);
const str = JSON.stringify(data);
const array = format.readFeatures(str);
const geojson = format.writeFeaturesObject(array);
const result = format.readFeatures(geojson);
expect(array.length).to.equal(result.length);
var got, exp, gotProp, expProp;
for (var i = 0, ii = array.length; i < ii; ++i) {
let got, exp, gotProp, expProp;
for (let i = 0, ii = array.length; i < ii; ++i) {
got = array[i];
exp = result[i];
expect(got.getGeometry().getCoordinates()).to.eql(
exp.getGeometry().getCoordinates());
exp.getGeometry().getCoordinates());
gotProp = got.getProperties();
delete gotProp.geometry;
expProp = exp.getProperties();
@@ -543,46 +543,46 @@ describe('ol.format.GeoJSON', function() {
});
it('transforms and encodes feature collection', function() {
var str = JSON.stringify(data);
var array = format.readFeatures(str);
var geojson = format.writeFeatures(array, {
const str = JSON.stringify(data);
const array = format.readFeatures(str);
const geojson = format.writeFeatures(array, {
featureProjection: 'EPSG:3857'
});
var result = format.readFeatures(geojson);
var got, exp;
for (var i = 0, ii = array.length; i < ii; ++i) {
const result = format.readFeatures(geojson);
let got, exp;
for (let i = 0, ii = array.length; i < ii; ++i) {
got = array[i];
exp = result[i];
expect(got.getGeometry().transform('EPSG:3857', 'EPSG:4326')
.getCoordinates()).to.eql(exp.getGeometry().getCoordinates());
.getCoordinates()).to.eql(exp.getGeometry().getCoordinates());
}
});
it('writes out a feature with a different geometryName correctly',
function() {
var feature = new Feature({'foo': 'bar'});
feature.setGeometryName('mygeom');
feature.setGeometry(new Point([5, 10]));
var geojson = format.writeFeaturesObject([feature]);
expect(geojson.features[0].properties.mygeom).to.eql(undefined);
});
function() {
const feature = new Feature({'foo': 'bar'});
feature.setGeometryName('mygeom');
feature.setGeometry(new Point([5, 10]));
const geojson = format.writeFeaturesObject([feature]);
expect(geojson.features[0].properties.mygeom).to.eql(undefined);
});
it('writes out a feature without properties correctly', function() {
var feature = new Feature(new Point([5, 10]));
var geojson = format.writeFeatureObject(feature);
const feature = new Feature(new Point([5, 10]));
const geojson = format.writeFeatureObject(feature);
expect(geojson.properties).to.eql(null);
});
it('writes out a feature without geometry correctly', function() {
var feature = new Feature();
var geojson = format.writeFeatureObject(feature);
const feature = new Feature();
const geojson = format.writeFeatureObject(feature);
expect(geojson.geometry).to.eql(null);
});
it('writes out a feature with id equal to 0 correctly', function() {
var feature = new Feature();
const feature = new Feature();
feature.setId(0);
var geojson = format.writeFeatureObject(feature);
const geojson = format.writeFeatureObject(feature);
expect(geojson.id).to.eql(0);
});
});
@@ -590,77 +590,77 @@ describe('ol.format.GeoJSON', function() {
describe('#writeGeometry', function() {
it('encodes point', function() {
var point = new Point([10, 20]);
var geojson = format.writeGeometry(point);
const point = new Point([10, 20]);
const geojson = format.writeGeometry(point);
expect(point.getCoordinates()).to.eql(
format.readGeometry(geojson).getCoordinates());
format.readGeometry(geojson).getCoordinates());
});
it('accepts featureProjection', function() {
var point = new Point(fromLonLat([10, 20]));
var geojson = format.writeGeometry(point, {featureProjection: 'EPSG:3857'});
var obj = JSON.parse(geojson);
const point = new Point(fromLonLat([10, 20]));
const geojson = format.writeGeometry(point, {featureProjection: 'EPSG:3857'});
const obj = JSON.parse(geojson);
expect(obj.coordinates).to.eql(toLonLat(point.getCoordinates()));
});
it('respects featureProjection passed to constructor', function() {
var format = new GeoJSON({featureProjection: 'EPSG:3857'});
var point = new Point(fromLonLat([10, 20]));
var geojson = format.writeGeometry(point);
var obj = JSON.parse(geojson);
const format = new GeoJSON({featureProjection: 'EPSG:3857'});
const point = new Point(fromLonLat([10, 20]));
const geojson = format.writeGeometry(point);
const obj = JSON.parse(geojson);
expect(obj.coordinates).to.eql(toLonLat(point.getCoordinates()));
});
it('encodes linestring', function() {
var linestring = new LineString([[10, 20], [30, 40]]);
var geojson = format.writeGeometry(linestring);
const linestring = new LineString([[10, 20], [30, 40]]);
const geojson = format.writeGeometry(linestring);
expect(linestring.getCoordinates()).to.eql(
format.readGeometry(geojson).getCoordinates());
format.readGeometry(geojson).getCoordinates());
});
it('encodes polygon', function() {
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
var inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]];
var inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
var polygon = new Polygon([outer, inner1, inner2]);
var geojson = format.writeGeometry(polygon);
const outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
const inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]];
const inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
const polygon = new Polygon([outer, inner1, inner2]);
const geojson = format.writeGeometry(polygon);
expect(polygon.getCoordinates()).to.eql(
format.readGeometry(geojson).getCoordinates());
format.readGeometry(geojson).getCoordinates());
});
it('maintains coordinate order by default', function() {
var cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
var ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
const cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
const ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
var right = new Polygon([ccw, cw]);
var rightMulti = new MultiPolygon([[ccw, cw]]);
var left = new Polygon([cw, ccw]);
var leftMulti = new MultiPolygon([[cw, ccw]]);
const right = new Polygon([ccw, cw]);
const rightMulti = new MultiPolygon([[ccw, cw]]);
const left = new Polygon([cw, ccw]);
const leftMulti = new MultiPolygon([[cw, ccw]]);
var rightObj = {
const rightObj = {
type: 'Polygon',
coordinates: [ccw, cw]
};
var rightMultiObj = {
const rightMultiObj = {
type: 'MultiPolygon',
coordinates: [[ccw, cw]]
};
var leftObj = {
const leftObj = {
type: 'Polygon',
coordinates: [cw, ccw]
};
var leftMultiObj = {
const leftMultiObj = {
type: 'MultiPolygon',
coordinates: [[cw, ccw]]
};
expect(JSON.parse(format.writeGeometry(right))).to.eql(rightObj);
expect(
JSON.parse(format.writeGeometry(rightMulti))).to.eql(rightMultiObj);
JSON.parse(format.writeGeometry(rightMulti))).to.eql(rightMultiObj);
expect(JSON.parse(format.writeGeometry(left))).to.eql(leftObj);
expect(JSON.parse(format.writeGeometry(leftMulti))).to.eql(leftMultiObj);
@@ -668,24 +668,24 @@ describe('ol.format.GeoJSON', function() {
it('allows serializing following the right-hand rule', function() {
var cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
var ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
var right = new Polygon([ccw, cw]);
var rightMulti = new MultiPolygon([[ccw, cw]]);
var left = new Polygon([cw, ccw]);
var leftMulti = new MultiPolygon([[cw, ccw]]);
const cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
const ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
const right = new Polygon([ccw, cw]);
const rightMulti = new MultiPolygon([[ccw, cw]]);
const left = new Polygon([cw, ccw]);
const leftMulti = new MultiPolygon([[cw, ccw]]);
var rightObj = {
const rightObj = {
type: 'Polygon',
coordinates: [ccw, cw]
};
var rightMultiObj = {
const rightMultiObj = {
type: 'MultiPolygon',
coordinates: [[ccw, cw]]
};
var json = format.writeGeometry(right, {rightHanded: true});
let json = format.writeGeometry(right, {rightHanded: true});
expect(JSON.parse(json)).to.eql(rightObj);
json = format.writeGeometry(rightMulti, {rightHanded: true});
expect(JSON.parse(json)).to.eql(rightMultiObj);
@@ -699,24 +699,24 @@ describe('ol.format.GeoJSON', function() {
it('allows serializing following the left-hand rule', function() {
var cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
var ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
var right = new Polygon([ccw, cw]);
var rightMulti = new MultiPolygon([[ccw, cw]]);
var left = new Polygon([cw, ccw]);
var leftMulti = new MultiPolygon([[cw, ccw]]);
const cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
const ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
const right = new Polygon([ccw, cw]);
const rightMulti = new MultiPolygon([[ccw, cw]]);
const left = new Polygon([cw, ccw]);
const leftMulti = new MultiPolygon([[cw, ccw]]);
var leftObj = {
const leftObj = {
type: 'Polygon',
coordinates: [cw, ccw]
};
var leftMultiObj = {
const leftMultiObj = {
type: 'MultiPolygon',
coordinates: [[cw, ccw]]
};
var json = format.writeGeometry(right, {rightHanded: false});
let json = format.writeGeometry(right, {rightHanded: false});
expect(JSON.parse(json)).to.eql(leftObj);
json = format.writeGeometry(rightMulti, {rightHanded: false});
expect(JSON.parse(json)).to.eql(leftMultiObj);
@@ -729,26 +729,26 @@ describe('ol.format.GeoJSON', function() {
});
it('encodes geometry collection', function() {
var collection = new GeometryCollection([
const collection = new GeometryCollection([
new Point([10, 20]),
new LineString([[30, 40], [50, 60]])
]);
var geojson = format.writeGeometry(collection);
var got = format.readGeometry(geojson);
const geojson = format.writeGeometry(collection);
const got = format.readGeometry(geojson);
expect(got).to.be.an(GeometryCollection);
var gotGeometries = got.getGeometries();
var geometries = collection.getGeometries();
const gotGeometries = got.getGeometries();
const geometries = collection.getGeometries();
expect(geometries.length).to.equal(gotGeometries.length);
for (var i = 0, ii = geometries.length; i < ii; ++i) {
for (let i = 0, ii = geometries.length; i < ii; ++i) {
expect(geometries[i].getCoordinates()).
to.eql(gotGeometries[i].getCoordinates());
to.eql(gotGeometries[i].getCoordinates());
}
});
it('encodes a circle as an empty geometry collection', function() {
var circle = new Circle([0, 0], 1);
var geojson = format.writeGeometryObject(circle);
const circle = new Circle([0, 0], 1);
const geojson = format.writeGeometryObject(circle);
expect(geojson).to.eql({
'type': 'GeometryCollection',
'geometries': []
@@ -756,74 +756,74 @@ describe('ol.format.GeoJSON', function() {
});
it('transforms and encodes a point', function() {
var point = new Point([2, 3]);
var geojson = format.writeGeometry(point, {
const point = new Point([2, 3]);
const geojson = format.writeGeometry(point, {
featureProjection: 'EPSG:3857'
});
var newPoint = format.readGeometry(geojson, {
const newPoint = format.readGeometry(geojson, {
featureProjection: 'EPSG:3857'
});
expect(point.getCoordinates()[0]).to.roughlyEqual(
newPoint.getCoordinates()[0], 1e-8);
newPoint.getCoordinates()[0], 1e-8);
expect(point.getCoordinates()[1]).to.roughlyEqual(
newPoint.getCoordinates()[1], 1e-8);
newPoint.getCoordinates()[1], 1e-8);
});
it('transforms and encodes geometry collection', function() {
var collection = new GeometryCollection([
const collection = new GeometryCollection([
new Point([2, 3]),
new LineString([[3, 2], [2, 1]])
]);
var geojson = format.writeGeometry(collection, {
const geojson = format.writeGeometry(collection, {
featureProjection: 'EPSG:3857'
});
var got = format.readGeometry(geojson, {
const got = format.readGeometry(geojson, {
featureProjection: 'EPSG:3857'
});
var gotGeometries = got.getGeometries();
var geometries = collection.getGeometries();
const gotGeometries = got.getGeometries();
const geometries = collection.getGeometries();
expect(geometries[0].getCoordinates()[0]).to.roughlyEqual(
gotGeometries[0].getCoordinates()[0], 1e-8);
gotGeometries[0].getCoordinates()[0], 1e-8);
expect(geometries[0].getCoordinates()[1]).to.roughlyEqual(
gotGeometries[0].getCoordinates()[1], 1e-8);
gotGeometries[0].getCoordinates()[1], 1e-8);
expect(geometries[1].getCoordinates()[0][0]).to.roughlyEqual(
gotGeometries[1].getCoordinates()[0][0], 1e-8);
gotGeometries[1].getCoordinates()[0][0], 1e-8);
expect(geometries[1].getCoordinates()[0][1]).to.roughlyEqual(
gotGeometries[1].getCoordinates()[0][1], 1e-8);
gotGeometries[1].getCoordinates()[0][1], 1e-8);
});
it('truncates transformed point with decimals option', function() {
var point = new Point([2, 3]).transform('EPSG:4326', 'EPSG:3857');
var geojson = format.writeGeometry(point, {
const point = new Point([2, 3]).transform('EPSG:4326', 'EPSG:3857');
const geojson = format.writeGeometry(point, {
featureProjection: 'EPSG:3857',
decimals: 2
});
expect(format.readGeometry(geojson).getCoordinates()).to.eql(
[2, 3]);
[2, 3]);
});
it('truncates a linestring with decimals option', function() {
var linestring = new LineString([[42.123456789, 38.987654321],
const linestring = new LineString([[42.123456789, 38.987654321],
[43, 39]]);
var geojson = format.writeGeometry(linestring, {
const geojson = format.writeGeometry(linestring, {
decimals: 6
});
expect(format.readGeometry(geojson).getCoordinates()).to.eql(
[[42.123457, 38.987654], [43, 39]]);
[[42.123457, 38.987654], [43, 39]]);
expect(linestring.getCoordinates()).to.eql(
[[42.123456789, 38.987654321], [43, 39]]);
[[42.123456789, 38.987654321], [43, 39]]);
});
it('rounds a linestring with decimals option = 0', function() {
var linestring = new LineString([[42.123456789, 38.987654321],
const linestring = new LineString([[42.123456789, 38.987654321],
[43, 39]]);
var geojson = format.writeGeometry(linestring, {
const geojson = format.writeGeometry(linestring, {
decimals: 0
});
expect(format.readGeometry(geojson).getCoordinates()).to.eql(
[[42, 39], [43, 39]]);
[[42, 39], [43, 39]]);
expect(linestring.getCoordinates()).to.eql(
[[42.123456789, 38.987654321], [43, 39]]);
[[42.123456789, 38.987654321], [43, 39]]);
});
});