diff --git a/frontend/.gitignore b/frontend/.gitignore index 3427f43..bb0ab8e 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -1,4 +1,4 @@ bundle.js -bundle.map.js +bundle.js.map diff --git a/frontend/bundle.js.map b/frontend/bundle.js.map deleted file mode 100644 index d0f35a2..0000000 --- a/frontend/bundle.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["src/utils.ts", "src/main.ts"], - "sourcesContent": ["export class Throttler {\n private hasBeenCalledWithinTime = false;\n private lastCallFunc: (() => any) | null = null;\n\n public constructor(private minimumTimeBetweenCall: number) {}\n\n public call(func: () => any) {\n this.lastCallFunc = func;\n if (this.hasBeenCalledWithinTime) return;\n this.hasBeenCalledWithinTime = true;\n func();\n setTimeout(() => {\n this.hasBeenCalledWithinTime = false;\n if (this.lastCallFunc) this.lastCallFunc();\n }, this.minimumTimeBetweenCall);\n }\n}\n", "import { Throttler } from \"./utils\";\n\ntype Position = {\n x: number;\n y: number;\n};\n\ntype Size = { width: number; height: number };\n\ntype Coordinate = {\n longitude: number;\n latitude: number;\n};\n\ntype ZipCodeReverseResponse = {\n nr: number | null;\n navn: string;\n};\n\nasync function fetchZipCode({\n longitude,\n latitude,\n}: Coordinate): Promise {\n return fetch(\n `https://api.dataforsyningen.dk/postnumre/reverse?x=${longitude}&y=${latitude}`,\n )\n .then((request) => request.json())\n .then((data) => {\n let zipCode = parseInt(data.nr);\n return {\n ...data,\n nr: isNaN(zipCode) ? null : zipCode,\n } as ZipCodeReverseResponse;\n })\n .catch(() => null as never);\n}\n\nfunction convertPixelsToCoordinate(mouse: Position, map: Size): Coordinate {\n const scalar = { x: 8, y: 3.6 };\n const offset = { x: 6.2, y: 57.93 };\n return {\n longitude: (mouse.x / map.width) * scalar.x + offset.x,\n latitude: Math.abs((mouse.y / map.height) * scalar.y - offset.y),\n };\n}\n\nfunction displayMousePosition(element: HTMLParagraphElement, mouse: Position) {\n element.innerHTML = `Mouse position: (${mouse.x}px, ${mouse.y}px)`;\n}\n\nfunction displayCoords(element: HTMLParagraphElement, coords: Coordinate) {\n element.innerHTML = `Coords: ${coords.longitude.toFixed(\n 3,\n )}, ${coords.latitude.toFixed(3)}`;\n}\n\nfunction displayZipCode(\n element: HTMLParagraphElement,\n zipCode: number | null,\n name: string,\n) {\n element.innerHTML =\n zipCode === null\n ? `Postnummer ikke fundet`\n : `Postnummer: ${zipCode}, ${name}`;\n}\n\nfunction setupMap(\n mousePositionElement: HTMLParagraphElement,\n coordsElement: HTMLParagraphElement,\n zipCodeElement: HTMLParagraphElement,\n) {\n const mapImg = document.querySelector(\"#map\")!;\n const fetcher = new Throttler(500);\n\n mapImg.onmousemove = async (event: MouseEvent) => {\n const mousePosition: Position = { x: event.offsetX, y: event.offsetY };\n displayMousePosition(mousePositionElement, mousePosition);\n const mapSize: Size = {\n width: mapImg.clientWidth,\n height: mapImg.clientHeight,\n };\n const coords = convertPixelsToCoordinate(mousePosition, mapSize);\n displayCoords(coordsElement, coords);\n fetcher.call(async () => {\n const response = await fetchZipCode(coords);\n displayZipCode(zipCodeElement, response.nr, response.navn);\n });\n };\n\n mapImg.onmouseleave = (_event: MouseEvent) => {\n [mousePositionElement, coordsElement, zipCodeElement].forEach(\n (e) => (e.innerHTML = \"\"),\n );\n };\n}\n\nfunction setupSearchBar(zipCodeElement: HTMLParagraphElement) {\n const searchInput =\n document.querySelector(\"#search-input\")!;\n const searchButton =\n document.querySelector(\"#search-button\")!;\n\n searchButton.onclick = async (_event: MouseEvent) => {\n const inputValue = searchInput.value;\n if (!/^\\d+$/.test(inputValue)) return;\n const data = await (\n await fetch(\n `https://api.dataforsyningen.dk/postnumre?nr=${inputValue}`,\n )\n ).json();\n displayZipCode(\n zipCodeElement,\n parseInt(data[0][\"nr\"]),\n data[0][\"navn\"],\n );\n };\n}\n\nfunction main() {\n const [mousePositionElement, coordsElement, zipCodeElement] = [\n \"#mouse-position\",\n \"#coords\",\n \"#zip-code\",\n ].map((id) => document.querySelector(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SAAS,cAAoCA,CAAE,CAAE,EAE/DL,EAAeV,CAAc,EAC7BH,EAASC,EAAsBC,EAAeC,CAAc,CAChE,CAEAc,EAAK", - "names": ["Throttler", "minimumTimeBetweenCall", "func", "fetchZipCode", "_0", "__async", "longitude", "latitude", "request", "data", "zipCode", "__spreadProps", "__spreadValues", "convertPixelsToCoordinate", "mouse", "map", "scalar", "offset", "displayMousePosition", "element", "displayCoords", "coords", "displayZipCode", "name", "setupMap", "mousePositionElement", "coordsElement", "zipCodeElement", "mapImg", "fetcher", "Throttler", "event", "mousePosition", "mapSize", "response", "_event", "e", "setupSearchBar", "searchInput", "searchButton", "inputValue", "main", "id"] -}