From e2ce7b448dc5885013442af4e9af41f12ba3bd12 Mon Sep 17 00:00:00 2001 From: Emilio Mariscal Date: Fri, 14 Aug 2026 11:38:08 -0300 Subject: [PATCH 1/6] Add 'my location' control --- .../shoelace/assets/icons/crosshair.svg | 3 ++ .../shoelace/assets/icons/crosshair2.svg | 3 ++ chatmap-ui/src/components/Map/controls.jsx | 41 +++++++++++++++++++ chatmap-ui/src/components/Map/index.jsx | 12 +++++- chatmap-ui/src/styles/main.css | 12 ++++++ 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 chatmap-ui/public/shoelace/assets/icons/crosshair.svg create mode 100644 chatmap-ui/public/shoelace/assets/icons/crosshair2.svg diff --git a/chatmap-ui/public/shoelace/assets/icons/crosshair.svg b/chatmap-ui/public/shoelace/assets/icons/crosshair.svg new file mode 100644 index 0000000..13bed74 --- /dev/null +++ b/chatmap-ui/public/shoelace/assets/icons/crosshair.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/chatmap-ui/public/shoelace/assets/icons/crosshair2.svg b/chatmap-ui/public/shoelace/assets/icons/crosshair2.svg new file mode 100644 index 0000000..3c28586 --- /dev/null +++ b/chatmap-ui/public/shoelace/assets/icons/crosshair2.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/chatmap-ui/src/components/Map/controls.jsx b/chatmap-ui/src/components/Map/controls.jsx index b7cddef..a0871a8 100644 --- a/chatmap-ui/src/components/Map/controls.jsx +++ b/chatmap-ui/src/components/Map/controls.jsx @@ -62,3 +62,44 @@ export class BackgroundControl { this._map = undefined; } } + +const locationHandler = async () => { + if (!navigator.geolocation) { + console.error("Geolocation is not supported by your browser"); + return; + } + + try { + const position = await new Promise((resolve, reject) => { + const watchId = navigator.geolocation.watchPosition( + (pos) => { + navigator.geolocation.clearWatch(watchId); + clearTimeout(timeoutId); + resolve(pos); + }, + (err) => { + navigator.geolocation.clearWatch(watchId); + clearTimeout(timeoutId); + reject(err); + }, + { + enableHighAccuracy: true, + timeout: 15000, + maximumAge: 0 + } + ); + + const timeoutId = setTimeout(() => { + navigator.geolocation.clearWatch(watchId); + reject(new Error("Location timeout: Could not get GPS fix within 15s")); + }, 15000); + }); + + return position.coords; + + } catch (error) { + console.error("Failed to get location:", error.message || error); + return false; + } +}; + diff --git a/chatmap-ui/src/components/Map/index.jsx b/chatmap-ui/src/components/Map/index.jsx index 282b922..3481948 100644 --- a/chatmap-ui/src/components/Map/index.jsx +++ b/chatmap-ui/src/components/Map/index.jsx @@ -1,5 +1,5 @@ import React, { useRef, useEffect, useState } from 'react'; -import { Map as MapGL } from 'maplibre-gl'; +import { Map as MapGL, GeolocateControl } from 'maplibre-gl'; import 'maplibre-gl/dist/maplibre-gl.css'; import { osm } from './source'; import Popup from './popup'; @@ -49,6 +49,16 @@ export default function Map({ dataFiles, center, zoom, className, onInteract, sh // Add background control map.current.addControl(new BackgroundControl()); + // Add location control + let geolocate = new GeolocateControl({ + positionOptions: { + enableHighAccuracy: true + }, + trackUserLocation: true + }); + // Add the control to the map. + map.current.addControl(geolocate); + // Add geojson data source map.current.addSource('locations', { data: data, diff --git a/chatmap-ui/src/styles/main.css b/chatmap-ui/src/styles/main.css index b6d8d01..68933a7 100644 --- a/chatmap-ui/src/styles/main.css +++ b/chatmap-ui/src/styles/main.css @@ -638,6 +638,18 @@ https://github.com/KarimMokhtar/react-drag-drop-files/issues/121 */ font-size: var(--hot-font-size-x-small); } +.maplibregl-ctrl button.maplibregl-ctrl-geolocate .maplibregl-ctrl-icon { + background-image: url('data:image/svg+xml,') !important; +} + +.maplibregl-ctrl button.maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-active .maplibregl-ctrl-icon { + background-image: url('data:image/svg+xml,') !important; +} + +.maplibregl-ctrl button.maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-background .maplibregl-ctrl-icon { + background-image: url('data:image/svg+xml,') !important; +} + /* Media queries */ /* Desktop */ From 46e17f46a0de444c98a3d0df80dde158ad5738eb Mon Sep 17 00:00:00 2001 From: Emilio Mariscal Date: Sat, 15 Aug 2026 18:58:45 -0300 Subject: [PATCH 2/6] Refactor: move WA parser datetime functions to its own file --- .../src/components/ChatMap/parsers/ignore.js | 11 +- .../components/ChatMap/parsers/whatsapp.js | 323 +----------------- .../tests/whatsapp.parseAndIndex.test.js | 3 +- .../tests/whatsapp.parseTimeString.test.js | 2 +- 4 files changed, 16 insertions(+), 323 deletions(-) diff --git a/chatmap-ui/src/components/ChatMap/parsers/ignore.js b/chatmap-ui/src/components/ChatMap/parsers/ignore.js index d7af287..7d2b1e7 100644 --- a/chatmap-ui/src/components/ChatMap/parsers/ignore.js +++ b/chatmap-ui/src/components/ChatMap/parsers/ignore.js @@ -14,5 +14,14 @@ const ignore = [ "", ] -export default ignore; +// Check if message is in list of ignored strings +export const isInTheIgnoreList = msg => { + for (let i = 0; i < ignore.length; i++) { + if (msg.indexOf(ignore[i]) > -1) { + return true; + } + }; + return false; +} + diff --git a/chatmap-ui/src/components/ChatMap/parsers/whatsapp.js b/chatmap-ui/src/components/ChatMap/parsers/whatsapp.js index 1fb4efe..8a62cdf 100644 --- a/chatmap-ui/src/components/ChatMap/parsers/whatsapp.js +++ b/chatmap-ui/src/components/ChatMap/parsers/whatsapp.js @@ -7,19 +7,18 @@ * of media files */ -import ignore from "./ignore"; +import { isInTheIgnoreList } from "./ignore"; +import { getDateFormat } from "./whatsapp-datetime"; // Regex to search for coordinates in the format , (ex: -31.006037,-64.262794) const LOCATION_PATTERN = /[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?).*$/; // Regex to search for messages in the format [,