Skip to content

Commit 9ccd125

Browse files
committed
Remove use of factory methods
Ref: Leaflet/Leaflet#9626
1 parent d60a95b commit 9ccd125

22 files changed

Lines changed: 107 additions & 107 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ The plugin can easily be extended to support other providers. Current extensions
5151
Add the control to a map instance:
5252

5353
```javascript
54-
var map = L.map('map').setView([0, 0], 2);
55-
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
54+
const map = new L.Map('map').setView([0, 0], 2);
55+
new L.TileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
5656
attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
5757
}).addTo(map);
58-
L.Control.geocoder().addTo(map);
58+
new L.Control.Geocoder().addTo(map);
5959
```
6060

6161
# Customizing
@@ -73,7 +73,7 @@ var geocoder = L.Control.geocoder({
7373
})
7474
.on('markgeocode', function(e) {
7575
var bbox = e.geocode.bbox;
76-
var poly = L.polygon([
76+
var poly = new L.Polygon([
7777
bbox.getSouthEast(),
7878
bbox.getNorthEast(),
7979
bbox.getNorthWest(),

demo-esbuild/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import 'leaflet-control-geocoder';
44
import 'leaflet/dist/leaflet.css';
55
import 'leaflet-control-geocoder/dist/Control.Geocoder.css';
66

7-
var map = L.map('map').setView([0, 0], 2);
8-
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
7+
const map = new L.Map('map').setView([0, 0], 2);
8+
new L.TileLayer('https://tile.osm.org/{z}/{x}/{y}.png', {
99
attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
1010
}).addTo(map);
1111

12-
L.Control.geocoder({
13-
geocoder: L.Control.Geocoder.nominatim()
12+
new L.Control.Geocoder({
13+
geocoder: new L.Control.Geocoder.Nominatim()
1414
}).addTo(map);

demo-rollup/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import L from 'leaflet';
22
import 'leaflet-control-geocoder';
33

4-
var map = L.map('map').setView([0, 0], 2);
5-
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
4+
const map = new L.Map('map').setView([0, 0], 2);
5+
new L.TileLayer('https://tile.osm.org/{z}/{x}/{y}.png', {
66
attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
77
}).addTo(map);
88

9-
L.Control.geocoder({
10-
geocoder: L.Control.Geocoder.nominatim()
9+
new L.Control.Geocoder({
10+
geocoder: new L.Control.Geocoder.Nominatim()
1111
}).addTo(map);

demo-unpkg/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
1515
<script src="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js"></script>
1616
<script>
17-
var map = L.map('map').setView([0, 0], 2);
18-
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
17+
const map = new L.Map('map').setView([0, 0], 2);
18+
new L.TileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
1919
attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
2020
}).addTo(map);
2121

22-
L.Control.geocoder({
23-
geocoder: L.Control.Geocoder.nominatim()
22+
new L.Control.Geocoder({
23+
geocoder: new L.Control.Geocoder.Nominatim()
2424
}).addTo(map);
2525
</script>
2626
</body>

demo-webpack/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import 'leaflet-control-geocoder';
44
import 'leaflet/dist/leaflet.css';
55
import 'leaflet-control-geocoder/dist/Control.Geocoder.css';
66

7-
var map = L.map('map').setView([0, 0], 2);
8-
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
7+
const map = new L.Map('map').setView([0, 0], 2);
8+
new L.TileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
99
attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
1010
}).addTo(map);
1111

12-
L.Control.geocoder({
13-
geocoder: L.Control.Geocoder.nominatim()
12+
new L.Control.Geocoder({
13+
geocoder: new L.Control.Geocoder.Nominatim()
1414
}).addTo(map);

demo/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<div id="map"></div>
3030

3131
<script>
32-
const map = L.map('map').setView([0, 0], 2);
32+
const map = new L.Map('map').setView([0, 0], 2);
3333

3434
let geocoder = L.Control.Geocoder.nominatim();
3535
// parse /?geocoder=nominatim from URL
@@ -52,7 +52,7 @@
5252
control.setQuery('Earth');
5353
}, 12000);
5454

55-
L.tileLayer('https://tile.osm.org/{z}/{x}/{y}.png', {
55+
new L.TileLayer('https://tile.osm.org/{z}/{x}/{y}.png', {
5656
attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
5757
}).addTo(map);
5858

@@ -69,7 +69,7 @@
6969
.setPopupContent(r.html || r.name)
7070
.openPopup();
7171
} else {
72-
marker = L.marker(r.center).bindPopup(r.name).addTo(map).openPopup();
72+
marker = new L.Marker(r.center).bindPopup(r.name).addTo(map).openPopup();
7373
}
7474
});
7575
});

spec/latlng.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('LatLng', () => {
88
// test cases from https://github.com/openstreetmap/openstreetmap-website/blob/master/test/controllers/geocoder_controller_test.rb
99
let expected;
1010
beforeEach(() => {
11-
expected = L.latLng(50.06773, 14.37742);
11+
expected = new L.LatLng(50.06773, 14.37742);
1212
});
1313

1414
it('geocodes basic lat/lon pairs', () => {
@@ -41,29 +41,29 @@ describe('LatLng', () => {
4141
geocode('50.06773N, 14.37742E');
4242
});
4343
it('geocodes lat/lon pairs using N/W with degrees', () => {
44-
expected = L.latLng(50.06773, -14.37742);
44+
expected = new L.LatLng(50.06773, -14.37742);
4545
geocode('N50.06773 W14.37742');
4646
geocode('N50.06773, W14.37742');
4747
geocode('50.06773N 14.37742W');
4848
geocode('50.06773N, 14.37742W');
4949
});
5050
it('geocodes lat/lon pairs using S/E with degrees', () => {
51-
expected = L.latLng(-50.06773, 14.37742);
51+
expected = new L.LatLng(-50.06773, 14.37742);
5252
geocode('S50.06773 E14.37742');
5353
geocode('S50.06773, E14.37742');
5454
geocode('50.06773S 14.37742E');
5555
geocode('50.06773S, 14.37742E');
5656
});
5757
it('geocodes lat/lon pairs using S/W with degrees', () => {
58-
expected = L.latLng(-50.06773, -14.37742);
58+
expected = new L.LatLng(-50.06773, -14.37742);
5959
geocode('S50.06773 W14.37742');
6060
geocode('S50.06773, W14.37742');
6161
geocode('50.06773S 14.37742W');
6262
geocode('50.06773S, 14.37742W');
6363
});
6464

6565
it('geocodes lat/lon pairs using N/E with degrees/mins', () => {
66-
expected = L.latLng(50.06773333333334, 14.377416666666667);
66+
expected = new L.LatLng(50.06773333333334, 14.377416666666667);
6767
geocode('N 50° 04.064 E 014° 22.645');
6868
geocode("N 50° 04.064' E 014° 22.645");
6969
geocode("N 50° 04.064', E 014° 22.645'");
@@ -73,7 +73,7 @@ describe('LatLng', () => {
7373
geocode("50° 04.064' N, 014° 22.645' E");
7474
});
7575
it('geocodes lat/lon pairs using N/W with degrees/mins', () => {
76-
expected = L.latLng(50.06773333333334, -14.377416666666667);
76+
expected = new L.LatLng(50.06773333333334, -14.377416666666667);
7777
geocode('N 50° 04.064 W 014° 22.645');
7878
geocode("N 50° 04.064' W 014° 22.645");
7979
geocode("N 50° 04.064', W 014° 22.645'");
@@ -83,7 +83,7 @@ describe('LatLng', () => {
8383
geocode("50° 04.064' N, 014° 22.645' W");
8484
});
8585
it('geocodes lat/lon pairs using S/E with degrees/mins', () => {
86-
expected = L.latLng(-50.06773333333334, 14.377416666666667);
86+
expected = new L.LatLng(-50.06773333333334, 14.377416666666667);
8787
geocode('S 50° 04.064 E 014° 22.645');
8888
geocode("S 50° 04.064' E 014° 22.645");
8989
geocode("S 50° 04.064', E 014° 22.645'");
@@ -93,7 +93,7 @@ describe('LatLng', () => {
9393
geocode("50° 04.064' S, 014° 22.645' E");
9494
});
9595
it('geocodes lat/lon pairs using S/W with degrees/mins', () => {
96-
expected = L.latLng(-50.06773333333334, -14.377416666666667);
96+
expected = new L.LatLng(-50.06773333333334, -14.377416666666667);
9797
geocode('S 50° 04.064 W 014° 22.645');
9898
geocode("S 50° 04.064' W 014° 22.645");
9999
geocode("S 50° 04.064', W 014° 22.645'");
@@ -112,7 +112,7 @@ describe('LatLng', () => {
112112
geocode('50°4\'3.828"N 14°22\'38.712"E');
113113
});
114114
it('geocodes lat/lon pairs using N/W with degrees/mins/secs', () => {
115-
expected = L.latLng(50.06773, -14.37742);
115+
expected = new L.LatLng(50.06773, -14.37742);
116116
geocode('N 50° 4\' 03.828" W 14° 22\' 38.712"');
117117
geocode('N 50° 4\' 03.828", W 14° 22\' 38.712"');
118118
geocode('N 50° 4′ 03.828″, W 14° 22′ 38.712″');
@@ -121,7 +121,7 @@ describe('LatLng', () => {
121121
geocode('50°4\'3.828"N 14°22\'38.712"W');
122122
});
123123
it('geocodes lat/lon pairs using S/E with degrees/mins/secs', () => {
124-
expected = L.latLng(-50.06773, 14.37742);
124+
expected = new L.LatLng(-50.06773, 14.37742);
125125
geocode('S 50° 4\' 03.828" E 14° 22\' 38.712"');
126126
geocode('S 50° 4\' 03.828", E 14° 22\' 38.712"');
127127
geocode('S 50° 4′ 03.828″, E 14° 22′ 38.712″');
@@ -130,7 +130,7 @@ describe('LatLng', () => {
130130
geocode('50°4\'3.828"S 14°22\'38.712"E');
131131
});
132132
it('geocodes lat/lon pairs using S/W with degrees/mins/secs', () => {
133-
expected = L.latLng(-50.06773, -14.37742);
133+
expected = new L.LatLng(-50.06773, -14.37742);
134134
geocode('S 50° 4\' 03.828" W 14° 22\' 38.712"');
135135
geocode('S 50° 4\' 03.828", W 14° 22\' 38.712"');
136136
geocode('S 50° 4′ 03.828″, W 14° 22′ 38.712″');

src/geocoders/arcgis.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ export class ArcGis implements IGeocoder {
3232
params
3333
);
3434
return data.candidates.map((loc): GeocodingResult => {
35-
const center = L.latLng(loc.location.y, loc.location.x);
36-
const bbox = L.latLngBounds(
37-
L.latLng(loc.extent.ymax, loc.extent.xmax),
38-
L.latLng(loc.extent.ymin, loc.extent.xmin)
35+
const center = new L.LatLng(loc.location.y, loc.location.x);
36+
const bbox = new L.LatLngBounds(
37+
new L.LatLng(loc.extent.ymax, loc.extent.xmax),
38+
new L.LatLng(loc.extent.ymin, loc.extent.xmin)
3939
);
4040
return {
4141
name: loc.address,
@@ -59,8 +59,8 @@ export class ArcGis implements IGeocoder {
5959
if (!data || data.error) {
6060
return [];
6161
}
62-
const center = L.latLng(data.location.y, data.location.x);
63-
const bbox = L.latLngBounds(center, center);
62+
const center = new L.LatLng(data.location.y, data.location.x);
63+
const bbox = new L.LatLngBounds(center, center);
6464
return [
6565
{
6666
name: data.address.Match_addr,

src/geocoders/azure.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ export class AzureMaps implements IGeocoder {
4141
return (data.results || []).map(
4242
(result): GeocodingResult => ({
4343
name: result.address.freeformAddress,
44-
bbox: L.latLngBounds(
44+
bbox: new L.LatLngBounds(
4545
[result.viewport.topLeftPoint.lat, result.viewport.topLeftPoint.lon],
4646
[result.viewport.btmRightPoint.lat, result.viewport.btmRightPoint.lon]
4747
),
48-
center: L.latLng(result.position.lat, result.position.lon)
48+
center: new L.LatLng(result.position.lat, result.position.lon)
4949
})
5050
);
5151
}
@@ -66,11 +66,11 @@ export class AzureMaps implements IGeocoder {
6666
return (data.addresses || []).map(
6767
(address): GeocodingResult => ({
6868
name: address.address.freeformAddress,
69-
bbox: L.latLngBounds(
69+
bbox: new L.LatLngBounds(
7070
[address.viewport.topLeftPoint.lat, address.viewport.topLeftPoint.lon],
7171
[address.viewport.btmRightPoint.lat, address.viewport.btmRightPoint.lon]
7272
),
73-
center: L.latLng(location.lat, location.lng)
73+
center: new L.LatLng(location.lat, location.lng)
7474
})
7575
);
7676
}

src/geocoders/bing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export class Bing implements IGeocoder {
4545
const bbox = resource.bbox;
4646
return {
4747
name: resource.name,
48-
bbox: L.latLngBounds([bbox[0], bbox[1]], [bbox[2], bbox[3]]),
49-
center: L.latLng(resource.point.coordinates)
48+
bbox: new L.LatLngBounds([bbox[0], bbox[1]], [bbox[2], bbox[3]]),
49+
center: new L.LatLng(...resource.point.coordinates as [number,number])
5050
};
5151
});
5252
}

0 commit comments

Comments
 (0)