import { MockMap, mockViewportSize } from "./mock/MockMap"; import { MockFeature } from "./mock/MockVTFeatures"; import { metresToPixels, shapeCentre } from "../utils/Measure"; import { chunk } from "lodash-es"; export const featureById = (map: MockMap, layerName: string, id: number) => map.layerState[layerName]?.features?.find((f) => f.attributes.id === id); export const layerByName = (mockMap: MockMap, layerName: string) => { const res = mockMap?.mockLayerDefs?.find((l) => l.name === layerName); // CONSIDER: throw in caller? if (!res) console.error(`Layer ${layerName} is not defined`); return res; }; export const featureCoords = (feature: MockFeature | undefined) => metresToPixels( feature?.mockMap?.zoom!, [feature?.mockMap.centreX!, feature?.mockMap.centreY!], mockViewportSize, shapeCentre(feature?.attributes?.shape) ); export const blobifySVG = (svg: string) => { if (typeof URL.createObjectURL === "function") { const blobURL = URL.createObjectURL( new Blob([svg], { type: "image/svg+xml" }) ); if (blobURL) return blobURL; } // We don't have this function defined, or implemented // just run a very simple sync non-crypto digest that we can use as a check const digest = chunk(Array.from(svg), 8).reduce((acc, chunk) => { const chunkNum = chunk.reduce( (num, c, idx) => c.charCodeAt(0) * Math.pow(2, idx) + num, 0 ); return chunkNum ^ acc; }, 0xdd55dd55); return digest.toString(36); };