KSvend Claude Happy commited on
Commit
8e098b4
·
1 Parent(s): b15c51f

fix: remove MapboxDraw during rectangle tap to fix mobile touch events

Browse files

MapboxDraw's simple_select mode intercepts click/tap events, preventing
the two-tap rectangle from working on mobile. Now temporarily removes
Draw control during the tap phase, re-adds it after the rectangle is
built. Also adds a visual marker on first tap for feedback.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>

Files changed (1) hide show
  1. frontend/js/map.js +25 -3
frontend/js/map.js CHANGED
@@ -165,10 +165,20 @@ function getAllCoords(geometry) {
165
  * First tap sets one corner, second tap sets the opposite corner.
166
  * Works on both touch (mobile) and click (desktop).
167
  */
 
 
168
  export function activateDrawRect() {
169
  if (!_aoiMap) return;
170
- if (_draw) _draw.deleteAll();
 
 
 
 
171
  _rectFirstCorner = null;
 
 
 
 
172
  _aoiMap.getCanvas().style.cursor = 'crosshair';
173
  // Remove previous listener if any, then add fresh
174
  _aoiMap.off('click', _onRectClick);
@@ -179,8 +189,13 @@ function _onRectClick(e) {
179
  const { lng, lat } = e.lngLat;
180
 
181
  if (!_rectFirstCorner) {
182
- // First tap — store corner
183
  _rectFirstCorner = [lng, lat];
 
 
 
 
 
184
  return;
185
  }
186
 
@@ -192,6 +207,12 @@ function _onRectClick(e) {
192
  _aoiMap.getCanvas().style.cursor = '';
193
  _aoiMap.off('click', _onRectClick);
194
 
 
 
 
 
 
 
195
  const minLon = Math.min(lon1, lon2);
196
  const maxLon = Math.max(lon1, lon2);
197
  const minLat = Math.min(lat1, lat2);
@@ -213,7 +234,8 @@ function _onRectClick(e) {
213
  };
214
 
215
  if (_draw) {
216
- _draw.deleteAll();
 
217
  _draw.add(feature);
218
  _onDrawUpdate();
219
  }
 
165
  * First tap sets one corner, second tap sets the opposite corner.
166
  * Works on both touch (mobile) and click (desktop).
167
  */
168
+ let _firstCornerMarker = null;
169
+
170
  export function activateDrawRect() {
171
  if (!_aoiMap) return;
172
+ // Temporarily remove Draw so it doesn't intercept taps
173
+ if (_draw) {
174
+ _draw.deleteAll();
175
+ _aoiMap.removeControl(_draw);
176
+ }
177
  _rectFirstCorner = null;
178
+ if (_firstCornerMarker) {
179
+ _firstCornerMarker.remove();
180
+ _firstCornerMarker = null;
181
+ }
182
  _aoiMap.getCanvas().style.cursor = 'crosshair';
183
  // Remove previous listener if any, then add fresh
184
  _aoiMap.off('click', _onRectClick);
 
189
  const { lng, lat } = e.lngLat;
190
 
191
  if (!_rectFirstCorner) {
192
+ // First tap — store corner and show marker
193
  _rectFirstCorner = [lng, lat];
194
+ const el = document.createElement('div');
195
+ el.style.cssText = 'width:12px;height:12px;border-radius:50%;background:#1A3A34;border:2px solid white;';
196
+ _firstCornerMarker = new maplibregl.Marker({ element: el })
197
+ .setLngLat([lng, lat])
198
+ .addTo(_aoiMap);
199
  return;
200
  }
201
 
 
207
  _aoiMap.getCanvas().style.cursor = '';
208
  _aoiMap.off('click', _onRectClick);
209
 
210
+ // Remove corner marker
211
+ if (_firstCornerMarker) {
212
+ _firstCornerMarker.remove();
213
+ _firstCornerMarker = null;
214
+ }
215
+
216
  const minLon = Math.min(lon1, lon2);
217
  const maxLon = Math.max(lon1, lon2);
218
  const minLat = Math.min(lat1, lat2);
 
234
  };
235
 
236
  if (_draw) {
237
+ // Re-add Draw control, insert the rectangle, and trigger update
238
+ _aoiMap.addControl(_draw);
239
  _draw.add(feature);
240
  _onDrawUpdate();
241
  }