@osimatic/helpers-js 1.4.9 → 1.4.10

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