Skip to content

Commit 1986e8b

Browse files
committed
add agent.md @by cursor
1 parent ee71657 commit 1986e8b

1 file changed

Lines changed: 257 additions & 0 deletions

File tree

agent.md

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
# Geospatial Dataset Publishing Platform - Agent Guide
2+
3+
## Project Overview
4+
5+
This is a comprehensive geospatial data visualization platform for publishing and visualizing tsunami hazard datasets globally. The platform combines modern web mapping technology with scientific data visualization to provide interactive access to ~200,000 tsunami hazard points worldwide.
6+
7+
## Architecture Overview
8+
9+
### Technology Stack
10+
11+
- **Backend**: Python (pygeoapi) - OGC API compliant geospatial API server
12+
- **Frontend**: Vanilla JavaScript + MapLibre GL JS + Chart.js
13+
- **Data Processing**: GDAL, Tippecanoe for vector tile generation
14+
- **Containerization**: Docker, Docker Compose
15+
- **Deployment**: Kubernetes (k8s manifests provided)
16+
17+
### Key Components
18+
19+
#### 1. Frontend (`/frontend`)
20+
21+
- **Build System**: Node.js with custom build script (`build.js`)
22+
- **Source**: `src/` directory (HTML, CSS, JS)
23+
- **Distribution**: `dist/` directory (auto-generated, DO NOT EDIT)
24+
- **Styling**: Google Maps-inspired responsive design
25+
- **Maps**: MapLibre GL JS with vector tile rendering
26+
27+
#### 2. Backend (`/pygeoapi`)
28+
29+
- **Configuration**: `pygeoapi-config.yml` - defines data collections and services
30+
- **Docker**: Custom Dockerfile with health checks
31+
- **API Standards**: OGC API - Features, Tiles, Maps compliance
32+
33+
#### 3. Data Pipeline (`/data`)
34+
35+
- **Source Data**: GeoJSON files converted to optimized formats
36+
- **Vector Tiles**: Generated using Tippecanoe (MVT format)
37+
- **Formats**: FlatGeobuf (.fgb) for efficient streaming
38+
39+
## Data Architecture
40+
41+
### Global Tsunami Hazard Dataset
42+
43+
- **Points**: ~200,000 global tsunami hazard locations
44+
- **Source**: Davies et al. (2018) - Global probabilistic tsunami hazard assessment
45+
- **Format**: Vector tiles (MVT) served via pygeoapi
46+
- **Properties**:
47+
- `ari10`, `ari50`, `ari100`, `ari200`, `ari500`, `ari1000`, `ari2500`: Annual Recurrence Interval runup heights (meters)
48+
- `ari500LL`, `ari500ZL`, `ari500M`, `ari500P`: Statistical variants for 500-year ARI
49+
- `rate_*`: Exceedance rates for various thresholds
50+
51+
### Risk Classification
52+
53+
- **Green (#4CAF50)**: Low Risk (0-5m runup) - Minimal damage
54+
- **Yellow (#FFC107)**: Medium Risk (5-10m runup) - Moderate impact
55+
- **Orange (#FF9800)**: High Risk (10-20m runup) - Significant damage
56+
- **Red (#F44336)**: Very High Risk (>20m runup) - Catastrophic damage
57+
58+
## Frontend Development Guidelines
59+
60+
### File Structure
61+
62+
```
63+
frontend/
64+
├── src/
65+
│ ├── index.html # Main application template
66+
│ └── js/
67+
│ ├── basemap-layer.js # Map initialization & base layers
68+
│ ├── hazard-layer.js # Tsunami hazard point visualization
69+
│ ├── hyderabad-layer.js # Regional dataset (Hyderabad)
70+
│ ├── norway-hazard-tiles.js # Regional dataset (Norway)
71+
│ └── points-layer.js # Generic point layer utilities
72+
├── dist/ # Auto-generated (DO NOT EDIT)
73+
├── build.js # Build system
74+
└── package.json # Dependencies
75+
```
76+
77+
### Key JavaScript Patterns
78+
79+
#### 1. Map Initialization
80+
81+
```javascript
82+
const map = initializeMap("map");
83+
// Defined in basemap-layer.js, returns configured MapLibre GL map
84+
```
85+
86+
#### 2. Layer Management
87+
88+
```javascript
89+
function addGlobalHazardTiles(map, apiBaseUrl) {
90+
// Pattern: Add vector tile source + styled layer + interactions
91+
}
92+
```
93+
94+
#### 3. Popup System
95+
96+
- Uses MapLibre GL popups with Chart.js integration
97+
- Smart positioning to prevent viewport overflow
98+
- CSV export functionality for point data
99+
100+
### Styling Guidelines
101+
102+
- **Design Language**: Google Maps inspired
103+
- **Colors**: Material Design color palette
104+
- **Typography**: Roboto font family
105+
- **Responsive**: Mobile-first approach with breakpoints at 768px and 480px
106+
- **Glass Morphism**: `backdrop-filter: blur()` for modern panel effects
107+
108+
## API Integration
109+
110+
### pygeoapi Endpoints
111+
112+
- **Base URL**: Configurable via `API_BASE_URL` environment variable
113+
- **Vector Tiles**: `/collections/{collection}/tiles/WebMercatorQuad/{z}/{y}/{x}?f=mvt`
114+
- **Collections**:
115+
- `hazardglobal`: Global tsunami hazard points
116+
- `hyderabad`: Regional Hyderabad ward boundaries
117+
- Additional collections as configured
118+
119+
### Data Loading Pattern
120+
121+
```javascript
122+
map.addSource("source-name", {
123+
type: "vector",
124+
tiles: [
125+
`${apiBaseUrl}/collections/{collection}/tiles/WebMercatorQuad/{z}/{y}/{x}?f=mvt`,
126+
],
127+
minzoom: 0,
128+
maxzoom: 15,
129+
});
130+
```
131+
132+
## Build and Deployment
133+
134+
### Development Workflow
135+
136+
1. **Edit source files** in `frontend/src/`
137+
2. **Build**: `cd frontend && npm run build`
138+
3. **Test locally**: Serve `frontend/dist/`
139+
4. **Deploy**: Use Docker Compose or Kubernetes manifests
140+
141+
### Environment Variables
142+
143+
- `API_BASE_URL`: Backend API endpoint (injected during build)
144+
- `VERSION`: Application version (from package.json)
145+
146+
### Docker Compose
147+
148+
```bash
149+
docker-compose up # Starts full stack (frontend + pygeoapi)
150+
```
151+
152+
### Kubernetes
153+
154+
```bash
155+
kubectl apply -f k8s-frontend.yaml
156+
kubectl apply -f k8s-pygeoapi.yaml
157+
```
158+
159+
## Data Processing Pipeline
160+
161+
### Vector Tile Generation
162+
163+
```bash
164+
make hazard-fgb # GeoJSON → FlatGeobuf conversion
165+
make hazard-tiles # FlatGeobuf → Vector tiles (MVT)
166+
```
167+
168+
### File Formats
169+
170+
- **Source**: GeoJSON (large files, ~94MB)
171+
- **Optimized**: FlatGeobuf (32% smaller, streamable)
172+
- **Tiles**: MVT (Mapbox Vector Tiles) for efficient web delivery
173+
174+
## Performance Optimizations
175+
176+
### Frontend
177+
178+
- **Vector Tiles**: Only load visible tiles based on zoom/pan
179+
- **Level of Detail**: Zoom-dependent point sizing and opacity
180+
- **Chart Rendering**: Lazy loading with timeout handling
181+
- **Popup Management**: Smart positioning and content streaming
182+
183+
### Backend
184+
185+
- **Caching**: Vector tiles cached at multiple levels
186+
- **Compression**: Gzip compression for tile delivery
187+
- **Health Checks**: Automated monitoring and recovery
188+
189+
## Common Development Tasks
190+
191+
### Adding New Dataset
192+
193+
1. **Prepare Data**: Convert to FlatGeobuf format
194+
2. **Generate Tiles**: Use Tippecanoe via Makefile
195+
3. **Configure pygeoapi**: Add collection in `pygeoapi-config.yml`
196+
4. **Frontend Layer**: Create new JavaScript module in `src/js/`
197+
5. **Build**: Run `npm run build`
198+
199+
### Styling Updates
200+
201+
1. **Edit**: Modify styles in `src/index.html` `<style>` section
202+
2. **Build**: `npm run build` to update distribution
203+
3. **Test**: Verify responsive behavior on multiple screen sizes
204+
205+
### API Changes
206+
207+
1. **Backend**: Update `pygeoapi-config.yml`
208+
2. **Frontend**: Modify API calls in relevant JS modules
209+
3. **Build**: Rebuild frontend to pick up changes
210+
211+
## Scientific Context
212+
213+
### Reference Paper
214+
215+
Davies, G., Griffin, J., Løvholt, F., Glimsdal, S., Harbitz, C., Thio, H.K., Lorito, S., Basili, R., Selva, J., Geist, E.L. and Baptista, M.A. (2018). A global probabilistic tsunami hazard assessment from earthquake sources. _Geological Society, London, Special Publications_, 456, 219-244.
216+
217+
### Data Significance
218+
219+
- **Global Coverage**: First comprehensive global PTHA using uniform methodology
220+
- **Probabilistic Approach**: Provides exceedance rates rather than single scenarios
221+
- **Uncertainty Quantification**: Includes confidence intervals and statistical variants
222+
- **Policy Relevance**: Supports international disaster risk reduction frameworks
223+
224+
## Troubleshooting
225+
226+
### Common Issues
227+
228+
1. **Build failures**: Check Node.js version and dependencies
229+
2. **API connection**: Verify `API_BASE_URL` configuration
230+
3. **Tile loading**: Check pygeoapi health and network connectivity
231+
4. **Performance**: Monitor browser console for JS errors
232+
233+
### Debug Tools
234+
235+
- **Browser DevTools**: Network tab for API calls, Console for JS errors
236+
- **Health Check**: `{API_BASE_URL}/health` endpoint
237+
- **Tile Inspector**: MapLibre GL debug tools for tile analysis
238+
239+
## Future Development
240+
241+
### Planned Features
242+
243+
- Point clustering for better performance at low zoom levels
244+
- Time series animation through different return periods
245+
- Advanced filtering by risk level and geographic region
246+
- 3D visualization with height-based extrusion
247+
248+
### Technical Debt
249+
250+
- Migrate from inline styles to separate CSS files
251+
- Implement proper state management for complex interactions
252+
- Add unit tests for JavaScript modules
253+
- Enhance error handling and user feedback
254+
255+
---
256+
257+
_This agent guide provides comprehensive context for AI assistants working on this geospatial visualization platform. It covers architecture, development patterns, data workflows, and scientific context needed for effective code assistance._

0 commit comments

Comments
 (0)