@osimatic/helpers-js 1.4.9 → 1.4.11

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/location.js CHANGED
@@ -447,7 +447,7 @@ class Polygon {
447
447
  const more = ring0.length > maxShow ? ` … (+${ring0.length - maxShow} sommets)` : '';
448
448
 
449
449
  return {
450
- label: `Polygon de ${n} sommets (départ : ${GeographicCoordinates.format(firstLat, firstLon)})`,
450
+ label: `Polygone de ${n} sommets (départ : ${GeographicCoordinates.format(firstLat, firstLon)})`,
451
451
  title: `Sommets : ${concise}${more}`
452
452
  };
453
453
  }
@@ -121,6 +121,106 @@ class OpenStreetMap {
121
121
  map.setView([46.52863469527167, 2.43896484375], 6);
122
122
  }
123
123
 
124
+ static getCountryBoundingBoxes() {
125
+ return {
126
+ // Europe
127
+ "fr": [[41.333, -5.142], [51.091, 9.559]], // France,
128
+ "de": [[47.270, 5.866], [55.058, 15.041]], // Germany
129
+ "es": [[27.642, -18.167], [43.792, 4.327]], // Spain incl. Canaries (approx)
130
+ "it": [[36.619, 6.627], [47.095, 18.520]], // Italy
131
+ "pt": [[36.840, -9.500], [42.280, -6.190]], // Portugal
132
+ "be": [[49.497, 2.545], [51.505, 6.407]], // Belgium
133
+ "nl": [[50.753, 3.358], [53.555, 7.227]], // Netherlands
134
+ "ch": [[45.818, 5.957], [47.808, 10.492]], // Switzerland
135
+ "at": [[46.372, 9.530], [49.021, 17.162]], // Austria
136
+ "gb": [[49.959, -8.649], [59.478, 1.759]], // United Kingdom,
137
+ "ie": [[51.390, -10.480], [55.387, -5.432]], // Ireland
138
+ "pl": [[49.003, 14.123], [54.836, 24.145]], // Poland
139
+ "se": [[55.340, 11.112], [69.061, 24.177]], // Sweden
140
+ "no": [[57.980, 4.500], [71.188, 31.078]], // Norway (Mainland approx)
141
+ "fi": [[59.810, 20.556], [70.092, 31.586]], // Finland
142
+ "dk": [[54.560, 8.089], [57.752, 12.690]], // Denmark
143
+
144
+ // Afrique / Moyen-Orient
145
+ "ma": [[27.662, -13.172], [35.922, -0.996]], // Morocco
146
+ "dz": [[18.976, -8.669], [37.093, 11.999]], // Algeria
147
+ "tn": [[30.233, 7.524], [37.544, 11.598]], // Tunisia
148
+ "eg": [[21.725, 24.700], [31.667, 36.895]], // Egypt
149
+ "za": [[-34.833, 16.470], [-22.126, 32.893]], // South Africa
150
+ "sa": [[15.615, 34.495], [32.154, 55.666]], // Saudi Arabia
151
+ "ae": [[22.634, 51.570], [26.084, 56.383]], // United Arab Emirates
152
+ "il": [[29.487, 34.268], [33.277, 35.876]], // Israel
153
+
154
+ // Amériques
155
+ "us": [[24.396, -124.848], [49.384, -66.885]], // United States (Contiguous)
156
+ "ca": [[41.675, -141.000], [83.113, -52.648]], // Canada
157
+ "mx": [[14.538, -118.365], [32.720, -86.711]], // Mexico
158
+ "br": [[-33.751, -73.987], [5.271, -34.729]], // Brazil
159
+ "ar": [[-55.051, -73.582], [-21.781, -53.591]], // Argentina
160
+
161
+ // Asie / Océanie
162
+ "cn": [[18.159, 73.499], [53.560, 134.772]], // China (mainland approx)
163
+ "in": [[6.554, 68.176], [35.674, 97.402]], // India
164
+ "jp": [[24.249, 122.938], [45.557, 153.987]], // Japan
165
+ "au": [[-43.740, 112.921], [-10.668, 153.639]], // Australia
166
+ "nz": [[-47.290, 166.509], [-34.392, 178.517]], // New Zealand
167
+ };
168
+ }
169
+
170
+ static getCountryBoundingBox(countryIsoCode) {
171
+ if (!countryIsoCode) {
172
+ return null;
173
+ }
174
+
175
+ const key = countryIsoCode.toLowerCase().trim();
176
+ const countryBox = OpenStreetMap.getCountryBoundingBoxes()[key];
177
+ return countryBox ? countryBox : null;
178
+ }
179
+
180
+ static centerMapOnCountry(map, countryIsoCode, opts = {}) {
181
+ if (!map) {
182
+ return;
183
+ }
184
+
185
+ const boundingBox = OpenStreetMap.getCountryBoundingBox(countryIsoCode);
186
+ if (null === boundingBox) {
187
+ return;
188
+ }
189
+
190
+ const padding = Array.isArray(opts.padding) ? opts.padding : [20, 20];
191
+ const minZoom = Number.isFinite(opts.minZoom) ? opts.minZoom : 3;
192
+ const maxZoomSmall = Number.isFinite(opts.maxZoomSmall) ? opts.maxZoomSmall : 10;
193
+ const maxZoomTiny = Number.isFinite(opts.maxZoomTiny) ? opts.maxZoomTiny : 12;
194
+
195
+ // Estimation de "taille" en degrés
196
+ const [[S, W], [N, E]] = boundingBox;
197
+ const latSpan = Math.max(0.0001, Math.abs(N - S));
198
+ const lonSpan = Math.max(0.0001, Math.abs(E - W));
199
+ const areaDeg = latSpan * lonSpan;
200
+
201
+ // Heuristique de zoom maximal selon la taille du pays (en degrés²)
202
+ // (fitBounds choisira le zoom, plafonné par maxZoom ci-dessous)
203
+ let maxZoom;
204
+ if (areaDeg > 200) { // très grand (US, CA, AU, BR, CN)
205
+ maxZoom = 7;
206
+ } else if (areaDeg > 50) { // grand
207
+ maxZoom = 8;
208
+ } else if (areaDeg > 20) { // moyen+
209
+ maxZoom = 9;
210
+ } else if (areaDeg > 5) { // moyen/petit
211
+ maxZoom = maxZoomSmall; // ~10
212
+ } else { // petit/micro-état
213
+ maxZoom = maxZoomTiny; // ~12
214
+ }
215
+
216
+ // fitBounds avec maxZoom pour éviter d'over-zoomer les petits pays
217
+ const bounds = L.latLngBounds([ [S, W], [N, E] ]);
218
+ map.fitBounds(bounds, { padding, maxZoom });
219
+ if (map.getZoom() < minZoom) {
220
+ map.setZoom(minZoom);
221
+ }
222
+ }
223
+
124
224
  centerOnMarkers(padding) {
125
225
  OpenStreetMap.centerMapToLocations(this.map, this.locations, padding);
126
226
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.4.9",
3
+ "version": "1.4.11",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"