diff --git a/.eslintrc.js b/.eslintrc.js
index 16754fdbd..ac16bdb1a 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -43,7 +43,8 @@ module.exports = {
// TODO: Re-enable the rules below and fix the linting issues.
'no-invalid-this': 'off',
'prefer-object-has-own': 'error',
- 'prefer-spread': 'off'
+ 'prefer-spread': 'off',
+ 'no-new': 'off'
},
overrides: [
{
@@ -71,8 +72,7 @@ module.exports = {
'*.html'
],
rules: {
- 'eol-last': 'off',
- 'no-new': 'off'
+ 'eol-last': 'off'
}
}
]
diff --git a/spec/.eslintrc.js b/spec/.eslintrc.js
index 309ea4b3a..14b105f8b 100644
--- a/spec/.eslintrc.js
+++ b/spec/.eslintrc.js
@@ -8,14 +8,10 @@ module.exports = {
mocha: true,
},
globals: {
- L: true,
expect: false,
chai: false,
sinon: false,
UIEventSimulator: false,
Hand: false,
- touchEventType: false, /* defined in SpecHelper.js */
- createContainer: false, /* defined in SpecHelper.js */
- removeMapContainer: false /* defined in SpecHelper.js */
}
};
diff --git a/spec/after.js b/spec/after.js
deleted file mode 100644
index 63bd3ea33..000000000
--- a/spec/after.js
+++ /dev/null
@@ -1 +0,0 @@
-L.Icon.Default.imagePath = '/base/dist/images/';
diff --git a/spec/before.js b/spec/before.js
deleted file mode 100644
index e69de29bb..000000000
diff --git a/spec/context.html b/spec/context.html
new file mode 100644
index 000000000..17ac0b87f
--- /dev/null
+++ b/spec/context.html
@@ -0,0 +1,45 @@
+
+
+
+
+ element is re-used
@@ -133,16 +136,16 @@ describe('Marker', () => {
});
it('removes text when changing to a blank DivIcon', () => {
- const marker = L.marker([0, 0], {icon: L.divIcon({html: 'Inner1Text'})});
+ const marker = new Marker([0, 0], {icon: new DivIcon({html: 'Inner1Text'})});
map.addLayer(marker);
- marker.setIcon(L.divIcon());
+ marker.setIcon(new DivIcon());
expect(marker._icon.innerHTML).to.not.contain('Inner1Text');
});
it('changes a DivIcon to an image', () => {
- const marker = L.marker([0, 0], {icon: L.divIcon({html: 'Inner1Text'})});
+ const marker = new Marker([0, 0], {icon: new DivIcon({html: 'Inner1Text'})});
map.addLayer(marker);
const oldIcon = marker._icon;
@@ -151,7 +154,7 @@ describe('Marker', () => {
expect(oldIcon).to.not.equal(marker._icon); // Check that the _icon is NOT re-used
expect(oldIcon.parentNode).to.equal(null);
- if (L.Browser.retina) {
+ if (Browser.retina) {
expect(marker._icon.src).to.contain('marker-icon-2x.png');
} else {
expect(marker._icon.src).to.contain('marker-icon.png');
@@ -160,11 +163,11 @@ describe('Marker', () => {
});
it('changes an image to a DivIcon', () => {
- const marker = L.marker([0, 0], {icon: icon1});
+ const marker = new Marker([0, 0], {icon: icon1});
map.addLayer(marker);
const oldIcon = marker._icon;
- marker.setIcon(L.divIcon({html: 'Inner1Text'}));
+ marker.setIcon(new DivIcon({html: 'Inner1Text'}));
expect(oldIcon).to.not.equal(marker._icon); // Check that the _icon is NOT re-used
expect(oldIcon.parentNode).to.equal(null);
@@ -174,7 +177,7 @@ describe('Marker', () => {
});
it('reuses the icon/shadow when changing icon', () => {
- const marker = L.marker([0, 0], {icon: icon1});
+ const marker = new Marker([0, 0], {icon: icon1});
map.addLayer(marker);
const oldIcon = marker._icon;
const oldShadow = marker._shadow;
@@ -189,7 +192,7 @@ describe('Marker', () => {
});
it('sets the alt attribute to a default value when no alt text is passed', () => {
- const marker = L.marker([0, 0], {icon: icon1});
+ const marker = new Marker([0, 0], {icon: icon1});
map.addLayer(marker);
const icon = marker._icon;
expect(icon.hasAttribute('alt')).to.be.true;
@@ -197,14 +200,14 @@ describe('Marker', () => {
});
it('doesn\'t set the alt attribute for DivIcons', () => {
- const marker = L.marker([0, 0], {icon: L.divIcon(), alt: 'test'});
+ const marker = new Marker([0, 0], {icon: new DivIcon(), alt: 'test'});
map.addLayer(marker);
const icon = marker._icon;
expect(icon.hasAttribute('alt')).to.be.false;
});
it('pan map to focus marker', () => {
- const marker = L.marker([70, 0], {icon: L.divIcon()});
+ const marker = new Marker([70, 0], {icon: new DivIcon()});
map.addLayer(marker);
expect(() => {
@@ -213,7 +216,7 @@ describe('Marker', () => {
});
it('pan map to focus marker with no iconSize', () => {
- const marker = L.marker([70, 0], {icon: L.divIcon({iconSize: null})});
+ const marker = new Marker([70, 0], {icon: new DivIcon({iconSize: null})});
map.addLayer(marker);
expect(() => {
@@ -225,11 +228,11 @@ describe('Marker', () => {
describe('#setLatLng', () => {
it('fires a move event', () => {
- const marker = L.marker([0, 0], {icon: icon1});
+ const marker = new Marker([0, 0], {icon: icon1});
map.addLayer(marker);
const beforeLatLng = marker._latlng;
- const afterLatLng = new L.LatLng(1, 2);
+ const afterLatLng = new LatLng(1, 2);
let eventArgs = null;
marker.on('move', (e) => {
@@ -249,7 +252,7 @@ describe('Marker', () => {
it('fires click event when clicked', () => {
const spy = sinon.spy();
- const marker = L.marker([0, 0]).addTo(map);
+ const marker = new Marker([0, 0]).addTo(map);
marker.on('click', spy);
UIEventSimulator.fire('click', marker._icon);
@@ -260,7 +263,7 @@ describe('Marker', () => {
it('fires click event when clicked with DivIcon', () => {
const spy = sinon.spy();
- const marker = L.marker([0, 0], {icon: L.divIcon()}).addTo(map);
+ const marker = new Marker([0, 0], {icon: new DivIcon()}).addTo(map);
marker.on('click', spy);
UIEventSimulator.fire('click', marker._icon);
@@ -271,7 +274,7 @@ describe('Marker', () => {
it('fires click event when clicked on DivIcon child element', () => {
const spy = sinon.spy();
- const marker = L.marker([0, 0], {icon: L.divIcon({html: '

'})}).addTo(map);
+ const marker = new Marker([0, 0], {icon: new DivIcon({html: '

'})}).addTo(map);
marker.on('click', spy);
@@ -285,8 +288,8 @@ describe('Marker', () => {
it('fires click event when clicked on DivIcon child element set using setIcon', () => {
const spy = sinon.spy();
- const marker = L.marker([0, 0]).addTo(map);
- marker.setIcon(L.divIcon({html: '

'}));
+ const marker = new Marker([0, 0]).addTo(map);
+ marker.setIcon(new DivIcon({html: '

'}));
marker.on('click', spy);
@@ -301,7 +304,7 @@ describe('Marker', () => {
const spy = sinon.spy();
const spy2 = sinon.spy();
const mapSpy = sinon.spy();
- const marker = L.marker([55.8, 37.6]);
+ const marker = new Marker([55.8, 37.6]);
map.addLayer(marker);
marker.on('click', spy);
marker.on('click', spy2);
@@ -316,7 +319,7 @@ describe('Marker', () => {
const spy = sinon.spy();
const spy2 = sinon.spy();
const mapSpy = sinon.spy();
- const marker = L.marker([55.8, 37.6]);
+ const marker = new Marker([55.8, 37.6]);
map.addLayer(marker);
marker.on('dblclick', spy);
marker.on('dblclick', spy2);
@@ -328,7 +331,7 @@ describe('Marker', () => {
});
it('do not catch event if it does not listen to it', (done) => {
- const marker = L.marker([55, 37]);
+ const marker = new Marker([55, 37]);
map.addLayer(marker);
marker.once('mousemove', (e) => {
// It should be the marker coordinates
diff --git a/spec/suites/layer/tile/GridLayerSpec.js b/spec/suites/layer/tile/GridLayerSpec.js
index 0bc5453e0..870656773 100644
--- a/spec/suites/layer/tile/GridLayerSpec.js
+++ b/spec/suites/layer/tile/GridLayerSpec.js
@@ -1,9 +1,12 @@
+import {Map, GridLayer, DomUtil, Point, Util} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('GridLayer', () => {
let container, map;
beforeEach(() => {
container = createContainer();
- map = L.map(container);
+ map = new Map(container);
container.style.width = '800px';
container.style.height = '600px';
});
@@ -14,22 +17,22 @@ describe('GridLayer', () => {
describe('#redraw', () => {
it('can be called before map.setView', () => {
- const grid = L.gridLayer().addTo(map);
+ const grid = new GridLayer().addTo(map);
expect(grid.redraw()).to.equal(grid);
});
});
describe('#setOpacity', () => {
it('can be called before map.setView', () => {
- const grid = L.gridLayer().addTo(map);
+ const grid = new GridLayer().addTo(map);
expect(grid.setOpacity(0.5)).to.equal(grid);
});
it('works when map has fadeAnimated=false (IE8 is exempt)', (done) => {
map.remove();
- map = L.map(container, {fadeAnimation: false}).setView([0, 0], 0);
+ map = new Map(container, {fadeAnimation: false}).setView([0, 0], 0);
- const grid = L.gridLayer().setOpacity(0.5).addTo(map);
+ const grid = new GridLayer().setOpacity(0.5).addTo(map);
grid.on('load', () => {
expect(grid._container.style.opacity).to.equal('0.5');
done();
@@ -42,7 +45,7 @@ describe('GridLayer', () => {
const tiles = [];
- const grid = L.gridLayer();
+ const grid = new GridLayer();
grid.createTile = function (coords) {
const tile = document.createElement('div');
tiles.push({coords, tile});
@@ -55,7 +58,7 @@ describe('GridLayer', () => {
for (let i = 0; i < tiles.length; i++) {
const coords = tiles[i].coords,
- pos = L.DomUtil.getPosition(tiles[i].tile);
+ pos = DomUtil.getPosition(tiles[i].tile);
loaded[`${pos.x}:${pos.y}`] = [coords.x, coords.y];
}
@@ -85,10 +88,10 @@ describe('GridLayer', () => {
it('removes tiles for unused zoom levels', (done) => {
map.remove();
- map = L.map(container, {fadeAnimation: false});
+ map = new Map(container, {fadeAnimation: false});
map.setView([0, 0], 1);
- const grid = L.gridLayer();
+ const grid = new GridLayer();
const tiles = {};
grid.createTile = function (coords) {
@@ -124,7 +127,7 @@ describe('GridLayer', () => {
map.setView([0, 0], 10);
- grid = L.gridLayer();
+ grid = new GridLayer();
});
it('only creates tiles for visible area on zoom in', (done) => {
@@ -205,7 +208,7 @@ describe('GridLayer', () => {
describe('#onAdd', () => {
it('is called after zoomend on first map load', () => {
- const layer = L.gridLayer().addTo(map);
+ const layer = new GridLayer().addTo(map);
const onAdd = layer.onAdd,
onAddSpy = sinon.spy();
@@ -232,7 +235,7 @@ describe('GridLayer', () => {
const maxZoom = 10,
minZoom = 5;
- L.gridLayer({
+ new GridLayer({
maxZoom,
minZoom
}).addTo(map);
@@ -244,27 +247,27 @@ describe('GridLayer', () => {
describe('accessing a gridlayer\'s properties', () => {
it('provides a container', () => {
- const layer = L.gridLayer().addTo(map);
+ const layer = new GridLayer().addTo(map);
expect(layer.getContainer()).to.be.ok;
});
});
describe('when a gridlayer is added to a map that already has a gridlayer', () => {
it('has its zoomlevels updated to fit the new layer', () => {
- L.gridLayer({minZoom: 10, maxZoom: 15}).addTo(map);
+ new GridLayer({minZoom: 10, maxZoom: 15}).addTo(map);
expect(map.getMinZoom()).to.equal(10);
expect(map.getMaxZoom()).to.equal(15);
- L.gridLayer({minZoom: 5, maxZoom: 10}).addTo(map);
+ new GridLayer({minZoom: 5, maxZoom: 10}).addTo(map);
expect(map.getMinZoom()).to.equal(5); // changed
expect(map.getMaxZoom()).to.equal(15); // unchanged
- L.gridLayer({minZoom: 10, maxZoom: 20}).addTo(map);
+ new GridLayer({minZoom: 10, maxZoom: 20}).addTo(map);
expect(map.getMinZoom()).to.equal(5); // unchanged
expect(map.getMaxZoom()).to.equal(20); // changed
- L.gridLayer({minZoom: 0, maxZoom: 25}).addTo(map);
+ new GridLayer({minZoom: 0, maxZoom: 25}).addTo(map);
expect(map.getMinZoom()).to.equal(0); // changed
expect(map.getMaxZoom()).to.equal(25); // changed
});
@@ -273,10 +276,10 @@ describe('GridLayer', () => {
describe('when a gridlayer is removed from a map', () => {
it('has its zoomlevels updated to only fit the layers it currently has', () => {
const tiles = [
- L.gridLayer({minZoom: 10, maxZoom: 15}).addTo(map),
- L.gridLayer({minZoom: 5, maxZoom: 10}).addTo(map),
- L.gridLayer({minZoom: 10, maxZoom: 20}).addTo(map),
- L.gridLayer({minZoom: 0, maxZoom: 25}).addTo(map)
+ new GridLayer({minZoom: 10, maxZoom: 15}).addTo(map),
+ new GridLayer({minZoom: 5, maxZoom: 10}).addTo(map),
+ new GridLayer({minZoom: 10, maxZoom: 20}).addTo(map),
+ new GridLayer({minZoom: 0, maxZoom: 25}).addTo(map)
];
expect(map.getMinZoom()).to.equal(0);
expect(map.getMaxZoom()).to.equal(25);
@@ -304,7 +307,7 @@ describe('GridLayer', () => {
it('calls createTile() with maxNativeZoom when map zoom is larger', (done) => {
map.setView([0, 0], 10);
- const grid = L.gridLayer({
+ const grid = new GridLayer({
maxNativeZoom: 5
});
let tileCount = 0;
@@ -328,7 +331,7 @@ describe('GridLayer', () => {
it('calls createTile() with minNativeZoom when map zoom is smaller', (done) => {
map.setView([0, 0], 3);
- const grid = L.gridLayer({
+ const grid = new GridLayer({
minNativeZoom: 5
});
let tileCount = 0;
@@ -353,7 +356,7 @@ describe('GridLayer', () => {
const initialZoom = 12;
map.setView([0, 0], initialZoom);
- const grid = L.gridLayer().addTo(map);
+ const grid = new GridLayer().addTo(map);
expect(grid._tileZoom).to.equal(initialZoom);
grid.options.maxNativeZoom = 11;
@@ -368,9 +371,9 @@ describe('GridLayer', () => {
beforeEach(() => {
clock = sinon.useFakeTimers();
- grid = L.gridLayer({
+ grid = new GridLayer({
attribution: 'Grid Layer',
- tileSize: L.point(256, 256)
+ tileSize: new Point(256, 256)
});
grid.createTile = function (coords) {
@@ -519,9 +522,9 @@ describe('GridLayer', () => {
beforeEach(() => {
clock = sinon.useFakeTimers();
- grid = L.gridLayer({
+ grid = new GridLayer({
attribution: 'Grid Layer',
- tileSize: L.point(256, 256)
+ tileSize: new Point(256, 256)
});
grid.createTile = function (coords) {
@@ -571,10 +574,10 @@ describe('GridLayer', () => {
return function () {
clock.tick(40); // 40msec/frame ~= 25fps
map.fire('_frame');
- L.Util.requestAnimFrame(_runFrames(n - 1));
+ Util.requestAnimFrame(_runFrames(n - 1));
};
} else {
- return L.Util.falseFn;
+ return Util.falseFn;
}
}
@@ -593,7 +596,7 @@ describe('GridLayer', () => {
expect(counts.tileunload).to.equal(0);
// Wait for a frame to let _updateOpacity starting.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
// Wait > 250msec for the tile fade-in animation to complete,
// which triggers the tile pruning
clock.tick(300);
@@ -630,7 +633,7 @@ describe('GridLayer', () => {
// so the remaining 4 tiles from z10 can then be pruned.
// However we have skipped any pruning from _updateOpacity,
// so we will have to rely on the setTimeout from _tileReady.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
// Wait > 250msec for the tile fade-in animation to complete,
// which triggers the tile pruning
clock.tick(300);
@@ -644,7 +647,7 @@ describe('GridLayer', () => {
map.setZoom(11, {animate: true});
// Animation (and new tiles loading) starts after 1 frame.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
// 16 extra tiles from z11 being loaded. Total 16 + 16 = 32.
expect(counts.tileloadstart).to.equal(32);
});
@@ -670,7 +673,7 @@ describe('GridLayer', () => {
// In this particular scenario, the tile unloads happen in the
// next render frame after the grid's 'load' event.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
expect(counts.tileloadstart).to.equal(32);
expect(counts.tileload).to.equal(32);
expect(counts.tileunload).to.equal(16);
@@ -698,7 +701,7 @@ describe('GridLayer', () => {
expect(counts.tileunload).to.equal(0);
// Wait for a frame to let _updateOpacity starting.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
// Wait > 250msec for the tile fade-in animation to complete,
// which triggers the tile pruning
clock.tick(300);
@@ -735,7 +738,7 @@ describe('GridLayer', () => {
// Wait for a frame for next _updateOpacity to prune
// all 16 tiles from z11 which are now covered by the
// 4 central active tiles of z10.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
expect(counts.tileunload).to.equal(16);
done();
});
@@ -745,7 +748,7 @@ describe('GridLayer', () => {
map.setZoom(10, {animate: true});
// Animation (and new tiles loading) starts after 1 frame.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
// We're one frame into the zoom animation, there are
// 16 tiles for z11 plus 4 tiles for z10 covering the
// bounds at the *beginning* of the zoom-*out* anim
@@ -770,7 +773,7 @@ describe('GridLayer', () => {
// In this particular scenario, the tile unloads happen in the
// next render frame after the grid's 'load' event.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
expect(counts.tileloadstart).to.equal(32);
expect(counts.tileload).to.equal(32);
expect(counts.tileunload).to.equal(16);
@@ -828,9 +831,9 @@ describe('GridLayer', () => {
beforeEach(() => {
clock = sinon.useFakeTimers();
- grid = L.gridLayer({
+ grid = new GridLayer({
attribution: 'Grid Layer',
- tileSize: L.point(256, 256)
+ tileSize: new Point(256, 256)
});
grid.createTile = function (coords) {
@@ -877,7 +880,7 @@ describe('GridLayer', () => {
expect(counts.tileunload).to.equal(0);
// Wait for a frame to let _updateOpacity starting.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
// Wait > 250msec for the tile fade-in animation to complete,
// which triggers the tile pruning
@@ -894,7 +897,7 @@ describe('GridLayer', () => {
// Wait for a frame to let _updateOpacity starting
// It will prune the 12 tiles outside the new bounds.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
expect(counts.tileunload).to.equal(12);
done();
});
@@ -933,7 +936,7 @@ describe('GridLayer', () => {
// Wait for a frame to let _updateOpacity starting
// It will prune the 12 tiles outside the new bounds.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
expect(counts.tileunload).to.equal(12);
grid.once('load', () => {
@@ -941,7 +944,7 @@ describe('GridLayer', () => {
expect(counts.tileload).to.equal(40);
// Wait an extra frame for the tile pruning to happen.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
expect(counts.tileunload).to.equal(24);
done();
});
@@ -997,9 +1000,9 @@ describe('GridLayer', () => {
describe('nowrap option', () => {
it('When false, uses same coords at zoom 0 for all tiles', (done) => {
- const grid = L.gridLayer({
+ const grid = new GridLayer({
attribution: 'Grid Layer',
- tileSize: L.point(256, 256),
+ tileSize: new Point(256, 256),
noWrap: false
});
const loadedTileKeys = [];
@@ -1018,9 +1021,9 @@ describe('GridLayer', () => {
});
it('When true, uses different coords at zoom level 0 for all tiles', (done) => {
- const grid = L.gridLayer({
+ const grid = new GridLayer({
attribution: 'Grid Layer',
- tileSize: L.point(256, 256),
+ tileSize: new Point(256, 256),
noWrap: true
});
const loadedTileKeys = [];
@@ -1039,9 +1042,9 @@ describe('GridLayer', () => {
});
it('When true and with bounds, loads just one tile at zoom level 0', (done) => {
- const grid = L.gridLayer({
+ const grid = new GridLayer({
attribution: 'Grid Layer',
- tileSize: L.point(256, 256),
+ tileSize: new Point(256, 256),
bounds: [[-90, -180], [90, 180]],
noWrap: true
});
@@ -1065,21 +1068,21 @@ describe('GridLayer', () => {
it('Throws error on map center at plus Infinity longitude', () => {
expect(() => {
map.panTo([Infinity, Infinity]);
- L.gridLayer().addTo(map);
+ new GridLayer().addTo(map);
}).to.throw('Attempted to load an infinite number of tiles');
});
it('Throws error on map center at minus Infinity longitude', () => {
expect(() => {
map.panTo([-Infinity, -Infinity]);
- L.gridLayer().addTo(map);
+ new GridLayer().addTo(map);
}).to.throw('Attempted to load an infinite number of tiles');
});
});
it('doesn\'t call map\'s getZoomScale method with null after _invalidateAll method was called', () => {
map.setView([0, 0], 0);
- const grid = L.gridLayer().addTo(map);
+ const grid = new GridLayer().addTo(map);
const wrapped = sinon.spy(map, 'getZoomScale');
grid._invalidateAll();
grid.redraw();
diff --git a/spec/suites/layer/tile/TileLayerSpec.js b/spec/suites/layer/tile/TileLayerSpec.js
index 79ec45d3b..867777428 100644
--- a/spec/suites/layer/tile/TileLayerSpec.js
+++ b/spec/suites/layer/tile/TileLayerSpec.js
@@ -1,3 +1,6 @@
+import {Map, TileLayer, Util, CRS, DomUtil, Browser} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('TileLayer', () => {
let container, map;
@@ -160,7 +163,7 @@ describe('TileLayer', () => {
beforeEach(() => {
container = createContainer();
- map = L.map(container);
+ map = new Map(container);
container.style.width = '800px';
container.style.height = '600px';
});
@@ -170,7 +173,7 @@ describe('TileLayer', () => {
});
function kittenLayerFactory(options) {
- return L.tileLayer(placeKitten, options || {});
+ return new TileLayer(placeKitten, options || {});
}
function eachImg(layer, callback) {
@@ -195,10 +198,10 @@ describe('TileLayer', () => {
return function () {
clock.tick(40); // 40msec/frame ~= 25fps
map.fire('_frame');
- L.Util.requestAnimFrame(_runFrames(n - 1));
+ Util.requestAnimFrame(_runFrames(n - 1));
};
} else {
- return L.Util.falseFn;
+ return Util.falseFn;
}
}
@@ -291,7 +294,7 @@ describe('TileLayer', () => {
});
it('replaces {y} with y coordinate', () => {
- const layer = L.tileLayer('http://example.com/{z}/{y}/{x}.png').addTo(map);
+ const layer = new TileLayer('http://example.com/{z}/{y}/{x}.png').addTo(map);
const urls = [
'http://example.com/2/1/1.png',
@@ -308,7 +311,7 @@ describe('TileLayer', () => {
});
it('replaces {-y} with inverse y coordinate', () => {
- const layer = L.tileLayer('http://example.com/{z}/{-y}/{x}.png').addTo(map);
+ const layer = new TileLayer('http://example.com/{z}/{-y}/{x}.png').addTo(map);
const urls = [
'http://example.com/2/2/1.png',
'http://example.com/2/2/2.png',
@@ -329,10 +332,10 @@ describe('TileLayer', () => {
simplediv.style.visibility = 'hidden';
document.body.appendChild(simplediv);
- const simpleMap = L.map(simplediv, {
- crs: L.CRS.Simple
+ const simpleMap = new Map(simplediv, {
+ crs: CRS.Simple
}).setView([0, 0], 5);
- const layer = L.tileLayer('http://example.com/{z}/{-y}/{x}.png');
+ const layer = new TileLayer('http://example.com/{z}/{-y}/{x}.png');
expect(() => {
layer.addTo(simpleMap);
@@ -343,7 +346,7 @@ describe('TileLayer', () => {
});
it('replaces {s} with [abc] by default', () => {
- const layer = L.tileLayer('http://{s}.example.com/{z}/{-y}/{x}.png').addTo(map);
+ const layer = new TileLayer('http://{s}.example.com/{z}/{-y}/{x}.png').addTo(map);
eachImg(layer, (img) => {
expect(['a', 'b', 'c'].includes(img.src[7])).to.eql(true);
@@ -351,7 +354,7 @@ describe('TileLayer', () => {
});
it('replaces {s} with specified prefixes', () => {
- const layer = L.tileLayer('http://{s}.example.com/{z}/{-y}/{x}.png', {
+ const layer = new TileLayer('http://{s}.example.com/{z}/{-y}/{x}.png', {
subdomains: 'qrs'
}).addTo(map);
@@ -362,7 +365,7 @@ describe('TileLayer', () => {
it('uses zoomOffset option', () => {
// Map view is set at zoom 2 in beforeEach.
- const layer = L.tileLayer('http://example.com/{z}/{y}/{x}.png', {
+ const layer = new TileLayer('http://example.com/{z}/{y}/{x}.png', {
zoomOffset: 1 // => zoom 2 + zoomOffset 1 => z 3 in URL.
}).addTo(map);
@@ -382,7 +385,7 @@ describe('TileLayer', () => {
it('uses negative zoomOffset option', () => {
// Map view is set at zoom 2 in beforeEach.
- const layer = L.tileLayer('http://example.com/{z}/{y}/{x}.png', {
+ const layer = new TileLayer('http://example.com/{z}/{y}/{x}.png', {
zoomOffset: -3 // => zoom 2 + zoomOffset -3 => z -1 in URL.
}).addTo(map);
@@ -402,7 +405,7 @@ describe('TileLayer', () => {
});
- const _describe = 'crossOrigin' in L.DomUtil.create('img') ? describe : describe.skip; // skip in IE<11
+ const _describe = 'crossOrigin' in DomUtil.create('img') ? describe : describe.skip; // skip in IE<11
_describe('crossOrigin option', () => {
beforeEach(() => {
map.setView([0, 0], 2);
@@ -417,7 +420,7 @@ describe('TileLayer', () => {
function testCrossOriginValue(crossOrigin, expectedValue) {
it(`uses crossOrigin value ${crossOrigin}`, () => {
- const layer = L.tileLayer('http://example.com/{z}/{y}/{x}.png', {
+ const layer = new TileLayer('http://example.com/{z}/{y}/{x}.png', {
crossOrigin
}).addTo(map);
@@ -432,8 +435,8 @@ describe('TileLayer', () => {
const minZoom = 1;
// override retina to load extra tiles
- const originalRetina = L.Browser.retina;
- L.Browser.retina = true;
+ const originalRetina = Browser.retina;
+ Browser.retina = true;
const kittenLayer = kittenLayerFactory({
maxZoom,
@@ -446,7 +449,7 @@ describe('TileLayer', () => {
expect(kittenLayer.options.minZoom).to.equal(minZoom);
// reset retina value
- L.Browser.retina = originalRetina;
+ Browser.retina = originalRetina;
done();
});
@@ -456,8 +459,8 @@ describe('TileLayer', () => {
it('resets invalid min/maxZoom to allow for tiles to be loaded without detectRetina', (done) => {
// override retina to load extra tiles
- const originalRetina = L.Browser.retina;
- L.Browser.retina = false;
+ const originalRetina = Browser.retina;
+ Browser.retina = false;
const kittenLayer = kittenLayerFactory({
// invalid min/maxZoom
@@ -471,7 +474,7 @@ describe('TileLayer', () => {
expect(kittenLayer.options.maxZoom).to.equal(kittenLayer.options.minZoom);
// reset retina value
- L.Browser.retina = originalRetina;
+ Browser.retina = originalRetina;
done();
});
@@ -482,7 +485,7 @@ describe('TileLayer', () => {
describe('#setUrl', () => {
it('fires only one load event', (done) => {
- const layer = L.tileLayer(placeKitten).addTo(map);
+ const layer = new TileLayer(placeKitten).addTo(map);
const counts = {
load: 0,
tileload: 0
diff --git a/spec/suites/layer/vector/CanvasSpec.js b/spec/suites/layer/vector/CanvasSpec.js
index 93e1d165d..c502b1e5e 100644
--- a/spec/suites/layer/vector/CanvasSpec.js
+++ b/spec/suites/layer/vector/CanvasSpec.js
@@ -1,3 +1,6 @@
+import {Map, Polygon, DomEvent, Marker, Circle, SVG, stamp, Util, Polyline, LayerGroup, Canvas} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('Canvas', () => {
let container, map, latLngs;
@@ -7,7 +10,7 @@ describe('Canvas', () => {
beforeEach(() => {
container = createContainer();
- map = L.map(container, {preferCanvas: true, zoomControl: false});
+ map = new Map(container, {preferCanvas: true, zoomControl: false});
map.setView([0, 0], 6);
latLngs = [p2ll(0, 0), p2ll(0, 100), p2ll(100, 100), p2ll(100, 0)];
});
@@ -20,7 +23,7 @@ describe('Canvas', () => {
let layer;
beforeEach(() => {
- layer = L.polygon(latLngs).addTo(map);
+ layer = new Polygon(latLngs).addTo(map);
});
it('should fire event when layer contains mouse', () => {
@@ -43,7 +46,7 @@ describe('Canvas', () => {
const mapSpy = sinon.spy();
const layerSpy = sinon.spy();
map.on('click', mapSpy);
- layer.on('click', L.DomEvent.stopPropagation).on('click', layerSpy);
+ layer.on('click', DomEvent.stopPropagation).on('click', layerSpy);
UIEventSimulator.fireAt('click', 50, 50);
expect(layerSpy.callCount).to.eql(1);
expect(mapSpy.callCount).to.eql(0);
@@ -51,18 +54,18 @@ describe('Canvas', () => {
it('DOM events fired on canvas polygon are propagated only once to the map even when two layers contains the event', () => {
const spy = sinon.spy();
- L.polygon(latLngs).addTo(map); // layer 2
+ new Polygon(latLngs).addTo(map); // layer 2
map.on('click', spy);
UIEventSimulator.fireAt('click', 50, 50);
expect(spy.callCount).to.eql(1);
});
it('should be transparent for DOM events going to non-canvas features', () => {
- const marker = L.marker(map.layerPointToLatLng([150, 150]))
+ const marker = new Marker(map.layerPointToLatLng([150, 150]))
.addTo(map);
- const circle = L.circle(map.layerPointToLatLng([200, 200]), {
+ const circle = new Circle(map.layerPointToLatLng([200, 200]), {
radius: 20000,
- renderer: L.svg()
+ renderer: new SVG()
}).addTo(map);
const spyPolygon = sinon.spy();
@@ -128,8 +131,7 @@ describe('Canvas', () => {
});
const mouse = hand.growFinger('mouse');
- // We move 5 pixels first to overcome the 3-pixel threshold of
- // L.Draggable.
+ // We move 5 pixels first to overcome the 3-pixel threshold of Draggable.
mouse.moveTo(50, 50, 0)
.down().moveBy(20, 10, 200).up();
});
@@ -138,7 +140,7 @@ describe('Canvas', () => {
const spy = sinon.spy();
const center = p2ll(300, 300);
const radius = p2ll(200, 200).distanceTo(center);
- const circle = L.circle(center, {radius}).addTo(map);
+ const circle = new Circle(center, {radius}).addTo(map);
circle.on('mousedown', spy);
const hand = new Hand({
@@ -159,7 +161,7 @@ describe('Canvas', () => {
describe('#events(interactive=false)', () => {
it('should not fire click when not interactive', () => {
- const layer = L.polygon(latLngs, {interactive: false}).addTo(map);
+ const layer = new Polygon(latLngs, {interactive: false}).addTo(map);
const spy = sinon.spy();
layer.on('click', spy);
UIEventSimulator.fireAt('click', 50, 50); // Click on the layer.
@@ -171,13 +173,13 @@ describe('Canvas', () => {
describe('#dashArray', () => {
it('can add polyline with dashArray', () => {
- L.polygon(latLngs, {
+ new Polygon(latLngs, {
dashArray: '5,5'
}).addTo(map);
});
it('can setStyle with dashArray', () => {
- const layer = L.polygon(latLngs).addTo(map);
+ const layer = new Polygon(latLngs).addTo(map);
layer.setStyle({
dashArray: '5,5'
});
@@ -185,23 +187,23 @@ describe('Canvas', () => {
});
it('removes vector on next animation frame', function (done) {
- const layer = L.circle([0, 0]).addTo(map),
- layerId = L.stamp(layer),
+ const layer = new Circle([0, 0]).addTo(map),
+ layerId = stamp(layer),
canvas = map.getRenderer(layer);
expect(canvas._layers).to.have.property(layerId);
map.removeLayer(layer);
// Defer check due to how Canvas renderer manages layer removal.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
expect(canvas._layers).to.not.have.property(layerId);
done();
}, this);
});
it('adds vectors even if they have been removed just before', function (done) {
- const layer = L.circle([0, 0]).addTo(map),
- layerId = L.stamp(layer),
+ const layer = new Circle([0, 0]).addTo(map),
+ layerId = stamp(layer),
canvas = map.getRenderer(layer);
expect(canvas._layers).to.have.property(layerId);
@@ -210,7 +212,7 @@ describe('Canvas', () => {
map.addLayer(layer);
expect(canvas._layers).to.have.property(layerId);
// Re-perform a deferred check due to how Canvas renderer manages layer removal.
- L.Util.requestAnimFrame(() => {
+ Util.requestAnimFrame(() => {
expect(canvas._layers).to.have.property(layerId);
done();
}, this);
@@ -218,13 +220,13 @@ describe('Canvas', () => {
describe('#bringToBack', () => {
it('is a no-op for layers not on a map', () => {
- const path = L.polyline([[1, 2], [3, 4], [5, 6]]);
+ const path = new Polyline([[1, 2], [3, 4], [5, 6]]);
expect(path.bringToBack()).to.equal(path);
});
it('is a no-op for layers no longer in a LayerGroup', () => {
- const group = L.layerGroup().addTo(map);
- const path = L.polyline([[1, 2], [3, 4], [5, 6]]).addTo(group);
+ const group = new LayerGroup().addTo(map);
+ const path = new Polyline([[1, 2], [3, 4], [5, 6]]).addTo(group);
group.clearLayers();
@@ -234,13 +236,13 @@ describe('Canvas', () => {
describe('#bringToFront', () => {
it('is a no-op for layers not on a map', () => {
- const path = L.polyline([[1, 2], [3, 4], [5, 6]]);
+ const path = new Polyline([[1, 2], [3, 4], [5, 6]]);
expect(path.bringToFront()).to.equal(path);
});
it('is a no-op for layers no longer in a LayerGroup', () => {
- const group = L.layerGroup().addTo(map);
- const path = L.polyline([[1, 2], [3, 4], [5, 6]]).addTo(group);
+ const group = new LayerGroup().addTo(map);
+ const path = new Polyline([[1, 2], [3, 4], [5, 6]]).addTo(group);
group.clearLayers();
@@ -250,24 +252,24 @@ describe('Canvas', () => {
describe('Canvas #remove', () => {
it('can remove the map without errors', (done) => {
- L.polygon(latLngs).addTo(map);
+ new Polygon(latLngs).addTo(map);
map.remove();
map = null;
- L.Util.requestAnimFrame(() => { done(); });
+ Util.requestAnimFrame(() => { done(); });
});
it('can remove renderer without errors', (done) => {
map.remove();
- const canvas = L.canvas();
- map = L.map(container, {renderer: canvas});
+ const canvas = new Canvas();
+ map = new Map(container, {renderer: canvas});
map.setView([0, 0], 6);
- L.polygon(latLngs).addTo(map);
+ new Polygon(latLngs).addTo(map);
canvas.remove();
map.remove();
map = null;
- L.Util.requestAnimFrame(() => { done(); });
+ Util.requestAnimFrame(() => { done(); });
});
});
});
diff --git a/spec/suites/layer/vector/CircleMarkerSpec.js b/spec/suites/layer/vector/CircleMarkerSpec.js
index 4d0040e93..c8ad98170 100644
--- a/spec/suites/layer/vector/CircleMarkerSpec.js
+++ b/spec/suites/layer/vector/CircleMarkerSpec.js
@@ -1,9 +1,12 @@
-describe('CircleMarker', () => {
+import {Map, CircleMarker, LatLng, Point} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
+describe('CircleMarker', () => {
let map, container;
beforeEach(() => {
container = container = createContainer();
- map = L.map(container);
+ map = new Map(container);
map.setView([0, 0], 1);
});
@@ -15,7 +18,7 @@
describe('when a CircleMarker is added to the map ', () => {
describe('with a radius set as an option', () => {
it('takes that radius', () => {
- const marker = L.circleMarker([0, 0], {radius: 20}).addTo(map);
+ const marker = new CircleMarker([0, 0], {radius: 20}).addTo(map);
expect(marker._radius).to.equal(20);
});
@@ -23,7 +26,7 @@
describe('and radius is set before adding it', () => {
it('takes that radius', () => {
- const marker = L.circleMarker([0, 0], {radius: 20});
+ const marker = new CircleMarker([0, 0], {radius: 20});
marker.setRadius(15);
marker.addTo(map);
expect(marker._radius).to.equal(15);
@@ -32,7 +35,7 @@
describe('and radius is set after adding it', () => {
it('takes that radius', () => {
- const marker = L.circleMarker([0, 0], {radius: 20});
+ const marker = new CircleMarker([0, 0], {radius: 20});
marker.addTo(map);
marker.setRadius(15);
expect(marker._radius).to.equal(15);
@@ -41,7 +44,7 @@
describe('and setStyle is used to change the radius after adding', () => {
it('takes the given radius', () => {
- const marker = L.circleMarker([0, 0], {radius: 20});
+ const marker = new CircleMarker([0, 0], {radius: 20});
marker.addTo(map);
marker.setStyle({radius: 15});
expect(marker._radius).to.equal(15);
@@ -50,7 +53,7 @@
describe('and setStyle is used to change the radius before adding', () => {
it('takes the given radius', () => {
- const marker = L.circleMarker([0, 0], {radius: 20});
+ const marker = new CircleMarker([0, 0], {radius: 20});
marker.setStyle({radius: 15});
marker.addTo(map);
expect(marker._radius).to.equal(15);
@@ -61,11 +64,11 @@
describe('#setLatLng', () => {
it('fires a move event', () => {
- const marker = L.circleMarker([0, 0]);
+ const marker = new CircleMarker([0, 0]);
map.addLayer(marker);
const beforeLatLng = marker._latlng;
- const afterLatLng = L.latLng(1, 2);
+ const afterLatLng = new LatLng(1, 2);
let eventArgs = null;
marker.on('move', (e) => {
@@ -83,9 +86,9 @@
describe('#_containsPoint', () => {
it('checks if a point is contained', () => {
- const point1 = L.point(200, 200);
- const point2 = L.point(10, 10);
- const circlemarker = L.circleMarker([10, 10], {radius: 20});
+ const point1 = new Point(200, 200);
+ const point2 = new Point(10, 10);
+ const circlemarker = new CircleMarker([10, 10], {radius: 20});
circlemarker.addTo(map);
diff --git a/spec/suites/layer/vector/CircleSpec.js b/spec/suites/layer/vector/CircleSpec.js
index 101701f47..40baf1cb8 100644
--- a/spec/suites/layer/vector/CircleSpec.js
+++ b/spec/suites/layer/vector/CircleSpec.js
@@ -1,11 +1,14 @@
+import {Map, Circle} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('Circle', () => {
let map, container, circle;
beforeEach(() => {
container = container = createContainer();
- map = L.map(container);
+ map = new Map(container);
map.setView([0, 0], 4);
- circle = L.circle([50, 30], {radius: 200}).addTo(map);
+ circle = new Circle([50, 30], {radius: 200}).addTo(map);
});
afterEach(() => {
@@ -14,13 +17,13 @@ describe('Circle', () => {
describe('#init', () => {
it('uses default radius if not given', () => {
- const circle = L.circle([0, 0]);
+ const circle = new Circle([0, 0]);
expect(circle.getRadius()).to.eql(10);
});
it('throws error if radius is NaN', () => {
expect(() => {
- L.circle([0, 0], NaN);
+ new Circle([0, 0], NaN);
}).to.throw('Circle radius cannot be NaN');
});
diff --git a/spec/suites/layer/vector/PathSpec.js b/spec/suites/layer/vector/PathSpec.js
index 4865569d1..8210bc2b7 100644
--- a/spec/suites/layer/vector/PathSpec.js
+++ b/spec/suites/layer/vector/PathSpec.js
@@ -1,9 +1,12 @@
+import {Map, Polyline, LayerGroup, Polygon} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('Path', () => {
let container, map;
beforeEach(() => {
container = container = createContainer();
- map = L.map(container);
+ map = new Map(container);
map.setView([0, 0], 0);
});
@@ -12,16 +15,16 @@ describe('Path', () => {
});
// The following two tests are skipped, as the ES6-ifycation of Leaflet
- // means that L.Path is no longer visible.
+ // means that Path is no longer visible.
describe('#bringToBack', () => {
it('is a no-op for layers not on a map', () => {
- const path = L.polyline([[1, 2], [3, 4], [5, 6]]);
+ const path = new Polyline([[1, 2], [3, 4], [5, 6]]);
expect(path.bringToBack()).to.equal(path);
});
it('is a no-op for layers no longer in a LayerGroup', () => {
- const group = L.layerGroup().addTo(map);
- const path = L.polyline([[1, 2], [3, 4], [5, 6]]).addTo(group);
+ const group = new LayerGroup().addTo(map);
+ const path = new Polyline([[1, 2], [3, 4], [5, 6]]).addTo(group);
group.clearLayers();
@@ -31,13 +34,13 @@ describe('Path', () => {
describe('#bringToFront', () => {
it('is a no-op for layers not on a map', () => {
- const path = L.polyline([[1, 2], [3, 4], [5, 6]]);
+ const path = new Polyline([[1, 2], [3, 4], [5, 6]]);
expect(path.bringToFront()).to.equal(path);
});
it('is a no-op for layers no longer in a LayerGroup', () => {
- const group = L.layerGroup().addTo(map);
- const path = L.polyline([[1, 2], [3, 4], [5, 6]]).addTo(group);
+ const group = new LayerGroup().addTo(map);
+ const path = new Polyline([[1, 2], [3, 4], [5, 6]]).addTo(group);
group.clearLayers();
@@ -48,7 +51,7 @@ describe('Path', () => {
describe('#events', () => {
it('fires click event', () => {
const spy = sinon.spy();
- const layer = L.polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
+ const layer = new Polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
layer.on('click', spy);
UIEventSimulator.fire('click', layer._path);
expect(spy.called).to.be.true;
@@ -58,7 +61,7 @@ describe('Path', () => {
const spy = sinon.spy();
const spy2 = sinon.spy();
const mapSpy = sinon.spy();
- const layer = L.polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
+ const layer = new Polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
layer.on('click', spy);
layer.on('click', spy2);
map.on('click', mapSpy);
@@ -69,13 +72,13 @@ describe('Path', () => {
});
it('can add a layer while being inside a moveend handler', () => {
- const zoneLayer = L.layerGroup();
+ const zoneLayer = new LayerGroup();
let polygon;
map.addLayer(zoneLayer);
map.on('moveend', () => {
zoneLayer.clearLayers();
- polygon = L.polygon([[1, 2], [3, 4], [5, 6]]);
+ polygon = new Polygon([[1, 2], [3, 4], [5, 6]]);
zoneLayer.addLayer(polygon);
});
@@ -90,13 +93,13 @@ describe('Path', () => {
});
it('it should return tolerance with stroke', () => {
- const path = L.polyline([[1, 2], [3, 4], [5, 6]]);
+ const path = new Polyline([[1, 2], [3, 4], [5, 6]]);
path.addTo(map);
expect(path._clickTolerance()).to.equal(path.options.weight / 2);
});
it('it should return zero tolerance without stroke', () => {
- const path = L.polyline([[1, 2], [3, 4], [5, 6]]);
+ const path = new Polyline([[1, 2], [3, 4], [5, 6]]);
path.addTo(map);
path.options.stroke = false;
expect(path._clickTolerance()).to.equal(0);
diff --git a/spec/suites/layer/vector/PolygonSpec.js b/spec/suites/layer/vector/PolygonSpec.js
index 7c173104b..af292dd39 100644
--- a/spec/suites/layer/vector/PolygonSpec.js
+++ b/spec/suites/layer/vector/PolygonSpec.js
@@ -1,9 +1,12 @@
+import {Map, polygon, LineUtil, latLng} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('Polygon', () => {
let map, container;
beforeEach(() => {
container = createContainer();
- map = L.map(container, {center: [55.8, 37.6], zoom: 6});
+ map = new Map(container, {center: [55.8, 37.6], zoom: 6});
});
afterEach(() => {
@@ -14,10 +17,10 @@ describe('Polygon', () => {
it('should never be flat', () => {
const latLngs = [[1, 2], [3, 4]];
- const polygon = L.polygon(latLngs);
+ const poly = polygon(latLngs);
- expect(L.LineUtil.isFlat(polygon._latlngs)).to.be.false;
- expect(polygon.getLatLngs()).to.eql(polygon._latlngs);
+ expect(LineUtil.isFlat(poly._latlngs)).to.be.false;
+ expect(poly.getLatLngs()).to.eql(poly._latlngs);
});
it('doesn\'t overwrite the given latlng array', () => {
@@ -27,16 +30,16 @@ describe('Polygon', () => {
];
const sourceLatLngs = originalLatLngs.slice();
- const polygon = L.polygon(sourceLatLngs);
+ const poly = polygon(sourceLatLngs);
expect(sourceLatLngs).to.eql(originalLatLngs);
- expect(polygon._latlngs).to.not.eql(sourceLatLngs);
+ expect(poly._latlngs).to.not.eql(sourceLatLngs);
});
it('can be called with an empty array', () => {
- const polygon = L.polygon([]);
- expect(polygon._latlngs).to.eql([[]]);
- expect(polygon.getLatLngs()).to.eql(polygon._latlngs);
+ const poly = polygon([]);
+ expect(poly._latlngs).to.eql([[]]);
+ expect(poly.getLatLngs()).to.eql(poly._latlngs);
});
it('can be initialized with holes', () => {
@@ -45,13 +48,13 @@ describe('Polygon', () => {
[[2, 3], [2, 4], [3, 4]] // hole
];
- const polygon = L.polygon(originalLatLngs);
+ const poly = polygon(originalLatLngs);
- expect(polygon._latlngs).to.eql([
- [L.latLng([0, 10]), L.latLng([10, 10]), L.latLng([10, 0])],
- [L.latLng([2, 3]), L.latLng([2, 4]), L.latLng([3, 4])]
+ expect(poly._latlngs).to.eql([
+ [latLng([0, 10]), latLng([10, 10]), latLng([10, 0])],
+ [latLng([2, 3]), latLng([2, 4]), latLng([3, 4])]
]);
- expect(polygon.getLatLngs()).to.eql(polygon._latlngs);
+ expect(poly.getLatLngs()).to.eql(poly._latlngs);
});
it('can be initialized with multi including hole', () => {
@@ -60,18 +63,18 @@ describe('Polygon', () => {
[[[0, 10], [10, 10], [10, 0]], [[2, 3], [2, 4], [3, 4]]]
];
- const polygon = L.polygon(latLngs);
+ const poly = polygon(latLngs);
- expect(polygon._latlngs).to.eql([
- [[L.latLng([10, 20]), L.latLng([30, 40]), L.latLng([50, 60])]],
- [[L.latLng([0, 10]), L.latLng([10, 10]), L.latLng([10, 0])], [L.latLng([2, 3]), L.latLng([2, 4]), L.latLng([3, 4])]]
+ expect(poly._latlngs).to.eql([
+ [[latLng([10, 20]), latLng([30, 40]), latLng([50, 60])]],
+ [[latLng([0, 10]), latLng([10, 10]), latLng([10, 0])], [latLng([2, 3]), latLng([2, 4]), latLng([3, 4])]]
]);
- expect(polygon.getLatLngs()).to.eql(polygon._latlngs);
+ expect(poly.getLatLngs()).to.eql(poly._latlngs);
});
it('can be added to the map when empty', () => {
- const polygon = L.polygon([]).addTo(map);
- const isAdded = map.hasLayer(polygon);
+ const poly = polygon([]).addTo(map);
+ const isAdded = map.hasLayer(poly);
expect(isAdded).to.be.true;
});
@@ -80,13 +83,13 @@ describe('Polygon', () => {
describe('#isEmpty', () => {
it('should return true for a polygon with no latlngs', () => {
- const layer = L.polygon([]);
+ const layer = polygon([]);
expect(layer.isEmpty()).to.be.true;
});
it('should return false for simple polygon', () => {
const latLngs = [[1, 2], [3, 4], [5, 6]];
- const layer = L.polygon(latLngs);
+ const layer = polygon(latLngs);
expect(layer.isEmpty()).to.be.false;
});
@@ -95,7 +98,7 @@ describe('Polygon', () => {
[[[10, 20], [30, 40], [50, 60]]],
[[[0, 10], [10, 10], [10, 0]], [[2, 3], [2, 4], [3, 4]]]
];
- const layer = L.polygon(latLngs);
+ const layer = polygon(latLngs);
expect(layer.isEmpty()).to.be.false;
});
@@ -109,9 +112,9 @@ describe('Polygon', () => {
];
const sourceLatLngs = originalLatLngs.slice();
- const polygon = L.polygon(sourceLatLngs);
+ const poly = polygon(sourceLatLngs);
- polygon.setLatLngs(sourceLatLngs);
+ poly.setLatLngs(sourceLatLngs);
expect(sourceLatLngs).to.eql(originalLatLngs);
});
@@ -122,12 +125,12 @@ describe('Polygon', () => {
[[2, 3], [2, 4], [3, 4]] // hole
];
- const polygon = L.polygon([]);
- polygon.setLatLngs(latLngs);
+ const poly = polygon([]);
+ poly.setLatLngs(latLngs);
- expect(polygon.getLatLngs()).to.eql([
- [L.latLng([0, 10]), L.latLng([10, 10]), L.latLng([10, 0])],
- [L.latLng([2, 3]), L.latLng([2, 4]), L.latLng([3, 4])]
+ expect(poly.getLatLngs()).to.eql([
+ [latLng([0, 10]), latLng([10, 10]), latLng([10, 0])],
+ [latLng([2, 3]), latLng([2, 4]), latLng([3, 4])]
]);
});
@@ -137,12 +140,12 @@ describe('Polygon', () => {
[[[0, 10], [10, 10], [10, 0]], [[2, 3], [2, 4], [3, 4]]]
];
- const polygon = L.polygon([]);
- polygon.setLatLngs(latLngs);
+ const poly = polygon([]);
+ poly.setLatLngs(latLngs);
- expect(polygon.getLatLngs()).to.eql([
- [[L.latLng([10, 20]), L.latLng([30, 40]), L.latLng([50, 60])]],
- [[L.latLng([0, 10]), L.latLng([10, 10]), L.latLng([10, 0])], [L.latLng([2, 3]), L.latLng([2, 4]), L.latLng([3, 4])]]
+ expect(poly.getLatLngs()).to.eql([
+ [[latLng([10, 20]), latLng([30, 40]), latLng([50, 60])]],
+ [[latLng([0, 10]), latLng([10, 10]), latLng([10, 0])], [latLng([2, 3]), latLng([2, 4]), latLng([3, 4])]]
]);
});
@@ -153,7 +156,7 @@ describe('Polygon', () => {
const latlngs = [
[[0, 0], [10, 0], [10, 10], [0, 10]]
];
- const layer = L.polygon(latlngs).addTo(map);
+ const layer = polygon(latlngs).addTo(map);
expect(layer.getCenter()).to.be.nearLatLng([5.019148099025293, 5]);
});
@@ -161,7 +164,7 @@ describe('Polygon', () => {
const latlngs = [
[[0, 0], [0.010, 0], [0.010, 0.010], [0, 0.010]]
];
- const layer = L.polygon(latlngs).addTo(map);
+ const layer = polygon(latlngs).addTo(map);
map.setZoom(0); // Make the polygon disappear in screen.
expect(layer.getCenter()).to.be.nearLatLng([0.005, 0.005]);
});
@@ -171,7 +174,7 @@ describe('Polygon', () => {
const latlngs = [
[[0, 0], [10, 0], [10, 10], [0, 10]]
];
- const layer = L.polygon(latlngs);
+ const layer = polygon(latlngs);
layer.getCenter();
}).to.throw('Must add layer to map before using getCenter()');
});
@@ -180,7 +183,7 @@ describe('Polygon', () => {
const latlngs = [
[[0, 0], [0.010, 0], [0.010, 0.010], [0, 0.010]]
];
- const layer = L.polygon(latlngs).addTo(map);
+ const layer = polygon(latlngs).addTo(map);
map.setZoom(0);
const center = layer.getCenter();
map.setZoom(18);
@@ -192,7 +195,7 @@ describe('Polygon', () => {
[[[10, 20], [30, 40], [50, 60]]],
[[[0, 10], [10, 10], [10, 0]], [[2, 3], [2, 4], [3, 4]]]
];
- const layer = L.polygon(latlngs).addTo(map);
+ const layer = polygon(latlngs).addTo(map);
expect(layer.getCenter()).to.be.nearLatLng([31.436532296911807, 39.99999999999979]);
});
});
@@ -200,47 +203,47 @@ describe('Polygon', () => {
describe('#_defaultShape', () => {
it('should return latlngs on a simple polygon', () => {
const latlngs = [
- L.latLng([1, 2]),
- L.latLng([3, 4])
+ latLng([1, 2]),
+ latLng([3, 4])
];
- const polygon = L.polygon(latlngs);
+ const poly = polygon(latlngs);
- expect(polygon._defaultShape()).to.eql(latlngs);
+ expect(poly._defaultShape()).to.eql(latlngs);
});
it('should return first latlngs on a polygon with hole', () => {
const latlngs = [
- [L.latLng([0, 12]), L.latLng([13, 14]), L.latLng([15, 16])],
- [L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6])]
+ [latLng([0, 12]), latLng([13, 14]), latLng([15, 16])],
+ [latLng([1, 2]), latLng([3, 4]), latLng([5, 6])]
];
- const polygon = L.polygon(latlngs);
+ const poly = polygon(latlngs);
- expect(polygon._defaultShape()).to.eql(latlngs[0]);
+ expect(poly._defaultShape()).to.eql(latlngs[0]);
});
it('should return first latlngs on a multipolygon', () => {
const latlngs = [
- [[L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6])]],
- [[L.latLng([11, 12]), L.latLng([13, 14]), L.latLng([15, 16])]]
+ [[latLng([1, 2]), latLng([3, 4]), latLng([5, 6])]],
+ [[latLng([11, 12]), latLng([13, 14]), latLng([15, 16])]]
];
- const polygon = L.polygon(latlngs);
+ const poly = polygon(latlngs);
- expect(polygon._defaultShape()).to.eql(latlngs[0][0]);
+ expect(poly._defaultShape()).to.eql(latlngs[0][0]);
});
it('should return first latlngs on a multipolygon with hole', () => {
const latlngs = [
- [[L.latLng([0, 10]), L.latLng([10, 10]), L.latLng([10, 0])],
- [L.latLng([2, 3]), L.latLng([2, 4]), L.latLng([3, 4])]],
- [[L.latLng([10, 20]), L.latLng([30, 40]), L.latLng([50, 60])]]
+ [[latLng([0, 10]), latLng([10, 10]), latLng([10, 0])],
+ [latLng([2, 3]), latLng([2, 4]), latLng([3, 4])]],
+ [[latLng([10, 20]), latLng([30, 40]), latLng([50, 60])]]
];
- const polygon = L.polygon(latlngs);
+ const poly = polygon(latlngs);
- expect(polygon._defaultShape()).to.eql(latlngs[0][0]);
+ expect(poly._defaultShape()).to.eql(latlngs[0][0]);
});
});
@@ -251,11 +254,11 @@ describe('Polygon', () => {
[3, 4]
];
- const polygon = L.polygon(latLngs);
+ const poly = polygon(latLngs);
- polygon.addLatLng([5, 6]);
+ poly.addLatLng([5, 6]);
- expect(polygon._latlngs).to.eql([[L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6])]]);
+ expect(poly._latlngs).to.eql([[latLng([1, 2]), latLng([3, 4]), latLng([5, 6])]]);
});
it('should add latlng to first latlngs on a polygon with hole', () => {
@@ -264,12 +267,12 @@ describe('Polygon', () => {
[[1, 2], [3, 4], [5, 6]]
];
- const polygon = L.polygon(latLngs);
+ const poly = polygon(latLngs);
- polygon.addLatLng([17, 0]);
+ poly.addLatLng([17, 0]);
- expect(polygon._latlngs[0]).to.eql([L.latLng([0, 12]), L.latLng([13, 14]), L.latLng([15, 16]), L.latLng([17, 0])]);
- expect(polygon._latlngs[1]).to.eql([L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6])]);
+ expect(poly._latlngs[0]).to.eql([latLng([0, 12]), latLng([13, 14]), latLng([15, 16]), latLng([17, 0])]);
+ expect(poly._latlngs[1]).to.eql([latLng([1, 2]), latLng([3, 4]), latLng([5, 6])]);
});
it('should add latlng by reference on a polygon with hole', () => {
@@ -278,12 +281,12 @@ describe('Polygon', () => {
[[1, 2], [3, 4], [5, 6]]
];
- const polygon = L.polygon(latLngs);
+ const poly = polygon(latLngs);
- polygon.addLatLng([7, 8], polygon._latlngs[1]);
+ poly.addLatLng([7, 8], poly._latlngs[1]);
- expect(polygon._latlngs[0]).to.eql([L.latLng([0, 12]), L.latLng([13, 14]), L.latLng([15, 16])]);
- expect(polygon._latlngs[1]).to.eql([L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6]), L.latLng([7, 8])]);
+ expect(poly._latlngs[0]).to.eql([latLng([0, 12]), latLng([13, 14]), latLng([15, 16])]);
+ expect(poly._latlngs[1]).to.eql([latLng([1, 2]), latLng([3, 4]), latLng([5, 6]), latLng([7, 8])]);
});
it('should add latlng to first latlngs on a multi', () => {
@@ -292,12 +295,12 @@ describe('Polygon', () => {
[[[11, 12], [13, 14], [15, 16]]]
];
- const polygon = L.polygon(latLngs);
+ const poly = polygon(latLngs);
- polygon.addLatLng([5, 6]);
+ poly.addLatLng([5, 6]);
- expect(polygon._latlngs[0]).to.eql([[L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6])]]);
- expect(polygon._latlngs[1]).to.eql([[L.latLng([11, 12]), L.latLng([13, 14]), L.latLng([15, 16])]]);
+ expect(poly._latlngs[0]).to.eql([[latLng([1, 2]), latLng([3, 4]), latLng([5, 6])]]);
+ expect(poly._latlngs[1]).to.eql([[latLng([11, 12]), latLng([13, 14]), latLng([15, 16])]]);
});
it('should add latlng to latlngs by reference on a multi', () => {
@@ -306,12 +309,12 @@ describe('Polygon', () => {
[[[1, 2], [3, 4]]]
];
- const polygon = L.polygon(latLngs);
+ const poly = polygon(latLngs);
- polygon.addLatLng([5, 6], polygon._latlngs[1][0]);
+ poly.addLatLng([5, 6], poly._latlngs[1][0]);
- expect(polygon._latlngs[1]).to.eql([[L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6])]]);
- expect(polygon._latlngs[0]).to.eql([[L.latLng([11, 12]), L.latLng([13, 14]), L.latLng([15, 16])]]);
+ expect(poly._latlngs[1]).to.eql([[latLng([1, 2]), latLng([3, 4]), latLng([5, 6])]]);
+ expect(poly._latlngs[0]).to.eql([[latLng([11, 12]), latLng([13, 14]), latLng([15, 16])]]);
});
it('should add latlng on first latlngs by default on a multipolygon with hole', () => {
@@ -320,13 +323,13 @@ describe('Polygon', () => {
[[[10, 20], [30, 40], [50, 60]]]
];
- const polygon = L.polygon(latLngs);
+ const poly = polygon(latLngs);
- polygon.addLatLng([-10, -10]);
+ poly.addLatLng([-10, -10]);
- expect(polygon._latlngs[0][0]).to.eql([L.latLng([0, 10]), L.latLng([10, 10]), L.latLng([10, 0]), L.latLng([-10, -10])]);
- expect(polygon._latlngs[0][1]).to.eql([L.latLng([2, 3]), L.latLng([2, 4]), L.latLng([3, 4])]);
- expect(polygon._latlngs[1][0]).to.eql([L.latLng([10, 20]), L.latLng([30, 40]), L.latLng([50, 60])]);
+ expect(poly._latlngs[0][0]).to.eql([latLng([0, 10]), latLng([10, 10]), latLng([10, 0]), latLng([-10, -10])]);
+ expect(poly._latlngs[0][1]).to.eql([latLng([2, 3]), latLng([2, 4]), latLng([3, 4])]);
+ expect(poly._latlngs[1][0]).to.eql([latLng([10, 20]), latLng([30, 40]), latLng([50, 60])]);
});
it('should add latlng by reference on a multipolygon with hole', () => {
@@ -335,13 +338,13 @@ describe('Polygon', () => {
[[[0, 10], [10, 10], [10, 0]], [[2, 3], [2, 4], [3, 4]]]
];
- const polygon = L.polygon(latLngs);
+ const poly = polygon(latLngs);
- polygon.addLatLng([2, 2], polygon._latlngs[1][1]);
+ poly.addLatLng([2, 2], poly._latlngs[1][1]);
- expect(polygon._latlngs[0][0]).to.eql([L.latLng([10, 20]), L.latLng([30, 40]), L.latLng([50, 60])]);
- expect(polygon._latlngs[1][0]).to.eql([L.latLng([0, 10]), L.latLng([10, 10]), L.latLng([10, 0])]);
- expect(polygon._latlngs[1][1]).to.eql([L.latLng([2, 3]), L.latLng([2, 4]), L.latLng([3, 4]), L.latLng([2, 2])]);
+ expect(poly._latlngs[0][0]).to.eql([latLng([10, 20]), latLng([30, 40]), latLng([50, 60])]);
+ expect(poly._latlngs[1][0]).to.eql([latLng([0, 10]), latLng([10, 10]), latLng([10, 0])]);
+ expect(poly._latlngs[1][1]).to.eql([latLng([2, 3]), latLng([2, 4]), latLng([3, 4]), latLng([2, 2])]);
});
});
@@ -350,13 +353,13 @@ describe('Polygon', () => {
const style = {
weight: 3
};
- const polygon = L.polygon([]);
+ const poly = polygon([]);
- polygon.addTo(map);
- polygon.setStyle(style);
+ poly.addTo(map);
+ poly.setStyle(style);
for (const [prop, expectedValue] of Object.entries(style)) {
- expect(polygon.options[prop]).to.equal(expectedValue);
+ expect(poly.options[prop]).to.equal(expectedValue);
}
});
});
diff --git a/spec/suites/layer/vector/PolylineSpec.js b/spec/suites/layer/vector/PolylineSpec.js
index ec006498c..246b0a501 100644
--- a/spec/suites/layer/vector/PolylineSpec.js
+++ b/spec/suites/layer/vector/PolylineSpec.js
@@ -1,9 +1,12 @@
+import {Map, polyline, latLng} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('Polyline', () => {
let map, container;
beforeEach(() => {
container = createContainer();
- map = L.map(container, {center: [55.8, 37.6], zoom: 6});
+ map = new Map(container, {center: [55.8, 37.6], zoom: 6});
});
afterEach(() => {
@@ -18,11 +21,11 @@ describe('Polyline', () => {
];
const sourceLatLngs = originalLatLngs.slice();
- const polyline = L.polyline(sourceLatLngs);
+ const polyln = polyline(sourceLatLngs);
expect(sourceLatLngs).to.eql(originalLatLngs);
- expect(polyline._latlngs).to.not.eql(sourceLatLngs);
- expect(polyline.getLatLngs()).to.eql(polyline._latlngs);
+ expect(polyln._latlngs).to.not.eql(sourceLatLngs);
+ expect(polyln.getLatLngs()).to.eql(polyln._latlngs);
});
it('should accept a multi', () => {
@@ -31,37 +34,37 @@ describe('Polyline', () => {
[[11, 12], [13, 14], [15, 16]]
];
- const polyline = L.polyline(latLngs);
+ const polyln = polyline(latLngs);
- expect(polyline._latlngs[0]).to.eql([L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6])]);
- expect(polyline._latlngs[1]).to.eql([L.latLng([11, 12]), L.latLng([13, 14]), L.latLng([15, 16])]);
- expect(polyline.getLatLngs()).to.eql(polyline._latlngs);
+ expect(polyln._latlngs[0]).to.eql([latLng([1, 2]), latLng([3, 4]), latLng([5, 6])]);
+ expect(polyln._latlngs[1]).to.eql([latLng([11, 12]), latLng([13, 14]), latLng([15, 16])]);
+ expect(polyln.getLatLngs()).to.eql(polyln._latlngs);
});
it('should accept an empty array', () => {
- const polyline = L.polyline([]);
+ const polyln = polyline([]);
- expect(polyline._latlngs).to.eql([]);
- expect(polyline.getLatLngs()).to.eql(polyline._latlngs);
+ expect(polyln._latlngs).to.eql([]);
+ expect(polyln.getLatLngs()).to.eql(polyln._latlngs);
});
it('can be added to the map when empty', () => {
- const polyline = L.polyline([]).addTo(map);
- expect(map.hasLayer(polyline)).to.be.true;
+ const polyln = polyline([]).addTo(map);
+ expect(map.hasLayer(polyln)).to.be.true;
});
});
describe('#isEmpty', () => {
it('should return true for a polyline with no latlngs', () => {
- const polyline = L.polyline([]);
- expect(polyline.isEmpty()).to.be.true;
+ const polyln = polyline([]);
+ expect(polyln.isEmpty()).to.be.true;
});
it('should return false for simple polyline', () => {
const latLngs = [[1, 2], [3, 4]];
- const polyline = L.polyline(latLngs);
- expect(polyline.isEmpty()).to.be.false;
+ const polyln = polyline(latLngs);
+ expect(polyln.isEmpty()).to.be.false;
});
it('should return false for multi-polyline', () => {
@@ -69,8 +72,8 @@ describe('Polyline', () => {
[[1, 2], [3, 4]],
[[11, 12], [13, 14]]
];
- const polyline = L.polyline(latLngs);
- expect(polyline.isEmpty()).to.be.false;
+ const polyln = polyline(latLngs);
+ expect(polyln.isEmpty()).to.be.false;
});
});
@@ -83,9 +86,9 @@ describe('Polyline', () => {
];
const sourceLatLngs = originalLatLngs.slice();
- const polyline = L.polyline(sourceLatLngs);
+ const polyln = polyline(sourceLatLngs);
- polyline.setLatLngs(sourceLatLngs);
+ polyln.setLatLngs(sourceLatLngs);
expect(sourceLatLngs).to.eql(originalLatLngs);
});
@@ -96,61 +99,61 @@ describe('Polyline', () => {
[[11, 12], [13, 14], [15, 16]]
];
- const polyline = L.polyline([]);
- polyline.setLatLngs(latLngs);
+ const polyln = polyline([]);
+ polyln.setLatLngs(latLngs);
- expect(polyline._latlngs[0]).to.eql([L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6])]);
- expect(polyline._latlngs[1]).to.eql([L.latLng([11, 12]), L.latLng([13, 14]), L.latLng([15, 16])]);
+ expect(polyln._latlngs[0]).to.eql([latLng([1, 2]), latLng([3, 4]), latLng([5, 6])]);
+ expect(polyln._latlngs[1]).to.eql([latLng([11, 12]), latLng([13, 14]), latLng([15, 16])]);
});
});
describe('#getCenter', () => {
it('should compute center of a big flat line on equator', () => {
- const polyline = L.polyline([[0, 0], [0, 90]]).addTo(map);
- expect(polyline.getCenter()).to.eql(L.latLng([0, 45]));
+ const polyln = polyline([[0, 0], [0, 90]]).addTo(map);
+ expect(polyln.getCenter()).to.eql(latLng([0, 45]));
});
it('should compute center of a big flat line on equator with maxZoom', () => {
map.setMaxZoom(18);
- const polyline = L.polyline([[0, 0], [0, 90]]).addTo(map);
- expect(polyline.getCenter()).to.be.nearLatLng([0, 45]);
+ const polyln = polyline([[0, 0], [0, 90]]).addTo(map);
+ expect(polyln.getCenter()).to.be.nearLatLng([0, 45]);
});
it('should compute center of a big flat line close to the pole', () => {
- const polyline = L.polyline([[80, 0], [80, 90]]).addTo(map);
- expect(polyline.getCenter()).to.be.nearLatLng([80, 45], 1e-2);
+ const polyln = polyline([[80, 0], [80, 90]]).addTo(map);
+ expect(polyln.getCenter()).to.be.nearLatLng([80, 45], 1e-2);
});
it('should compute center of a big diagonal line', () => {
- const polyline = L.polyline([[0, 0], [80, 80]]).addTo(map);
- expect(polyline.getCenter()).to.be.nearLatLng([57.04516467328689, 40], 1);
+ const polyln = polyline([[0, 0], [80, 80]]).addTo(map);
+ expect(polyln.getCenter()).to.be.nearLatLng([57.04516467328689, 40], 1);
});
it('should compute center of a diagonal line close to the pole', () => {
- const polyline = L.polyline([[70, 70], [84, 84]]).addTo(map);
- expect(polyline.getCenter()).to.be.nearLatLng([79.01810060159328, 77], 1);
+ const polyln = polyline([[70, 70], [84, 84]]).addTo(map);
+ expect(polyln.getCenter()).to.be.nearLatLng([79.01810060159328, 77], 1);
});
it('should compute center of a big multiline', () => {
- const polyline = L.polyline([[10, -80], [0, 0], [0, 10], [10, 90]]).addTo(map);
- expect(polyline.getCenter()).to.be.nearLatLng([0, 5], 1);
+ const polyln = polyline([[10, -80], [0, 0], [0, 10], [10, 90]]).addTo(map);
+ expect(polyln.getCenter()).to.be.nearLatLng([0, 5], 1);
});
it('should compute center of a small flat line', () => {
- const polyline = L.polyline([[0, 0], [0, 0.090]]).addTo(map);
+ const polyln = polyline([[0, 0], [0, 0.090]]).addTo(map);
map.setZoom(0); // Make the line disappear in screen;
- expect(polyline.getCenter()).to.be.nearLatLng([0, 0.045]);
+ expect(polyln.getCenter()).to.be.nearLatLng([0, 0.045]);
});
it('throws error if not yet added to map', () => {
expect(() => {
- const polyline = L.polyline([[0, 0], [0, 0.090]]);
- polyline.getCenter();
+ const poly = polyline([[0, 0], [0, 0.090]]);
+ poly.getCenter();
}).to.throw('Must add layer to map before using getCenter()');
});
it('should compute same center for low and high zoom', () => {
- const layer = L.polyline([[10, -80], [0, 0], [0, 10], [10, 90]]).addTo(map);
+ const layer = polyline([[10, -80], [0, 0], [0, 10], [10, 90]]).addTo(map);
map.setZoom(0);
const center = layer.getCenter();
map.setZoom(18);
@@ -158,30 +161,30 @@ describe('Polyline', () => {
});
it('should compute center of a zick-zack line', () => {
- const polyline = L.polyline([[0, 0], [50, 50], [30, 30], [35, 35]]).addTo(map);
- expect(polyline.getCenter()).to.be.nearLatLng([40.551864181628666, 38.36684065813897]);
+ const polyln = polyline([[0, 0], [50, 50], [30, 30], [35, 35]]).addTo(map);
+ expect(polyln.getCenter()).to.be.nearLatLng([40.551864181628666, 38.36684065813897]);
});
});
describe('#_defaultShape', () => {
it('should return latlngs when flat', () => {
- const latLngs = [L.latLng([1, 2]), L.latLng([3, 4])];
+ const latLngs = [latLng([1, 2]), latLng([3, 4])];
- const polyline = L.polyline(latLngs);
+ const polyln = polyline(latLngs);
- expect(polyline._defaultShape()).to.eql(latLngs);
+ expect(polyln._defaultShape()).to.eql(latLngs);
});
it('should return first latlngs on a multi', () => {
const latLngs = [
- [L.latLng([1, 2]), L.latLng([3, 4])],
- [L.latLng([11, 12]), L.latLng([13, 14])]
+ [latLng([1, 2]), latLng([3, 4])],
+ [latLng([11, 12]), latLng([13, 14])]
];
- const polyline = L.polyline(latLngs);
+ const polyln = polyline(latLngs);
- expect(polyline._defaultShape()).to.eql(latLngs[0]);
+ expect(polyln._defaultShape()).to.eql(latLngs[0]);
});
});
@@ -193,11 +196,11 @@ describe('Polyline', () => {
[3, 4]
];
- const polyline = L.polyline(latLngs);
+ const polyln = polyline(latLngs);
- polyline.addLatLng([5, 6]);
+ polyln.addLatLng([5, 6]);
- expect(polyline._latlngs).to.eql([L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6])]);
+ expect(polyln._latlngs).to.eql([latLng([1, 2]), latLng([3, 4]), latLng([5, 6])]);
});
it('should add latlng to first latlngs on a multi', () => {
@@ -206,12 +209,12 @@ describe('Polyline', () => {
[[11, 12], [13, 14]]
];
- const polyline = L.polyline(latLngs);
+ const polyln = polyline(latLngs);
- polyline.addLatLng([5, 6]);
+ polyln.addLatLng([5, 6]);
- expect(polyline._latlngs[0]).to.eql([L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6])]);
- expect(polyline._latlngs[1]).to.eql([L.latLng([11, 12]), L.latLng([13, 14])]);
+ expect(polyln._latlngs[0]).to.eql([latLng([1, 2]), latLng([3, 4]), latLng([5, 6])]);
+ expect(polyln._latlngs[1]).to.eql([latLng([11, 12]), latLng([13, 14])]);
});
it('should add latlng to latlngs by reference', () => {
@@ -220,20 +223,20 @@ describe('Polyline', () => {
[[1, 2], [3, 4]]
];
- const polyline = L.polyline(latLngs);
+ const polyln = polyline(latLngs);
- polyline.addLatLng([5, 6], polyline._latlngs[1]);
+ polyln.addLatLng([5, 6], polyln._latlngs[1]);
- expect(polyline._latlngs[1]).to.eql([L.latLng([1, 2]), L.latLng([3, 4]), L.latLng([5, 6])]);
- expect(polyline._latlngs[0]).to.eql([L.latLng([11, 12]), L.latLng([13, 14])]);
+ expect(polyln._latlngs[1]).to.eql([latLng([1, 2]), latLng([3, 4]), latLng([5, 6])]);
+ expect(polyln._latlngs[0]).to.eql([latLng([11, 12]), latLng([13, 14])]);
});
it('should add latlng on empty polyline', () => {
- const polyline = L.polyline([]);
+ const polyln = polyline([]);
- polyline.addLatLng([1, 2]);
+ polyln.addLatLng([1, 2]);
- expect(polyline._latlngs).to.eql([L.latLng([1, 2])]);
+ expect(polyln._latlngs).to.eql([latLng([1, 2])]);
});
});
@@ -242,13 +245,13 @@ describe('Polyline', () => {
const style = {
weight: 3
};
- const polyline = L.polyline([]);
+ const polyln = polyline([]);
- polyline.addTo(map);
- polyline.setStyle(style);
+ polyln.addTo(map);
+ polyln.setStyle(style);
for (const [prop, expectedValue] of Object.entries(style)) {
- expect(polyline.options[prop]).to.equal(expectedValue);
+ expect(polyln.options[prop]).to.equal(expectedValue);
}
});
});
@@ -258,13 +261,13 @@ describe('Polyline', () => {
const style = {
weight: 3
};
- const polyline = L.polyline([]);
+ const polyln = polyline([]);
- polyline.addTo(map);
- polyline.setStyle(style);
+ polyln.addTo(map);
+ polyln.setStyle(style);
for (const [prop, expectedValue] of Object.entries(style)) {
- expect(polyline.options[prop]).to.equal(expectedValue);
+ expect(polyln.options[prop]).to.equal(expectedValue);
}
});
});
@@ -274,21 +277,21 @@ describe('Polyline', () => {
const p1 = map.latLngToLayerPoint([55.8, 37.6]);
const p2 = map.latLngToLayerPoint([57.123076977278, 44.861962891635]);
const latlngs = [[56.485503424111, 35.545556640339], [55.972522915346, 36.116845702918], [55.502459116923, 34.930322265253], [55.31534617509, 38.973291015816]]
- .map(ll => L.latLng(ll[0], ll[1]));
- const polyline = L.polyline([], {
+ .map(ll => latLng(ll[0], ll[1]));
+ const polyln = polyline([], {
'noClip': true
});
- map.addLayer(polyline);
+ map.addLayer(polyln);
- expect(polyline.closestLayerPoint(p1)).to.equal(null);
+ expect(polyln.closestLayerPoint(p1)).to.equal(null);
- polyline.setLatLngs(latlngs);
- const point = polyline.closestLayerPoint(p1);
+ polyln.setLatLngs(latlngs);
+ const point = polyln.closestLayerPoint(p1);
expect(point).not.to.equal(null);
expect(point.distance).to.not.equal(Infinity);
expect(point.distance).to.not.equal(NaN);
- const point2 = polyline.closestLayerPoint(p2);
+ const point2 = polyln.closestLayerPoint(p2);
expect(point.distance).to.be.lessThan(point2.distance);
});
diff --git a/spec/suites/layer/vector/RectangleSpec.js b/spec/suites/layer/vector/RectangleSpec.js
index b99db887a..88da7eb0a 100644
--- a/spec/suites/layer/vector/RectangleSpec.js
+++ b/spec/suites/layer/vector/RectangleSpec.js
@@ -1,9 +1,12 @@
+import {Map, rectangle, LineUtil, latLng, Canvas, Polygon} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('Rectangle', () => {
let map, container;
beforeEach(() => {
container = createContainer();
- map = L.map(container, {center: [55.8, 37.6], zoom: 6});
+ map = new Map(container, {center: [55.8, 37.6], zoom: 6});
});
afterEach(() => {
@@ -14,10 +17,10 @@ describe('Rectangle', () => {
it('should never be flat', () => {
const latLngs = [[1, 2], [3, 4]];
- const rectangle = L.rectangle(latLngs);
+ const rect = rectangle(latLngs);
- expect(L.LineUtil.isFlat(rectangle._latlngs)).to.be.false;
- expect(rectangle.getLatLngs()).to.eql(rectangle._latlngs);
+ expect(LineUtil.isFlat(rect._latlngs)).to.be.false;
+ expect(rect.getLatLngs()).to.eql(rect._latlngs);
});
it('doesn\'t overwrite the given latlng array', () => {
@@ -27,16 +30,16 @@ describe('Rectangle', () => {
];
const sourceLatLngs = originalLatLngs.slice();
- const rectangle = L.rectangle(sourceLatLngs);
+ const rect = rectangle(sourceLatLngs);
expect(sourceLatLngs).to.eql(originalLatLngs);
- expect(rectangle._latlngs).to.not.eql(sourceLatLngs);
+ expect(rect._latlngs).to.not.eql(sourceLatLngs);
});
it('cannot be called with an empty array', () => {
// Throws error due to undefined lat
expect(() => {
- L.rectangle([]);
+ rectangle([]);
}).to.throw();
});
@@ -46,12 +49,12 @@ describe('Rectangle', () => {
[40, 50], [60, 70] // extended bounds
];
- const rectangle = L.rectangle(originalLatLngs);
+ const rect = rectangle(originalLatLngs);
- expect(rectangle._latlngs).to.eql([
- [L.latLng([0, 10]), L.latLng([60, 10]), L.latLng([60, 70]), L.latLng([0, 70])]
+ expect(rect._latlngs).to.eql([
+ [latLng([0, 10]), latLng([60, 10]), latLng([60, 70]), latLng([0, 70])]
]);
- expect(rectangle.getLatLngs()).to.eql(rectangle._latlngs);
+ expect(rect.getLatLngs()).to.eql(rect._latlngs);
});
});
@@ -63,9 +66,9 @@ describe('Rectangle', () => {
];
const sourceLatLngs = originalLatLngs.slice();
- const rectangle = L.rectangle(sourceLatLngs);
+ const rect = rectangle(sourceLatLngs);
- rectangle.setBounds(sourceLatLngs);
+ rect.setBounds(sourceLatLngs);
expect(sourceLatLngs).to.eql(originalLatLngs);
});
@@ -81,14 +84,14 @@ describe('Rectangle', () => {
[7, 8]
];
- const rectangle = L.rectangle(originalLatLngs);
- rectangle.setBounds(newLatLngs);
+ const rect = rectangle(originalLatLngs);
+ rect.setBounds(newLatLngs);
- expect(rectangle._latlngs).to.eql([
- [L.latLng([5, 6]), L.latLng([7, 6]), L.latLng([7, 8]), L.latLng([5, 8])]
+ expect(rect._latlngs).to.eql([
+ [latLng([5, 6]), latLng([7, 6]), latLng([7, 8]), latLng([5, 8])]
]);
- expect(rectangle.getLatLngs()).to.eql(rectangle._latlngs);
+ expect(rect.getLatLngs()).to.eql(rect._latlngs);
});
it('can be set with extending bounds', () => {
@@ -101,13 +104,13 @@ describe('Rectangle', () => {
[40, 50], [60, 70] // extending bounds
];
- const rectangle = L.rectangle(originalLatLngs);
- rectangle.setBounds(newLatLngs);
+ const rect = rectangle(originalLatLngs);
+ rect.setBounds(newLatLngs);
- expect(rectangle._latlngs).to.eql([
- [L.latLng([0, 10]), L.latLng([60, 10]), L.latLng([60, 70]), L.latLng([0, 70])]
+ expect(rect._latlngs).to.eql([
+ [latLng([0, 10]), latLng([60, 10]), latLng([60, 70]), latLng([0, 70])]
]);
- expect(rectangle.getLatLngs()).to.eql(rectangle._latlngs);
+ expect(rect.getLatLngs()).to.eql(rect._latlngs);
});
});
@@ -115,10 +118,10 @@ describe('Rectangle', () => {
it('doesn\'t apply `focus` listener if element is undefined', () => {
map.remove();
- map = L.map(container, {renderer: L.canvas()});
+ map = new Map(container, {renderer: new Canvas()});
map.setView([0, 0], 6);
expect(() => {
- L.polygon([[[2, 3], [4, 5]]]).addTo(map).bindTooltip('test');
+ new Polygon([[[2, 3], [4, 5]]]).addTo(map).bindTooltip('test');
}).to.not.throw();
});
});
diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js
index cdd9448fa..a32718707 100644
--- a/spec/suites/map/MapSpec.js
+++ b/spec/suites/map/MapSpec.js
@@ -1,10 +1,13 @@
+import {Map, latLng, Point, LatLngBounds, TileLayer, Handler, DomEvent, Bounds, Layer, control as lControl, GridLayer, Util, Marker, Polygon, DivIcon, CircleMarker, Canvas} from 'leaflet';
+import {createContainer, removeMapContainer} from '../SpecHelper.js';
+
describe('Map', () => {
let container,
map;
beforeEach(() => {
container = container = createContainer();
- map = L.map(container);
+ map = new Map(container);
});
afterEach(() => {
@@ -35,12 +38,12 @@ describe('Map', () => {
describe('corner case checking', () => {
it('throws an exception upon reinitialization', () => {
- expect(() => L.map(container))
+ expect(() => new Map(container))
.to.throw('Map container is already initialized.');
});
it('throws an exception if a container is not found', () => {
- expect(() => L.map('nonexistentdivelement'))
+ expect(() => new Map('nonexistentdivelement'))
.to.throw('Map container not found.');
});
});
@@ -88,7 +91,7 @@ describe('Map', () => {
it('throws error if container is reused by other instance', () => {
map.remove();
- const map2 = L.map(container);
+ const map2 = new Map(container);
expect(() => {
map.remove();
@@ -107,14 +110,14 @@ describe('Map', () => {
});
it('returns a precise center when zoomed in after being set (#426)', () => {
- const center = L.latLng(10, 10);
+ const center = latLng(10, 10);
map.setView(center, 1);
map.setZoom(19);
expect(map.getCenter()).to.eql(center);
});
it('returns correct center after invalidateSize (#1919)', () => {
- const center = L.latLng(10, 10);
+ const center = latLng(10, 10);
map.setView(center, 1);
map.invalidateSize();
expect(map.getCenter()).not.to.eql(center);
@@ -124,7 +127,7 @@ describe('Map', () => {
map.setView([10, 10], 1);
const center = map.getCenter();
center.lat += 10;
- expect(map.getCenter()).to.eql(L.latLng(10, 10));
+ expect(map.getCenter()).to.eql(latLng(10, 10));
});
});
@@ -174,14 +177,14 @@ describe('Map', () => {
});
it('defaults to zoom passed as map option', () => {
- const map = L.map(document.createElement('div'), {zoom: 13});
+ const map = new Map(document.createElement('div'), {zoom: 13});
const zoom = map.setView([51.605, -0.11]).getZoom();
map.remove(); // clean up
expect(zoom).to.equal(13);
});
it('passes duration option to panBy', () => {
- const map = L.map(document.createElement('div'), {zoom: 13, center: [0, 0]});
+ const map = new Map(document.createElement('div'), {zoom: 13, center: [0, 0]});
map.panBy = sinon.spy();
map.setView([51.605, -0.11], 13, {animate: true, duration: 13});
map.remove(); // clean up
@@ -215,7 +218,7 @@ describe('Map', () => {
});
it('overwrites zoom passed as map option', () => {
- const map2 = L.map(document.createElement('div'), {zoom: 13});
+ const map2 = new Map(document.createElement('div'), {zoom: 13});
map2.setZoom(15);
const zoom = map2.getZoom();
@@ -237,7 +240,7 @@ describe('Map', () => {
});
it('does not overwrite zoom passed as map option', () => {
- const map2 = L.map(document.createElement('div'), {zoom: 13});
+ const map2 = new Map(document.createElement('div'), {zoom: 13});
map2.setView([0, 0]);
map2.setZoom(15);
const zoom = map2.getZoom();
@@ -306,14 +309,14 @@ describe('Map', () => {
});
it('pass Point and change pixel in view', () => {
- const point = L.point(5, 5);
+ const point = new Point(5, 5);
map.setZoomAround(point, 5);
expect(map.getBounds().contains(map.options.crs.pointToLatLng(point, 5))).to.be.false;
});
it('pass Point and change pixel in view at high zoom', () => {
- const point = L.point(5, 5);
+ const point = new Point(5, 5);
map.setZoomAround(point, 18);
expect(map.getBounds().contains(map.options.crs.pointToLatLng(point, 18))).to.be.false;
@@ -332,7 +335,7 @@ describe('Map', () => {
});
it('throws if map is not loaded', () => {
- const unloadedMap = L.map(document.createElement('div'));
+ const unloadedMap = new Map(document.createElement('div'));
expect(() => unloadedMap.setZoomAround([5, 5], 4)).to.throw();
});
@@ -359,7 +362,7 @@ describe('Map', () => {
describe('#getBounds', () => {
it('is safe to call from within a moveend callback during initial load (#1027)', () => {
- const map = L.map(document.createElement('div'));
+ const map = new Map(document.createElement('div'));
map.on('moveend', () => {
map.getBounds();
});
@@ -394,10 +397,10 @@ describe('Map', () => {
container.style.height = '';
container.style.width = '';
map.setZoom(16);
- const bounds = L.latLngBounds(
+ const bounds = new LatLngBounds(
[62.18475569507688, 6.926335173954951],
[62.140483526511694, 6.923933370740089]);
- const padding = L.point(-50, -50);
+ const padding = new Point(-50, -50);
// control case: default crs
let boundsZoom = map.getBoundsZoom(bounds, false, padding);
@@ -408,10 +411,10 @@ describe('Map', () => {
const crsMock = sinon.mock(map.options.crs);
crsMock.expects('latLngToPoint')
.withExactArgs(bounds.getNorthWest(), 16)
- .returns(L.point(7800503.059925064, 6440062.353052008));
+ .returns(new Point(7800503.059925064, 6440062.353052008));
crsMock.expects('latLngToPoint')
.withExactArgs(bounds.getSouthEast(), 16)
- .returns(L.point(7801987.203481699, 6425186.447901004));
+ .returns(new Point(7801987.203481699, 6425186.447901004));
boundsZoom = map.getBoundsZoom(bounds, false, padding);
crsMock.restore();
@@ -432,10 +435,10 @@ describe('Map', () => {
// large view, cannot fit within maxBounds
container.style.width = container.style.height = '1000px';
// maxBounds
- const bounds = L.latLngBounds([51.5, -0.05], [51.55, 0.05]);
+ const bounds = new LatLngBounds([51.5, -0.05], [51.55, 0.05]);
map.setMaxBounds(bounds, {animate: false});
// set view outside
- map.setView(L.latLng([53.0, 0.15]), 12, {animate: false});
+ map.setView(latLng([53.0, 0.15]), 12, {animate: false});
// get center of bounds in pixels
const boundsCenter = map.project(bounds.getCenter()).round();
expect(map.project(map.getCenter()).round()).to.eql(boundsCenter);
@@ -445,12 +448,12 @@ describe('Map', () => {
// small view, can fit within maxBounds
container.style.width = container.style.height = '200px';
// maxBounds
- const bounds = L.latLngBounds([51, -0.2], [52, 0.2]);
+ const bounds = new LatLngBounds([51, -0.2], [52, 0.2]);
map.setMaxBounds(bounds, {animate: false});
// set view outside maxBounds on one direction only
// leaves untouched the other coordinate (that is not already centered)
const initCenter = [53.0, 0.1];
- map.setView(L.latLng(initCenter), 16, {animate: false});
+ map.setView(latLng(initCenter), 16, {animate: false});
// one pixel coordinate hasn't changed, the other has
const pixelCenter = map.project(map.getCenter()).round();
const pixelInit = map.project(initCenter).round();
@@ -461,13 +464,13 @@ describe('Map', () => {
});
it('remove listeners when called without arguments', (done) => {
- L.tileLayer('', {minZoom: 0, maxZoom: 20}).addTo(map);
+ new TileLayer('', {minZoom: 0, maxZoom: 20}).addTo(map);
container.style.width = container.style.height = '500px';
- const bounds = L.latLngBounds([51.5, -0.05], [51.55, 0.05]);
+ const bounds = new LatLngBounds([51.5, -0.05], [51.55, 0.05]);
map.setMaxBounds(bounds, {animate: false});
map.setMaxBounds();
// set view outside
- const center = L.latLng([0, 0]);
+ const center = latLng([0, 0]);
map.once('moveend', () => {
expect(center.equals(map.getCenter())).to.be.true;
done();
@@ -476,9 +479,9 @@ describe('Map', () => {
});
it('does not try to remove listeners if it wasn\'t set before', () => {
- L.tileLayer('', {minZoom: 0, maxZoom: 20}).addTo(map);
+ new TileLayer('', {minZoom: 0, maxZoom: 20}).addTo(map);
container.style.width = container.style.height = '500px';
- const bounds = L.latLngBounds([51.5, -0.05], [51.55, 0.05]);
+ const bounds = new LatLngBounds([51.5, -0.05], [51.55, 0.05]);
map.off = sinon.spy();
map.setMaxBounds(bounds, {animate: false});
expect(map.off.called).not.to.be.true;
@@ -599,11 +602,11 @@ describe('Map', () => {
it('minZoom and maxZoom options overrides any minZoom and maxZoom set on layers', () => {
removeMapContainer(map, container);
container = createContainer();
- map = L.map(container, {minZoom: 2, maxZoom: 20});
+ map = new Map(container, {minZoom: 2, maxZoom: 20});
- L.tileLayer('', {minZoom: 4, maxZoom: 10}).addTo(map);
- L.tileLayer('', {minZoom: 6, maxZoom: 17}).addTo(map);
- L.tileLayer('', {minZoom: 0, maxZoom: 22}).addTo(map);
+ new TileLayer('', {minZoom: 4, maxZoom: 10}).addTo(map);
+ new TileLayer('', {minZoom: 6, maxZoom: 17}).addTo(map);
+ new TileLayer('', {minZoom: 0, maxZoom: 22}).addTo(map);
expect(map.getMinZoom()).to.equal(2);
expect(map.getMaxZoom()).to.equal(20);
@@ -612,9 +615,9 @@ describe('Map', () => {
it('layer minZoom overrides map zoom if map has no minZoom set and layer minZoom is bigger than map zoom', () => {
removeMapContainer(map, container);
container = createContainer();
- map = L.map(container, {zoom: 10});
+ map = new Map(container, {zoom: 10});
- L.tileLayer('', {minZoom: 15}).addTo(map);
+ new TileLayer('', {minZoom: 15}).addTo(map);
expect(map.getMinZoom()).to.equal(15);
});
@@ -622,9 +625,9 @@ describe('Map', () => {
it('layer maxZoom overrides map zoom if map has no maxZoom set and layer maxZoom is smaller than map zoom', () => {
removeMapContainer(map, container);
container = createContainer();
- map = L.map(container, {zoom: 20});
+ map = new Map(container, {zoom: 20});
- L.tileLayer('', {maxZoom: 15}).addTo(map);
+ new TileLayer('', {maxZoom: 15}).addTo(map);
expect(map.getMaxZoom()).to.equal(15);
});
@@ -632,9 +635,9 @@ describe('Map', () => {
it('map\'s zoom is adjusted to layer\'s minZoom even if initialized with smaller value', () => {
removeMapContainer(map, container);
container = createContainer();
- map = L.map(container, {zoom: 10});
+ map = new Map(container, {zoom: 10});
- L.tileLayer('', {minZoom: 15}).addTo(map);
+ new TileLayer('', {minZoom: 15}).addTo(map);
expect(map.getZoom()).to.equal(15);
});
@@ -642,9 +645,9 @@ describe('Map', () => {
it('map\'s zoom is adjusted to layer\'s maxZoom even if initialized with larger value', () => {
removeMapContainer(map, container);
container = createContainer();
- map = L.map(container, {zoom: 20});
+ map = new Map(container, {zoom: 20});
- L.tileLayer('', {maxZoom: 15}).addTo(map);
+ new TileLayer('', {maxZoom: 15}).addTo(map);
expect(map.getZoom()).to.equal(15);
});
@@ -652,13 +655,13 @@ describe('Map', () => {
describe('#addHandler', () => {
function getHandler(callback = () => {}) {
- return L.Handler.extend({
+ return Handler.extend({
addHooks() {
- L.DomEvent.on(window, 'click', this.handleClick, this);
+ DomEvent.on(window, 'click', this.handleClick, this);
},
removeHooks() {
- L.DomEvent.off(window, 'click', this.handleClick, this);
+ DomEvent.off(window, 'click', this.handleClick, this);
},
handleClick: callback
@@ -666,8 +669,7 @@ describe('Map', () => {
}
it('checking enabled method', () => {
- L.ClickHandler = getHandler();
- map.addHandler('clickHandler', L.ClickHandler);
+ map.addHandler('clickHandler', getHandler());
expect(map.clickHandler.enabled()).to.eql(false);
@@ -680,18 +682,16 @@ describe('Map', () => {
it('automatically enabled, when has a property named the same as the handler', () => {
map.remove();
- map = L.map(container, {clickHandler: true});
+ map = new Map(container, {clickHandler: true});
- L.ClickHandler = getHandler();
- map.addHandler('clickHandler', L.ClickHandler);
+ map.addHandler('clickHandler', getHandler());
expect(map.clickHandler.enabled()).to.eql(true);
});
it('checking handling events when enabled/disabled', () => {
const spy = sinon.spy();
- L.ClickHandler = getHandler(spy);
- map.addHandler('clickHandler', L.ClickHandler);
+ map.addHandler('clickHandler', getHandler(spy));
UIEventSimulator.fire('click', window);
UIEventSimulator.fire('click', window);
@@ -764,7 +764,7 @@ describe('Map', () => {
});
it('return empty pane when map deleted', () => {
- const map2 = L.map(document.createElement('div'));
+ const map2 = new Map(document.createElement('div'));
map2.remove();
expect(map2.getPanes()).to.eql({});
@@ -778,7 +778,7 @@ describe('Map', () => {
it('return undefined on empty container id', () => {
const container2 = createContainer();
- const map2 = L.map(container2);
+ const map2 = new Map(container2);
map2.remove(); // clean up
expect(map2.getContainer()._leaflet_id).to.eql(undefined);
@@ -787,13 +787,13 @@ describe('Map', () => {
describe('#getSize', () => {
it('return map size in pixels', () => {
- expect(map.getSize()).to.eql(L.point([400, 400]));
+ expect(map.getSize()).to.eql(new Point(400, 400));
});
it('return map size if not specified', () => {
- const map2 = L.map(document.createElement('div'));
+ const map2 = new Map(document.createElement('div'));
- expect(map2.getSize()).to.eql(L.point([0, 0]));
+ expect(map2.getSize()).to.eql(new Point(0, 0));
map2.remove(); // clean up
});
@@ -802,13 +802,13 @@ describe('Map', () => {
container.style.width = '0px';
container.style.height = '0px';
- expect(map.getSize()).to.eql(L.point([0, 0]));
+ expect(map.getSize()).to.eql(new Point(0, 0));
});
it('return new pixels on change', () => {
container.style.width = '300px';
- expect(map.getSize()).to.eql(L.point([300, 400]));
+ expect(map.getSize()).to.eql(new Point(300, 400));
});
it('return clone of size object from map', () => {
@@ -817,11 +817,11 @@ describe('Map', () => {
it('return previous size on empty map', () => {
const container2 = createContainer();
- const map2 = L.map(container2);
+ const map2 = new Map(container2);
map2.remove(); // clean up
- expect(map2.getSize()).to.eql(L.point([400, 400]));
+ expect(map2.getSize()).to.eql(new Point(400, 400));
});
});
@@ -831,24 +831,24 @@ describe('Map', () => {
});
it('return map bounds in pixels', () => {
- expect(map.getPixelBounds()).to.eql(L.bounds([-72, -72], [328, 328]));
+ expect(map.getPixelBounds()).to.eql(new Bounds([-72, -72], [328, 328]));
});
it('return changed map bounds if really zoomed in', () => {
map.setZoom(20);
- expect(map.getPixelBounds()).to.eql(L.bounds([134217528, 134217528], [134217928, 134217928]));
+ expect(map.getPixelBounds()).to.eql(new Bounds([134217528, 134217528], [134217928, 134217928]));
});
it('return new pixels on view change', () => {
map.setView([50, 50], 5);
- expect(map.getPixelBounds()).to.eql(L.bounds([5034, 2578], [5434, 2978]));
+ expect(map.getPixelBounds()).to.eql(new Bounds([5034, 2578], [5434, 2978]));
});
it('throw error if center and zoom were not set / map not loaded', () => {
const container2 = createContainer();
- const map2 = L.map(container2);
+ const map2 = new Map(container2);
expect(map2.getPixelBounds).to.throw();
@@ -862,24 +862,24 @@ describe('Map', () => {
});
it('return pixel origin', () => {
- expect(map.getPixelOrigin()).to.eql(L.point([-72, -72]));
+ expect(map.getPixelOrigin()).to.eql(new Point(-72, -72));
});
it('return new pixels on view change', () => {
map.setView([50, 50], 5);
- expect(map.getPixelOrigin()).to.eql(L.point([5034, 2578]));
+ expect(map.getPixelOrigin()).to.eql(new Point(5034, 2578));
});
it('return changed map bounds if really zoomed in', () => {
map.setZoom(20);
- expect(map.getPixelOrigin()).to.eql(L.point([134217528, 134217528]));
+ expect(map.getPixelOrigin()).to.eql(new Point(134217528, 134217528));
});
it('throw error if center and zoom were not set / map not loaded', () => {
const container2 = createContainer();
- const map2 = L.map(container2);
+ const map2 = new Map(container2);
expect(map2.getPixelOrigin).to.throw();
@@ -889,34 +889,34 @@ describe('Map', () => {
describe('#getPixelWorldBounds', () => {
it('return map bounds in pixels', () => {
- expect(map.getPixelWorldBounds()).to.eql(L.bounds(
+ expect(map.getPixelWorldBounds()).to.eql(new Bounds(
[5.551115123125783e-17, 5.551115123125783e-17], [1, 1]));
});
it('return changed map bounds if really zoomed in', () => {
map.setZoom(20);
- expect(map.getPixelWorldBounds()).to.eql(L.bounds(
+ expect(map.getPixelWorldBounds()).to.eql(new Bounds(
[1.4901161193847656e-8, 1.4901161193847656e-8], [268435456, 268435456]));
});
it('return new pixels on zoom change', () => {
map.setZoom(5);
- expect(map.getPixelWorldBounds()).to.eql(L.bounds(
+ expect(map.getPixelWorldBounds()).to.eql(new Bounds(
[4.547473508864641e-13, 4.547473508864641e-13], [8192, 8192]));
map.setView([0, 0]);
// view does not change pixel world bounds
- expect(map.getPixelWorldBounds()).to.eql(L.bounds(
+ expect(map.getPixelWorldBounds()).to.eql(new Bounds(
[4.547473508864641e-13, 4.547473508864641e-13], [8192, 8192]));
});
it('return infinity bounds on infinity zoom', () => {
map.setZoom(Infinity);
- expect(map.getPixelWorldBounds()).to.eql(L.bounds(
+ expect(map.getPixelWorldBounds()).to.eql(new Bounds(
[Infinity, Infinity], [Infinity, Infinity]));
});
});
@@ -924,7 +924,7 @@ describe('Map', () => {
describe('#hasLayer', () => {
it('throws when called without proper argument', () => {
const hasLayer = map.hasLayer.bind(map);
- expect(() => hasLayer(new L.Layer())).to.not.throw(); // control case
+ expect(() => hasLayer(new Layer())).to.not.throw(); // control case
expect(() => hasLayer(undefined)).to.throw();
expect(() => hasLayer(null)).to.throw();
@@ -934,7 +934,7 @@ describe('Map', () => {
});
function layerSpy() {
- const layer = new L.Layer();
+ const layer = new Layer();
layer.onAdd = sinon.spy();
layer.onRemove = sinon.spy();
return layer;
@@ -1004,7 +1004,7 @@ describe('Map', () => {
});
it('throws if adding something which is not a layer', () => {
- const control = L.control.layers();
+ const control = lControl.layers();
expect(() => {
map.addLayer(control);
}).to.throw();
@@ -1015,7 +1015,7 @@ describe('Map', () => {
const spy = sinon.spy();
map.on('zoomlevelschange', spy);
expect(spy.called).not.to.be.true;
- L.tileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
+ new TileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
expect(spy.called).to.be.true;
});
});
@@ -1023,10 +1023,10 @@ describe('Map', () => {
describe('when a new layer with greater zoomlevel coverage than the current layer is added to a map', () => {
it('fires a zoomlevelschange event', () => {
const spy = sinon.spy();
- L.tileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
+ new TileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
map.on('zoomlevelschange', spy);
expect(spy.called).not.to.be.true;
- L.tileLayer('', {minZoom: 0, maxZoom: 15}).addTo(map);
+ new TileLayer('', {minZoom: 0, maxZoom: 15}).addTo(map);
expect(spy.called).to.be.true;
});
});
@@ -1034,12 +1034,12 @@ describe('Map', () => {
describe('when a new layer with the same or lower zoomlevel coverage as the current layer is added to a map', () => {
it('fires no zoomlevelschange event', () => {
const spy = sinon.spy();
- L.tileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
+ new TileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
map.on('zoomlevelschange', spy);
expect(spy.called).not.to.be.true;
- L.tileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
+ new TileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
expect(spy.called).not.to.be.true;
- L.tileLayer('', {minZoom: 0, maxZoom: 5}).addTo(map);
+ new TileLayer('', {minZoom: 0, maxZoom: 5}).addTo(map);
expect(spy.called).not.to.be.true;
});
});
@@ -1108,14 +1108,14 @@ describe('Map', () => {
});
it('supports adding and removing a tile layer without initializing the map', () => {
- const layer = L.tileLayer('');
+ const layer = new TileLayer('');
map.addLayer(layer);
map.removeLayer(layer);
});
it('supports adding and removing a tile layer without initializing the map', () => {
map.setView([0, 0], 18);
- const layer = L.gridLayer();
+ const layer = new GridLayer();
map.addLayer(layer);
map.removeLayer(layer);
});
@@ -1124,7 +1124,7 @@ describe('Map', () => {
it('fires a zoomlevelschange event', () => {
map.setView([0, 0], 0);
const spy = sinon.spy();
- const tl = L.tileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
+ const tl = new TileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
map.on('zoomlevelschange', spy);
expect(spy.called).not.to.be.true;
@@ -1136,9 +1136,9 @@ describe('Map', () => {
describe('when a tile layer is removed from a map and it had greater zoom level coverage than the remainding layer', () => {
it('fires a zoomlevelschange event', () => {
map.setView([0, 0], 0);
- L.tileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
+ new TileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map);
const spy = sinon.spy(),
- t2 = L.tileLayer('', {minZoom: 0, maxZoom: 15}).addTo(map);
+ t2 = new TileLayer('', {minZoom: 0, maxZoom: 15}).addTo(map);
map.on('zoomlevelschange', spy);
expect(spy.called).to.be.false;
@@ -1151,9 +1151,9 @@ describe('Map', () => {
it('fires no zoomlevelschange event', () => {
map.setView([0, 0], 0);
const spy = sinon.spy(),
- t1 = L.tileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map),
- t2 = L.tileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map),
- t3 = L.tileLayer('', {minZoom: 0, maxZoom: 5}).addTo(map);
+ t1 = new TileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map),
+ t2 = new TileLayer('', {minZoom: 0, maxZoom: 10}).addTo(map),
+ t3 = new TileLayer('', {minZoom: 0, maxZoom: 5}).addTo(map);
map.on('zoomlevelschange', spy);
map.removeLayer(t2);
@@ -1168,12 +1168,12 @@ describe('Map', () => {
describe('#eachLayer', () => {
it('returns self', () => {
- expect(map.eachLayer(L.Util.falseFn)).to.equal(map);
+ expect(map.eachLayer(Util.falseFn)).to.equal(map);
});
it('calls the provided function for each layer', () => {
- const t1 = L.tileLayer('').addTo(map),
- t2 = L.tileLayer('').addTo(map),
+ const t1 = new TileLayer('').addTo(map),
+ t2 = new TileLayer('').addTo(map),
spy = sinon.spy();
map.eachLayer(spy);
@@ -1185,7 +1185,7 @@ describe('Map', () => {
it('calls the provided function with the provided context', () => {
const spy = sinon.spy();
- L.tileLayer('').addTo(map);
+ new TileLayer('').addTo(map);
map.eachLayer(spy, map);
@@ -1297,7 +1297,7 @@ describe('Map', () => {
const center = [0, 0];
// The edge case is only if view is set directly during map initialization
- map = L.map(container, {
+ map = new Map(container, {
center,
zoom: 0
});
@@ -1341,7 +1341,7 @@ describe('Map', () => {
const center = [0, 0];
// The edge case is only if view is set directly during map initialization
- map = L.map(container, {
+ map = new Map(container, {
center,
zoom: 0,
trackResize: false
@@ -1375,7 +1375,7 @@ describe('Map', () => {
expect(spy.called).to.be.false;
// make sure afterEach works correctly
- map = L.map(container);
+ map = new Map(container);
done();
// we need the 10 ms to be sure that the ResizeObserver is not triggered
}, 10);
@@ -1392,7 +1392,7 @@ describe('Map', () => {
it('move to requested center and zoom, and call zoomend once', function (done) {
this.timeout(10000); // This test takes longer than usual due to frames
- const newCenter = L.latLng(10, 11),
+ const newCenter = latLng(10, 11),
newZoom = 12;
const callback = function () {
expect(map.getCenter()).to.eql(newCenter);
@@ -1406,7 +1406,7 @@ describe('Map', () => {
it('flyTo start latlng == end latlng', function (done) {
this.timeout(10000); // This test takes longer than usual due to frames
- const dc = L.latLng(38.91, -77.04);
+ const dc = latLng(38.91, -77.04);
map.setView(dc, 14);
map.on('zoomend', () => {
@@ -1420,7 +1420,7 @@ describe('Map', () => {
});
describe('#zoomIn and #zoomOut', () => {
- const center = L.latLng(22, 33);
+ const center = latLng(22, 33);
beforeEach(() => {
map.setView(center, 10);
});
@@ -1491,7 +1491,7 @@ describe('Map', () => {
});
describe('#_getBoundsCenterZoom', () => {
- const center = L.latLng(50.5, 30.51);
+ const center = latLng(50.5, 30.51);
it('Returns valid center on empty bounds in unitialized map', () => {
// Edge case from #5153
@@ -1502,8 +1502,8 @@ describe('Map', () => {
});
describe('#fitBounds', () => {
- const center = L.latLng(50.5, 30.51);
- let bounds = L.latLngBounds(L.latLng(1, 102), L.latLng(11, 122)),
+ const center = latLng(50.5, 30.51);
+ let bounds = new LatLngBounds(latLng(1, 102), latLng(11, 122)),
boundsCenter = bounds.getCenter();
beforeEach(() => {
@@ -1570,7 +1570,7 @@ describe('Map', () => {
map.fitBounds(bounds);
});
- bounds = L.latLngBounds([57.73, 11.93], [57.75, 11.95]);
+ bounds = new LatLngBounds([57.73, 11.93], [57.75, 11.95]);
boundsCenter = bounds.getCenter();
map.setZoom(0);
});
@@ -1585,15 +1585,15 @@ describe('Map', () => {
map.fitBounds(bounds);
});
- bounds = L.latLngBounds([90, -180], [-90, 180]);
+ bounds = new LatLngBounds([90, -180], [-90, 180]);
boundsCenter = bounds.getCenter();
map.setZoom(22);
});
});
describe('#fitBounds after layers set', () => {
- const center = L.latLng(22, 33),
- bounds = L.latLngBounds(L.latLng(1, 102), L.latLng(11, 122));
+ const center = latLng(22, 33),
+ bounds = new LatLngBounds(latLng(1, 102), latLng(11, 122));
beforeEach(() => {
// fitBounds needs a map container with non-null area
@@ -1601,14 +1601,14 @@ describe('Map', () => {
});
it('Snaps to a number after adding tile layer', () => {
- map.addLayer(L.tileLayer(''));
+ map.addLayer(new TileLayer(''));
expect(map.getZoom()).to.equal(undefined);
map.fitBounds(bounds);
expect(map.getZoom()).to.equal(2);
});
it('Snaps to a number after adding marker', () => {
- map.addLayer(L.marker(center));
+ map.addLayer(new Marker(center));
expect(map.getZoom()).to.equal(undefined);
map.fitBounds(bounds);
expect(map.getZoom()).to.equal(2);
@@ -1617,7 +1617,7 @@ describe('Map', () => {
});
describe('#fitWorld', () => {
- const bounds = L.latLngBounds([90, -180], [-90, 180]),
+ const bounds = new LatLngBounds([90, -180], [-90, 180]),
boundsCenter = bounds.getCenter();
@@ -1642,7 +1642,7 @@ describe('Map', () => {
beforeEach(() => {
container.style.height = container.style.width = '500px';
- map.setView(L.latLng([53.0, 0.15]), 12, {animate: false});
+ map.setView(latLng([53.0, 0.15]), 12, {animate: false});
center = map.getCenter().clone();
tl = map.getBounds().getNorthWest();
tlPix = map.getPixelBounds().min;
@@ -1659,25 +1659,25 @@ describe('Map', () => {
distanceMoved;
map.panInside(map.unproject(p), {padding, animate: false});
distanceMoved = map.getPixelBounds().min.subtract(tlPix);
- expect(distanceMoved.equals(L.point([-10, -20]))).to.eql(true);
+ expect(distanceMoved.equals(new Point(-10, -20))).to.eql(true);
tlPix = map.getPixelBounds().min;
p = [map.getPixelBounds().max.x - 10, map.getPixelBounds().min.y]; // Top-right
map.panInside(map.unproject(p), {padding, animate: false});
distanceMoved = map.getPixelBounds().min.subtract(tlPix);
- expect(distanceMoved.equals(L.point([30, -20]))).to.eql(true);
+ expect(distanceMoved.equals(new Point(30, -20))).to.eql(true);
tlPix = map.getPixelBounds().min;
p = [map.getPixelBounds().min.x + 35, map.getPixelBounds().max.y]; // Bottom-left
map.panInside(map.unproject(p), {padding, animate: false});
distanceMoved = map.getPixelBounds().min.subtract(tlPix);
- expect(distanceMoved.equals(L.point([-5, 20]))).to.eql(true);
+ expect(distanceMoved.equals(new Point(-5, 20))).to.eql(true);
tlPix = map.getPixelBounds().min;
p = [map.getPixelBounds().max.x - 15, map.getPixelBounds().max.y]; // Bottom-right
map.panInside(map.unproject(p), {padding, animate: false});
distanceMoved = map.getPixelBounds().min.subtract(tlPix);
- expect(distanceMoved.equals(L.point([25, 20]))).to.eql(true);
+ expect(distanceMoved.equals(new Point(25, 20))).to.eql(true);
});
it('supports different padding values for each border', () => {
@@ -1687,7 +1687,7 @@ describe('Map', () => {
expect(center).to.eql(map.getCenter());
const br = map.getPixelBounds().max; // Bottom-Right
- map.panInside(map.unproject(L.point(br.x + 20, br.y)), opts);
+ map.panInside(map.unproject(new Point(br.x + 20, br.y)), opts);
expect(center).to.not.eql(map.getCenter());
});
@@ -1700,7 +1700,7 @@ describe('Map', () => {
});
it('pans only on the Y axis when the target\'s X coord is within bounds but the Y is not', () => {
- const p = L.latLng(tl.lat + 5, tl.lng);
+ const p = latLng(tl.lat + 5, tl.lng);
map.panInside(p, {animate: false});
expect(map.getBounds().contains(p)).to.be.true;
const dx = Math.abs(map.getCenter().lng - center.lng);
@@ -1709,7 +1709,7 @@ describe('Map', () => {
});
it('pans only on the X axis when the target\'s Y coord is within bounds but the X is not', () => {
- const p = L.latLng(tl.lat, tl.lng - 5);
+ const p = latLng(tl.lat, tl.lng - 5);
map.panInside(p, 0, {animate: false});
expect(map.getBounds().contains(p)).to.be.true;
expect(map.getCenter().lng).to.not.eql(center.lng);
@@ -1719,15 +1719,15 @@ describe('Map', () => {
it('pans correctly when padding takes up more than half the display bounds', () => {
const oldCenter = map.project(center);
- const targetOffset = L.point(0, -5); // arbitrary point above center
+ const targetOffset = new Point(0, -5); // arbitrary point above center
const target = oldCenter.add(targetOffset);
- const paddingOffset = L.point(0, 15);
+ const paddingOffset = new Point(0, 15);
const padding = map.getSize().divideBy(2) // half size
.add(paddingOffset); // padding more than half the display bounds (replicates issue #7445)
map.panInside(map.unproject(target), {paddingBottomRight: [0, padding.y], animate: false});
const offset = map.project(map.getCenter()).subtract(oldCenter); // distance moved during the pan
const result = paddingOffset.add(targetOffset).subtract(offset);
- expect(result.trunc().equals(L.point(0, 0))).to.be.true;
+ expect(result.trunc().equals(new Point(0, 0))).to.be.true;
});
});
@@ -1739,7 +1739,7 @@ describe('Map', () => {
it('DOM events propagate from polygon to map', () => {
const spy = sinon.spy();
map.on('mousemove', spy);
- const layer = L.polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
+ const layer = new Polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
UIEventSimulator.fire('mousemove', layer._path);
expect(spy.calledOnce).to.be.true;
});
@@ -1747,7 +1747,7 @@ describe('Map', () => {
it('DOM events propagate from marker to map', () => {
const spy = sinon.spy();
map.on('mousemove', spy);
- const layer = L.marker([1, 2]).addTo(map);
+ const layer = new Marker([1, 2]).addTo(map);
UIEventSimulator.fire('mousemove', layer._icon);
expect(spy.calledOnce).to.be.true;
});
@@ -1756,8 +1756,8 @@ describe('Map', () => {
const mapSpy = sinon.spy();
const layerSpy = sinon.spy();
map.on('mousemove', mapSpy);
- const layer = L.marker([1, 2]).addTo(map);
- layer.on('mousemove', L.DomEvent.stopPropagation).on('mousemove', layerSpy);
+ const layer = new Marker([1, 2]).addTo(map);
+ layer.on('mousemove', DomEvent.stopPropagation).on('mousemove', layerSpy);
UIEventSimulator.fire('mousemove', layer._icon);
expect(layerSpy.calledOnce).to.be.true;
expect(mapSpy.called).not.to.be.true;
@@ -1767,8 +1767,8 @@ describe('Map', () => {
const mapSpy = sinon.spy();
const layerSpy = sinon.spy();
map.on('mousemove', mapSpy);
- const layer = L.polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
- layer.on('mousemove', L.DomEvent.stopPropagation).on('mousemove', layerSpy);
+ const layer = new Polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
+ layer.on('mousemove', DomEvent.stopPropagation).on('mousemove', layerSpy);
UIEventSimulator.fire('mousemove', layer._path);
expect(layerSpy.calledOnce).to.be.true;
expect(mapSpy.called).not.to.be.true;
@@ -1778,8 +1778,8 @@ describe('Map', () => {
const mapSpy = sinon.spy(),
layerSpy = sinon.spy(),
otherSpy = sinon.spy();
- const layer = L.polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
- const other = L.polygon([[10, 20], [30, 40], [50, 60]]).addTo(map);
+ const layer = new Polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
+ const other = new Polygon([[10, 20], [30, 40], [50, 60]]).addTo(map);
map.on('mouseout', mapSpy);
layer.on('mouseout', layerSpy);
other.on('mouseout', otherSpy);
@@ -1790,13 +1790,13 @@ describe('Map', () => {
});
it('mouseout is forwarded when using a DivIcon', () => {
- const icon = L.divIcon({
+ const icon = new DivIcon({
html: '
this is text in a child element
',
iconSize: [100, 100]
});
const mapSpy = sinon.spy(),
layerSpy = sinon.spy(),
- layer = L.marker([1, 2], {icon}).addTo(map);
+ layer = new Marker([1, 2], {icon}).addTo(map);
map.on('mouseout', mapSpy);
layer.on('mouseout', layerSpy);
UIEventSimulator.fire('mouseout', layer._icon, {relatedTarget: container});
@@ -1805,13 +1805,13 @@ describe('Map', () => {
});
it('mouseout is not forwarded if relatedTarget is a target\'s child', () => {
- const icon = L.divIcon({
+ const icon = new DivIcon({
html: '
this is text in a child element
',
iconSize: [100, 100]
});
const mapSpy = sinon.spy(),
layerSpy = sinon.spy(),
- layer = L.marker([1, 2], {icon}).addTo(map),
+ layer = new Marker([1, 2], {icon}).addTo(map),
child = layer._icon.querySelector('p');
map.on('mouseout', mapSpy);
layer.on('mouseout', layerSpy);
@@ -1821,13 +1821,13 @@ describe('Map', () => {
});
it('mouseout is not forwarded if fired on target\'s child', () => {
- const icon = L.divIcon({
+ const icon = new DivIcon({
html: '
this is text in a child element
',
iconSize: [100, 100]
});
const mapSpy = sinon.spy(),
layerSpy = sinon.spy(),
- layer = L.marker([1, 2], {icon}).addTo(map),
+ layer = new Marker([1, 2], {icon}).addTo(map),
child = layer._icon.querySelector('p');
map.on('mouseout', mapSpy);
layer.on('mouseout', layerSpy);
@@ -1840,8 +1840,8 @@ describe('Map', () => {
const mapSpy = sinon.spy(),
layerSpy = sinon.spy(),
otherSpy = sinon.spy();
- const layer = L.polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
- const other = L.polygon([[10, 20], [30, 40], [50, 60]]).addTo(map);
+ const layer = new Polygon([[1, 2], [3, 4], [5, 6]]).addTo(map);
+ const other = new Polygon([[10, 20], [30, 40], [50, 60]]).addTo(map);
map.on('mouseout', mapSpy);
layer.on('mouseout', layerSpy);
other.on('mouseout', otherSpy);
@@ -1853,7 +1853,7 @@ describe('Map', () => {
it('preclick is fired before click on marker and map', () => {
let called = 0;
- const layer = L.marker([1, 2], {bubblingMouseEvents: true}).addTo(map);
+ const layer = new Marker([1, 2], {bubblingMouseEvents: true}).addTo(map);
layer.on('preclick', (e) => {
expect(called++).to.eql(0);
expect(e.latlng).to.be.ok;
@@ -1877,20 +1877,20 @@ describe('Map', () => {
it('prevents default action of contextmenu if there is any listener', () => {
removeMapContainer(map, container);
container = createContainer();
- map = L.map(container, {
- renderer: L.canvas(),
+ map = new Map(container, {
+ renderer: new Canvas(),
center: [0, 0],
zoom: 0
});
container.style.width = container.style.height = '300px';
- map.setView(L.latLng([0, 0]), 12);
+ map.setView(latLng([0, 0]), 12);
const spy = sinon.spy();
map.on('contextmenu', (e) => {
spy(e.originalEvent.defaultPrevented);
});
- const marker = L.circleMarker([0, 0]).addTo(map);
+ const marker = new CircleMarker([0, 0]).addTo(map);
UIEventSimulator.fireAt('contextmenu', 0, 0); // first
@@ -1926,7 +1926,7 @@ describe('Map', () => {
});
it('returns undefined if map not initialized but layers added', () => {
- map.addLayer(L.tileLayer(''));
+ map.addLayer(new TileLayer(''));
expect(map.getZoom()).to.equal(undefined);
});
});
@@ -1958,7 +1958,7 @@ describe('Map', () => {
const child = document.createElement('div');
parent.appendChild(child);
container.appendChild(parent);
- L.DomEvent.on(child, 'click', () => {
+ DomEvent.on(child, 'click', () => {
parent.remove();
});
expect(() => {
@@ -1969,22 +1969,22 @@ describe('Map', () => {
describe('#distance', () => {
it('measure distance in meters', () => {
- const LA = L.latLng(34.0485672098387, -118.217781922035);
- const columbus = L.latLng(39.95715687063701, -83.00205705857633);
+ const LA = latLng(34.0485672098387, -118.217781922035);
+ const columbus = latLng(39.95715687063701, -83.00205705857633);
expect(map.distance(LA, columbus)).to.be.within(3173910, 3173915);
});
it('accurately measure in small distances', () => {
- const p1 = L.latLng(40.160857881285416, -83.00841851162649);
- const p2 = L.latLng(40.16246493902907, -83.008622359483);
+ const p1 = latLng(40.160857881285416, -83.00841851162649);
+ const p2 = latLng(40.16246493902907, -83.008622359483);
expect(map.distance(p1, p2)).to.be.within(175, 185);
});
it('accurately measure in long distances', () => {
- const canada = L.latLng(60.01810635103154, -112.19675246283015);
- const newZeland = L.latLng(-42.36275164460971, 172.39309066597883);
+ const canada = latLng(60.01810635103154, -112.19675246283015);
+ const newZeland = latLng(-42.36275164460971, 172.39309066597883);
expect(map.distance(canada, newZeland)).to.be.within(13274700, 13274800);
});
@@ -2002,7 +2002,7 @@ describe('Map', () => {
});
it('return 0 with 2 same latLng', () => {
- const p = L.latLng(20, 50);
+ const p = latLng(20, 50);
expect(map.distance(p, p)).to.eql(0);
});
@@ -2010,14 +2010,14 @@ describe('Map', () => {
describe('#containerPointToLayerPoint', () => {
it('return same point of LayerPoint is 0, 0', () => {
- expect(map.containerPointToLayerPoint(L.point(25, 25))).to.eql(L.point(25, 25));
+ expect(map.containerPointToLayerPoint(new Point(25, 25))).to.eql(new Point(25, 25));
});
it('return point relative to LayerPoint', (done) => {
map.setView([20, 20], 2);
map.once('moveend', () => {
- expect(map.containerPointToLayerPoint(L.point(30, 30))).to.eql(L.point(80, 80));
+ expect(map.containerPointToLayerPoint(new Point(30, 30))).to.eql(new Point(80, 80));
done();
});
@@ -2027,14 +2027,14 @@ describe('Map', () => {
describe('#layerPointToContainerPoint', () => {
it('return same point of ContainerPoint is 0, 0', () => {
- expect(map.layerPointToContainerPoint(L.point(25, 25))).to.eql(L.point(25, 25));
+ expect(map.layerPointToContainerPoint(new Point(25, 25))).to.eql(new Point(25, 25));
});
it('return point relative to ContainerPoint', (done) => {
map.setView([20, 20], 2);
map.once('moveend', () => {
- expect(map.layerPointToContainerPoint(L.point(30, 30))).to.eql(L.point(-20, -20));
+ expect(map.layerPointToContainerPoint(new Point(30, 30))).to.eql(new Point(-20, -20));
done();
});
@@ -2044,59 +2044,59 @@ describe('Map', () => {
describe('_addZoomLimit', () => {
it('update zoom levels when min zoom is a number in a layer that is added to map', () => {
- map._addZoomLimit(L.tileLayer('', {minZoom: 4}));
+ map._addZoomLimit(new TileLayer('', {minZoom: 4}));
expect(map._layersMinZoom).to.equal(4);
});
it('update zoom levels when max zoom is a number in a layer that is added to map', () => {
- map._addZoomLimit(L.tileLayer('', {maxZoom: 10}));
+ map._addZoomLimit(new TileLayer('', {maxZoom: 10}));
expect(map._layersMaxZoom).to.equal(10);
});
it('update zoom levels when min zoom is a number in two layers that are added to map', () => {
- map._addZoomLimit(L.tileLayer('', {minZoom: 6}));
- map._addZoomLimit(L.tileLayer('', {minZoom: 4}));
+ map._addZoomLimit(new TileLayer('', {minZoom: 6}));
+ map._addZoomLimit(new TileLayer('', {minZoom: 4}));
expect(map._layersMinZoom).to.equal(4);
});
it('update zoom levels when max zoom is a number in two layers that are added to map', () => {
- map._addZoomLimit(L.tileLayer('', {maxZoom: 10}));
- map._addZoomLimit(L.tileLayer('', {maxZoom: 8}));
+ map._addZoomLimit(new TileLayer('', {maxZoom: 10}));
+ map._addZoomLimit(new TileLayer('', {maxZoom: 8}));
expect(map._layersMaxZoom).to.equal(10);
});
// This test shows the NaN usage - it's not clear if NaN is a wanted "feature"
it('update zoom levels when min zoom is NaN in a layer that is added to map, so that min zoom becomes NaN,', () => {
- map._addZoomLimit(L.tileLayer('', {minZoom: NaN}));
+ map._addZoomLimit(new TileLayer('', {minZoom: NaN}));
expect(isNaN(map._layersMinZoom)).to.be.true;
});
// This test shows the NaN usage - it's not clear if NaN is a wanted "feature"
it('update zoom levels when max zoom is NaN in a layer that is added to map, so that max zoom becomes NaN', () => {
- map._addZoomLimit(L.tileLayer('', {maxZoom: NaN}));
+ map._addZoomLimit(new TileLayer('', {maxZoom: NaN}));
expect(isNaN(map._layersMaxZoom)).to.be.true;
});
// This test shows the NaN usage - it's not clear if NaN is a wanted "feature"
// Test is clearly wrong, but kept for future fixes
// it("update zoom levels when min zoom is NaN in at least one of many layers that are added to map, so that min zoom becomes NaN", function () {
- // map._addZoomLimit(L.tileLayer("", {minZoom: 6}));
- // map._addZoomLimit(L.tileLayer("", {minZoom: NaN})); --> Results in maxZoom = NaN --> _updateZoomLevels is not called.
+ // map._addZoomLimit(new TileLayer("", {minZoom: 6}));
+ // map._addZoomLimit(new TileLayer("", {minZoom: NaN})); --> Results in maxZoom = NaN --> _updateZoomLevels is not called.
// Not same logic as for maxZoom.
- // map._addZoomLimit(L.tileLayer("", {minZoom: 4}));
+ // map._addZoomLimit(new TileLayer("", {minZoom: 4}));
// expect(isNaN(map._layersMinZoom)).to.be.true;
// });
// This test shows the NaN usage - it's not clear if NaN is a wanted "feature"
it('update zoom levels when max zoom is NaN in at least one of many layers that are added to map, so that max zoom becomes NaN', () => {
- map._addZoomLimit(L.tileLayer('', {maxZoom: 10}));
- map._addZoomLimit(L.tileLayer('', {maxZoom: 8}));
- map._addZoomLimit(L.tileLayer('', {maxZoom: NaN}));
+ map._addZoomLimit(new TileLayer('', {maxZoom: 10}));
+ map._addZoomLimit(new TileLayer('', {maxZoom: 8}));
+ map._addZoomLimit(new TileLayer('', {maxZoom: NaN}));
expect(isNaN(map._layersMaxZoom)).to.be.true;
});
it('doesn\'t update zoom levels when min and max zoom are both NaN in a layer that is added to map', () => {
- map._addZoomLimit(L.tileLayer('', {minZoom: NaN, maxZoom: NaN}));
+ map._addZoomLimit(new TileLayer('', {minZoom: NaN, maxZoom: NaN}));
expect(map._layersMinZoom === undefined && map._layersMaxZoom === undefined).to.be.true;
});
});
@@ -2110,9 +2110,9 @@ describe('Map', () => {
});
it('returns geographical coordinate for point relative to map container', () => {
- const center = L.latLng(10, 10);
+ const center = latLng(10, 10);
map.setView(center, 50);
- const p = map.containerPointToLatLng(L.point(200, 200));
+ const p = map.containerPointToLatLng(new Point(200, 200));
expect(p.lat).to.be.within(10.0000000, 10.0000001);
expect(p.lng).to.be.within(10.0000000, 10.0000001);
});
@@ -2128,7 +2128,7 @@ describe('Map', () => {
});
it('returns point relative to map container for geographical coordinate', () => {
- const center = L.latLng(10, 10);
+ const center = latLng(10, 10);
map.setView(center);
const p = map.latLngToContainerPoint(center);
expect(p.x).to.be.equal(200);
@@ -2145,7 +2145,7 @@ describe('Map', () => {
});
it('pans the map to accurate location', () => {
- const center = L.latLng([50, 30]);
+ const center = latLng([50, 30]);
expect(map.panTo(center)).to.equal(map);
expect(map.getCenter().distanceTo(center)).to.be.lessThan(5);
});
@@ -2167,15 +2167,15 @@ describe('Map', () => {
it('doesn\'t pan if already in bounds', () => {
map.setView([0, 0]);
- const bounds = L.latLngBounds([[-1, -1], [1, 1]]);
- const expectedCenter = L.latLng([0, 0]);
+ const bounds = new LatLngBounds([[-1, -1], [1, 1]]);
+ const expectedCenter = latLng([0, 0]);
expect(map.panInsideBounds(bounds)).to.equal(map);
expect(map.getCenter()).to.be.nearLatLng(expectedCenter);
});
it('pans to closest view in bounds', () => {
- const bounds = L.latLngBounds([[41.8, -87.6], [40.7, -74]]);
- const expectedCenter = L.latLng([41.59452223189, -74.2738647460]);
+ const bounds = new LatLngBounds([[41.8, -87.6], [40.7, -74]]);
+ const expectedCenter = latLng([41.59452223189, -74.2738647460]);
map.setView([50.5, 30.5], 10);
expect(map.panInsideBounds(bounds)).to.equal(map);
expect(map.getCenter()).to.be.nearLatLng(expectedCenter);
@@ -2191,7 +2191,7 @@ describe('Map', () => {
});
it('returns the corresponding pixel coordinate relative to the origin pixel', () => {
- const center = L.latLng([10, 10]);
+ const center = latLng([10, 10]);
map.setView(center, 0);
const p = map.latLngToLayerPoint(center);
expect(p.x).to.be.equal(200);
@@ -2208,9 +2208,9 @@ describe('Map', () => {
});
it('returns the corresponding geographical coordinate for a pixel coordinate relative to the origin pixel', () => {
- const center = L.latLng(10, 10);
+ const center = latLng(10, 10);
map.setView(center, 10);
- const point = L.point(200, 200);
+ const point = new Point(200, 200);
const latlng = map.layerPointToLatLng(point);
expect(latlng).to.be.nearLatLng([9.9999579356371, 10.000305175781252]);
});
@@ -2446,7 +2446,7 @@ describe('Map', () => {
});
describe('#panBy', () => {
- const offset = L.point(1000, 1000);
+ const offset = new Point(1000, 1000);
it('throws if map is not set before', () => {
expect(() => {
@@ -2455,7 +2455,7 @@ describe('Map', () => {
});
it('pans the map by given offset', () => {
- const center = L.latLng([0, 0]);
+ const center = latLng([0, 0]);
map.setView(center, 7);
const offsetCenterPoint = map.options.crs.latLngToPoint(center, 7).add(offset);
const target = map.options.crs.pointToLatLng(offsetCenterPoint, 7);
@@ -2470,16 +2470,16 @@ describe('Map', () => {
it('returns the latitude and langitude with given point', () => {
map.setView([0, 0], 6);
- const expectedOutput = L.latLng(82.7432022836318, -175.60546875000003);
- const offset = L.point(200, 1000);
+ const expectedOutput = latLng(82.7432022836318, -175.60546875000003);
+ const offset = new Point(200, 1000);
const output = map.unproject(offset);
expect(output).to.be.nearLatLng(expectedOutput);
});
it('return the latitude and langitude with different zoom and points', () => {
map.setView([0, 0], 10);
- const expectedOutput = L.latLng(85.03926769025156, -179.98626708984378);
- const offset = L.point(10, 100);
+ const expectedOutput = latLng(85.03926769025156, -179.98626708984378);
+ const offset = new Point(10, 100);
const output = map.unproject(offset);
expect(output).to.be.nearLatLng(expectedOutput);
diff --git a/spec/suites/map/handler/Map.BoxZoom.js b/spec/suites/map/handler/Map.BoxZoom.js
index a53fbac27..07c6cf493 100644
--- a/spec/suites/map/handler/Map.BoxZoom.js
+++ b/spec/suites/map/handler/Map.BoxZoom.js
@@ -1,9 +1,12 @@
+import {Map} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('Map.BoxZoom', () => {
let container, map;
beforeEach(() => {
container = createContainer();
- map = L.map(container, {
+ map = new Map(container, {
center: [0, 0],
zoom: 3
});
diff --git a/spec/suites/map/handler/Map.DoubleClickZoomSpec.js b/spec/suites/map/handler/Map.DoubleClickZoomSpec.js
index ba6c062ac..0f6fea19d 100644
--- a/spec/suites/map/handler/Map.DoubleClickZoomSpec.js
+++ b/spec/suites/map/handler/Map.DoubleClickZoomSpec.js
@@ -1,9 +1,12 @@
+import {Map} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('Map.DoubleClickZoom', () => {
let container, map;
beforeEach(() => {
container = createContainer();
- map = L.map(container, {
+ map = new Map(container, {
center: [0, 0],
zoom: 3,
zoomAnimation: false
diff --git a/spec/suites/map/handler/Map.DragSpec.js b/spec/suites/map/handler/Map.DragSpec.js
index 6646ed54c..8d3a34316 100644
--- a/spec/suites/map/handler/Map.DragSpec.js
+++ b/spec/suites/map/handler/Map.DragSpec.js
@@ -1,3 +1,6 @@
+import {Map, DomUtil, Point, LatLng, Marker} from 'leaflet';
+import {createContainer, removeMapContainer, touchEventType} from '../../SpecHelper.js';
+
describe('Map.Drag', () => {
let container, map;
@@ -12,7 +15,7 @@ describe('Map.Drag', () => {
describe('#addHook', () => {
it('calls the map with dragging enabled', () => {
- map = L.map(container, {
+ map = new Map(container, {
dragging: true
});
@@ -22,7 +25,7 @@ describe('Map.Drag', () => {
});
it('calls the map with dragging and worldCopyJump enabled', () => {
- map = L.map(container, {
+ map = new Map(container, {
dragging: true,
worldCopyJump: true
});
@@ -34,7 +37,7 @@ describe('Map.Drag', () => {
it('calls the map with dragging disabled and worldCopyJump enabled; ' +
'enables dragging after setting center and zoom', () => {
- map = L.map(container, {
+ map = new Map(container, {
dragging: false,
worldCopyJump: true
});
@@ -46,9 +49,9 @@ describe('Map.Drag', () => {
});
});
- const MyMap = L.Map.extend({
+ const MyMap = Map.extend({
_getPosition() {
- return L.DomUtil.getPosition(this.dragging._draggable._element);
+ return DomUtil.getPosition(this.dragging._draggable._element);
},
getOffset() {
return this._getPosition().subtract(this._initialPos);
@@ -65,8 +68,8 @@ describe('Map.Drag', () => {
});
map.setView([0, 0], 1);
- const start = L.point(200, 200);
- const offset = L.point(256, 32);
+ const start = new Point(200, 200);
+ const offset = new Point(256, 32);
const finish = start.add(offset);
const hand = new Hand({
@@ -87,7 +90,7 @@ describe('Map.Drag', () => {
});
describe('in CSS scaled container', () => {
- const scale = L.point(2, 1.5);
+ const scale = new Point(2, 1.5);
beforeEach(() => {
container.style.webkitTransformOrigin = 'top left';
@@ -101,8 +104,8 @@ describe('Map.Drag', () => {
});
map.setView([0, 0], 1);
- const start = L.point(200, 200);
- const offset = L.point(256, 32);
+ const start = new Point(200, 200);
+ const offset = new Point(256, 32);
const finish = start.add(offset);
const hand = new Hand({
@@ -126,12 +129,12 @@ describe('Map.Drag', () => {
});
it('does not change the center of the map when mouse is moved less than the drag threshold', (done) => {
- map = L.map(container, {
+ map = new Map(container, {
dragging: true,
inertia: false
});
- const originalCenter = L.latLng(0, 0);
+ const originalCenter = new LatLng(0, 0);
map.setView(originalCenter.clone(), 1);
const spy = sinon.spy();
@@ -151,13 +154,13 @@ describe('Map.Drag', () => {
const mouse = hand.growFinger('mouse');
// We move 2 pixels to stay below the default 3-pixel threshold of
- // L.Draggable. This should result in a click and not a drag.
+ // Draggable. This should result in a click and not a drag.
mouse.moveTo(200, 200, 0)
.down().moveBy(1, 0, 20).moveBy(1, 0, 200).up();
});
it('does not trigger preclick nor click', (done) => {
- map = L.map(container, {
+ map = new Map(container, {
dragging: true,
inertia: false
});
@@ -189,12 +192,12 @@ describe('Map.Drag', () => {
it('does not trigger preclick nor click when dragging on top of a static marker', (done) => {
container.style.width = container.style.height = '600px';
- map = L.map(container, {
+ map = new Map(container, {
dragging: true,
inertia: false
});
map.setView([0, 0], 1);
- const marker = L.marker(map.getCenter()).addTo(map);
+ const marker = new Marker(map.getCenter()).addTo(map);
const clickSpy = sinon.spy();
const preclickSpy = sinon.spy();
const markerDragSpy = sinon.spy();
@@ -222,19 +225,19 @@ describe('Map.Drag', () => {
const mouse = hand.growFinger('mouse');
// We move 5 pixels first to overcome the 3-pixel threshold of
- // L.Draggable.
+ // Draggable.
mouse.moveTo(300, 280, 0)
.down().moveBy(5, 0, 20).moveBy(20, 20, 100).up();
});
it('does not trigger preclick nor click when dragging a marker', (done) => {
container.style.width = container.style.height = '600px';
- map = L.map(container, {
+ map = new Map(container, {
dragging: true,
inertia: false
});
map.setView([0, 0], 1);
- const marker = L.marker(map.getCenter(), {draggable: true}).addTo(map);
+ const marker = new Marker(map.getCenter(), {draggable: true}).addTo(map);
const clickSpy = sinon.spy();
const preclickSpy = sinon.spy();
const markerDragSpy = sinon.spy();
@@ -262,17 +265,17 @@ describe('Map.Drag', () => {
const mouse = hand.growFinger('mouse');
// We move 5 pixels first to overcome the 3-pixel threshold of
- // L.Draggable.
+ // Draggable.
mouse.moveTo(300, 280, 0)
.down().moveBy(5, 0, 20).moveBy(50, 50, 100).up();
});
it('does not change the center of the map when drag is disabled on click', (done) => {
- map = L.map(container, {
+ map = new Map(container, {
dragging: true,
inertia: false
});
- const originalCenter = L.latLng(0, 0);
+ const originalCenter = new LatLng(0, 0);
map.setView(originalCenter.clone(), 1);
map.on('mousedown', () => {
@@ -295,7 +298,7 @@ describe('Map.Drag', () => {
const mouse = hand.growFinger('mouse');
// We move 5 pixels first to overcome the 3-pixel threshold of
- // L.Draggable.
+ // Draggable.
mouse.moveTo(200, 200, 0)
.down().moveBy(5, 0, 20).moveBy(256, 32, 200).up();
});
@@ -309,8 +312,8 @@ describe('Map.Drag', () => {
});
map.setView([0, 0], 1);
- const start = L.point(200, 200);
- const offset = L.point(256, 32);
+ const start = new Point(200, 200);
+ const offset = new Point(256, 32);
const finish = start.add(offset);
const hand = new Hand({
@@ -331,12 +334,12 @@ describe('Map.Drag', () => {
});
it.skipIfNotTouch('does not change the center of the map when finger is moved less than the drag threshold', (done) => {
- map = L.map(container, {
+ map = new Map(container, {
dragging: true,
inertia: false
});
- const originalCenter = L.latLng(0, 0);
+ const originalCenter = new LatLng(0, 0);
map.setView(originalCenter, 1);
const spy = sinon.spy();
@@ -357,13 +360,13 @@ describe('Map.Drag', () => {
const toucher = hand.growFinger(touchEventType);
// We move 2 pixels to stay below the default 3-pixel threshold of
- // L.Draggable. This should result in a click and not a drag.
+ // Draggable. This should result in a click and not a drag.
toucher.moveTo(200, 200, 0)
.down().moveBy(1, 0, 20).moveBy(1, 0, 200).up();
});
it.skipIfNotTouch('reset itself after touchend', (done) => {
- map = L.map(container, {
+ map = new Map(container, {
dragging: true,
inertia: false,
zoomAnimation: false // If true, the test has to wait extra 250msec
diff --git a/spec/suites/map/handler/Map.KeyboardSpec.js b/spec/suites/map/handler/Map.KeyboardSpec.js
index 1b89c7851..cbddf2774 100644
--- a/spec/suites/map/handler/Map.KeyboardSpec.js
+++ b/spec/suites/map/handler/Map.KeyboardSpec.js
@@ -1,3 +1,6 @@
+import {Map, Popup} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('Map.Keyboard', () => {
const KEYCODE_LOWERCASE_A = 'KeyA';
const KEYCODE_ARROW_LEFT = 'ArrowLeft';
@@ -12,12 +15,12 @@ describe('Map.Keyboard', () => {
beforeEach(() => {
container = createContainer();
- map = L.map(container, {
+ map = new Map(container, {
zoomAnimation: false // If true, the test has to wait extra 250msec
});
// make keyboard-caused panning instant to cut down on test running time
- map.panBy = function (offset) { return L.Map.prototype.panBy.call(this, offset, {animate: false}); };
+ map.panBy = function (offset) { return Map.prototype.panBy.call(this, offset, {animate: false}); };
map.setView([0, 0], 5);
@@ -122,7 +125,7 @@ describe('Map.Keyboard', () => {
describe('popup closing', () => {
it('closes a popup when pressing escape', () => {
- const popup = L.popup().setLatLng([0, 0]).setContent('Null Island');
+ const popup = new Popup().setLatLng([0, 0]).setContent('Null Island');
map.openPopup(popup);
expect(popup.isOpen()).to.be.true;
@@ -137,7 +140,7 @@ describe('Map.Keyboard', () => {
describe('popup closing disabled', () => {
it('close of popup when pressing escape disabled via options', () => {
- const popup = L.popup({closeOnEscapeKey: false}).setLatLng([0, 0]).setContent('Null Island');
+ const popup = new Popup({closeOnEscapeKey: false}).setLatLng([0, 0]).setContent('Null Island');
map.openPopup(popup);
expect(popup.isOpen()).to.be.true;
diff --git a/spec/suites/map/handler/Map.ScrollWheelZoomSpec.js b/spec/suites/map/handler/Map.ScrollWheelZoomSpec.js
index 5198c35a9..bef6c1aca 100644
--- a/spec/suites/map/handler/Map.ScrollWheelZoomSpec.js
+++ b/spec/suites/map/handler/Map.ScrollWheelZoomSpec.js
@@ -1,3 +1,6 @@
+import {Map, DomEvent} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('Map.ScrollWheelZoom', () => {
let container, map;
const wheel = 'onwheel' in window ? 'wheel' : 'mousewheel';
@@ -12,7 +15,7 @@ describe('Map.ScrollWheelZoom', () => {
beforeEach(() => {
container = createContainer();
- map = L.map(container, {
+ map = new Map(container, {
center: [0, 0],
zoom: 3,
zoomAnimation: false
@@ -101,7 +104,7 @@ describe('Map.ScrollWheelZoom', () => {
map.setZoom(zoom, {animate: false});
expect(map.getZoom()).to.equal(zoom);
- map.options.wheelPxPerZoomLevel = 30 / L.DomEvent.getWheelPxFactor();
+ map.options.wheelPxPerZoomLevel = 30 / DomEvent.getWheelPxFactor();
UIEventSimulator.fire(wheel, container, scrollIn);
map.once('zoomend', () => {
diff --git a/spec/suites/map/handler/Map.TapHoldSpec.js b/spec/suites/map/handler/Map.TapHoldSpec.js
index 08b5b9454..547591aaa 100644
--- a/spec/suites/map/handler/Map.TapHoldSpec.js
+++ b/spec/suites/map/handler/Map.TapHoldSpec.js
@@ -1,3 +1,6 @@
+import {Map, Browser, extend, Point} from 'leaflet';
+import {createContainer, removeMapContainer} from '../../SpecHelper.js';
+
describe('Map.TapHoldSpec.js', () => {
let container, clock, spy, map;
@@ -7,7 +10,7 @@ describe('Map.TapHoldSpec.js', () => {
beforeEach(() => {
container = createContainer();
- map = L.map(container, {
+ map = new Map(container, {
center: [51.505, -0.09],
zoom: 13,
tapHold: true
@@ -77,7 +80,7 @@ describe('Map.TapHoldSpec.js', () => {
expect(spy.notCalled).to.be.true;
});
- (L.Browser.pointer ? it : it.skip)('ignores events from mouse', () => {
+ (Browser.pointer ? it : it.skip)('ignores events from mouse', () => {
UIEventSimulator.fire('pointerdown', container, {pointerId:0, pointerType:'mouse', ...posStart});
clock.tick(650);
@@ -132,7 +135,7 @@ describe('Map.TapHoldSpec.js', () => {
});
it('ignores long movements', () => {
- expect(L.point(posStart.clientX, posStart.clientY).distanceTo([posFar.clientX, posFar.clientY]))
+ expect(new Point(posStart.clientX, posStart.clientY).distanceTo([posFar.clientX, posFar.clientY]))
.to.be.above(map.options.tapTolerance);
UIEventSimulator.fire('touchstart', container, {touches: [posStart]});
@@ -148,7 +151,7 @@ describe('Map.TapHoldSpec.js', () => {
});
it('.originalEvent has expected properties', () => {
- L.extend(posStart, {
+ extend(posStart, {
screenX: 2,
screenY: 2,
});
@@ -158,7 +161,7 @@ describe('Map.TapHoldSpec.js', () => {
clock.tick(650);
const originalEvent = spy.lastCall.args[0].originalEvent;
- const expectedProps = L.extend({
+ const expectedProps = extend({
type: 'contextmenu',
bubbles: true,
cancelable: true,
diff --git a/spec/suites/map/handler/Map.TouchZoomSpec.js b/spec/suites/map/handler/Map.TouchZoomSpec.js
index 7c7e7aae7..d681d9b3a 100644
--- a/spec/suites/map/handler/Map.TouchZoomSpec.js
+++ b/spec/suites/map/handler/Map.TouchZoomSpec.js
@@ -1,9 +1,12 @@
+import {LatLng, Map, Polygon, Rectangle} from 'leaflet';
+import {createContainer, removeMapContainer, touchEventType} from '../../SpecHelper.js';
+
describe('Map.TouchZoom', () => {
let container, map;
beforeEach(() => {
container = createContainer();
- map = L.map(container, {
+ map = new Map(container, {
touchZoom: true,
inertia: false,
zoomAnimation: false // If true, the test has to wait extra 250msec
@@ -18,7 +21,7 @@ describe('Map.TouchZoom', () => {
it.skipIfNotTouch('Increases zoom when pinching out', (done) => {
map.setView([0, 0], 1);
map.once('zoomend', () => {
- expect(map.getCenter().equals(L.latLng({lat:0, lng:0}))).to.be.true;
+ expect(map.getCenter().equals(new LatLng(0, 0))).to.be.true;
// Initial zoom 1, initial distance 50px, final distance 450px
expect(map.getZoom()).to.equal(4);
@@ -39,7 +42,7 @@ describe('Map.TouchZoom', () => {
it.skipIfNotTouch('Decreases zoom when pinching in', (done) => {
map.setView([0, 0], 4);
map.once('zoomend', () => {
- expect(map.getCenter().equals(L.latLng({lat:0, lng:0}))).to.be.true;
+ expect(map.getCenter().equals(new LatLng(0, 0))).to.be.true;
// Initial zoom 4, initial distance 450px, final distance 50px
expect(map.getZoom()).to.equal(1);
@@ -71,14 +74,14 @@ describe('Map.TouchZoom', () => {
expect(spy.callCount > 1).to.be.true;
expect(pinchZoomEvent).to.be.true;
- expect(map.getCenter().equals(L.latLng({lat:0, lng:0}))).to.be.true;
+ expect(map.getCenter().equals(new LatLng(0, 0))).to.be.true;
// Initial zoom 4, initial distance 450px, final distance 50px
expect(map.getZoom()).to.equal(1);
done();
});
- L.rectangle(map.getBounds().pad(-0.2)).addTo(map);
+ new Rectangle(map.getBounds().pad(-0.2)).addTo(map);
const hand = new Hand({timing: 'fastframe'});
const f1 = hand.growFinger(touchEventType);
@@ -94,7 +97,7 @@ describe('Map.TouchZoom', () => {
it.skipIfNotTouch('Dragging is possible after pinch zoom', (done) => {
map.setView([0, 0], 8);
- L.polygon([
+ new Polygon([
[0, 0],
[0, 1],
[1, 1],
@@ -121,7 +124,7 @@ describe('Map.TouchZoom', () => {
.down().moveBy(-200, 0, 500).up(100);
f1.wait(100).moveTo(200, 300, 0).down()
- .moveBy(5, 0, 20) // We move 5 pixels first to overcome the 3-pixel threshold of L.Draggable (fastframe)
+ .moveBy(5, 0, 20) // We move 5 pixels first to overcome the 3-pixel threshold of Draggable (fastframe)
.moveBy(-150, 0, 200) // Dragging
.up();
@@ -130,7 +133,7 @@ describe('Map.TouchZoom', () => {
it.skipIfNotTouch('TouchZoom works with disabled map dragging', (done) => {
map.remove();
- map = new L.Map(container, {
+ map = new Map(container, {
touchZoom: true,
inertia: false,
zoomAnimation: false, // If true, the test has to wait extra 250msec,
@@ -139,7 +142,7 @@ describe('Map.TouchZoom', () => {
map.setView([0, 0], 4);
map.once('zoomend', () => {
- expect(map.getCenter().equals(L.latLng({lat:0, lng:0}))).to.be.true;
+ expect(map.getCenter().equals(new LatLng(0, 0))).to.be.true;
// Initial zoom 4, initial distance 450px, final distance 50px
expect(map.getZoom()).to.equal(1);
@@ -160,7 +163,7 @@ describe('Map.TouchZoom', () => {
it.skipIfNotTouch('Layer is rendered correctly while pinch zoom when zoomAnim is true', (done) => {
map.remove();
- map = new L.Map(container, {
+ map = new Map(container, {
touchZoom: true,
inertia: false,
zoomAnimation: true
@@ -168,7 +171,7 @@ describe('Map.TouchZoom', () => {
map.setView([0, 0], 8);
- const polygon = L.polygon([
+ const polygon = new Polygon([
[0, 0],
[0, 1],
[1, 1],
@@ -222,7 +225,7 @@ describe('Map.TouchZoom', () => {
it.skipIfNotTouch('Layer is rendered correctly while pinch zoom when zoomAnim is false', (done) => {
map.remove();
- map = new L.Map(container, {
+ map = new Map(container, {
touchZoom: true,
inertia: false,
zoomAnimation: false
@@ -230,7 +233,7 @@ describe('Map.TouchZoom', () => {
map.setView([0, 0], 8);
- const polygon = L.polygon([
+ const polygon = new Polygon([
[0, 0],
[0, 1],
[1, 1],