import { Portal, Link, Field } from "./types"; export const decodeEntity = (entity: any[]): Portal | Link | Field | null => { switch (entity[2][0]) { case 'r': // Field return decodeField(entity[2]) case 'p': //Portal return decodePortal(entity[2]) case 'e': // Link return decodeLink(entity[2]) default: return null } } export const decodePortal = (e: any[]): Portal => { return new Portal( e[8], e[7], e[1], { latitude: e[2] / 1E6, longitude: e[3] / 1E6, guid: e[8] }, e[4], e[6], e[10], e[5], e[13], e[15], e[14], e[16], ) } export const decodeField = (e: any[]): Field => { return new Field( e[1], [ { latitude: e[2][0][1] / 1E6, longitude: e[2][0][2] / 1E6, guid: e[2][0][0] }, { latitude: e[2][1][1] / 1E6, longitude: e[2][1][2] / 1E6, guid: e[2][1][0] }, { latitude: e[2][2][1] / 1E6, longitude: e[2][2][2] / 1E6, guid: e[2][2][0] } ] ) } export const decodeLink = (e: any[]): Link => { return new Link( e[1], [ { latitude: e[3] / 1E6, longitude: e[4] / 1E6, guid: e[2] }, { latitude: e[6] / 1E6, longitude: e[7] / 1E6, guid: e[5] } ] ) }