@osimatic/helpers-js 1.4.4 → 1.4.5
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 +31 -0
- package/open_street_map.js +30 -7
- package/package.json +1 -1
package/location.js
CHANGED
|
@@ -523,6 +523,37 @@ class GeographicCoordinates {
|
|
|
523
523
|
return { type: 'Point', coordinates: [Number(long), Number(lat)] };
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
+
static getAllLatLongsFromGeoJsonList(geoJsonList) {
|
|
527
|
+
if (typeof geoJsonList == 'string') {
|
|
528
|
+
geoJsonList = JSON.parse(geoJsonList);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const arr = [];
|
|
532
|
+
for (const geoJsonItem of geoJsonList) {
|
|
533
|
+
if (!geoJsonItem) {
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
if (geoJsonItem.type === 'Point') {
|
|
538
|
+
const [lon, lat] = geoJsonItem.coordinates || [];
|
|
539
|
+
arr.push([lat, lon]);
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (geoJsonItem.type === 'Polygon') {
|
|
544
|
+
for (const ring of geoJsonItem.coordinates || []) {
|
|
545
|
+
for (const [lon,lat] of ring) {
|
|
546
|
+
arr.push([lat, lon]);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
return arr;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
|
|
526
557
|
static haversine(lat1, long1, lat2, long2) {
|
|
527
558
|
const R = 6371000;
|
|
528
559
|
const toRad = d => d * Math.PI / 180;
|
package/open_street_map.js
CHANGED
|
@@ -112,19 +112,43 @@ class OpenStreetMap {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
centerOnFrance() {
|
|
115
|
-
this.map
|
|
115
|
+
OpenStreetMap.centerOnFrance(this.map);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static centerOnFrance(map) {
|
|
119
|
+
map.setView([46.52863469527167, 2.43896484375], 6);
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
centerOnMarkers(padding) {
|
|
119
|
-
this.map.
|
|
123
|
+
OpenStreetMap.centerMapToLocations(this.map, this.locations, padding);
|
|
124
|
+
}
|
|
120
125
|
|
|
121
|
-
|
|
126
|
+
static centerMapToLocations(map, locationsList, padding=[20,20]) {
|
|
127
|
+
if (!map || locationsList.length === 0) {
|
|
122
128
|
return;
|
|
123
129
|
}
|
|
124
130
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
map.invalidateSize(false);
|
|
132
|
+
|
|
133
|
+
const bounds = L.latLngBounds(locationsList);
|
|
134
|
+
map.fitBounds(bounds, { padding: padding });
|
|
135
|
+
if (map.getZoom() > 18) {
|
|
136
|
+
map.setZoom(18);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
static centerMapToGooglePlace(map, place) {
|
|
141
|
+
if (place?.geometry?.location) {
|
|
142
|
+
const loc = place.geometry.location;
|
|
143
|
+
OpenStreetMap.centerMapToCoordinates(map, loc.lat(), loc.lng());
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static centerMapToCoordinates(map, lat, long) {
|
|
148
|
+
if (!map) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
map.setView([lat, long], Math.max(map.getZoom(), 15));
|
|
128
152
|
}
|
|
129
153
|
|
|
130
154
|
connectMarkers() {
|
|
@@ -144,7 +168,6 @@ class OpenStreetMap {
|
|
|
144
168
|
listLineCoordinates.forEach(line => {
|
|
145
169
|
L.polyline(line, {color: '#728bec'}).addTo(this.map);
|
|
146
170
|
});
|
|
147
|
-
|
|
148
171
|
}
|
|
149
172
|
}
|
|
150
173
|
|