Debug issues with work item CRUD
This commit is contained in:
46
mobile/src/util.js
Normal file
46
mobile/src/util.js
Normal file
@@ -0,0 +1,46 @@
|
||||
export const geoDistance = (lat1, lng1, lat2, lng2, unit) => {
|
||||
var radlat1 = Math.PI * lat1 / 180
|
||||
var radlat2 = Math.PI * lat2 / 180
|
||||
var theta = lng1 - lng2
|
||||
var radtheta = Math.PI * theta / 180
|
||||
var dist =
|
||||
Math.sin(radlat1) * Math.sin(radlat2) +
|
||||
Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta)
|
||||
dist = Math.acos(dist)
|
||||
dist = dist * 180 / Math.PI
|
||||
dist = dist * 60 * 1.1515
|
||||
if (unit == "K") {
|
||||
dist = dist * 1.609344
|
||||
} else if (unit == "N") {
|
||||
dist = dist * 0.8684
|
||||
}
|
||||
return dist
|
||||
}
|
||||
|
||||
export const formatLatLng = (lat, lng) =>
|
||||
`${Math.abs(lat).toFixed(4)}°${lat >= 0 ? "N" : "S"}, ${Math.abs(lng).toFixed(
|
||||
4
|
||||
)}°${lng >= 0 ? "E" : "W"}`
|
||||
|
||||
export const parseLatLng = (str) => {
|
||||
const [lat, lng] = str.split(", ")
|
||||
return {
|
||||
type: "Point",
|
||||
coordinates: [
|
||||
parseFloat(
|
||||
(lng[lng.length - 1] === "W" ? "-" : "") +
|
||||
lng.substring(0, lng.length - 2)
|
||||
),
|
||||
parseFloat(
|
||||
(lat[lat.length - 1] === "S" ? "-" : "") +
|
||||
lat.substring(0, lat.length - 2)
|
||||
),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
export const workItemTypeEnum = [
|
||||
{ value: "order", text: "Work Order" },
|
||||
{ value: "inspection", text: "Inspection" },
|
||||
{ value: "complaint", text: "Complaint" },
|
||||
]
|
||||
Reference in New Issue
Block a user