Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
import Attribution from '../../../../src/ol/control/Attribution.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import Tile from '../../../../src/ol/Tile.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import Attribution from '../../../../src/ol/control/Attribution.js';
|
||||
import TileLayer from '../../../../src/ol/layer/Tile.js';
|
||||
import TileSource from '../../../../src/ol/source/Tile.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import {createXYZ} from '../../../../src/ol/tilegrid.js';
|
||||
|
||||
describe('ol.control.Attribution', function() {
|
||||
|
||||
describe('ol.control.Attribution', function () {
|
||||
let map;
|
||||
|
||||
const tileLoadFunction = function() {
|
||||
const tileLoadFunction = function () {
|
||||
const tile = new Tile([0, 0, -1], 2 /* LOADED */);
|
||||
tile.getImage = function() {
|
||||
tile.getImage = function () {
|
||||
const image = new Image();
|
||||
image.width = 256;
|
||||
image.height = 256;
|
||||
@@ -21,98 +20,107 @@ describe('ol.control.Attribution', function() {
|
||||
return tile;
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
const target = document.createElement('div');
|
||||
target.style.width = '100px';
|
||||
target.style.height = '100px';
|
||||
document.body.appendChild(target);
|
||||
map = new Map({
|
||||
target: target,
|
||||
controls: [new Attribution({
|
||||
collapsed: false,
|
||||
collapsible: false
|
||||
})],
|
||||
controls: [
|
||||
new Attribution({
|
||||
collapsed: false,
|
||||
collapsible: false,
|
||||
}),
|
||||
],
|
||||
layers: [
|
||||
new TileLayer({
|
||||
source: new TileSource({
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: createXYZ(),
|
||||
attributions: 'foo'
|
||||
})
|
||||
attributions: 'foo',
|
||||
}),
|
||||
}),
|
||||
new TileLayer({
|
||||
source: new TileSource({
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: createXYZ(),
|
||||
attributions: 'bar'
|
||||
})
|
||||
attributions: 'bar',
|
||||
}),
|
||||
}),
|
||||
new TileLayer({
|
||||
source: new TileSource({
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: createXYZ(),
|
||||
attributions: 'foo'
|
||||
})
|
||||
})
|
||||
attributions: 'foo',
|
||||
}),
|
||||
}),
|
||||
],
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
})
|
||||
zoom: 0,
|
||||
}),
|
||||
});
|
||||
map.getLayers().forEach(function(layer) {
|
||||
map.getLayers().forEach(function (layer) {
|
||||
const source = layer.getSource();
|
||||
source.getTile = tileLoadFunction;
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
disposeMap(map);
|
||||
map = null;
|
||||
});
|
||||
|
||||
it('does not add duplicate attributions', function() {
|
||||
it('does not add duplicate attributions', function () {
|
||||
map.renderSync();
|
||||
const attribution = map.getTarget().querySelectorAll('.ol-attribution li');
|
||||
expect(attribution.length).to.be(2);
|
||||
});
|
||||
|
||||
it('renders attributions as non-collapsible if source is configured with attributionsCollapsible set to false', function() {
|
||||
it('renders attributions as non-collapsible if source is configured with attributionsCollapsible set to false', function () {
|
||||
map.getControls().clear();
|
||||
map.addControl(new Attribution());
|
||||
const source = new TileSource({
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: createXYZ(),
|
||||
attributions: 'foo',
|
||||
attributionsCollapsible: false
|
||||
attributionsCollapsible: false,
|
||||
});
|
||||
source.getTile = tileLoadFunction;
|
||||
map.addLayer(new TileLayer({
|
||||
source: source
|
||||
}));
|
||||
map.addLayer(
|
||||
new TileLayer({
|
||||
source: source,
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
|
||||
const attribution = map.getTarget().querySelectorAll('.ol-attribution.ol-uncollapsible');
|
||||
const attribution = map
|
||||
.getTarget()
|
||||
.querySelectorAll('.ol-attribution.ol-uncollapsible');
|
||||
expect(attribution.length).to.be(1);
|
||||
});
|
||||
|
||||
it('renders attributions as collapsible if configured with collapsible set to true', function() {
|
||||
it('renders attributions as collapsible if configured with collapsible set to true', function () {
|
||||
map.getControls().clear();
|
||||
map.addControl(new Attribution({collapsible: true}));
|
||||
const source = new TileSource({
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: createXYZ(),
|
||||
attributions: 'foo',
|
||||
attributionsCollapsible: false
|
||||
attributionsCollapsible: false,
|
||||
});
|
||||
source.getTile = tileLoadFunction;
|
||||
map.addLayer(new TileLayer({
|
||||
source: source
|
||||
}));
|
||||
map.addLayer(
|
||||
new TileLayer({
|
||||
source: source,
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
|
||||
const attribution = map.getTarget().querySelectorAll('.ol-attribution.ol-uncollapsible');
|
||||
const attribution = map
|
||||
.getTarget()
|
||||
.querySelectorAll('.ol-attribution.ol-uncollapsible');
|
||||
expect(attribution.length).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import Control from '../../../../src/ol/control/Control.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
|
||||
describe('ol.control.Control', function() {
|
||||
describe('ol.control.Control', function () {
|
||||
let map, control;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
map = new Map({
|
||||
target: document.createElement('div')
|
||||
target: document.createElement('div'),
|
||||
});
|
||||
const element = document.createElement('div');
|
||||
control = new Control({element: element});
|
||||
control.setMap(map);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
disposeMap(map);
|
||||
map = null;
|
||||
control = null;
|
||||
});
|
||||
|
||||
describe('dispose', function() {
|
||||
it('removes the control element from its parent', function() {
|
||||
describe('dispose', function () {
|
||||
it('removes the control element from its parent', function () {
|
||||
control.dispose();
|
||||
expect(control.element.parentNode).to.be(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.control.Control\'s target', function() {
|
||||
describe('target as string or element', function() {
|
||||
it('transforms target from string to element', function() {
|
||||
describe("ol.control.Control's target", function () {
|
||||
describe('target as string or element', function () {
|
||||
it('transforms target from string to element', function () {
|
||||
const target = document.createElement('div');
|
||||
target.id = 'mycontrol';
|
||||
document.body.appendChild(target);
|
||||
@@ -38,7 +38,7 @@ describe('ol.control.Control\'s target', function() {
|
||||
ctrl.dispose();
|
||||
target.parentNode.removeChild(target);
|
||||
});
|
||||
it('accepts element for target', function() {
|
||||
it('accepts element for target', function () {
|
||||
const target = document.createElement('div');
|
||||
target.id = 'mycontrol';
|
||||
document.body.appendChild(target);
|
||||
@@ -47,7 +47,7 @@ describe('ol.control.Control\'s target', function() {
|
||||
ctrl.dispose();
|
||||
target.parentNode.removeChild(target);
|
||||
});
|
||||
it('ignores non-existing target id', function() {
|
||||
it('ignores non-existing target id', function () {
|
||||
const ctrl = new Control({target: 'doesnotexist'});
|
||||
expect(ctrl.target_).to.equal(null);
|
||||
ctrl.dispose();
|
||||
@@ -55,22 +55,22 @@ describe('ol.control.Control\'s target', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.control.Control\'s event target', function() {
|
||||
it('is the Control when the Control uses the default target', function(done) {
|
||||
describe("ol.control.Control's event target", function () {
|
||||
it('is the Control when the Control uses the default target', function (done) {
|
||||
const ctrl = new Control({element: document.createElement('div')});
|
||||
ctrl.on('test-event', function(e) {
|
||||
ctrl.on('test-event', function (e) {
|
||||
expect(e.target).to.be(ctrl);
|
||||
done();
|
||||
});
|
||||
ctrl.dispatchEvent('test-event');
|
||||
ctrl.dispose();
|
||||
});
|
||||
it('is the Control when the Control has a custom target', function(done) {
|
||||
it('is the Control when the Control has a custom target', function (done) {
|
||||
const ctrl = new Control({
|
||||
element: document.createElement('div'),
|
||||
target: document.createElement('div')
|
||||
target: document.createElement('div'),
|
||||
});
|
||||
ctrl.on('test-event', function(e) {
|
||||
ctrl.on('test-event', function (e) {
|
||||
expect(e.target).to.be(ctrl);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
import FullScreen from '../../../../src/ol/control/FullScreen.js';
|
||||
|
||||
describe('ol.control.FullScreen', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('can be constructed without arguments', function() {
|
||||
describe('ol.control.FullScreen', function () {
|
||||
describe('constructor', function () {
|
||||
it('can be constructed without arguments', function () {
|
||||
const instance = new FullScreen();
|
||||
expect(instance).to.be.an(FullScreen);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,34 +1,31 @@
|
||||
import EventType from '../../../../src/ol/pointer/EventType.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import MousePosition from '../../../../src/ol/control/MousePosition.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import EventType from '../../../../src/ol/pointer/EventType.js';
|
||||
|
||||
describe('ol/control/MousePosition', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('can be constructed without arguments', function() {
|
||||
describe('ol/control/MousePosition', function () {
|
||||
describe('constructor', function () {
|
||||
it('can be constructed without arguments', function () {
|
||||
const instance = new MousePosition();
|
||||
expect(instance).to.be.an(MousePosition);
|
||||
expect(instance.element.className).to.be('ol-mouse-position');
|
||||
});
|
||||
|
||||
it('creates the element with the provided class name', function() {
|
||||
it('creates the element with the provided class name', function () {
|
||||
const className = 'foobar';
|
||||
const instance = new MousePosition({
|
||||
className: className
|
||||
className: className,
|
||||
});
|
||||
expect(instance.element.className).to.be(className);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('configuration options', function() {
|
||||
describe('configuration options', function () {
|
||||
let target, map;
|
||||
const width = 360;
|
||||
const height = 180;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
target = document.createElement('div');
|
||||
const style = target.style;
|
||||
style.position = 'absolute';
|
||||
@@ -44,11 +41,11 @@ describe('ol/control/MousePosition', function() {
|
||||
view: new View({
|
||||
projection: 'EPSG:4326',
|
||||
center: [0, 0],
|
||||
resolution: 1
|
||||
})
|
||||
resolution: 1,
|
||||
}),
|
||||
});
|
||||
});
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
map.dispose();
|
||||
document.body.removeChild(target);
|
||||
});
|
||||
@@ -59,20 +56,23 @@ describe('ol/control/MousePosition', function() {
|
||||
const position = viewport.getBoundingClientRect();
|
||||
const evt = new PointerEvent(type, {
|
||||
clientX: position.left + x + width / 2,
|
||||
clientY: position.top + y + height / 2
|
||||
clientY: position.top + y + height / 2,
|
||||
});
|
||||
document.querySelector('div.ol-viewport').dispatchEvent(evt);
|
||||
}
|
||||
|
||||
describe('undefinedHTML', function() {
|
||||
it('renders undefinedHTML when mouse moves out', function() {
|
||||
describe('undefinedHTML', function () {
|
||||
it('renders undefinedHTML when mouse moves out', function () {
|
||||
const ctrl = new MousePosition({
|
||||
undefinedHTML: 'some text'
|
||||
undefinedHTML: 'some text',
|
||||
});
|
||||
ctrl.setMap(map);
|
||||
map.renderSync();
|
||||
|
||||
const element = document.querySelector('.ol-mouse-position', map.getTarget());
|
||||
const element = document.querySelector(
|
||||
'.ol-mouse-position',
|
||||
map.getTarget()
|
||||
);
|
||||
|
||||
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
|
||||
expect(element.innerHTML).to.be('some text');
|
||||
@@ -84,12 +84,15 @@ describe('ol/control/MousePosition', function() {
|
||||
expect(element.innerHTML).to.be('some text');
|
||||
});
|
||||
|
||||
it('clears the mouse position by default when the mouse moves outside the viewport', function() {
|
||||
it('clears the mouse position by default when the mouse moves outside the viewport', function () {
|
||||
const ctrl = new MousePosition();
|
||||
ctrl.setMap(map);
|
||||
map.renderSync();
|
||||
|
||||
const element = document.querySelector('.ol-mouse-position', map.getTarget());
|
||||
const element = document.querySelector(
|
||||
'.ol-mouse-position',
|
||||
map.getTarget()
|
||||
);
|
||||
|
||||
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
|
||||
expect(element.innerHTML).to.be(' ');
|
||||
@@ -102,14 +105,17 @@ describe('ol/control/MousePosition', function() {
|
||||
expect(element.innerHTML).to.be(' ');
|
||||
});
|
||||
|
||||
it('retains the mouse position when undefinedHTML is falsey and mouse moves outside the viewport', function() {
|
||||
it('retains the mouse position when undefinedHTML is falsey and mouse moves outside the viewport', function () {
|
||||
const ctrl = new MousePosition({
|
||||
undefinedHTML: ''
|
||||
undefinedHTML: '',
|
||||
});
|
||||
ctrl.setMap(map);
|
||||
map.renderSync();
|
||||
|
||||
const element = document.querySelector('.ol-mouse-position', map.getTarget());
|
||||
const element = document.querySelector(
|
||||
'.ol-mouse-position',
|
||||
map.getTarget()
|
||||
);
|
||||
|
||||
simulateEvent(EventType.POINTEROUT, width + 1, height + 1);
|
||||
expect(element.innerHTML).to.be('');
|
||||
|
||||
@@ -1,46 +1,45 @@
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import Control from '../../../../src/ol/control/Control.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import OverviewMap from '../../../../src/ol/control/OverviewMap.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
|
||||
describe('ol.control.OverviewMap', function() {
|
||||
describe('ol.control.OverviewMap', function () {
|
||||
let map, target;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
target = document.createElement('div');
|
||||
document.body.appendChild(target);
|
||||
map = new Map({
|
||||
target: target
|
||||
target: target,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
map.dispose();
|
||||
document.body.removeChild(target);
|
||||
map = null;
|
||||
target = null;
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates an overview map with the default options', function() {
|
||||
describe('constructor', function () {
|
||||
it('creates an overview map with the default options', function () {
|
||||
const control = new OverviewMap();
|
||||
expect(control).to.be.a(OverviewMap);
|
||||
expect(control).to.be.a(Control);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setMap()', function() {
|
||||
|
||||
it('keeps ovmap view rotation in sync with map view rotation', function() {
|
||||
describe('setMap()', function () {
|
||||
it('keeps ovmap view rotation in sync with map view rotation', function () {
|
||||
const view = new View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
rotation: Math.PI / 2
|
||||
rotation: Math.PI / 2,
|
||||
});
|
||||
map.setView(view);
|
||||
|
||||
const control = new OverviewMap({
|
||||
rotateWithView: true
|
||||
rotateWithView: true,
|
||||
});
|
||||
map.addControl(control);
|
||||
const ovView = control.ovmap_.getView();
|
||||
@@ -50,9 +49,9 @@ describe('ol.control.OverviewMap', function() {
|
||||
expect(ovView.getRotation()).to.be(Math.PI / 4);
|
||||
});
|
||||
|
||||
it('maintains rotation in sync if view added later', function() {
|
||||
it('maintains rotation in sync if view added later', function () {
|
||||
const control = new OverviewMap({
|
||||
rotateWithView: true
|
||||
rotateWithView: true,
|
||||
});
|
||||
map.addControl(control);
|
||||
const ovInitialView = control.ovmap_.getView();
|
||||
@@ -61,7 +60,7 @@ describe('ol.control.OverviewMap', function() {
|
||||
const view = new View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
rotation: Math.PI / 2
|
||||
rotation: Math.PI / 2,
|
||||
});
|
||||
map.setView(view);
|
||||
const ovView = control.ovmap_.getView();
|
||||
@@ -71,15 +70,15 @@ describe('ol.control.OverviewMap', function() {
|
||||
expect(ovView.getRotation()).to.be(Math.PI / 4);
|
||||
});
|
||||
|
||||
it('stops listening to old maps', function() {
|
||||
it('stops listening to old maps', function () {
|
||||
const control = new OverviewMap({
|
||||
rotateWithView: true
|
||||
rotateWithView: true,
|
||||
});
|
||||
|
||||
const view = new View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
rotation: 0
|
||||
rotation: 0,
|
||||
});
|
||||
map.setView(view);
|
||||
map.addControl(control);
|
||||
@@ -94,39 +93,51 @@ describe('ol.control.OverviewMap', function() {
|
||||
expect(ovView.getRotation()).to.be(Math.PI / 8);
|
||||
});
|
||||
|
||||
it('reflects projection change of main map', function() {
|
||||
it('reflects projection change of main map', function () {
|
||||
const control = new OverviewMap({
|
||||
rotateWithView: true
|
||||
rotateWithView: true,
|
||||
});
|
||||
|
||||
map.addControl(control);
|
||||
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:3857');
|
||||
expect(control.ovmap_.getView().getProjection().getCode()).to.be(
|
||||
'EPSG:3857'
|
||||
);
|
||||
|
||||
map.setView(new View({
|
||||
projection: 'EPSG:4326'
|
||||
}));
|
||||
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:4326');
|
||||
map.setView(
|
||||
new View({
|
||||
projection: 'EPSG:4326',
|
||||
})
|
||||
);
|
||||
expect(control.ovmap_.getView().getProjection().getCode()).to.be(
|
||||
'EPSG:4326'
|
||||
);
|
||||
});
|
||||
|
||||
it('retains explicitly set view', function() {
|
||||
it('retains explicitly set view', function () {
|
||||
const overviewMapView = new View();
|
||||
const control = new OverviewMap({
|
||||
rotateWithView: true,
|
||||
view: overviewMapView
|
||||
view: overviewMapView,
|
||||
});
|
||||
|
||||
map.addControl(control);
|
||||
expect(control.ovmap_.getView()).to.be(overviewMapView);
|
||||
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:3857');
|
||||
expect(control.ovmap_.getView().getProjection().getCode()).to.be(
|
||||
'EPSG:3857'
|
||||
);
|
||||
|
||||
map.setView(new View({
|
||||
projection: 'EPSG:4326'
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
projection: 'EPSG:4326',
|
||||
})
|
||||
);
|
||||
expect(control.ovmap_.getView()).to.be(overviewMapView);
|
||||
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:3857');
|
||||
expect(control.ovmap_.getView().getProjection().getCode()).to.be(
|
||||
'EPSG:3857'
|
||||
);
|
||||
});
|
||||
|
||||
it('set target to null', function() {
|
||||
it('set target to null', function () {
|
||||
const control = new OverviewMap();
|
||||
|
||||
map.addControl(control);
|
||||
@@ -137,7 +148,5 @@ describe('ol.control.OverviewMap', function() {
|
||||
|
||||
expect(control.ovmap_.getTarget()).to.be(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
import Rotate from '../../../../src/ol/control/Rotate.js';
|
||||
|
||||
describe('ol.control.Rotate', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('can be constructed without arguments', function() {
|
||||
describe('ol.control.Rotate', function () {
|
||||
describe('constructor', function () {
|
||||
it('can be constructed without arguments', function () {
|
||||
const instance = new Rotate();
|
||||
expect(instance).to.be.an(Rotate);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,118 +1,133 @@
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import ScaleLine, {render} from '../../../../src/ol/control/ScaleLine.js';
|
||||
import {fromLonLat, clearAllProjections, addCommon} from '../../../../src/ol/proj.js';
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
import ScaleLine, {render} from '../../../../src/ol/control/ScaleLine.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import proj4 from 'proj4';
|
||||
import {
|
||||
addCommon,
|
||||
clearAllProjections,
|
||||
fromLonLat,
|
||||
} from '../../../../src/ol/proj.js';
|
||||
import {register} from '../../../../src/ol/proj/proj4.js';
|
||||
|
||||
describe('ol.control.ScaleLine', function() {
|
||||
describe('ol.control.ScaleLine', function () {
|
||||
let map;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
const target = document.createElement('div');
|
||||
target.style.height = '256px';
|
||||
document.body.appendChild(target);
|
||||
map = new Map({
|
||||
target: target
|
||||
target: target,
|
||||
});
|
||||
});
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
disposeMap(map);
|
||||
map = null;
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
it('can be constructed without arguments', function() {
|
||||
describe('constructor', function () {
|
||||
it('can be constructed without arguments', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
expect(ctrl).to.be.an(ScaleLine);
|
||||
});
|
||||
});
|
||||
|
||||
describe('configuration options', function() {
|
||||
|
||||
describe('className', function() {
|
||||
it('defaults to "ol-scale-line"', function() {
|
||||
describe('configuration options', function () {
|
||||
describe('className', function () {
|
||||
it('defaults to "ol-scale-line"', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
const element = document.querySelector('.ol-scale-line', map.getTarget());
|
||||
const element = document.querySelector(
|
||||
'.ol-scale-line',
|
||||
map.getTarget()
|
||||
);
|
||||
expect(element).to.not.be(null);
|
||||
expect(element).to.be.a(HTMLDivElement);
|
||||
});
|
||||
it('can be configured', function() {
|
||||
it('can be configured', function () {
|
||||
const ctrl = new ScaleLine({
|
||||
className: 'humpty-dumpty'
|
||||
className: 'humpty-dumpty',
|
||||
});
|
||||
ctrl.setMap(map);
|
||||
|
||||
// check that the default was not chosen
|
||||
const element1 = document.querySelector('.ol-scale-line', map.getTarget());
|
||||
const element1 = document.querySelector(
|
||||
'.ol-scale-line',
|
||||
map.getTarget()
|
||||
);
|
||||
expect(element1).to.be(null);
|
||||
// check if the configured classname was chosen
|
||||
const element2 = document.querySelector('.humpty-dumpty', map.getTarget());
|
||||
const element2 = document.querySelector(
|
||||
'.humpty-dumpty',
|
||||
map.getTarget()
|
||||
);
|
||||
expect(element2).to.not.be(null);
|
||||
expect(element2).to.be.a(HTMLDivElement);
|
||||
});
|
||||
});
|
||||
|
||||
describe('minWidth', function() {
|
||||
it('defaults to 64', function() {
|
||||
describe('minWidth', function () {
|
||||
it('defaults to 64', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
expect(ctrl.minWidth_).to.be(64);
|
||||
});
|
||||
it('can be configured', function() {
|
||||
it('can be configured', function () {
|
||||
const ctrl = new ScaleLine({
|
||||
minWidth: 4711
|
||||
minWidth: 4711,
|
||||
});
|
||||
expect(ctrl.minWidth_).to.be(4711);
|
||||
});
|
||||
});
|
||||
|
||||
describe('render', function() {
|
||||
it('defaults to `ol.control.ScaleLine.render`', function() {
|
||||
describe('render', function () {
|
||||
it('defaults to `ol.control.ScaleLine.render`', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
expect(ctrl.render_).to.be(render);
|
||||
});
|
||||
it('can be configured', function() {
|
||||
const myRender = function() {};
|
||||
it('can be configured', function () {
|
||||
const myRender = function () {};
|
||||
const ctrl = new ScaleLine({
|
||||
render: myRender
|
||||
render: myRender,
|
||||
});
|
||||
expect(ctrl.render_).to.be(myRender);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('synchronisation with map view', function() {
|
||||
it('calls `render` as soon as the map is rendered', function(done) {
|
||||
describe('synchronisation with map view', function () {
|
||||
it('calls `render` as soon as the map is rendered', function (done) {
|
||||
const renderSpy = sinon.spy();
|
||||
const ctrl = new ScaleLine({
|
||||
render: renderSpy
|
||||
render: renderSpy,
|
||||
});
|
||||
expect(renderSpy.called).to.be(false);
|
||||
ctrl.setMap(map);
|
||||
expect(renderSpy.called).to.be(false);
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
})
|
||||
);
|
||||
expect(renderSpy.called).to.be(false);
|
||||
map.once('postrender', function() {
|
||||
map.once('postrender', function () {
|
||||
expect(renderSpy.called).to.be(true);
|
||||
expect(renderSpy.callCount).to.be(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('calls `render` as often as the map is rendered', function() {
|
||||
it('calls `render` as often as the map is rendered', function () {
|
||||
const renderSpy = sinon.spy();
|
||||
const ctrl = new ScaleLine({
|
||||
render: renderSpy
|
||||
render: renderSpy,
|
||||
});
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
expect(renderSpy.callCount).to.be(1);
|
||||
map.renderSync();
|
||||
@@ -120,18 +135,20 @@ describe('ol.control.ScaleLine', function() {
|
||||
map.renderSync();
|
||||
expect(renderSpy.callCount).to.be(3);
|
||||
});
|
||||
it('calls `render` as when the view changes', function(done) {
|
||||
it('calls `render` as when the view changes', function (done) {
|
||||
const renderSpy = sinon.spy();
|
||||
const ctrl = new ScaleLine({
|
||||
render: renderSpy
|
||||
render: renderSpy,
|
||||
});
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
map.once('postrender', function() {
|
||||
map.once('postrender', function () {
|
||||
expect(renderSpy.callCount).to.be(2);
|
||||
done();
|
||||
});
|
||||
@@ -139,47 +156,51 @@ describe('ol.control.ScaleLine', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('static method `render`', function() {
|
||||
it('updates the rendered text', function() {
|
||||
describe('static method `render`', function () {
|
||||
it('updates the rendered text', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
expect(ctrl.element.innerText).to.be('');
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
multiWorld: true,
|
||||
zoom: 0
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
center: [0, 0],
|
||||
multiWorld: true,
|
||||
zoom: 0,
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('10000 km');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUnits', function() {
|
||||
it('returns "metric" by default', function() {
|
||||
describe('#getUnits', function () {
|
||||
it('returns "metric" by default', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
expect(ctrl.getUnits()).to.be('metric');
|
||||
});
|
||||
it('returns what is configured via `units` property', function() {
|
||||
it('returns what is configured via `units` property', function () {
|
||||
const ctrl = new ScaleLine({
|
||||
units: 'nautical'
|
||||
units: 'nautical',
|
||||
});
|
||||
expect(ctrl.getUnits()).to.be('nautical');
|
||||
});
|
||||
it('returns what is configured `setUnits` method', function() {
|
||||
it('returns what is configured `setUnits` method', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setUnits('nautical');
|
||||
expect(ctrl.getUnits()).to.be('nautical');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setUnits', function() {
|
||||
it('triggers rerendering', function() {
|
||||
describe('#setUnits', function () {
|
||||
it('triggers rerendering', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
multiWorld: true,
|
||||
zoom: 0
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
center: [0, 0],
|
||||
multiWorld: true,
|
||||
zoom: 0,
|
||||
})
|
||||
);
|
||||
ctrl.setMap(map);
|
||||
|
||||
map.renderSync();
|
||||
@@ -191,52 +212,54 @@ describe('ol.control.ScaleLine', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('different units result in different contents', function() {
|
||||
describe('different units result in different contents', function () {
|
||||
let ctrl;
|
||||
let metricHtml;
|
||||
let nauticalHtml;
|
||||
let degreesHtml;
|
||||
let imperialHtml;
|
||||
let usHtml;
|
||||
beforeEach(function(done) {
|
||||
beforeEach(function (done) {
|
||||
ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
}));
|
||||
map.once('postrender', function() {
|
||||
map.setView(
|
||||
new View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
})
|
||||
);
|
||||
map.once('postrender', function () {
|
||||
metricHtml = ctrl.element.innerHTML;
|
||||
done();
|
||||
});
|
||||
});
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
map.setView(null);
|
||||
map.removeControl(ctrl);
|
||||
});
|
||||
|
||||
it('renders a scaleline for "metric"', function() {
|
||||
it('renders a scaleline for "metric"', function () {
|
||||
expect(metricHtml).to.not.be(undefined);
|
||||
});
|
||||
it('renders a different scaleline for "nautical"', function() {
|
||||
it('renders a different scaleline for "nautical"', function () {
|
||||
ctrl.setUnits('nautical');
|
||||
nauticalHtml = ctrl.element.innerHTML;
|
||||
expect(nauticalHtml).to.not.be(metricHtml);
|
||||
});
|
||||
it('renders a different scaleline for "degrees"', function() {
|
||||
it('renders a different scaleline for "degrees"', function () {
|
||||
ctrl.setUnits('degrees');
|
||||
degreesHtml = ctrl.element.innerHTML;
|
||||
expect(degreesHtml).to.not.be(metricHtml);
|
||||
expect(degreesHtml).to.not.be(nauticalHtml);
|
||||
});
|
||||
it('renders a different scaleline for "imperial"', function() {
|
||||
it('renders a different scaleline for "imperial"', function () {
|
||||
ctrl.setUnits('imperial');
|
||||
imperialHtml = ctrl.element.innerHTML;
|
||||
expect(imperialHtml).to.not.be(metricHtml);
|
||||
expect(imperialHtml).to.not.be(nauticalHtml);
|
||||
expect(imperialHtml).to.not.be(degreesHtml);
|
||||
});
|
||||
it('renders a different scaleline for "us"', function() {
|
||||
it('renders a different scaleline for "us"', function () {
|
||||
ctrl.setUnits('us');
|
||||
usHtml = ctrl.element.innerHTML;
|
||||
expect(usHtml).to.not.be(metricHtml);
|
||||
@@ -247,94 +270,110 @@ describe('ol.control.ScaleLine', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('projections affect the scaleline', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
proj4.defs('Indiana-East', 'PROJCS["IN83-EF",GEOGCS["LL83",DATUM["NAD83",' +
|
||||
'SPHEROID["GRS1980",6378137.000,298.25722210]],PRIMEM["Greenwich",0],' +
|
||||
'UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],' +
|
||||
'PARAMETER["false_easting",328083.333],' +
|
||||
'PARAMETER["false_northing",820208.333],' +
|
||||
'PARAMETER["scale_factor",0.999966666667],' +
|
||||
'PARAMETER["central_meridian",-85.66666666666670],' +
|
||||
'PARAMETER["latitude_of_origin",37.50000000000000],' +
|
||||
'UNIT["Foot_US",0.30480060960122]]');
|
||||
describe('projections affect the scaleline', function () {
|
||||
beforeEach(function () {
|
||||
proj4.defs(
|
||||
'Indiana-East',
|
||||
'PROJCS["IN83-EF",GEOGCS["LL83",DATUM["NAD83",' +
|
||||
'SPHEROID["GRS1980",6378137.000,298.25722210]],PRIMEM["Greenwich",0],' +
|
||||
'UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],' +
|
||||
'PARAMETER["false_easting",328083.333],' +
|
||||
'PARAMETER["false_northing",820208.333],' +
|
||||
'PARAMETER["scale_factor",0.999966666667],' +
|
||||
'PARAMETER["central_meridian",-85.66666666666670],' +
|
||||
'PARAMETER["latitude_of_origin",37.50000000000000],' +
|
||||
'UNIT["Foot_US",0.30480060960122]]'
|
||||
);
|
||||
register(proj4);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
clearAllProjections();
|
||||
addCommon();
|
||||
});
|
||||
|
||||
it('is rendered differently for different projections', function() {
|
||||
it('is rendered differently for different projections', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: fromLonLat([7, 52]),
|
||||
zoom: 2,
|
||||
projection: 'EPSG:3857'
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
center: fromLonLat([7, 52]),
|
||||
zoom: 2,
|
||||
projection: 'EPSG:3857',
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('2000 km');
|
||||
map.setView(new View({
|
||||
center: [7, 52],
|
||||
multiWorld: true,
|
||||
zoom: 2,
|
||||
projection: 'EPSG:4326'
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
center: [7, 52],
|
||||
multiWorld: true,
|
||||
zoom: 2,
|
||||
projection: 'EPSG:4326',
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('5000 km');
|
||||
map.setView(new View({
|
||||
center: fromLonLat([-85.685, 39.891], 'Indiana-East'),
|
||||
zoom: 7,
|
||||
projection: 'Indiana-East'
|
||||
}));
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('100 km');
|
||||
});
|
||||
|
||||
it('shows the same scale for different projections at higher resolutions', function() {
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: fromLonLat([-85.685, 39.891]),
|
||||
zoom: 7,
|
||||
projection: 'EPSG:3857'
|
||||
}));
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('100 km');
|
||||
map.setView(new View({
|
||||
center: [-85.685, 39.891],
|
||||
zoom: 7,
|
||||
projection: 'EPSG:4326'
|
||||
}));
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('100 km');
|
||||
map.setView(new View({
|
||||
center: fromLonLat([-85.685, 39.891], 'Indiana-East'),
|
||||
zoom: 7,
|
||||
projection: 'Indiana-East'
|
||||
}));
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('100 km');
|
||||
});
|
||||
|
||||
it('Projection\'s metersPerUnit affect scale for non-degree units', function() {
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
resolutions: [1],
|
||||
projection: new Projection({
|
||||
code: 'METERS',
|
||||
units: 'm',
|
||||
getPointResolution: function(r) {
|
||||
return r;
|
||||
}
|
||||
map.setView(
|
||||
new View({
|
||||
center: fromLonLat([-85.685, 39.891], 'Indiana-East'),
|
||||
zoom: 7,
|
||||
projection: 'Indiana-East',
|
||||
})
|
||||
}));
|
||||
);
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('100 km');
|
||||
});
|
||||
|
||||
it('shows the same scale for different projections at higher resolutions', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
map.setView(
|
||||
new View({
|
||||
center: fromLonLat([-85.685, 39.891]),
|
||||
zoom: 7,
|
||||
projection: 'EPSG:3857',
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('100 km');
|
||||
map.setView(
|
||||
new View({
|
||||
center: [-85.685, 39.891],
|
||||
zoom: 7,
|
||||
projection: 'EPSG:4326',
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('100 km');
|
||||
map.setView(
|
||||
new View({
|
||||
center: fromLonLat([-85.685, 39.891], 'Indiana-East'),
|
||||
zoom: 7,
|
||||
projection: 'Indiana-East',
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('100 km');
|
||||
});
|
||||
|
||||
it("Projection's metersPerUnit affect scale for non-degree units", function () {
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
map.setView(
|
||||
new View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
resolutions: [1],
|
||||
projection: new Projection({
|
||||
code: 'METERS',
|
||||
units: 'm',
|
||||
getPointResolution: function (r) {
|
||||
return r;
|
||||
},
|
||||
}),
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
|
||||
ctrl.setUnits('metric');
|
||||
@@ -349,20 +388,21 @@ describe('ol.control.ScaleLine', function() {
|
||||
ctrl.setUnits('us');
|
||||
expect(ctrl.element.innerText).to.be('500 ft');
|
||||
|
||||
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
resolutions: [1],
|
||||
projection: new Projection({
|
||||
code: 'PIXELS',
|
||||
units: 'pixels',
|
||||
metersPerUnit: 1 / 1000,
|
||||
getPointResolution: function(r) {
|
||||
return r;
|
||||
}
|
||||
map.setView(
|
||||
new View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
resolutions: [1],
|
||||
projection: new Projection({
|
||||
code: 'PIXELS',
|
||||
units: 'pixels',
|
||||
metersPerUnit: 1 / 1000,
|
||||
getPointResolution: function (r) {
|
||||
return r;
|
||||
},
|
||||
}),
|
||||
})
|
||||
}));
|
||||
);
|
||||
map.renderSync();
|
||||
|
||||
ctrl.setUnits('metric');
|
||||
@@ -378,15 +418,17 @@ describe('ol.control.ScaleLine', function() {
|
||||
expect(ctrl.element.innerText).to.be('5 in');
|
||||
});
|
||||
|
||||
it('Metric display works with Geographic (EPSG:4326) projection', function() {
|
||||
it('Metric display works with Geographic (EPSG:4326) projection', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
multiWorld: true,
|
||||
zoom: 0, /* min zoom */
|
||||
projection: 'EPSG:4326'
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
center: [0, 0],
|
||||
multiWorld: true,
|
||||
zoom: 0 /* min zoom */,
|
||||
projection: 'EPSG:4326',
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
expect(ctrl.element.innerText).to.be('10000 km');
|
||||
map.getView().setZoom(28); /* max zoom */
|
||||
@@ -395,16 +437,17 @@ describe('ol.control.ScaleLine', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('latitude may affect scale line in EPSG:4326', function() {
|
||||
|
||||
it('is rendered differently at different latitudes for metric', function() {
|
||||
describe('latitude may affect scale line in EPSG:4326', function () {
|
||||
it('is rendered differently at different latitudes for metric', function () {
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: [7, 0],
|
||||
zoom: 2,
|
||||
projection: 'EPSG:4326'
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
center: [7, 0],
|
||||
zoom: 2,
|
||||
projection: 'EPSG:4326',
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
const innerHtml0 = ctrl.element.innerHTML;
|
||||
map.getView().setCenter([7, 52]);
|
||||
@@ -413,17 +456,19 @@ describe('ol.control.ScaleLine', function() {
|
||||
expect(innerHtml0).to.not.be(innerHtml52);
|
||||
});
|
||||
|
||||
it('is rendered the same at different latitudes for degrees', function() {
|
||||
it('is rendered the same at different latitudes for degrees', function () {
|
||||
const ctrl = new ScaleLine({
|
||||
units: 'degrees'
|
||||
units: 'degrees',
|
||||
});
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: [7, 0],
|
||||
zoom: 2,
|
||||
projection: 'EPSG:4326',
|
||||
multiWorld: true
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
center: [7, 0],
|
||||
zoom: 2,
|
||||
projection: 'EPSG:4326',
|
||||
multiWorld: true,
|
||||
})
|
||||
);
|
||||
map.renderSync();
|
||||
const innerHtml0 = ctrl.element.innerHTML;
|
||||
map.getView().setCenter([7, 52]);
|
||||
@@ -431,16 +476,15 @@ describe('ol.control.ScaleLine', function() {
|
||||
const innerHtml52 = ctrl.element.innerHTML;
|
||||
expect(innerHtml0).to.be(innerHtml52);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('zoom affects the scaleline', function() {
|
||||
describe('zoom affects the scaleline', function () {
|
||||
let currentZoom;
|
||||
let ctrl;
|
||||
let renderedHtmls;
|
||||
let mapView;
|
||||
|
||||
const getMetricUnit = function(zoom) {
|
||||
const getMetricUnit = function (zoom) {
|
||||
if (zoom > 30) {
|
||||
return 'μm';
|
||||
} else if (zoom > 20) {
|
||||
@@ -452,7 +496,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
}
|
||||
};
|
||||
|
||||
const getImperialUnit = function(zoom) {
|
||||
const getImperialUnit = function (zoom) {
|
||||
if (zoom >= 21) {
|
||||
return 'in';
|
||||
} else if (zoom >= 10) {
|
||||
@@ -462,29 +506,30 @@ describe('ol.control.ScaleLine', function() {
|
||||
}
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
currentZoom = 33;
|
||||
renderedHtmls = {};
|
||||
ctrl = new ScaleLine({
|
||||
minWidth: 10
|
||||
minWidth: 10,
|
||||
});
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
zoom: currentZoom,
|
||||
maxZoom: currentZoom,
|
||||
multiWorld: true
|
||||
}));
|
||||
map.setView(
|
||||
new View({
|
||||
center: [0, 0],
|
||||
zoom: currentZoom,
|
||||
maxZoom: currentZoom,
|
||||
multiWorld: true,
|
||||
})
|
||||
);
|
||||
mapView = map.getView();
|
||||
map.renderSync();
|
||||
|
||||
});
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
map.removeControl(ctrl);
|
||||
map.setView(null);
|
||||
});
|
||||
|
||||
it('metric: is rendered differently for different zoomlevels', function() {
|
||||
it('metric: is rendered differently for different zoomlevels', function () {
|
||||
ctrl.setUnits('metric');
|
||||
map.renderSync();
|
||||
renderedHtmls[ctrl.element.innerHTML] = true;
|
||||
@@ -499,7 +544,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
expect(unit).to.eql(getMetricUnit(currentZoom));
|
||||
}
|
||||
});
|
||||
it('degrees: is rendered differently for different zoomlevels', function() {
|
||||
it('degrees: is rendered differently for different zoomlevels', function () {
|
||||
ctrl.setUnits('degrees');
|
||||
map.renderSync();
|
||||
renderedHtmls[ctrl.element.innerHTML] = true;
|
||||
@@ -511,7 +556,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
renderedHtmls[currentHtml] = true;
|
||||
}
|
||||
});
|
||||
it('imperial: is rendered differently for different zoomlevels', function() {
|
||||
it('imperial: is rendered differently for different zoomlevels', function () {
|
||||
ctrl.setUnits('imperial');
|
||||
map.renderSync();
|
||||
renderedHtmls[ctrl.element.innerHTML] = true;
|
||||
@@ -526,7 +571,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
expect(unit).to.eql(getImperialUnit(currentZoom));
|
||||
}
|
||||
});
|
||||
it('nautical: is rendered differently for different zoomlevels', function() {
|
||||
it('nautical: is rendered differently for different zoomlevels', function () {
|
||||
ctrl.setUnits('nautical');
|
||||
map.renderSync();
|
||||
renderedHtmls[ctrl.element.innerHTML] = true;
|
||||
@@ -538,7 +583,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
renderedHtmls[currentHtml] = true;
|
||||
}
|
||||
});
|
||||
it('us: is rendered differently for different zoomlevels', function() {
|
||||
it('us: is rendered differently for different zoomlevels', function () {
|
||||
ctrl.setUnits('us');
|
||||
map.renderSync();
|
||||
renderedHtmls[ctrl.element.innerHTML] = true;
|
||||
@@ -551,5 +596,4 @@ describe('ol.control.ScaleLine', function() {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
import Zoom from '../../../../src/ol/control/Zoom.js';
|
||||
|
||||
describe('ol.control.Zoom', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('can be constructed without arguments', function() {
|
||||
describe('ol.control.Zoom', function () {
|
||||
describe('constructor', function () {
|
||||
it('can be constructed without arguments', function () {
|
||||
const instance = new Zoom();
|
||||
expect(instance).to.be.an(Zoom);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import Event from '../../../../src/ol/events/Event.js';
|
||||
import EventTarget from '../../../../src/ol/events/Target.js';
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import ZoomSlider from '../../../../src/ol/control/ZoomSlider.js';
|
||||
import Event from '../../../../src/ol/events/Event.js';
|
||||
import EventTarget from '../../../../src/ol/events/Target.js';
|
||||
|
||||
describe('ol.control.ZoomSlider', function() {
|
||||
describe('ol.control.ZoomSlider', function () {
|
||||
let map, target, zoomslider;
|
||||
|
||||
const createElement = document.createElement;
|
||||
@@ -19,17 +19,17 @@ describe('ol.control.ZoomSlider', function() {
|
||||
return element;
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
target = document.createElement('div');
|
||||
document.body.appendChild(target);
|
||||
zoomslider = new ZoomSlider();
|
||||
map = new Map({
|
||||
target: target,
|
||||
controls: [zoomslider]
|
||||
controls: [zoomslider],
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
zoomslider.dispose();
|
||||
map.dispose();
|
||||
document.body.removeChild(target);
|
||||
@@ -38,8 +38,8 @@ describe('ol.control.ZoomSlider', function() {
|
||||
target = null;
|
||||
});
|
||||
|
||||
describe('DOM creation', function() {
|
||||
it('creates the expected DOM elements', function() {
|
||||
describe('DOM creation', function () {
|
||||
it('creates the expected DOM elements', function () {
|
||||
const zoomSliderContainers = target.querySelectorAll('.ol-zoomslider');
|
||||
|
||||
expect(zoomSliderContainers.length).to.be(1);
|
||||
@@ -47,31 +47,36 @@ describe('ol.control.ZoomSlider', function() {
|
||||
const zoomSliderContainer = zoomSliderContainers[0];
|
||||
expect(zoomSliderContainer instanceof HTMLDivElement).to.be(true);
|
||||
|
||||
let hasUnselectableCls = zoomSliderContainer.classList.contains('ol-unselectable');
|
||||
let hasUnselectableCls = zoomSliderContainer.classList.contains(
|
||||
'ol-unselectable'
|
||||
);
|
||||
expect(hasUnselectableCls).to.be(true);
|
||||
|
||||
const zoomSliderThumbs = zoomSliderContainer.querySelectorAll('.ol-zoomslider-thumb');
|
||||
const zoomSliderThumbs = zoomSliderContainer.querySelectorAll(
|
||||
'.ol-zoomslider-thumb'
|
||||
);
|
||||
expect(zoomSliderThumbs.length).to.be(1);
|
||||
|
||||
const zoomSliderThumb = zoomSliderThumbs[0];
|
||||
expect(zoomSliderThumb instanceof HTMLButtonElement).to.be(true);
|
||||
|
||||
hasUnselectableCls = zoomSliderThumb.classList.contains('ol-unselectable');
|
||||
hasUnselectableCls = zoomSliderThumb.classList.contains(
|
||||
'ol-unselectable'
|
||||
);
|
||||
expect(hasUnselectableCls).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#initSlider_', function() {
|
||||
it('sets limits', function() {
|
||||
describe('#initSlider_', function () {
|
||||
it('sets limits', function () {
|
||||
zoomslider.initSlider_();
|
||||
expect(zoomslider.widthLimit_).not.to.be(0);
|
||||
expect(zoomslider.heightLimit_).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#direction_', function() {
|
||||
it('is horizontal for wide containers', function() {
|
||||
describe('#direction_', function () {
|
||||
it('is horizontal for wide containers', function () {
|
||||
const control = new ZoomSlider({});
|
||||
control.element.style.width = '1000px';
|
||||
control.element.style.height = '10px';
|
||||
@@ -84,7 +89,7 @@ describe('ol.control.ZoomSlider', function() {
|
||||
control.dispose();
|
||||
});
|
||||
|
||||
it('is vertical for tall containers', function() {
|
||||
it('is vertical for tall containers', function () {
|
||||
const control = new ZoomSlider({});
|
||||
control.element.style.width = '10px';
|
||||
control.element.style.height = '1000px';
|
||||
@@ -98,23 +103,23 @@ describe('ol.control.ZoomSlider', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Pointer event handling', function() {
|
||||
describe('Pointer event handling', function () {
|
||||
let map;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
map = new Map({
|
||||
target: createMapDiv(500, 100),
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
resolutions: [16, 8, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625]
|
||||
})
|
||||
resolutions: [16, 8, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625],
|
||||
}),
|
||||
});
|
||||
});
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
disposeMap(map);
|
||||
});
|
||||
|
||||
it('[horizontal] handles a drag sequence', function() {
|
||||
it('[horizontal] handles a drag sequence', function () {
|
||||
document.createElement = createEventElement;
|
||||
const control = new ZoomSlider();
|
||||
map.addControl(control);
|
||||
@@ -126,8 +131,8 @@ describe('ol.control.ZoomSlider', function() {
|
||||
control.element.firstChild.style.height = '10px';
|
||||
map.renderSync();
|
||||
const event = new Event();
|
||||
event.type = 'pointerdown',
|
||||
event.target = control.element.firstElementChild;
|
||||
(event.type = 'pointerdown'),
|
||||
(event.target = control.element.firstElementChild);
|
||||
event.clientX = control.widthLimit_;
|
||||
event.clientY = 0;
|
||||
control.element.dispatchEvent(event);
|
||||
@@ -135,12 +140,12 @@ describe('ol.control.ZoomSlider', function() {
|
||||
expect(control.dragging_).to.be(true);
|
||||
expect(control.dragListenerKeys_.length).to.be(2);
|
||||
event.type = 'pointermove';
|
||||
event.clientX = 6 * control.widthLimit_ / 8;
|
||||
event.clientX = (6 * control.widthLimit_) / 8;
|
||||
event.clientY = 0;
|
||||
control.element.dispatchEvent(event);
|
||||
expect(control.currentResolution_).to.be(4);
|
||||
event.type = 'pointermove';
|
||||
event.clientX = 4 * control.widthLimit_ / 8;
|
||||
event.clientX = (4 * control.widthLimit_) / 8;
|
||||
event.clientY = 0;
|
||||
control.element.dispatchEvent(event);
|
||||
event.type = 'pointerup';
|
||||
@@ -149,7 +154,7 @@ describe('ol.control.ZoomSlider', function() {
|
||||
expect(control.dragListenerKeys_.length).to.be(0);
|
||||
expect(control.dragging_).to.be(false);
|
||||
});
|
||||
it('[horizontal] handles a drag sequence ending outside its bounds', function() {
|
||||
it('[horizontal] handles a drag sequence ending outside its bounds', function () {
|
||||
document.createElement = createEventElement;
|
||||
const control = new ZoomSlider();
|
||||
map.addControl(control);
|
||||
@@ -170,12 +175,12 @@ describe('ol.control.ZoomSlider', function() {
|
||||
expect(control.dragging_).to.be(true);
|
||||
expect(control.dragListenerKeys_.length).to.be(2);
|
||||
event.type = 'pointermove';
|
||||
event.clientX = 6 * control.widthLimit_ / 8;
|
||||
event.clientX = (6 * control.widthLimit_) / 8;
|
||||
event.clientY = 0;
|
||||
control.element.dispatchEvent(event);
|
||||
expect(control.currentResolution_).to.be(4);
|
||||
event.type = 'pointermove';
|
||||
event.clientX = 12 * control.widthLimit_ / 8;
|
||||
event.clientX = (12 * control.widthLimit_) / 8;
|
||||
event.clientY = 0;
|
||||
control.element.dispatchEvent(event);
|
||||
event.type = 'pointerup';
|
||||
@@ -185,7 +190,7 @@ describe('ol.control.ZoomSlider', function() {
|
||||
expect(control.dragging_).to.be(false);
|
||||
expect(control.currentResolution_).to.be(16);
|
||||
});
|
||||
it('[vertical] handles a drag sequence', function() {
|
||||
it('[vertical] handles a drag sequence', function () {
|
||||
document.createElement = createEventElement;
|
||||
const control = new ZoomSlider();
|
||||
control.element.style.width = '10px';
|
||||
@@ -207,12 +212,12 @@ describe('ol.control.ZoomSlider', function() {
|
||||
expect(control.dragListenerKeys_.length).to.be(2);
|
||||
event.type = 'pointermove';
|
||||
event.clientX = 0;
|
||||
event.clientY = 2 * control.heightLimit_ / 8;
|
||||
event.clientY = (2 * control.heightLimit_) / 8;
|
||||
control.element.dispatchEvent(event);
|
||||
expect(control.currentResolution_).to.be(0.25);
|
||||
event.type = 'pointermove';
|
||||
event.clientX = 0;
|
||||
event.clientY = 4 * control.heightLimit_ / 8;
|
||||
event.clientY = (4 * control.heightLimit_) / 8;
|
||||
control.element.dispatchEvent(event);
|
||||
event.type = 'pointerup';
|
||||
control.element.dispatchEvent(event);
|
||||
@@ -220,7 +225,7 @@ describe('ol.control.ZoomSlider', function() {
|
||||
expect(control.dragListenerKeys_.length).to.be(0);
|
||||
expect(control.dragging_).to.be(false);
|
||||
});
|
||||
it('[vertical] handles a drag sequence ending outside its bounds', function() {
|
||||
it('[vertical] handles a drag sequence ending outside its bounds', function () {
|
||||
document.createElement = createEventElement;
|
||||
const control = new ZoomSlider();
|
||||
control.element.style.width = '10px';
|
||||
@@ -242,12 +247,12 @@ describe('ol.control.ZoomSlider', function() {
|
||||
expect(control.dragListenerKeys_.length).to.be(2);
|
||||
event.type = 'pointermove';
|
||||
event.clientX = 0;
|
||||
event.clientY = 2 * control.heightLimit_ / 8;
|
||||
event.clientY = (2 * control.heightLimit_) / 8;
|
||||
control.element.dispatchEvent(event);
|
||||
expect(control.currentResolution_).to.be(0.25);
|
||||
event.type = 'pointermove';
|
||||
event.clientX = 0;
|
||||
event.clientY = 12 * control.heightLimit_ / 8;
|
||||
event.clientY = (12 * control.heightLimit_) / 8;
|
||||
control.element.dispatchEvent(event);
|
||||
event.type = 'pointerup';
|
||||
control.element.dispatchEvent(event);
|
||||
@@ -256,5 +261,4 @@ describe('ol.control.ZoomSlider', function() {
|
||||
expect(control.dragging_).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
import ZoomToExtent from '../../../../src/ol/control/ZoomToExtent.js';
|
||||
|
||||
describe('ol.control.ZoomToExtent', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('can be constructed without arguments', function() {
|
||||
describe('ol.control.ZoomToExtent', function () {
|
||||
describe('constructor', function () {
|
||||
it('can be constructed without arguments', function () {
|
||||
const instance = new ZoomToExtent();
|
||||
expect(instance).to.be.an(ZoomToExtent);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user