Initial commit: MVP scaffolding for Line of Sight application

- React frontend with MapLibre integration
- Node.js Express backend with dummy API
- Docker containerization (PostgreSQL+PostGIS, backend, frontend)
- Interactive map with direction selector
- 20 mock conurbations data
- Full project structure ready for PR workflow
This commit is contained in:
Agent Zero
2026-03-16 15:27:35 +00:00
commit b40116b56f
14 changed files with 808 additions and 0 deletions
+243
View File
@@ -0,0 +1,243 @@
import React, { useState, useEffect, useRef } from 'react';
import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
import apiService from './services/api';
import './styles/App.css';
const APP = () => {
const mapContainerRef = useRef(null);
const mapRef = useRef(null);
const [selectedPoint, setSelectedPoint] = useState({ lat: 51.5074, lon: -0.1278 });
const [direction, setDirection] = useState(45);
const [lineOfSightData, setLineOfSightData] = useState(null);
const [loading, setLoading] = useState(false);
const [mapStyle, setMapStyle] = useState('light'); // 'light' or 'dark'
const [tolerance, setTolerance] = useState(50);
useEffect(() => {
// Initialize MapLibre map
mapRef.current = new maplibregl.Map({
container: mapContainerRef.current,
style: getMapStyle(mapStyle),
center: [-0.1278, 51.5074], // London
zoom: 3,
pitch: 0
});
mapRef.current.on('load', () => {
console.log('Map loaded successfully');
});
mapRef.current.on('click', (e) => {
const { lng, lat } = e.lngLat;
setSelectedPoint({ lat, lon: lng });
// Clear previous line
if (mapRef.current.getSource('line-of-sight')) {
mapRef.current.removeLayer('line-of-sight');
mapRef.current.removeSource('line-of-sight');
}
});
return () => {
mapRef.current.remove();
};
}, []);
useEffect(() => {
// Update map style when toggle changes
if (mapRef.current) {
mapRef.current.setStyle(getMapStyle(mapStyle));
}
}, [mapStyle]);
const getMapStyle = (style) => {
return style === 'dark'
? 'https://demotiles.maplibre.org/style.json'
: 'https://demotiles.maplibre.org/style.json'; // Using same for now, can be customized
};
const handleShowLineOfSight = async () => {
setLoading(true);
try {
const response = await apiService.getLineOfSight(
selectedPoint.lat,
selectedPoint.lon,
direction,
tolerance
);
setLineOfSightData(response.data);
renderLineOnMap(response.data);
} catch (error) {
console.error('Error fetching line of sight:', error);
} finally {
setLoading(false);
}
};
const renderLineOnMap = (data) => {
const map = mapRef.current;
if (!map) return;
// Clear existing line
if (map.getSource('line-of-sight')) {
map.removeLayer('line-of-sight');
map.removeSource('line-of-sight');
}
// Add line source
map.addSource('line-of-sight', {
type: 'geojson',
data: {
type: 'Feature',
properties: {},
geometry: {
type: 'LineString',
coordinates: data.line_coordinates.map(coord => [coord.lon, coord.lat])
}
}
});
// Add line layer
map.addLayer({
id: 'line-of-sight',
type: 'line',
source: 'line-of-sight',
layout: {
'line-join': 'round',
'line-cap': 'round'
},
paint: {
'line-color': '#FF6B6B',
'line-width': 4,
'line-opacity': 0.8
}
});
// Add city markers
data.conurbations.forEach((city, index) => {
const markerId = `city-${index}`;
// Create marker element
const el = document.createElement('div');
el.className = 'city-marker';
el.innerHTML = `
<div class="marker-dot"></div>
<div class="marker-label">${city.name}</div>
<div class="marker-pop">${(city.population / 1000000).toFixed(1)}M</div>
`;
// Add marker to map
new maplibregl.Marker(el)
.setLngLat([city.lon, city.lat])
.setPopup(new maplibregl.Popup().setHTML(
`<strong>${city.name}</strong><br/>Population: ${city.population.toLocaleString()}<br/>Distance: ${city.distance_km} km`
))
.addTo(map);
});
// Fit bounds to show line
const bounds = new maplibregl.LngLatBounds();
data.line_coordinates.forEach(coord => {
bounds.extend([coord.lon, coord.lat]);
});
map.fitBounds(bounds, { padding: 50 });
};
return (
<div className="app-container">
<div className="map-container" ref={mapContainerRef}></div>
<div className="controls">
<div className="control-group">
<h3>Line of Sight Settings</h3>
<div className="setting-row">
<label>Start Point:</label>
<span>{selectedPoint.lat.toFixed(4)}, {selectedPoint.lon.toFixed(4)}</span>
</div>
<div className="setting-row">
<label>Direction (0-360°):</label>
<input
type="range"
min="0"
max="360"
value={direction}
onChange={(e) => setDirection(parseInt(e.target.value))}
/>
<span>{direction}°</span>
</div>
<div className="setting-row">
<label>Fuzziness Tolerance (km):</label>
<input
type="number"
value={tolerance}
onChange={(e) => setTolerance(parseInt(e.target.value))}
min="10"
max="200"
/>
<span>{tolerance} km</span>
</div>
<div className="setting-row">
<label>Map Style:</label>
<button onClick={() => setMapStyle('light')}>Light</button>
<button onClick={() => setMapStyle('dark')}>Dark</button>
</div>
<button
className="action-btn"
onClick={handleShowLineOfSight}
disabled={loading}
>
{loading ? 'Calculating...' : '📡 Show Line of Sight'}
</button>
</div>
{lineOfSightData && (
<div className="results-panel">
<h3>Conurbations Found ({lineOfSightData.conurbations.length})</h3>
<table>
<thead>
<tr>
<th>#</th>
<th>City</th>
<th>Population</th>
<th>Distance</th>
</tr>
</thead>
<tbody>
{lineOfSightData.conurbations.slice(0, 10).map((city, index) => (
<tr key={city.id}>
<td>{index + 1}</td>
<td>{city.name}</td>
<td>{(city.population / 1000000).toFixed(1)}M</td>
<td>{city.distance_km} km</td>
</tr>
))}
</tbody>
</table>
{lineOfSightData.conurbations.length > 10 && (
<p className="more-info">... and {lineOfSightData.conurbations.length - 10} more cities</p>
)}
</div>
)}
<div className="instructions">
<h3>How to Use</h3>
<ol>
<li>Click anywhere on the map to select a starting point</li>
<li>Adjust the direction using the slider (0-360°)</li>
<li>Set your fuzziness tolerance (how close cities must be to the line)</li>
<li>Click "Show Line of Sight" to visualize the path and cities</li>
</ol>
</div>
</div>
</div>
);
};
export default APP;
+11
View File
@@ -0,0 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import './styles/index.css';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
+25
View File
@@ -0,0 +1,25 @@
import axios from 'axios';
const API_BASE_URL = process.env.REACT_APP_API_URL || 'http://localhost:3001/api';
const api = axios.create({
baseURL: API_BASE_URL,
timeout: 10000,
headers: {
'Content-Type': 'application/json'
}
});
export const getLineOfSight = async (lat, lon, direction, tolerance) => {
const response = await api.get('/line-of-sight', {
params: { lat, lon, direction, tolerance }
});
return response;
};
export const healthCheck = async () => {
const response = await api.get('/health');
return response;
};
export default { getLineOfSight, healthCheck };
+226
View File
@@ -0,0 +1,226 @@
.app-container {
display: flex;
height: 100vh;
width: 100vw;
overflow: hidden;
}
.map-container {
flex: 1;
height: 100%;
position: relative;
z-index: 1;
}
.controls {
width: 350px;
background: white;
padding: 20px;
box-shadow: -2px 0 10px rgba(0,0,0,0.1);
overflow-y: auto;
z-index: 2;
}
.control-group {
background: #f8f9fa;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
}
.control-group h3 {
margin-top: 0;
color: #2c3e50;
font-size: 16px;
margin-bottom: 15px;
}
.setting-row {
display: flex;
align-items: center;
margin-bottom: 12px;
gap: 10px;
}
.setting-row label {
flex: 1;
font-size: 14px;
color: #555;
}
.setting-row input[type="range"] {
flex: 2;
}
.setting-row input[type="number"] {
width: 80px;
padding: 5px;
border: 1px solid #ddd;
border-radius: 4px;
}
.setting-row span {
font-weight: bold;
color: #2c3e50;
}
.setting-row button {
padding: 6px 12px;
margin: 0 5px;
border: 1px solid #ddd;
background: white;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s;
}
.setting-row button:hover {
background: #e9ecef;
}
.action-btn {
width: 100%;
padding: 12px;
background: #4CAF50;
color: white;
border: none;
border-radius: 6px;
font-size: 16px;
font-weight: bold;
cursor: pointer;
transition: background 0.3s;
margin-top: 10px;
}
.action-btn:hover:not(:disabled) {
background: #45a049;
}
.action-btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.results-panel {
background: #f8f9fa;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
}
.results-panel h3 {
margin-top: 0;
color: #2c3e50;
font-size: 16px;
margin-bottom: 15px;
}
.results-panel table {
width: 100%;
border-collapse: collapse;
font-size: 13px;
}
.results-panel th {
background: #34495e;
color: white;
padding: 10px;
text-align: left;
}
.results-panel td {
padding: 8px;
border-bottom: 1px solid #ddd;
}
.results-panel tr:nth-child(even) {
background: #f8f9fa;
}
.results-panel tr:hover {
background: #e9ecef;
}
.more-info {
color: #666;
font-size: 12px;
text-align: center;
margin-top: 10px;
}
.instructions {
background: #fff3cd;
padding: 15px;
border-radius: 8px;
border-left: 4px solid #ffc107;
}
.instructions h3 {
margin-top: 0;
color: #856404;
font-size: 16px;
}
.instructions ol {
margin: 0;
padding-left: 20px;
font-size: 13px;
color: #856404;
}
.instructions li {
margin-bottom: 8px;
}
.city-marker {
display: flex;
flex-direction: column;
align-items: center;
font-family: sans-serif;
}
.marker-dot {
width: 12px;
height: 12px;
background: #e74c3c;
border: 2px solid white;
border-radius: 50%;
box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.marker-label {
background: white;
padding: 4px 8px;
border-radius: 4px;
font-size: 11px;
font-weight: bold;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
margin-top: 2px;
white-space: nowrap;
}
.marker-pop {
background: #34495e;
color: white;
padding: 2px 6px;
border-radius: 4px;
font-size: 10px;
margin-top: 2px;
white-space: nowrap;
}
@media (max-width: 768px) {
.app-container {
flex-direction: column;
}
.controls {
width: 100%;
max-height: 40vh;
order: -1;
}
.map-container {
height: 60vh;
}
}
+14
View File
@@ -0,0 +1,14 @@
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #f5f5f5;
}
#root {
height: 100vh;
}