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
+56 -56
View File
@@ -4,84 +4,84 @@ import AtlasManager from '../../../../src/ol/style/AtlasManager.js';
describe('ol.style.Atlas', function() {
var defaultRender = function(context, x, y) {
const defaultRender = function(context, x, y) {
};
describe('#constructor', function() {
it('inits the atlas', function() {
var atlas = new Atlas(256, 1);
const atlas = new Atlas(256, 1);
expect(atlas.emptyBlocks_).to.eql(
[{x: 0, y: 0, width: 256, height: 256}]);
[{x: 0, y: 0, width: 256, height: 256}]);
});
});
describe('#add (squares with same size)', function() {
it('adds one entry', function() {
var atlas = new Atlas(128, 1);
var info = atlas.add('1', 32, 32, defaultRender);
const atlas = new Atlas(128, 1);
const info = atlas.add('1', 32, 32, defaultRender);
expect(info).to.eql(
{offsetX: 1, offsetY: 1, image: atlas.canvas_});
{offsetX: 1, offsetY: 1, image: atlas.canvas_});
expect(atlas.get('1')).to.eql(info);
});
it('adds two entries', function() {
var atlas = new Atlas(128, 1);
const atlas = new Atlas(128, 1);
atlas.add('1', 32, 32, defaultRender);
var info = atlas.add('2', 32, 32, defaultRender);
const info = atlas.add('2', 32, 32, defaultRender);
expect(info).to.eql(
{offsetX: 34, offsetY: 1, image: atlas.canvas_});
{offsetX: 34, offsetY: 1, image: atlas.canvas_});
expect(atlas.get('2')).to.eql(info);
});
it('adds three entries', function() {
var atlas = new Atlas(128, 1);
const atlas = new Atlas(128, 1);
atlas.add('1', 32, 32, defaultRender);
atlas.add('2', 32, 32, defaultRender);
var info = atlas.add('3', 32, 32, defaultRender);
const info = atlas.add('3', 32, 32, defaultRender);
expect(info).to.eql(
{offsetX: 67, offsetY: 1, image: atlas.canvas_});
{offsetX: 67, offsetY: 1, image: atlas.canvas_});
expect(atlas.get('3')).to.eql(info);
});
it('adds four entries (new row)', function() {
var atlas = new Atlas(128, 1);
const atlas = new Atlas(128, 1);
atlas.add('1', 32, 32, defaultRender);
atlas.add('2', 32, 32, defaultRender);
atlas.add('3', 32, 32, defaultRender);
var info = atlas.add('4', 32, 32, defaultRender);
const info = atlas.add('4', 32, 32, defaultRender);
expect(info).to.eql(
{offsetX: 1, offsetY: 34, image: atlas.canvas_});
{offsetX: 1, offsetY: 34, image: atlas.canvas_});
expect(atlas.get('4')).to.eql(info);
});
it('returns null when an entry is too big', function() {
var atlas = new Atlas(128, 1);
const atlas = new Atlas(128, 1);
atlas.add('1', 32, 32, defaultRender);
atlas.add('2', 32, 32, defaultRender);
atlas.add('3', 32, 32, defaultRender);
var info = atlas.add(4, 100, 100, defaultRender);
const info = atlas.add(4, 100, 100, defaultRender);
expect(info).to.eql(null);
});
it('fills up the whole atlas', function() {
var atlas = new Atlas(128, 1);
const atlas = new Atlas(128, 1);
for (var i = 1; i <= 16; i++) {
for (let i = 1; i <= 16; i++) {
expect(atlas.add(i.toString(), 28, 28, defaultRender)).to.be.ok();
}
@@ -93,32 +93,32 @@ describe('ol.style.Atlas', function() {
describe('#add (rectangles with different sizes)', function() {
it('adds a bunch of rectangles', function() {
var atlas = new Atlas(128, 1);
const atlas = new Atlas(128, 1);
expect(atlas.add('1', 64, 32, defaultRender)).to.eql(
{offsetX: 1, offsetY: 1, image: atlas.canvas_});
{offsetX: 1, offsetY: 1, image: atlas.canvas_});
expect(atlas.add('2', 64, 32, defaultRender)).to.eql(
{offsetX: 1, offsetY: 34, image: atlas.canvas_});
{offsetX: 1, offsetY: 34, image: atlas.canvas_});
expect(atlas.add('3', 64, 32, defaultRender)).to.eql(
{offsetX: 1, offsetY: 67, image: atlas.canvas_});
{offsetX: 1, offsetY: 67, image: atlas.canvas_});
// this one can not be added anymore
expect(atlas.add('4', 64, 32, defaultRender)).to.eql(null);
// but there is still room for smaller ones
expect(atlas.add('5', 40, 32, defaultRender)).to.eql(
{offsetX: 66, offsetY: 1, image: atlas.canvas_});
{offsetX: 66, offsetY: 1, image: atlas.canvas_});
expect(atlas.add('6', 40, 32, defaultRender)).to.eql(
{offsetX: 66, offsetY: 34, image: atlas.canvas_});
{offsetX: 66, offsetY: 34, image: atlas.canvas_});
});
it('fills up the whole atlas (rectangles in portrait format)', function() {
var atlas = new Atlas(128, 1);
const atlas = new Atlas(128, 1);
for (var i = 1; i <= 32; i++) {
for (let i = 1; i <= 32; i++) {
expect(atlas.add(i.toString(), 28, 14, defaultRender)).to.be.ok();
}
@@ -127,9 +127,9 @@ describe('ol.style.Atlas', function() {
});
it('fills up the whole atlas (rectangles in landscape format)', function() {
var atlas = new Atlas(128, 1);
const atlas = new Atlas(128, 1);
for (var i = 1; i <= 32; i++) {
for (let i = 1; i <= 32; i++) {
expect(atlas.add(i.toString(), 14, 28, defaultRender)).to.be.ok();
}
@@ -141,8 +141,8 @@ describe('ol.style.Atlas', function() {
describe('#add (rendering)', function() {
it('calls the render callback with the right values', function() {
var atlas = new Atlas(128, 1);
var rendererCallback = sinon.spy();
const atlas = new Atlas(128, 1);
let rendererCallback = sinon.spy();
atlas.add('1', 32, 32, rendererCallback);
expect(rendererCallback.calledOnce).to.be.ok();
@@ -156,9 +156,9 @@ describe('ol.style.Atlas', function() {
});
it('is possible to actually draw on the canvas', function() {
var atlas = new Atlas(128, 1);
const atlas = new Atlas(128, 1);
var rendererCallback = function(context, x, y) {
const rendererCallback = function(context, x, y) {
context.fillStyle = '#FFA500';
context.fillRect(x, y, 32, 32);
};
@@ -173,13 +173,13 @@ describe('ol.style.Atlas', function() {
describe('ol.style.AtlasManager', function() {
var defaultRender = function(context, x, y) {
const defaultRender = function(context, x, y) {
};
describe('#constructor', function() {
it('inits the atlas manager', function() {
var manager = new AtlasManager();
const manager = new AtlasManager();
expect(manager.atlases_).to.not.be.empty();
});
});
@@ -187,8 +187,8 @@ describe('ol.style.AtlasManager', function() {
describe('#add', function() {
it('adds one entry', function() {
var manager = new AtlasManager({initialSize: 128});
var info = manager.add('1', 32, 32, defaultRender);
const manager = new AtlasManager({initialSize: 128});
const info = manager.add('1', 32, 32, defaultRender);
expect(info).to.eql({
offsetX: 1, offsetY: 1, image: manager.atlases_[0].canvas_,
@@ -198,8 +198,8 @@ describe('ol.style.AtlasManager', function() {
});
it('adds one entry (also to the hit detection atlas)', function() {
var manager = new AtlasManager({initialSize: 128});
var info = manager.add('1', 32, 32, defaultRender, defaultRender);
const manager = new AtlasManager({initialSize: 128});
const info = manager.add('1', 32, 32, defaultRender, defaultRender);
expect(info).to.eql({
offsetX: 1, offsetY: 1, image: manager.atlases_[0].canvas_,
@@ -209,10 +209,10 @@ describe('ol.style.AtlasManager', function() {
});
it('creates a new atlas if needed', function() {
var manager = new AtlasManager({initialSize: 128});
const manager = new AtlasManager({initialSize: 128});
expect(manager.add('1', 100, 100, defaultRender, defaultRender))
.to.be.ok();
var info = manager.add('2', 100, 100, defaultRender, defaultRender);
.to.be.ok();
const info = manager.add('2', 100, 100, defaultRender, defaultRender);
expect(info).to.be.ok();
expect(info.image.width).to.eql(256);
expect(manager.atlases_).to.have.length(2);
@@ -221,12 +221,12 @@ describe('ol.style.AtlasManager', function() {
});
it('creates new atlases until one is large enough', function() {
var manager = new AtlasManager({initialSize: 128});
const manager = new AtlasManager({initialSize: 128});
expect(manager.add('1', 100, 100, defaultRender, defaultRender))
.to.be.ok();
.to.be.ok();
expect(manager.atlases_).to.have.length(1);
expect(manager.hitAtlases_).to.have.length(1);
var info = manager.add('2', 500, 500, defaultRender, defaultRender);
const info = manager.add('2', 500, 500, defaultRender, defaultRender);
expect(info).to.be.ok();
expect(info.image.width).to.eql(512);
expect(manager.atlases_).to.have.length(3);
@@ -235,14 +235,14 @@ describe('ol.style.AtlasManager', function() {
});
it('checks all existing atlases and create a new if needed', function() {
var manager = new AtlasManager({initialSize: 128});
const manager = new AtlasManager({initialSize: 128});
expect(manager.add('1', 100, 100, defaultRender, defaultRender))
.to.be.ok();
.to.be.ok();
expect(manager.add('2', 100, 100, defaultRender, defaultRender))
.to.be.ok();
.to.be.ok();
expect(manager.atlases_).to.have.length(2);
expect(manager.hitAtlases_).to.have.length(2);
var info = manager.add(3, 500, 500, defaultRender, defaultRender);
const info = manager.add(3, 500, 500, defaultRender, defaultRender);
expect(info).to.be.ok();
expect(info.image.width).to.eql(512);
expect(manager.atlases_).to.have.length(3);
@@ -251,18 +251,18 @@ describe('ol.style.AtlasManager', function() {
});
it('returns null if the size exceeds the maximum size', function() {
var manager = new AtlasManager(
{initialSize: 128, maxSize: 2048});
const manager = new AtlasManager(
{initialSize: 128, maxSize: 2048});
expect(manager.add('1', 100, 100, defaultRender, defaultRender))
.to.be.ok();
.to.be.ok();
expect(manager.add('2', 2048, 2048, defaultRender, defaultRender))
.to.eql(null);
.to.eql(null);
});
it('always has the same offset for the hit-detection', function() {
var manager = new AtlasManager({initialSize: 128});
const manager = new AtlasManager({initialSize: 128});
// add one image without hit-detection callback
var info = manager.add('1', 32, 32, defaultRender);
let info = manager.add('1', 32, 32, defaultRender);
// add then one with hit-detection callback
info = manager.add('2', 32, 32, defaultRender, defaultRender);
@@ -277,7 +277,7 @@ describe('ol.style.AtlasManager', function() {
describe('#getInfo', function() {
it('returns null if no entry for the given id', function() {
var manager = new AtlasManager({initialSize: 128});
const manager = new AtlasManager({initialSize: 128});
expect(manager.getInfo('123456')).to.eql(null);
});
});
+29 -29
View File
@@ -9,7 +9,7 @@ describe('ol.style.Circle', function() {
describe('#constructor', function() {
it('creates a canvas if no atlas is used (no fill-style)', function() {
var style = new CircleStyle({radius: 10});
const style = new CircleStyle({radius: 10});
expect(style.getImage()).to.be.an(HTMLCanvasElement);
expect(style.getSize()).to.eql([21, 21]);
expect(style.getImageSize()).to.eql([21, 21]);
@@ -22,7 +22,7 @@ describe('ol.style.Circle', function() {
});
it('creates a canvas if no atlas is used (fill-style)', function() {
var style = new CircleStyle({
const style = new CircleStyle({
radius: 10,
fill: new Fill({
color: '#FFFF00'
@@ -40,8 +40,8 @@ describe('ol.style.Circle', function() {
});
it('adds itself to an atlas manager (no fill-style)', function() {
var atlasManager = new AtlasManager({initialSize: 512});
var style = new CircleStyle({radius: 10, atlasManager: atlasManager});
const atlasManager = new AtlasManager({initialSize: 512});
const style = new CircleStyle({radius: 10, atlasManager: atlasManager});
expect(style.getImage()).to.be.an(HTMLCanvasElement);
expect(style.getSize()).to.eql([21, 21]);
expect(style.getImageSize()).to.eql([512, 512]);
@@ -54,8 +54,8 @@ describe('ol.style.Circle', function() {
});
it('adds itself to an atlas manager (fill-style)', function() {
var atlasManager = new AtlasManager({initialSize: 512});
var style = new CircleStyle({
const atlasManager = new AtlasManager({initialSize: 512});
const style = new CircleStyle({
radius: 10,
atlasManager: atlasManager,
fill: new Fill({
@@ -77,14 +77,14 @@ describe('ol.style.Circle', function() {
describe('#clone', function() {
it('creates a new ol.style.Circle', function() {
var original = new CircleStyle();
var clone = original.clone();
const original = new CircleStyle();
const clone = original.clone();
expect(clone).to.be.an(CircleStyle);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
var original = new CircleStyle({
const original = new CircleStyle({
fill: new Fill({
color: '#319FD3'
}),
@@ -96,7 +96,7 @@ describe('ol.style.Circle', function() {
});
original.setOpacity(0.5);
original.setScale(1.5);
var clone = original.clone();
const clone = original.clone();
expect(original.getFill().getColor()).to.eql(clone.getFill().getColor());
expect(original.getOpacity()).to.eql(clone.getOpacity());
expect(original.getRadius()).to.eql(clone.getRadius());
@@ -106,7 +106,7 @@ describe('ol.style.Circle', function() {
});
it('the clone does not reference the same objects as the original', function() {
var original = new CircleStyle({
const original = new CircleStyle({
fill: new Fill({
color: '#319FD3'
}),
@@ -114,7 +114,7 @@ describe('ol.style.Circle', function() {
color: '#319FD3'
})
});
var clone = original.clone();
const clone = original.clone();
expect(original.getFill()).to.not.be(clone.getFill());
expect(original.getStroke()).to.not.be(clone.getStroke());
@@ -129,37 +129,37 @@ describe('ol.style.Circle', function() {
describe('#getChecksum', function() {
it('calculates the same hash code for default options', function() {
var style1 = new CircleStyle();
var style2 = new CircleStyle();
const style1 = new CircleStyle();
const style2 = new CircleStyle();
expect(style1.getChecksum()).to.eql(style2.getChecksum());
});
it('calculates not the same hash code (radius)', function() {
var style1 = new CircleStyle();
var style2 = new CircleStyle({
const style1 = new CircleStyle();
const style2 = new CircleStyle({
radius: 5
});
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
});
it('calculates the same hash code (radius)', function() {
var style1 = new CircleStyle({
const style1 = new CircleStyle({
radius: 5
});
var style2 = new CircleStyle({
const style2 = new CircleStyle({
radius: 5
});
expect(style1.getChecksum()).to.eql(style2.getChecksum());
});
it('calculates not the same hash code (color)', function() {
var style1 = new CircleStyle({
const style1 = new CircleStyle({
radius: 5,
fill: new Fill({
color: '#319FD3'
})
});
var style2 = new CircleStyle({
const style2 = new CircleStyle({
radius: 5,
stroke: new Stroke({
color: '#319FD3'
@@ -169,7 +169,7 @@ describe('ol.style.Circle', function() {
});
it('calculates the same hash code (everything set)', function() {
var style1 = new CircleStyle({
const style1 = new CircleStyle({
radius: 5,
fill: new Fill({
color: '#319FD3'
@@ -183,7 +183,7 @@ describe('ol.style.Circle', function() {
width: 2
})
});
var style2 = new CircleStyle({
const style2 = new CircleStyle({
radius: 5,
fill: new Fill({
color: '#319FD3'
@@ -201,7 +201,7 @@ describe('ol.style.Circle', function() {
});
it('calculates not the same hash code (stroke width differs)', function() {
var style1 = new CircleStyle({
const style1 = new CircleStyle({
radius: 5,
fill: new Fill({
color: '#319FD3'
@@ -215,7 +215,7 @@ describe('ol.style.Circle', function() {
width: 3
})
});
var style2 = new CircleStyle({
const style2 = new CircleStyle({
radius: 5,
fill: new Fill({
color: '#319FD3'
@@ -233,7 +233,7 @@ describe('ol.style.Circle', function() {
});
it('invalidates a cached checksum if values change (fill)', function() {
var style1 = new CircleStyle({
const style1 = new CircleStyle({
radius: 5,
fill: new Fill({
color: '#319FD3'
@@ -242,7 +242,7 @@ describe('ol.style.Circle', function() {
color: '#319FD3'
})
});
var style2 = new CircleStyle({
const style2 = new CircleStyle({
radius: 5,
fill: new Fill({
color: '#319FD3'
@@ -258,7 +258,7 @@ describe('ol.style.Circle', function() {
});
it('invalidates a cached checksum if values change (stroke)', function() {
var style1 = new CircleStyle({
const style1 = new CircleStyle({
radius: 5,
fill: new Fill({
color: '#319FD3'
@@ -267,7 +267,7 @@ describe('ol.style.Circle', function() {
color: '#319FD3'
})
});
var style2 = new CircleStyle({
const style2 = new CircleStyle({
radius: 5,
fill: new Fill({
color: '#319FD3'
@@ -286,7 +286,7 @@ describe('ol.style.Circle', function() {
describe('#setRadius', function() {
it('changes the circle radius', function() {
var style = new CircleStyle({
const style = new CircleStyle({
radius: 10,
fill: new Fill({
color: '#FFFF00'
+6 -6
View File
@@ -5,25 +5,25 @@ describe('ol.style.Fill', function() {
describe('#clone', function() {
it('creates a new ol.style.Fill', function() {
var original = new Fill();
var clone = original.clone();
const original = new Fill();
const clone = original.clone();
expect(clone).to.be.an(Fill);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
var original = new Fill({
const original = new Fill({
color: '#319FD3'
});
var clone = original.clone();
const clone = original.clone();
expect(original.getColor()).to.eql(clone.getColor());
});
it('the clone does not reference the same objects as the original', function() {
var original = new Fill({
const original = new Fill({
color: [63, 255, 127, 0.7]
});
var clone = original.clone();
const clone = original.clone();
expect(original.getColor()).to.not.be(clone.getColor());
clone.getColor()[2] = 0;
+32 -32
View File
@@ -5,28 +5,28 @@ import IconImage from '../../../../src/ol/style/IconImage.js';
describe('ol.style.Icon', function() {
var size = [36, 48];
var src = 'data:image/gif;base64,' +
const size = [36, 48];
const src = 'data:image/gif;base64,' +
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=';
describe('constructor', function() {
it('caches canvas images with a uid as src', function() {
var canvas = document.createElement('canvas');
const canvas = document.createElement('canvas');
new Icon({
img: canvas,
imgSize: size
});
expect(IconImage.get(
canvas, getUid(canvas), size, '').getImage()).to.eql(canvas);
canvas, getUid(canvas), size, '').getImage()).to.eql(canvas);
});
it('imgSize overrides img.width and img.height', function(done) {
var style = new Icon({
const style = new Icon({
src: src,
imgSize: size
});
var iconImage = style.iconImage_;
const iconImage = style.iconImage_;
iconImage.addEventListener('change', function() {
expect([iconImage.image_.width, iconImage.image_.height]).to.eql(size);
done();
@@ -39,17 +39,17 @@ describe('ol.style.Icon', function() {
describe('#clone', function() {
it('creates a new ol.style.Icon', function() {
var original = new Icon({
const original = new Icon({
src: src
});
var clone = original.clone();
const clone = original.clone();
expect(clone).to.be.an(Icon);
expect(clone).to.not.be(original);
});
it('copies all values ', function() {
var canvas = document.createElement('canvas');
var original = new Icon({
const canvas = document.createElement('canvas');
const original = new Icon({
anchor: [1, 0],
anchorOrigin: 'bottom-right',
anchorXUnits: 'pixels',
@@ -67,7 +67,7 @@ describe('ol.style.Icon', function() {
size: [10, 12]
});
var clone = original.clone();
const clone = original.clone();
expect(original.getImage(1)).to.be(clone.getImage(1));
expect(original.iconImage_).to.be(clone.iconImage_);
expect(original.getAnchor()).to.eql(clone.getAnchor());
@@ -85,24 +85,24 @@ describe('ol.style.Icon', function() {
expect(original.getRotateWithView()).to.eql(clone.getRotateWithView());
expect(original.getSnapToPixel()).to.eql(clone.getSnapToPixel());
var original2 = new Icon({
const original2 = new Icon({
src: src
});
var clone2 = original2.clone();
const clone2 = original2.clone();
expect(original2.getImage(1)).to.be(clone2.getImage(1));
expect(original2.iconImage_).to.be(clone2.iconImage_);
expect(original2.getSrc()).to.eql(clone2.getSrc());
});
it('the clone does not reference the same objects as the original', function() {
var original = new Icon({
const original = new Icon({
anchor: [1, 0],
color: [1, 2, 3, 0.4],
src: src,
offset: [1, 2],
size: [10, 12]
});
var clone = original.clone();
const clone = original.clone();
expect(original.getAnchor()).not.to.be(clone.getAnchor());
expect(original.offset_).not.to.be(clone.offset_);
expect(original.getColor()).not.to.be(clone.getColor());
@@ -120,10 +120,10 @@ describe('ol.style.Icon', function() {
});
describe('#getAnchor', function() {
var fractionAnchor = [0.25, 0.25];
const fractionAnchor = [0.25, 0.25];
it('uses fractional units by default', function() {
var iconStyle = new Icon({
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor
@@ -132,7 +132,7 @@ describe('ol.style.Icon', function() {
});
it('uses pixels units', function() {
var iconStyle = new Icon({
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: [2, 18],
@@ -143,7 +143,7 @@ describe('ol.style.Icon', function() {
});
it('uses a bottom left anchor origin', function() {
var iconStyle = new Icon({
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor,
@@ -153,7 +153,7 @@ describe('ol.style.Icon', function() {
});
it('uses a bottom right anchor origin', function() {
var iconStyle = new Icon({
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor,
@@ -163,7 +163,7 @@ describe('ol.style.Icon', function() {
});
it('uses a top right anchor origin', function() {
var iconStyle = new Icon({
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor,
@@ -174,11 +174,11 @@ describe('ol.style.Icon', function() {
});
describe('#getOrigin', function() {
var offset = [16, 20];
var imageSize = [144, 192];
const offset = [16, 20];
const imageSize = [144, 192];
it('uses a top left offset origin (default)', function() {
var iconStyle = new Icon({
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset
@@ -187,7 +187,7 @@ describe('ol.style.Icon', function() {
});
it('uses a bottom left offset origin', function() {
var iconStyle = new Icon({
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
@@ -198,7 +198,7 @@ describe('ol.style.Icon', function() {
});
it('uses a bottom right offset origin', function() {
var iconStyle = new Icon({
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
@@ -209,7 +209,7 @@ describe('ol.style.Icon', function() {
});
it('uses a top right offset origin', function() {
var iconStyle = new Icon({
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
@@ -221,23 +221,23 @@ describe('ol.style.Icon', function() {
});
describe('#getImageSize', function() {
var imgSize = [144, 192];
const imgSize = [144, 192];
it('takes the real image size', function() {
// pretend that the image is already in the cache,
// this image will be used for the icon.
var src = 'test.png';
var iconImage = new IconImage(null, 'test.png', imgSize);
const src = 'test.png';
const iconImage = new IconImage(null, 'test.png', imgSize);
iconImageCache.set(src, null, null, iconImage);
var iconStyle = new Icon({
const iconStyle = new Icon({
src: 'test.png'
});
expect(iconStyle.getImageSize()).to.eql(imgSize);
});
it('uses the given image size', function() {
var iconStyle = new Icon({
const iconStyle = new Icon({
img: {src: 'test.png'},
imgSize: imgSize
});
+3 -3
View File
@@ -4,7 +4,7 @@ import {iconImageCache} from '../../../../src/ol/style.js';
import IconImage from '../../../../src/ol/style/IconImage.js';
describe('ol.style.IconImageCache', function() {
var originalMaxCacheSize;
let originalMaxCacheSize;
beforeEach(function() {
iconImageCache.clear();
@@ -19,7 +19,7 @@ describe('ol.style.IconImageCache', function() {
describe('#expire', function() {
it('expires images when expected', function() {
var i, src, iconImage;
let i, src, iconImage;
for (i = 0; i < 4; ++i) {
src = i + '';
@@ -61,7 +61,7 @@ describe('ol.style.IconImageCache', function() {
describe('#setSize', function() {
it('sets max cache size and expires cache', function() {
var i, src, iconImage;
let i, src, iconImage;
for (i = 0; i < 3; ++i) {
src = i + '';
+32 -32
View File
@@ -9,7 +9,7 @@ describe('ol.style.RegularShape', function() {
describe('#constructor', function() {
it('can use rotateWithView', function() {
var style = new RegularShape({
const style = new RegularShape({
rotateWithView: true,
radius: 0
});
@@ -17,7 +17,7 @@ describe('ol.style.RegularShape', function() {
});
it('can use radius', function() {
var style = new RegularShape({
const style = new RegularShape({
radius: 5,
radius2: 10
});
@@ -26,7 +26,7 @@ describe('ol.style.RegularShape', function() {
});
it('can use radius1 as an alias for radius', function() {
var style = new RegularShape({
const style = new RegularShape({
radius1: 5,
radius2: 10
});
@@ -35,7 +35,7 @@ describe('ol.style.RegularShape', function() {
});
it('creates a canvas if no atlas is used (no fill-style)', function() {
var style = new RegularShape({radius: 10});
const style = new RegularShape({radius: 10});
expect(style.getImage()).to.be.an(HTMLCanvasElement);
expect(style.getSize()).to.eql([21, 21]);
expect(style.getImageSize()).to.eql([21, 21]);
@@ -48,7 +48,7 @@ describe('ol.style.RegularShape', function() {
});
it('creates a canvas if no atlas is used (fill-style)', function() {
var style = new RegularShape({
const style = new RegularShape({
radius: 10,
fill: new Fill({
color: '#FFFF00'
@@ -66,9 +66,9 @@ describe('ol.style.RegularShape', function() {
});
it('adds itself to an atlas manager (no fill-style)', function() {
var atlasManager = new AtlasManager({initialSize: 512});
var style = new RegularShape(
{radius: 10, atlasManager: atlasManager});
const atlasManager = new AtlasManager({initialSize: 512});
const style = new RegularShape(
{radius: 10, atlasManager: atlasManager});
expect(style.getImage()).to.be.an(HTMLCanvasElement);
expect(style.getSize()).to.eql([21, 21]);
expect(style.getImageSize()).to.eql([512, 512]);
@@ -81,8 +81,8 @@ describe('ol.style.RegularShape', function() {
});
it('adds itself to an atlas manager (fill-style)', function() {
var atlasManager = new AtlasManager({initialSize: 512});
var style = new RegularShape({
const atlasManager = new AtlasManager({initialSize: 512});
const style = new RegularShape({
radius: 10,
atlasManager: atlasManager,
fill: new Fill({
@@ -104,16 +104,16 @@ describe('ol.style.RegularShape', function() {
describe('#clone', function() {
it('creates a new ol.style.RegularShape', function() {
var original = new RegularShape({
const original = new RegularShape({
points: 5
});
var clone = original.clone();
const clone = original.clone();
expect(clone).to.be.an(RegularShape);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
var original = new RegularShape({
const original = new RegularShape({
fill: new Fill({
color: '#319FD3'
}),
@@ -130,7 +130,7 @@ describe('ol.style.RegularShape', function() {
});
original.setOpacity(0.5);
original.setScale(1.5);
var clone = original.clone();
const clone = original.clone();
expect(original.getAngle()).to.eql(clone.getAngle());
expect(original.getFill().getColor()).to.eql(clone.getFill().getColor());
expect(original.getOpacity()).to.eql(clone.getOpacity());
@@ -145,7 +145,7 @@ describe('ol.style.RegularShape', function() {
});
it('the clone does not reference the same objects as the original', function() {
var original = new RegularShape({
const original = new RegularShape({
fill: new Fill({
color: '#319FD3'
}),
@@ -153,7 +153,7 @@ describe('ol.style.RegularShape', function() {
color: '#319FD3'
})
});
var clone = original.clone();
const clone = original.clone();
expect(original.getFill()).to.not.be(clone.getFill());
expect(original.getStroke()).to.not.be(clone.getStroke());
@@ -168,11 +168,11 @@ describe('ol.style.RegularShape', function() {
describe('#getChecksum', function() {
it('calculates not the same hash code (radius)', function() {
var style1 = new RegularShape({
const style1 = new RegularShape({
radius: 4,
radius2: 5
});
var style2 = new RegularShape({
const style2 = new RegularShape({
radius: 3,
radius2: 5
});
@@ -180,11 +180,11 @@ describe('ol.style.RegularShape', function() {
});
it('calculates not the same hash code (radius2)', function() {
var style1 = new RegularShape({
const style1 = new RegularShape({
radius: 4,
radius2: 5
});
var style2 = new RegularShape({
const style2 = new RegularShape({
radius: 4,
radius2: 6
});
@@ -192,23 +192,23 @@ describe('ol.style.RegularShape', function() {
});
it('calculates the same hash code (radius)', function() {
var style1 = new RegularShape({
const style1 = new RegularShape({
radius: 5
});
var style2 = new RegularShape({
const style2 = new RegularShape({
radius: 5
});
expect(style1.getChecksum()).to.eql(style2.getChecksum());
});
it('calculates not the same hash code (color)', function() {
var style1 = new RegularShape({
const style1 = new RegularShape({
radius: 5,
fill: new Fill({
color: '#319FD3'
})
});
var style2 = new RegularShape({
const style2 = new RegularShape({
radius: 5,
stroke: new Stroke({
color: '#319FD3'
@@ -218,7 +218,7 @@ describe('ol.style.RegularShape', function() {
});
it('calculates the same hash code (everything set)', function() {
var style1 = new RegularShape({
const style1 = new RegularShape({
radius: 5,
radius2: 3,
angle: 1.41,
@@ -235,7 +235,7 @@ describe('ol.style.RegularShape', function() {
width: 2
})
});
var style2 = new RegularShape({
const style2 = new RegularShape({
radius: 5,
radius2: 3,
angle: 1.41,
@@ -256,7 +256,7 @@ describe('ol.style.RegularShape', function() {
});
it('calculates not the same hash code (stroke width differs)', function() {
var style1 = new RegularShape({
const style1 = new RegularShape({
radius: 5,
radius2: 3,
angle: 1.41,
@@ -273,7 +273,7 @@ describe('ol.style.RegularShape', function() {
width: 3
})
});
var style2 = new RegularShape({
const style2 = new RegularShape({
radius: 5,
radius2: 3,
angle: 1.41,
@@ -294,7 +294,7 @@ describe('ol.style.RegularShape', function() {
});
it('invalidates a cached checksum if values change (fill)', function() {
var style1 = new RegularShape({
const style1 = new RegularShape({
radius: 5,
fill: new Fill({
color: '#319FD3'
@@ -303,7 +303,7 @@ describe('ol.style.RegularShape', function() {
color: '#319FD3'
})
});
var style2 = new RegularShape({
const style2 = new RegularShape({
radius: 5,
fill: new Fill({
color: '#319FD3'
@@ -319,7 +319,7 @@ describe('ol.style.RegularShape', function() {
});
it('invalidates a cached checksum if values change (stroke)', function() {
var style1 = new RegularShape({
const style1 = new RegularShape({
radius: 5,
fill: new Fill({
color: '#319FD3'
@@ -328,7 +328,7 @@ describe('ol.style.RegularShape', function() {
color: '#319FD3'
})
});
var style2 = new RegularShape({
const style2 = new RegularShape({
radius: 5,
fill: new Fill({
color: '#319FD3'
+6 -6
View File
@@ -5,14 +5,14 @@ describe('ol.style.Stroke', function() {
describe('#clone', function() {
it('creates a new ol.style.Stroke', function() {
var original = new Stroke();
var clone = original.clone();
const original = new Stroke();
const clone = original.clone();
expect(clone).to.be.an(Stroke);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
var original = new Stroke({
const original = new Stroke({
color: '#319FD3',
lineCap: 'square',
lineJoin: 'miter',
@@ -21,7 +21,7 @@ describe('ol.style.Stroke', function() {
miterLimit: 20,
width: 5
});
var clone = original.clone();
const clone = original.clone();
expect(original.getColor()).to.eql(clone.getColor());
expect(original.getLineCap()).to.eql(clone.getLineCap());
expect(original.getLineJoin()).to.eql(clone.getLineJoin());
@@ -32,11 +32,11 @@ describe('ol.style.Stroke', function() {
});
it('the clone does not reference the same objects as the original', function() {
var original = new Stroke({
const original = new Stroke({
color: [1, 2, 3, 0.4],
lineDash: [1, 2, 3]
});
var clone = original.clone();
const clone = original.clone();
expect(original.getColor()).to.not.be(clone.getColor());
expect(original.getLineDash()).to.not.be(clone.getLineDash());
+34 -34
View File
@@ -9,16 +9,16 @@ import Text from '../../../../src/ol/style/Text.js';
describe('ol.style.Style', function() {
var testFill = new Fill({
const testFill = new Fill({
color: 'rgba(255, 255, 255, 0.6)'
});
var testStroke = new Stroke({
const testStroke = new Stroke({
color: '#319FD3',
width: 1
});
var testText = new Text({
const testText = new Text({
font: '12px Calibri,sans-serif',
fill: new Fill({
color: '#000'
@@ -29,21 +29,21 @@ describe('ol.style.Style', function() {
})
});
var testImage = new CircleStyle({
const testImage = new CircleStyle({
radius: 5
});
describe('#clone', function() {
it('creates a new ol.style.Style', function() {
var original = new Style();
var clone = original.clone();
const original = new Style();
const clone = original.clone();
expect(clone).to.be.an(Style);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
var original = new Style({
const original = new Style({
geometry: new Point([0, 0, 0]),
fill: new Fill({
color: '#319FD3'
@@ -59,7 +59,7 @@ describe('ol.style.Style', function() {
}),
zIndex: 2
});
var clone = original.clone();
const clone = original.clone();
expect(original.getGeometry().getCoordinates()).to.eql(clone.getGeometry().getCoordinates());
expect(original.getFill().getColor()).to.eql(clone.getFill().getColor());
expect(original.getImage().getRadius()).to.eql(clone.getImage().getRadius());
@@ -69,7 +69,7 @@ describe('ol.style.Style', function() {
});
it('the clone does not reference the same objects as the original', function() {
var original = new Style({
const original = new Style({
geometry: new Point([0, 0, 0]),
fill: new Fill({
color: '#319FD3'
@@ -84,7 +84,7 @@ describe('ol.style.Style', function() {
text: 'test'
})
});
var clone = original.clone();
const clone = original.clone();
expect(original.getGeometry()).not.to.be(clone.getGeometry());
expect(original.getFill()).not.to.be(clone.getFill());
expect(original.getImage()).not.to.be(clone.getImage());
@@ -107,7 +107,7 @@ describe('ol.style.Style', function() {
describe('#setZIndex', function() {
it('sets the zIndex', function() {
var style = new Style();
const style = new Style();
style.setZIndex(0.7);
expect(style.getZIndex()).to.be(0.7);
@@ -115,7 +115,7 @@ describe('ol.style.Style', function() {
});
describe('#getFill', function() {
var style = new Style({
const style = new Style({
fill: testFill
});
@@ -125,7 +125,7 @@ describe('ol.style.Style', function() {
});
describe('#setFill', function() {
var style = new Style();
const style = new Style();
it('sets the fill style of a style', function() {
style.setFill(testFill);
@@ -134,7 +134,7 @@ describe('ol.style.Style', function() {
});
describe('#getImage', function() {
var style = new Style({
const style = new Style({
image: testImage
});
@@ -144,7 +144,7 @@ describe('ol.style.Style', function() {
});
describe('#setImage', function() {
var style = new Style();
const style = new Style();
it('sets the image style of a style', function() {
style.setImage(testImage);
@@ -153,7 +153,7 @@ describe('ol.style.Style', function() {
});
describe('#getStroke', function() {
var style = new Style({
const style = new Style({
stroke: testStroke
});
@@ -163,7 +163,7 @@ describe('ol.style.Style', function() {
});
describe('#setStroke', function() {
var style = new Style();
const style = new Style();
it('sets the stroke style of a style', function() {
style.setStroke(testStroke);
@@ -172,7 +172,7 @@ describe('ol.style.Style', function() {
});
describe('#getText', function() {
var style = new Style({
const style = new Style({
text: testText
});
@@ -182,7 +182,7 @@ describe('ol.style.Style', function() {
});
describe('#setText', function() {
var style = new Style();
const style = new Style();
it('sets the text style of a style', function() {
style.setText(testText);
@@ -191,43 +191,43 @@ describe('ol.style.Style', function() {
});
describe('#setGeometry', function() {
var style = new Style();
const style = new Style();
it('creates a geometry function from a string', function() {
var feature = new Feature();
const feature = new Feature();
feature.set('myGeom', new Point([0, 0]));
style.setGeometry('myGeom');
expect(style.getGeometryFunction()(feature))
.to.eql(feature.get('myGeom'));
.to.eql(feature.get('myGeom'));
});
it('creates a geometry function from a geometry', function() {
var geom = new Point([0, 0]);
const geom = new Point([0, 0]);
style.setGeometry(geom);
expect(style.getGeometryFunction()())
.to.eql(geom);
.to.eql(geom);
});
it('returns the configured geometry function', function() {
var geom = new Point([0, 0]);
const geom = new Point([0, 0]);
style.setGeometry(function() {
return geom;
});
expect(style.getGeometryFunction()())
.to.eql(geom);
.to.eql(geom);
});
});
describe('#getGeometry', function() {
it('returns whatever was passed to setGeometry', function() {
var style = new Style();
const style = new Style();
style.setGeometry('foo');
expect(style.getGeometry()).to.eql('foo');
var geom = new Point([1, 2]);
const geom = new Point([1, 2]);
style.setGeometry(geom);
expect(style.getGeometry()).to.eql(geom);
var fn = function() {
const fn = function() {
return geom;
};
style.setGeometry(fn);
@@ -241,23 +241,23 @@ describe('ol.style.Style', function() {
});
describe('ol.style.Style.createFunction()', function() {
var style = new Style();
const style = new Style();
it('creates a style function from a single style', function() {
var styleFunction = Style.createFunction(style);
const styleFunction = Style.createFunction(style);
expect(styleFunction()).to.eql([style]);
});
it('creates a style function from an array of styles', function() {
var styleFunction = Style.createFunction([style]);
const styleFunction = Style.createFunction([style]);
expect(styleFunction()).to.eql([style]);
});
it('passes through a function', function() {
var original = function() {
const original = function() {
return [style];
};
var styleFunction = Style.createFunction(original);
const styleFunction = Style.createFunction(original);
expect(styleFunction).to.be(original);
});
+9 -9
View File
@@ -8,19 +8,19 @@ describe('ol.style.Text', function() {
describe('#constructor', function() {
it('uses a default fill style if none passed', function() {
var style = new Text();
const style = new Text();
expect(style.getFill().getColor()).to.be('#333');
});
it('uses a provided fill style if one passed', function() {
var style = new Text({
const style = new Text({
fill: new Fill({color: '#123456'})
});
expect(style.getFill().getColor()).to.be('#123456');
});
it('can always be resetted to no color', function() {
var style = new Text();
const style = new Text();
style.getFill().setColor();
expect(style.getFill().getColor()).to.be(undefined);
});
@@ -30,14 +30,14 @@ describe('ol.style.Text', function() {
describe('#clone', function() {
it('creates a new ol.style.Text', function() {
var original = new Text();
var clone = original.clone();
const original = new Text();
const clone = original.clone();
expect(clone).to.be.an(Text);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
var original = new Text({
const original = new Text({
font: '12px serif',
offsetX: 4,
offsetY: 10,
@@ -60,7 +60,7 @@ describe('ol.style.Text', function() {
color: 'black'
})
});
var clone = original.clone();
const clone = original.clone();
expect(original.getFont()).to.eql(clone.getFont());
expect(original.getOffsetX()).to.eql(clone.getOffsetX());
expect(original.getOffsetY()).to.eql(clone.getOffsetY());
@@ -77,7 +77,7 @@ describe('ol.style.Text', function() {
});
it('the clone does not reference the same objects as the original', function() {
var original = new Text({
const original = new Text({
fill: new Fill({
color: '#319FD3'
}),
@@ -85,7 +85,7 @@ describe('ol.style.Text', function() {
color: '#319FD3'
})
});
var clone = original.clone();
const clone = original.clone();
expect(original.getFill()).to.not.be(clone.getFill());
expect(original.getStroke()).to.not.be(clone.getStroke());