mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 19:16:41 +07:00
typed some utils
This commit is contained in:
parent
cf6866240b
commit
5c3f09ec2c
5 changed files with 34 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
|||
import { divIcon } from 'leaflet';
|
||||
import { DivIcon, divIcon } from 'leaflet';
|
||||
|
||||
export const clusterIcon = cluster => divIcon({
|
||||
export const clusterIcon = (cluster): DivIcon => divIcon({
|
||||
html: `
|
||||
<div class="custom-marker-cluster">
|
||||
<span>${cluster.getChildCount()}</span>
|
|
@ -1,11 +1,13 @@
|
|||
const ru = [' ','\\.',',',':','\\?','#','Я','я','Ю','ю','Ч','ч','Ш','ш','Щ','щ','Ж','ж','А','а','Б','б','В','в','Г','г','Д','д','Е','е','Ё','ё','З','з','И','и','Й','й','К','к','Л','л','М','м','Н','н', 'О','о','П','п','Р','р','С','с','Т','т','У','у','Ф','ф','Х','х','Ц','ц','Ы','ы','Ь','ь','Ъ','ъ','Э','э'];
|
||||
const en = ['_','','','','','','Ya','ya','Yu','yu','Ch','ch','Sh','sh','Sh','sh','Zh','zh','A','a','B','b','V','v','G','g','D','d','E','e','E','e','Z','z','I','i','J','j','K','k','L','l','M','m','N','n', 'O','o','P','p','R','r','S','s','T','t','U','u','F','f','H','h','C','c','Y','y','','','','','E', 'e'];
|
||||
|
||||
export const toHours = (info) => {
|
||||
const hrs = parseInt(Number(info), 10);
|
||||
export const toHours = (info: number): string => {
|
||||
const hrs = parseInt(String(info), 10);
|
||||
const min = Math.round((Number(info) - hrs) * 60);
|
||||
const lmin = min < 10 ? '0' + min : min;
|
||||
return `${hrs}:${lmin}`;
|
||||
};
|
||||
|
||||
export const toTranslit = string => ru.reduce((text, el, i) => (text.replace(new RegExp(ru[i], 'g'), en[i])), (String(string) || ''));
|
||||
export const toTranslit = (string: string): string => (
|
||||
ru.reduce((text, el, i) => (text.replace(new RegExp(ru[i], 'g'), en[i])), (String(string) || ''))
|
||||
);
|
|
@ -1,14 +1,17 @@
|
|||
export const middleCoord = (l1, l2) => ({
|
||||
interface ILatLng {
|
||||
lat: number,
|
||||
lng: number,
|
||||
}
|
||||
|
||||
export const middleCoord = (l1: ILatLng, l2: ILatLng): ILatLng => ({
|
||||
lat: (l2.lat + ((l1.lat - l2.lat) / 2)),
|
||||
lng: (l2.lng + ((l1.lng - l2.lng) / 2))
|
||||
});
|
||||
|
||||
export const deg2rad = deg => ((deg * Math.PI) / 180);
|
||||
export const rad2deg = rad => ((rad / Math.PI) * 180);
|
||||
export const deg2rad = (deg: number): number => ((deg * Math.PI) / 180);
|
||||
export const rad2deg = (rad: number): number => ((rad / Math.PI) * 180);
|
||||
|
||||
window.rad2deg = rad2deg;
|
||||
|
||||
export const findDistance = (t1, n1, t2, n2) => {
|
||||
export const findDistance = (t1: number, n1: number, t2: number, n2: number): number => {
|
||||
// convert coordinates to radians
|
||||
const lat1 = deg2rad(t1);
|
||||
const lon1 = deg2rad(n1);
|
||||
|
@ -23,12 +26,11 @@ export const findDistance = (t1, n1, t2, n2) => {
|
|||
const a = (Math.sin(dlat / 2) ** 2) +
|
||||
(Math.cos(lat1) * Math.cos(lat2) * (Math.sin(dlon / 2) ** 2));
|
||||
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); // great circle distance in radians
|
||||
// const dm = c * 3961; // great circle distance in miles
|
||||
const dk = c * 6373; // great circle distance in km
|
||||
|
||||
// round the results down to the nearest 1/1000
|
||||
// const mi = round(dm);
|
||||
return (Math.round(dk * 1000) / 1000);
|
||||
};
|
||||
|
||||
export const getLabelDirection = angle => (((angle % Math.PI) >= -(Math.PI / 2) && (angle % Math.PI) <= (Math.PI / 2)) ? 'left' : 'right');
|
||||
export const getLabelDirection = (angle: number): 'left' | 'right' => (
|
||||
((angle % Math.PI) >= -(Math.PI / 2) && (angle % Math.PI) <= (Math.PI / 2)) ? 'left' : 'right'
|
||||
);
|
|
@ -5,7 +5,6 @@ export interface IRoutePoint {
|
|||
lng: number,
|
||||
}
|
||||
|
||||
|
||||
interface IGPXSticker {
|
||||
latlng: IRoutePoint,
|
||||
text?: string,
|
||||
|
@ -45,7 +44,7 @@ export const getGPXString = ({ route, title, stickers }: IGetGPXString): string
|
|||
</gpx>
|
||||
`);
|
||||
|
||||
export const downloadGPXTrack = ({ track, title }: { track: string, title?: string }) => (
|
||||
export const downloadGPXTrack = ({ track, title }: { track: string, title?: string }): void => (
|
||||
saveAs(
|
||||
new Blob([track], { type: 'application/gpx+xml;charset=utf-8' }),
|
||||
`${title || 'track'}.gpx`
|
||||
|
|
|
@ -1,8 +1,16 @@
|
|||
import { history } from '$redux/store';
|
||||
|
||||
export const getPath = () => (window.location && window.location.pathname);
|
||||
export const pushPath = url => history.push(url);
|
||||
export const replacePath = url => history.replace(url);
|
||||
interface IUrlData {
|
||||
path: string,
|
||||
mode: 'edit' | '',
|
||||
host: string,
|
||||
hash: string,
|
||||
protocol: 'http' | 'https',
|
||||
}
|
||||
|
||||
export const getPath = (): string => (window.location && window.location.pathname);
|
||||
export const pushPath = (url: string): string => history.push(url);
|
||||
export const replacePath = (url: string): string => history.replace(url);
|
||||
|
||||
export const getUrlData = (url = getPath()) => {
|
||||
const [, path, mode] = url.split('/');
|
||||
|
@ -31,14 +39,15 @@ export const pushLoaderState = state => {
|
|||
};
|
||||
|
||||
export const pushNetworkInitError = () => {
|
||||
document.getElementById('loader-error').style.opacity = 1;
|
||||
document.getElementById('loader-error').style.opacity = String(1);
|
||||
};
|
||||
|
||||
export const copyToClipboard = str => {
|
||||
const el = document.createElement('textarea');
|
||||
el.value = str;
|
||||
el.setAttribute('readonly', '');
|
||||
el.style = { position: 'absolute', left: '-9999px' };
|
||||
el.style.position = 'absolute';
|
||||
el.style.left = '-9999px';
|
||||
document.body.appendChild(el);
|
||||
el.select();
|
||||
document.execCommand('copy');
|
Loading…
Add table
Add a link
Reference in a new issue