-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathBaseUtil.js
More file actions
28 lines (24 loc) · 944 Bytes
/
BaseUtil.js
File metadata and controls
28 lines (24 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export function isString(str) {
return typeof str === 'string' && str.constructor === String;
}
export function isArray(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}
export function isObject(obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}
export function isValidLatlng(coord) {
return isArray(coord) && coord.length === 2 && coord[0] >= -180 && coord[0] <= 180 && coord[1] >= -90 && coord[1] <= 90;
}
export function featureCoordValid(feature) {
if (feature && feature.geometry && feature.geometry.type) {
const type = feature.geometry.type;
if (type === 'Point') {
return isValidLatlng(feature.geometry.coordinates);
} else if (type === 'LineString') {
return isValidLatlng(feature.geometry.coordinates[0]);
} else if (type === 'Polygon' || type === 'MultiLineString') {
return isValidLatlng(feature.geometry.coordinates[0][0]);
}
}
}