@osimatic/helpers-js 1.4.2 → 1.4.4

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
@@ -429,6 +429,10 @@ class PostalAddress {
429
429
 
430
430
  class Polygon {
431
431
  static format(geoJsonPolygon) {
432
+ if (typeof geoJsonPolygon == 'string') {
433
+ geoJsonPolygon = JSON.parse(geoJsonPolygon);
434
+ }
435
+
432
436
  const rings = geoJsonPolygon.coordinates || [];
433
437
  const ring0 = rings[0] || [];
434
438
  const n = ring0.length ? ring0.length - (JSON.stringify(ring0[0])===JSON.stringify(ring0[ring0.length-1]) ? 1 : 0) : 0;
@@ -504,6 +508,10 @@ class GeographicCoordinates {
504
508
  }
505
509
 
506
510
  static formatPoint(geoJsonPoint, fractionDigit=6) {
511
+ if (typeof geoJsonPoint == 'string') {
512
+ geoJsonPoint = JSON.parse(geoJsonPoint);
513
+ }
514
+
507
515
  const [long, lat] = geoJsonPoint.coordinates || [];
508
516
  if (typeof long == 'undefined' || typeof lat == 'undefined') {
509
517
  return '';
@@ -21,22 +21,31 @@ class OpenStreetMap {
21
21
  this.markers = [];
22
22
  this.locations = [];
23
23
 
24
- if (!mapContainer.length) {
24
+ this.map = OpenStreetMap.createMap(mapContainer, options);
25
+ if (null === this.map) {
25
26
  return;
26
27
  }
27
28
 
29
+ this.centerOnFrance();
30
+ }
31
+
32
+ static createMap(mapContainer, options) {
33
+ if (!mapContainer.length) {
34
+ return null;
35
+ }
36
+
28
37
  const container = L.DomUtil.get(mapContainer[0]);
29
38
  if (container != null) {
30
39
  container._leaflet_id = null;
31
40
  }
32
41
 
33
- this.map = L.map(mapContainer[0], options || {});
42
+ const map = L.map(mapContainer[0], options || {});
34
43
 
35
44
  L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
36
- attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
37
- }).addTo(this.map);
45
+ attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
46
+ }).addTo(map);
38
47
 
39
- this.centerOnFrance();
48
+ return map;
40
49
  }
41
50
 
42
51
  static getUrl(latitude, longitude) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"