73 lines
1.4 KiB
TypeScript
73 lines
1.4 KiB
TypeScript
export function wait(t?: number, data?: any): Promise<any> {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
resolve(data);
|
|
}, t || 1000);
|
|
})
|
|
}
|
|
|
|
|
|
export function getBasePath(): string {
|
|
if (process.env.PUBLIC_URL.startsWith('http')) {
|
|
return process.env.PUBLIC_URL;
|
|
} else {
|
|
return window.location.origin + process.env.PUBLIC_URL;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function parseGeoJSONFeature(data: any): any {
|
|
if (typeof data.lgtd === 'number' && typeof data.lttd === 'number') {
|
|
return {
|
|
type: "Feature",
|
|
properties: data,
|
|
geometry: {
|
|
type: "Point",
|
|
coordinates: [data.lgtd, data.lttd]
|
|
}
|
|
};
|
|
} else if (data.geometry) {
|
|
let geometryObj = data.geometry;
|
|
if (typeof geometryObj === 'string') {
|
|
try {
|
|
geometryObj = JSON.parse(geometryObj);
|
|
} catch (e) {
|
|
geometryObj = null;
|
|
}
|
|
}
|
|
if (geometryObj?.type) {
|
|
return {
|
|
type: "Feature",
|
|
properties: data,
|
|
geometry: geometryObj
|
|
}
|
|
}
|
|
} else {
|
|
return {
|
|
type: "Feature",
|
|
properties: data,
|
|
};
|
|
}
|
|
}
|
|
|
|
export function parseGeoJSON(data: any): any {
|
|
const ret: any = {
|
|
type: "FeatureCollection",
|
|
crs: {
|
|
type: "name",
|
|
properties: {
|
|
name: "urn:ogc:def:crs:OGC:1.3:CRS84"
|
|
}
|
|
},
|
|
features: []
|
|
};
|
|
|
|
if (Array.isArray(data)) {
|
|
ret.features = data.map(parseGeoJSONFeature);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|