KSvend commited on
Commit
b30fbad
·
1 Parent(s): 59bad34

feat: wire size toggles and click-to-place in app.js

Browse files
Files changed (1) hide show
  1. frontend/js/app.js +14 -36
frontend/js/app.js CHANGED
@@ -4,7 +4,7 @@
4
  */
5
 
6
  import { submitJob, getJob, requestMagicLink, verifyToken, listJobs } from './api.js';
7
- import { initAoiMap, activateDrawRect, geocode, loadGeoJSON, initResultsMap } from './map.js';
8
  import { initIndicators, getSelectedIds } from './indicators.js';
9
  import { renderResults } from './results.js';
10
 
@@ -167,15 +167,20 @@ function setupDefineArea() {
167
 
168
  const continueBtn = document.getElementById('aoi-continue-btn');
169
  const geocoderInput = document.getElementById('geocoder-input');
170
- const rectBtn = document.getElementById('draw-rect-btn');
171
- const uploadInput = document.getElementById('geojson-upload');
172
- const uploadLabel = document.getElementById('upload-label');
173
  const areaDisplay = document.getElementById('aoi-area-display');
174
-
175
- const AOI_MAX_KM2 = 10000;
176
 
177
  continueBtn.disabled = true;
178
 
 
 
 
 
 
 
 
 
 
179
  // Init map once
180
  if (!_aoiMapInit) {
181
  _aoiMapInit = true;
@@ -183,14 +188,10 @@ function setupDefineArea() {
183
  _currentBbox = bbox;
184
  if (bbox) {
185
  const area = _bboxAreaKm2(bbox);
186
- const overLimit = area > AOI_MAX_KM2;
187
  areaDisplay.style.display = '';
188
  areaDisplay.textContent = `${Math.round(area).toLocaleString()} km²`;
189
- areaDisplay.className = 'aoi-area-display' + (overLimit ? ' aoi-area-over' : '');
190
- if (overLimit) {
191
- areaDisplay.textContent += ` — exceeds ${AOI_MAX_KM2.toLocaleString()} km² limit`;
192
- }
193
- continueBtn.disabled = overLimit;
194
  } else {
195
  areaDisplay.style.display = 'none';
196
  continueBtn.disabled = true;
@@ -198,7 +199,7 @@ function setupDefineArea() {
198
  });
199
  }
200
 
201
- // Geocoder
202
  geocoderInput.addEventListener('keydown', async (e) => {
203
  if (e.key !== 'Enter') return;
204
  const query = geocoderInput.value.trim();
@@ -210,29 +211,6 @@ function setupDefineArea() {
210
  }
211
  });
212
 
213
- // Draw button
214
- rectBtn.addEventListener('click', () => {
215
- rectBtn.classList.add('active');
216
- activateDrawRect();
217
- });
218
-
219
- // GeoJSON upload
220
- uploadInput.addEventListener('change', (e) => {
221
- const file = e.target.files[0];
222
- if (!file) return;
223
- const reader = new FileReader();
224
- reader.onload = (ev) => {
225
- try {
226
- const geojson = JSON.parse(ev.target.result);
227
- loadGeoJSON(geojson);
228
- uploadLabel.textContent = file.name;
229
- } catch {
230
- showError('Invalid GeoJSON file.');
231
- }
232
- };
233
- reader.readAsText(file);
234
- });
235
-
236
  // Date defaults: last 12 months
237
  const today = new Date();
238
  const yearAgo = new Date(today);
 
4
  */
5
 
6
  import { submitJob, getJob, requestMagicLink, verifyToken, listJobs } from './api.js';
7
+ import { initAoiMap, setAoiSize, geocode, initResultsMap } from './map.js';
8
  import { initIndicators, getSelectedIds } from './indicators.js';
9
  import { renderResults } from './results.js';
10
 
 
167
 
168
  const continueBtn = document.getElementById('aoi-continue-btn');
169
  const geocoderInput = document.getElementById('geocoder-input');
 
 
 
170
  const areaDisplay = document.getElementById('aoi-area-display');
171
+ const sizeButtons = document.querySelectorAll('.size-toggle-btn');
 
172
 
173
  continueBtn.disabled = true;
174
 
175
+ // Size toggle buttons
176
+ sizeButtons.forEach(btn => {
177
+ btn.addEventListener('click', () => {
178
+ sizeButtons.forEach(b => b.classList.remove('active'));
179
+ btn.classList.add('active');
180
+ setAoiSize(parseInt(btn.dataset.km2));
181
+ });
182
+ });
183
+
184
  // Init map once
185
  if (!_aoiMapInit) {
186
  _aoiMapInit = true;
 
188
  _currentBbox = bbox;
189
  if (bbox) {
190
  const area = _bboxAreaKm2(bbox);
 
191
  areaDisplay.style.display = '';
192
  areaDisplay.textContent = `${Math.round(area).toLocaleString()} km²`;
193
+ areaDisplay.className = 'aoi-area-display';
194
+ continueBtn.disabled = false;
 
 
 
195
  } else {
196
  areaDisplay.style.display = 'none';
197
  continueBtn.disabled = true;
 
199
  });
200
  }
201
 
202
+ // Geocoder — auto-places AOI
203
  geocoderInput.addEventListener('keydown', async (e) => {
204
  if (e.key !== 'Enter') return;
205
  const query = geocoderInput.value.trim();
 
211
  }
212
  });
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  // Date defaults: last 12 months
215
  const today = new Date();
216
  const yearAgo = new Date(today);