@osimatic/helpers-js 1.1.77 → 1.1.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +76 -76
- package/array.js +93 -90
- package/bank.js +20 -20
- package/contact_details.js +194 -194
- package/count_down.js +102 -102
- package/data_table.js +416 -416
- package/date_time.js +592 -592
- package/details_sub_array.js +123 -123
- package/draw.js +52 -52
- package/duration.js +198 -198
- package/event_bus.js +38 -38
- package/file.js +146 -146
- package/flash_message.js +35 -35
- package/form_date.js +610 -610
- package/form_helper.js +410 -410
- package/google_charts.js +347 -347
- package/google_maps.js +169 -169
- package/google_recaptcha.js +87 -87
- package/http_client.js +469 -469
- package/import_from_csv.js +273 -273
- package/index.js +55 -55
- package/jwt.js +288 -288
- package/list_box.js +112 -112
- package/location.js +431 -431
- package/media.js +218 -218
- package/multiple_action_in_table.js +336 -336
- package/network.js +756 -756
- package/number.js +99 -99
- package/open_street_map.js +142 -142
- package/package.json +15 -15
- package/paging.js +278 -278
- package/php.min.js +5 -5
- package/revolut.js +22 -22
- package/select_all.js +121 -121
- package/shopping_cart.js +31 -31
- package/social_network.js +109 -109
- package/sortable_list.js +37 -37
- package/string.js +162 -162
- package/util.js +16 -16
- package/visitor.js +77 -77
- package/web_rtc.js +114 -114
- package/web_socket.js +97 -97
package/number.js
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
class NumberFormatter {
|
|
2
|
-
static getDecimalFormatter(locale, digits = 2) {
|
|
3
|
-
this.decimalFormatter = this.decimalFormatter || {};
|
|
4
|
-
if (typeof this.decimalFormatter[locale+digits] == 'undefined') {
|
|
5
|
-
this.decimalFormatter[locale+digits] = new Intl.NumberFormat(locale, { minimumFractionDigits: digits, maximumFractionDigits: digits });
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return this.decimalFormatter[locale+digits];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static getCurrencyFormatter(locale, currency, digits = 2) {
|
|
12
|
-
this.currencyFormatter = this.currencyFormatter || {};
|
|
13
|
-
if (typeof this.currencyFormatter[locale+currency+digits] == 'undefined') {
|
|
14
|
-
this.currencyFormatter[locale+currency+digits] = new Intl.NumberFormat(locale, { minimumFractionDigits: digits, maximumFractionDigits: digits, style: 'currency', currency });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return this.currencyFormatter[locale+currency+digits];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static getPercentFormatter(locale, digits = 2) {
|
|
21
|
-
this.percentFormatter = this.percentFormatter || {};
|
|
22
|
-
if (typeof this.percentFormatter[locale+digits] == 'undefined') {
|
|
23
|
-
this.percentFormatter[locale+digits] = new Intl.NumberFormat(locale, { minimumFractionDigits: digits, maximumFractionDigits: digits, style: 'percent' });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return this.percentFormatter[locale+digits];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
Number.prototype.format = Number.prototype.format || function(nbDecimal=2, locale='fr-FR') {
|
|
31
|
-
return Number.format(this, nbDecimal, locale);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (!Number.format) {
|
|
35
|
-
Number.format = function(number, nbDecimal=2, locale='fr-FR') {
|
|
36
|
-
return NumberFormatter.getDecimalFormatter(locale, nbDecimal).format(number);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
Number.prototype.formatCurrency = Number.prototype.formatCurrency || function(currency, nbDecimal=2, locale='fr-FR') {
|
|
41
|
-
return Number.formatCurrency(this, currency, nbDecimal, locale);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
Number.formatCurrency = Number.formatCurrency || function(number, currency, nbDecimal=2, locale='fr-FR') {
|
|
45
|
-
return NumberFormatter.getCurrencyFormatter(locale, currency, nbDecimal).format(number);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
Number.prototype.formatPercent = Number.prototype.formatPercent || function(nbDecimal=2, locale='fr-FR') {
|
|
49
|
-
return Number.formatPercent(this, nbDecimal, locale);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
Number.formatPercent = Number.formatPercent || function(number, nbDecimal=2, locale='fr-FR') {
|
|
53
|
-
return NumberFormatter.getPercentFormatter(locale, nbDecimal).format(number);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Number.prototype.format(n, x, s, c)
|
|
58
|
-
*
|
|
59
|
-
* @param integer n: length of decimal
|
|
60
|
-
* @param mixed s: sections delimiter
|
|
61
|
-
* @param mixed c: decimal delimiter
|
|
62
|
-
* @param integer x: length of sections
|
|
63
|
-
*/
|
|
64
|
-
Number.prototype.formatForDisplay = Number.prototype.formatForDisplay || function(n, s, c, x) {
|
|
65
|
-
let re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\D' : '$') + ')',
|
|
66
|
-
num = this.toFixed(Math.max(0, ~~n));
|
|
67
|
-
return (c ? num.replace('.', c) : num).replace(new RegExp(re, 'g'), '$&' + (s || ','));
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
Number.prototype.truncate = Number.prototype.truncate || function() {
|
|
71
|
-
return this < 0 ? Math.ceil(this) : Math.floor(this);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
Number.prototype.padLeft2 = Number.prototype.padLeft2 || function() {
|
|
75
|
-
return Number.padLeft2(this);
|
|
76
|
-
}
|
|
77
|
-
Number.padLeft2 = Number.padLeft2 || function(n) {
|
|
78
|
-
return n > 9 ? "" + n : "0" + n;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
Number.prototype.roundDecimal = Number.prototype.roundDecimal || function(precision) {
|
|
82
|
-
return Number.roundDecimal(this, precision);
|
|
83
|
-
}
|
|
84
|
-
Number.roundDecimal = Number.roundDecimal || function(number, precision) {
|
|
85
|
-
precision = precision || 2;
|
|
86
|
-
let tmp = Math.pow(10, precision);
|
|
87
|
-
return Math.round(number*tmp) / tmp;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
Math.getDecimals = Math.getDecimals || function(number) {
|
|
91
|
-
return parseInt((number+"").split(".")[1] || 0);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!Number.random) {
|
|
95
|
-
Number.random = function(min, max) {
|
|
96
|
-
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
1
|
+
class NumberFormatter {
|
|
2
|
+
static getDecimalFormatter(locale, digits = 2) {
|
|
3
|
+
this.decimalFormatter = this.decimalFormatter || {};
|
|
4
|
+
if (typeof this.decimalFormatter[locale+digits] == 'undefined') {
|
|
5
|
+
this.decimalFormatter[locale+digits] = new Intl.NumberFormat(locale, { minimumFractionDigits: digits, maximumFractionDigits: digits });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return this.decimalFormatter[locale+digits];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static getCurrencyFormatter(locale, currency, digits = 2) {
|
|
12
|
+
this.currencyFormatter = this.currencyFormatter || {};
|
|
13
|
+
if (typeof this.currencyFormatter[locale+currency+digits] == 'undefined') {
|
|
14
|
+
this.currencyFormatter[locale+currency+digits] = new Intl.NumberFormat(locale, { minimumFractionDigits: digits, maximumFractionDigits: digits, style: 'currency', currency });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return this.currencyFormatter[locale+currency+digits];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static getPercentFormatter(locale, digits = 2) {
|
|
21
|
+
this.percentFormatter = this.percentFormatter || {};
|
|
22
|
+
if (typeof this.percentFormatter[locale+digits] == 'undefined') {
|
|
23
|
+
this.percentFormatter[locale+digits] = new Intl.NumberFormat(locale, { minimumFractionDigits: digits, maximumFractionDigits: digits, style: 'percent' });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return this.percentFormatter[locale+digits];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Number.prototype.format = Number.prototype.format || function(nbDecimal=2, locale='fr-FR') {
|
|
31
|
+
return Number.format(this, nbDecimal, locale);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!Number.format) {
|
|
35
|
+
Number.format = function(number, nbDecimal=2, locale='fr-FR') {
|
|
36
|
+
return NumberFormatter.getDecimalFormatter(locale, nbDecimal).format(number);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Number.prototype.formatCurrency = Number.prototype.formatCurrency || function(currency, nbDecimal=2, locale='fr-FR') {
|
|
41
|
+
return Number.formatCurrency(this, currency, nbDecimal, locale);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Number.formatCurrency = Number.formatCurrency || function(number, currency, nbDecimal=2, locale='fr-FR') {
|
|
45
|
+
return NumberFormatter.getCurrencyFormatter(locale, currency, nbDecimal).format(number);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Number.prototype.formatPercent = Number.prototype.formatPercent || function(nbDecimal=2, locale='fr-FR') {
|
|
49
|
+
return Number.formatPercent(this, nbDecimal, locale);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Number.formatPercent = Number.formatPercent || function(number, nbDecimal=2, locale='fr-FR') {
|
|
53
|
+
return NumberFormatter.getPercentFormatter(locale, nbDecimal).format(number);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Number.prototype.format(n, x, s, c)
|
|
58
|
+
*
|
|
59
|
+
* @param integer n: length of decimal
|
|
60
|
+
* @param mixed s: sections delimiter
|
|
61
|
+
* @param mixed c: decimal delimiter
|
|
62
|
+
* @param integer x: length of sections
|
|
63
|
+
*/
|
|
64
|
+
Number.prototype.formatForDisplay = Number.prototype.formatForDisplay || function(n, s, c, x) {
|
|
65
|
+
let re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\D' : '$') + ')',
|
|
66
|
+
num = this.toFixed(Math.max(0, ~~n));
|
|
67
|
+
return (c ? num.replace('.', c) : num).replace(new RegExp(re, 'g'), '$&' + (s || ','));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
Number.prototype.truncate = Number.prototype.truncate || function() {
|
|
71
|
+
return this < 0 ? Math.ceil(this) : Math.floor(this);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Number.prototype.padLeft2 = Number.prototype.padLeft2 || function() {
|
|
75
|
+
return Number.padLeft2(this);
|
|
76
|
+
}
|
|
77
|
+
Number.padLeft2 = Number.padLeft2 || function(n) {
|
|
78
|
+
return n > 9 ? "" + n : "0" + n;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
Number.prototype.roundDecimal = Number.prototype.roundDecimal || function(precision) {
|
|
82
|
+
return Number.roundDecimal(this, precision);
|
|
83
|
+
}
|
|
84
|
+
Number.roundDecimal = Number.roundDecimal || function(number, precision) {
|
|
85
|
+
precision = precision || 2;
|
|
86
|
+
let tmp = Math.pow(10, precision);
|
|
87
|
+
return Math.round(number*tmp) / tmp;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Math.getDecimals = Math.getDecimals || function(number) {
|
|
91
|
+
return parseInt((number+"").split(".")[1] || 0);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!Number.random) {
|
|
95
|
+
Number.random = function(min, max) {
|
|
96
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
100
|
module.exports = { NumberFormatter };
|
package/open_street_map.js
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* https://leafletjs.com/
|
|
3
|
-
* https://switch2osm.org/the-basics/
|
|
4
|
-
* https://www.openstreetmap.org/help
|
|
5
|
-
*/
|
|
6
|
-
class OpenStreetMap {
|
|
7
|
-
|
|
8
|
-
constructor(mapId, options) {
|
|
9
|
-
/*let [lat, lng] = button.data('coordinates').split(',');
|
|
10
|
-
let map = L.map('modal_map_canvas2').setView([lat, lng], 17);
|
|
11
|
-
|
|
12
|
-
L.marker([lat, lng], {
|
|
13
|
-
icon: L.icon({iconUrl: getIconOfMapMarker(button.data('type_marker'))}),
|
|
14
|
-
title: popoverContent.title
|
|
15
|
-
//popupopen: setTimeout(displayEmployeesAndCompaniesAndTasks, 250)
|
|
16
|
-
}).addTo(map)
|
|
17
|
-
.bindPopup(popoverContent.content)
|
|
18
|
-
//.openPopup()
|
|
19
|
-
;*/
|
|
20
|
-
|
|
21
|
-
this.markers = [];
|
|
22
|
-
this.locations = [];
|
|
23
|
-
this.mapId = mapId;
|
|
24
|
-
|
|
25
|
-
if (!$('#'+mapId).length) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let container = L.DomUtil.get(mapId);
|
|
30
|
-
if (container != null) {
|
|
31
|
-
container._leaflet_id = null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
this.map = L.map(mapId, options || {});
|
|
35
|
-
|
|
36
|
-
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
37
|
-
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
38
|
-
}).addTo(this.map);
|
|
39
|
-
|
|
40
|
-
this.centerOnFrance();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static getUrl(latitude, longitude) {
|
|
44
|
-
return 'https://www.openstreetmap.org/?mlat='+latitude+'&mlon='+longitude+'#map=17/'+latitude+'/'+longitude+'&layers=N';
|
|
45
|
-
//return 'https://www.openstreetmap.org/#map=17/'+latitude+'/'+longitude+'';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
static getUrlFromCoordinates(locationCoordinates) {
|
|
49
|
-
locationCoordinates = locationCoordinates.split(',');
|
|
50
|
-
return this.getUrl(parseFloat(locationCoordinates[0]), parseFloat(locationCoordinates[1]));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
setZoom(zoom) {
|
|
54
|
-
this.map.setZoom(zoom);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
deleteMarkers() {
|
|
58
|
-
this.locations = [];
|
|
59
|
-
|
|
60
|
-
//this.markers.forEach(marker => marker.setMap(null));
|
|
61
|
-
|
|
62
|
-
this.markers.length = 0;
|
|
63
|
-
this.markers = [];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
addMarkers(listLocations, icon) {
|
|
67
|
-
if (listLocations.length === 0) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
listLocations.forEach(location => this.addMarker(location, icon));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
addMarker(coordinates, options) {
|
|
75
|
-
let locationCoordinates = coordinates.split(',');
|
|
76
|
-
let latitude = parseFloat(locationCoordinates[0]);
|
|
77
|
-
let longitude = parseFloat(locationCoordinates[1]);
|
|
78
|
-
|
|
79
|
-
let marker = L.marker([latitude, longitude], {
|
|
80
|
-
icon: L.icon({
|
|
81
|
-
iconUrl: options['icon'],
|
|
82
|
-
iconSize: [22, 32],
|
|
83
|
-
}),
|
|
84
|
-
title: options['title'],
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
//marker.on('click', () => {
|
|
88
|
-
marker.on('popupopen', () => {
|
|
89
|
-
//console.log('popupopen');
|
|
90
|
-
if (typeof options['on_click'] == 'function') {
|
|
91
|
-
options['on_click']();
|
|
92
|
-
}
|
|
93
|
-
return false;
|
|
94
|
-
});
|
|
95
|
-
marker.addTo(this.map);
|
|
96
|
-
marker.bindPopup(options['popup_content']);
|
|
97
|
-
|
|
98
|
-
this.markers.push(marker);
|
|
99
|
-
this.locations.push([latitude, longitude]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
setView(location, zoom) {
|
|
103
|
-
this.map.setView(location, zoom);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
centerOnFrance() {
|
|
107
|
-
this.map.setView([46.52863469527167, 2.43896484375], 6);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
centerOnMarkers(padding) {
|
|
111
|
-
this.map.invalidateSize(false);
|
|
112
|
-
|
|
113
|
-
if (this.locations.length === 0) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
this.map.fitBounds(new L.LatLngBounds(this.locations), {
|
|
118
|
-
padding: typeof padding != 'undefined' ? padding : [0, 0]
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
connectMarkers() {
|
|
123
|
-
if (this.locations.length === 0) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
let prevLocation = null;
|
|
128
|
-
let listLineCoordinates = [];
|
|
129
|
-
this.locations.forEach(location => {
|
|
130
|
-
if (prevLocation != null) {
|
|
131
|
-
listLineCoordinates.push([prevLocation, location]);
|
|
132
|
-
}
|
|
133
|
-
prevLocation = location;
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
listLineCoordinates.forEach(line => {
|
|
137
|
-
L.polyline(line, {color: '#728bec'}).addTo(this.map);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
1
|
+
/**
|
|
2
|
+
* https://leafletjs.com/
|
|
3
|
+
* https://switch2osm.org/the-basics/
|
|
4
|
+
* https://www.openstreetmap.org/help
|
|
5
|
+
*/
|
|
6
|
+
class OpenStreetMap {
|
|
7
|
+
|
|
8
|
+
constructor(mapId, options) {
|
|
9
|
+
/*let [lat, lng] = button.data('coordinates').split(',');
|
|
10
|
+
let map = L.map('modal_map_canvas2').setView([lat, lng], 17);
|
|
11
|
+
|
|
12
|
+
L.marker([lat, lng], {
|
|
13
|
+
icon: L.icon({iconUrl: getIconOfMapMarker(button.data('type_marker'))}),
|
|
14
|
+
title: popoverContent.title
|
|
15
|
+
//popupopen: setTimeout(displayEmployeesAndCompaniesAndTasks, 250)
|
|
16
|
+
}).addTo(map)
|
|
17
|
+
.bindPopup(popoverContent.content)
|
|
18
|
+
//.openPopup()
|
|
19
|
+
;*/
|
|
20
|
+
|
|
21
|
+
this.markers = [];
|
|
22
|
+
this.locations = [];
|
|
23
|
+
this.mapId = mapId;
|
|
24
|
+
|
|
25
|
+
if (!$('#'+mapId).length) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let container = L.DomUtil.get(mapId);
|
|
30
|
+
if (container != null) {
|
|
31
|
+
container._leaflet_id = null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.map = L.map(mapId, options || {});
|
|
35
|
+
|
|
36
|
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
37
|
+
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
38
|
+
}).addTo(this.map);
|
|
39
|
+
|
|
40
|
+
this.centerOnFrance();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static getUrl(latitude, longitude) {
|
|
44
|
+
return 'https://www.openstreetmap.org/?mlat='+latitude+'&mlon='+longitude+'#map=17/'+latitude+'/'+longitude+'&layers=N';
|
|
45
|
+
//return 'https://www.openstreetmap.org/#map=17/'+latitude+'/'+longitude+'';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static getUrlFromCoordinates(locationCoordinates) {
|
|
49
|
+
locationCoordinates = locationCoordinates.split(',');
|
|
50
|
+
return this.getUrl(parseFloat(locationCoordinates[0]), parseFloat(locationCoordinates[1]));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setZoom(zoom) {
|
|
54
|
+
this.map.setZoom(zoom);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
deleteMarkers() {
|
|
58
|
+
this.locations = [];
|
|
59
|
+
|
|
60
|
+
//this.markers.forEach(marker => marker.setMap(null));
|
|
61
|
+
|
|
62
|
+
this.markers.length = 0;
|
|
63
|
+
this.markers = [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
addMarkers(listLocations, icon) {
|
|
67
|
+
if (listLocations.length === 0) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
listLocations.forEach(location => this.addMarker(location, icon));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
addMarker(coordinates, options) {
|
|
75
|
+
let locationCoordinates = coordinates.split(',');
|
|
76
|
+
let latitude = parseFloat(locationCoordinates[0]);
|
|
77
|
+
let longitude = parseFloat(locationCoordinates[1]);
|
|
78
|
+
|
|
79
|
+
let marker = L.marker([latitude, longitude], {
|
|
80
|
+
icon: L.icon({
|
|
81
|
+
iconUrl: options['icon'],
|
|
82
|
+
iconSize: [22, 32],
|
|
83
|
+
}),
|
|
84
|
+
title: options['title'],
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
//marker.on('click', () => {
|
|
88
|
+
marker.on('popupopen', () => {
|
|
89
|
+
//console.log('popupopen');
|
|
90
|
+
if (typeof options['on_click'] == 'function') {
|
|
91
|
+
options['on_click']();
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
});
|
|
95
|
+
marker.addTo(this.map);
|
|
96
|
+
marker.bindPopup(options['popup_content']);
|
|
97
|
+
|
|
98
|
+
this.markers.push(marker);
|
|
99
|
+
this.locations.push([latitude, longitude]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
setView(location, zoom) {
|
|
103
|
+
this.map.setView(location, zoom);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
centerOnFrance() {
|
|
107
|
+
this.map.setView([46.52863469527167, 2.43896484375], 6);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
centerOnMarkers(padding) {
|
|
111
|
+
this.map.invalidateSize(false);
|
|
112
|
+
|
|
113
|
+
if (this.locations.length === 0) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this.map.fitBounds(new L.LatLngBounds(this.locations), {
|
|
118
|
+
padding: typeof padding != 'undefined' ? padding : [0, 0]
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
connectMarkers() {
|
|
123
|
+
if (this.locations.length === 0) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let prevLocation = null;
|
|
128
|
+
let listLineCoordinates = [];
|
|
129
|
+
this.locations.forEach(location => {
|
|
130
|
+
if (prevLocation != null) {
|
|
131
|
+
listLineCoordinates.push([prevLocation, location]);
|
|
132
|
+
}
|
|
133
|
+
prevLocation = location;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
listLineCoordinates.forEach(line => {
|
|
137
|
+
L.polyline(line, {color: '#728bec'}).addTo(this.map);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
143
|
module.exports = { OpenStreetMap };
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@osimatic/helpers-js",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"main": "main.js",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
-
},
|
|
8
|
-
"keywords": [],
|
|
9
|
-
"author": "",
|
|
10
|
-
"license": "ISC",
|
|
11
|
-
"description": "",
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"ilib": "^14.16.0"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@osimatic/helpers-js",
|
|
3
|
+
"version": "1.1.78",
|
|
4
|
+
"main": "main.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"description": "",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"ilib": "^14.16.0"
|
|
14
|
+
}
|
|
15
|
+
}
|