@selkirk-systems/selkirk-utils 1.0.4 → 1.0.6
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/dist/index.js +0 -1
- package/dist/utils/DateUtils.js +1 -2
- package/lib/index.js +0 -1
- package/lib/utils/DateUtils.js +1 -2
- package/package.json +2 -2
- package/lib/utils/MapUtils.js +0 -194
package/dist/index.js
CHANGED
|
@@ -7,7 +7,6 @@ export * from './utils/FetchUtils';
|
|
|
7
7
|
export * from './utils/IncidentUtils';
|
|
8
8
|
export * from './utils/LayerUtils';
|
|
9
9
|
export * from './utils/ListUtils';
|
|
10
|
-
export * from './utils/MapUtils';
|
|
11
10
|
export * from './utils/NumberUtils';
|
|
12
11
|
export * from './utils/ObjUtils';
|
|
13
12
|
export * from './utils/StringUtils';
|
package/dist/utils/DateUtils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { COMMON_DATE_FORMAT } from "../../../../../modem-management-web/src/constants/UIConstants";
|
|
2
1
|
import { format } from "date-fns";
|
|
3
|
-
export const formatDate = (timestamp, formatStr) => {
|
|
2
|
+
export const formatDate = (timestamp, formatStr, COMMON_DATE_FORMAT) => {
|
|
4
3
|
if (timestamp === null || timestamp === undefined) return '';
|
|
5
4
|
return format(timestamp, formatStr || COMMON_DATE_FORMAT);
|
|
6
5
|
};
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,6 @@ export * from './utils/FetchUtils';
|
|
|
7
7
|
export * from './utils/IncidentUtils';
|
|
8
8
|
export * from './utils/LayerUtils';
|
|
9
9
|
export * from './utils/ListUtils';
|
|
10
|
-
export * from './utils/MapUtils';
|
|
11
10
|
export * from './utils/NumberUtils';
|
|
12
11
|
export * from './utils/ObjUtils';
|
|
13
12
|
export * from './utils/StringUtils';
|
package/lib/utils/DateUtils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { COMMON_DATE_FORMAT } from "../../../../../modem-management-web/src/constants/UIConstants";
|
|
2
1
|
import { format } from "date-fns"
|
|
3
2
|
|
|
4
|
-
export const formatDate = ( timestamp, formatStr ) => {
|
|
3
|
+
export const formatDate = ( timestamp, formatStr, COMMON_DATE_FORMAT ) => {
|
|
5
4
|
|
|
6
5
|
if ( timestamp === null || timestamp === undefined ) return '';
|
|
7
6
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selkirk-systems/selkirk-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Utils we often use in our web projects",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Marcos Bernal <mbernal@selkirksystems.com>",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"clsx": "^2.1.1"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "012f9133ce543c620758aafd8620fcb8e65e157e"
|
|
44
44
|
}
|
package/lib/utils/MapUtils.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-redeclare */
|
|
2
|
-
import * as numeral from "numeral";
|
|
3
|
-
import * as L from "leaflet";
|
|
4
|
-
|
|
5
|
-
const long =
|
|
6
|
-
/^(\+|-)?(?:180(?:(?:\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\.[0-9]{1,6})?))$/;
|
|
7
|
-
const lat =
|
|
8
|
-
/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/;
|
|
9
|
-
const latitude = (coordinate) => lat.test(coordinate);
|
|
10
|
-
const longitude = (coordinate) => long.test(coordinate);
|
|
11
|
-
const latLong = (lat, long) => latitude(lat) && longitude(long);
|
|
12
|
-
|
|
13
|
-
const validationLatitudeLongitude = {
|
|
14
|
-
latitude,
|
|
15
|
-
longitude,
|
|
16
|
-
latLong,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const boundContains = (bounds, arrayOfLayers) => {
|
|
20
|
-
return arrayOfLayers.filter((layer) => {
|
|
21
|
-
return bounds.contains(layer.getLatLng());
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const checkGeoFence = (point, polygon) => {
|
|
26
|
-
if (polygon[0] !== polygon[polygon.length - 1])
|
|
27
|
-
polygon[polygon.length] = polygon[0];
|
|
28
|
-
let j = 0;
|
|
29
|
-
let oddNodes = false;
|
|
30
|
-
let x = point[1];
|
|
31
|
-
let y = point[0];
|
|
32
|
-
let n = polygon.length;
|
|
33
|
-
for (let i = 0; i < n; i++) {
|
|
34
|
-
j++;
|
|
35
|
-
if (j === n) {
|
|
36
|
-
j = 0;
|
|
37
|
-
}
|
|
38
|
-
if (
|
|
39
|
-
(polygon[i][0] < y && polygon[j][0] >= y) ||
|
|
40
|
-
(polygon[j][0] < y && polygon[i][0] >= y)
|
|
41
|
-
) {
|
|
42
|
-
if (
|
|
43
|
-
polygon[i][1] +
|
|
44
|
-
((y - polygon[i][0]) / (polygon[j][0] - polygon[i][0])) *
|
|
45
|
-
(polygon[j][1] - polygon[i][1]) <
|
|
46
|
-
x
|
|
47
|
-
) {
|
|
48
|
-
oddNodes = !oddNodes;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return oddNodes;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const validateLatLng = (lat, lng) => {
|
|
56
|
-
return validationLatitudeLongitude.latLong(lat, lng);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const getMetersPerPixelAndZoom = (map, centerLatLng, size) => {
|
|
60
|
-
var pointC = map.latLngToContainerPoint(centerLatLng);
|
|
61
|
-
var pointX = [pointC.x + size, pointC.y]; // add one pixel to x
|
|
62
|
-
var pointY = [pointC.x, pointC.y + size]; // add one pixel to y
|
|
63
|
-
|
|
64
|
-
// convert containerpoints to latlng's
|
|
65
|
-
var latLngC = map.containerPointToLatLng(pointC);
|
|
66
|
-
var latLngX = map.containerPointToLatLng(pointX);
|
|
67
|
-
var latLngY = map.containerPointToLatLng(pointY);
|
|
68
|
-
|
|
69
|
-
var distanceX = latLngC.distanceTo(latLngX); // calculate distance between c and x (latitude)
|
|
70
|
-
var distanceY = latLngC.distanceTo(latLngY); // calculate distance between c and y (longitude)
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
x: distanceX,
|
|
74
|
-
y: distanceY,
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export const leadZero = (num, padding) => {
|
|
79
|
-
var len = (parseInt(num) + "").length;
|
|
80
|
-
if (padding > len) {
|
|
81
|
-
return new Array(padding - len + 1).join("0") + num;
|
|
82
|
-
}
|
|
83
|
-
return num + "";
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export const decimalToDecialDegrees = (dec) => {
|
|
87
|
-
return numeral(dec).format("0.000000");
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export const decimalToDecimalMinutesSeconds = (dec) => {
|
|
91
|
-
if (dec === undefined || dec === null) return dec;
|
|
92
|
-
|
|
93
|
-
var sign = dec > 0 ? "" : "-",
|
|
94
|
-
dec = Math.abs(dec),
|
|
95
|
-
decRnd = Math.floor(dec);
|
|
96
|
-
|
|
97
|
-
const min = (dec - decRnd) * 60.0,
|
|
98
|
-
minRnd = Math.floor(min);
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
sign +
|
|
102
|
-
decRnd +
|
|
103
|
-
" " +
|
|
104
|
-
leadZero(minRnd, 2) +
|
|
105
|
-
" " +
|
|
106
|
-
leadZero(numeral((min - minRnd) * 60.0).format("0.00"), 2)
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
export const decimalDegreeMinutesToDecimalDegrees = (strVal) => {
|
|
110
|
-
if (strVal === undefined || strVal === null) return strVal;
|
|
111
|
-
|
|
112
|
-
var dm = strVal.split(/\s/);
|
|
113
|
-
var dec = parseInt(dm[0]);
|
|
114
|
-
|
|
115
|
-
var sign = dec < 0 ? -1 : 1,
|
|
116
|
-
deg = Math.abs(dec),
|
|
117
|
-
mm = parseFloat(dm[1]) || 0;
|
|
118
|
-
return sign * (deg + mm / 60.0);
|
|
119
|
-
};
|
|
120
|
-
export const decimalToDecimalDegreeMinutes = (dec) => {
|
|
121
|
-
if (dec === undefined || dec === null) return dec;
|
|
122
|
-
|
|
123
|
-
var sign = dec > 0 ? "" : "-",
|
|
124
|
-
dec = Math.abs(dec),
|
|
125
|
-
decRnd = Math.floor(dec);
|
|
126
|
-
|
|
127
|
-
return (
|
|
128
|
-
sign +
|
|
129
|
-
decRnd +
|
|
130
|
-
"°" +
|
|
131
|
-
leadZero(numeral((dec - decRnd) * 60.0).format("0.0000"), 2)
|
|
132
|
-
);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export const FORMAT = {
|
|
136
|
-
DDM: "DDM",
|
|
137
|
-
DD: "DD",
|
|
138
|
-
DMS: "DMS",
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export const formatCoord = (dec, format) => {
|
|
142
|
-
switch (format) {
|
|
143
|
-
case FORMAT.DMS:
|
|
144
|
-
return decimalToDecimalMinutesSeconds(dec);
|
|
145
|
-
case FORMAT.DDM:
|
|
146
|
-
return decimalToDecimalDegreeMinutes(dec);
|
|
147
|
-
default:
|
|
148
|
-
return decimalToDecialDegrees(dec);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export const getVerticalHeight =(percent)=>{
|
|
153
|
-
var h = Math.max(
|
|
154
|
-
document.documentElement.clientHeight,
|
|
155
|
-
window.innerHeight || 0
|
|
156
|
-
);
|
|
157
|
-
return (percent * h) / 100;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Feature array needs to include latitude and longitudes
|
|
162
|
-
*/
|
|
163
|
-
export const InBounds = (bounds,features)=>{
|
|
164
|
-
|
|
165
|
-
const inBoundsFeatures = [];
|
|
166
|
-
|
|
167
|
-
features.forEach(clusterGroup=>{
|
|
168
|
-
if(!clusterGroup.enabled) return;
|
|
169
|
-
const features = clusterGroup.features;
|
|
170
|
-
|
|
171
|
-
for (let i = 0; i < features.length; i++) {
|
|
172
|
-
const feature = features[i];
|
|
173
|
-
|
|
174
|
-
if(bounds.contains([feature.latitude,feature.longitude])){
|
|
175
|
-
inBoundsFeatures.push(feature);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
return inBoundsFeatures;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export const getCircleBounds = (radius,center,map)=>{
|
|
185
|
-
const metresPerPixel = 40075016.686 * Math.abs(Math.cos(map.getCenter().lat * Math.PI/180)) / Math.pow(2, map.getZoom()+8);
|
|
186
|
-
const meters = radius * metresPerPixel;
|
|
187
|
-
|
|
188
|
-
const circle = L.circle(center,{radius:meters}).addTo(map);
|
|
189
|
-
const bounds = circle.getBounds();
|
|
190
|
-
circle.removeFrom(map);
|
|
191
|
-
|
|
192
|
-
return bounds;
|
|
193
|
-
|
|
194
|
-
}
|