Skip to content

Commit 4b6de95

Browse files
committed
make clientside helpers local variables; update comments
1 parent 7eeb7fc commit 4b6de95

File tree

1 file changed

+36
-41
lines changed

1 file changed

+36
-41
lines changed

src/lib/cyleaflet_clientside.js

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,43 @@ if (!window.dash_clientside) {
55
window.dash_clientside = {};
66
}
77

8-
window.dash_clientside.cyleaflet_utils = {
9-
// Proj4 coordinate conversion object
10-
// object with 2 methods: `forward` converts from lat/lon to x/y,
11-
// and `inverse` converts from x/y to lat/lon.
12-
// - EPSG:4326 is the 'standard' lat/lon coordinate system,
13-
// - EPSG:3857 is the 'Web Mercator' projection used by many
14-
// online mapping serveces including Leaflet
15-
// Note: proj4.js is imported as an part of `external_scripts`
16-
// in demos/usage-cy-leaflet-aio-ekl.py
17-
_proj4js_converter: proj4('EPSG:4326', 'EPSG:3857'),
8+
// Proj4 coordinate conversion object
9+
// object with 2 methods: `forward` converts from lat/lon to x/y,
10+
// and `inverse` converts from x/y to lat/lon.
11+
// - EPSG:4326 is the 'standard' lat/lon coordinate system,
12+
// - EPSG:3857 is the 'Web Mercator' projection used by many
13+
// online mapping serveces including Leaflet
14+
var _proj4js_converter = proj4('EPSG:4326', 'EPSG:3857');
1815

19-
lonLatToXY: function (lon, lat) {
20-
var xy = this._proj4js_converter.forward([lon, lat]);
21-
var x = xy[0];
22-
var y = -xy[1];
23-
return [x, y];
24-
},
16+
function lonLatToXY(lon, lat) {
17+
var xy = _proj4js_converter.forward([lon, lat]);
18+
var x = xy[0];
19+
var y = -xy[1];
20+
return [x, y];
21+
}
2522

26-
xYToLonLat: function (x, y) {
27-
var lonlat = this._proj4js_converter.inverse([x, -y]);
28-
var lon = lonlat[0];
29-
var lat = lonlat[1];
30-
return [lon, lat];
31-
},
23+
function xYToLonLat(x, y) {
24+
var lonlat = _proj4js_converter.inverse([x, -y]);
25+
var lon = lonlat[0];
26+
var lat = lonlat[1];
27+
return [lon, lat];
28+
}
3229

33-
transformElements: function (elements) {
34-
return elements.map((e) => {
35-
if (e.data.hasOwnProperty('lat')) {
36-
var xy = this.lonLatToXY(e.data.lon, e.data.lat);
37-
return {
38-
data: e.data,
39-
position: {
40-
y: xy[1],
41-
x: xy[0],
42-
},
43-
};
44-
}
45-
return e;
46-
});
47-
},
30+
31+
window.dash_clientside.cyleaflet_utils = {
4832
};
4933

5034
window.dash_clientside.cyleaflet = {
5135
updateLeafBounds: function (cyExtent) {
5236
if (!cyExtent) {
5337
return window.dash_clientside.no_update;
5438
}
55-
var utils = window.dash_clientside.cyleaflet_utils;
5639

57-
var lonLatMin = utils.xYToLonLat(cyExtent.x1, cyExtent.y1);
40+
var lonLatMin = xYToLonLat(cyExtent.x1, cyExtent.y1);
5841
var lonMin = lonLatMin[0];
5942
var latMin = lonLatMin[1];
6043

61-
var lonLatMax = utils.xYToLonLat(cyExtent.x2, cyExtent.y2);
44+
var lonLatMax = xYToLonLat(cyExtent.x2, cyExtent.y2);
6245
var lonMax = lonLatMax[0];
6346
var latMax = lonLatMax[1];
6447

@@ -83,6 +66,18 @@ window.dash_clientside.cyleaflet = {
8366
];
8467
},
8568
transformElements: function (elements) {
86-
return window.dash_clientside.cyleaflet_utils.transformElements(elements);
69+
return elements.map((e) => {
70+
if (e.data.hasOwnProperty('lat')) {
71+
var xy = lonLatToXY(e.data.lon, e.data.lat);
72+
return {
73+
data: e.data,
74+
position: {
75+
y: xy[1],
76+
x: xy[0],
77+
},
78+
};
79+
}
80+
return e;
81+
});
8782
},
8883
};

0 commit comments

Comments
 (0)