-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
825 lines (703 loc) · 23.4 KB
/
index.html
File metadata and controls
825 lines (703 loc) · 23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manhattan Community Mapping</title>
<!-- Mapbox -->
<script src="https://api.mapbox.com/mapbox-gl-js/v3.3.0/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v3.3.0/mapbox-gl.css" rel="stylesheet" />
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&family=Fraunces:wght@600&display=swap" rel="stylesheet">
<style>
:root {
--color-bg: #d2232a;
--color-surface: #FFFFFF;
--color-primary: #1D4ED8;
--color-primary-hover: #1E40AF;
--color-text: #1C1917;
--color-text-muted: #1C1917;
--color-border: #E7E5E4;
--color-error: #DC2626;
--color-success: #16A34A;
--radius: 8px;
--shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
--shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
background: var(--color-bg);
}
body {
font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
background: var(--color-bg);
color: var(--color-text);
line-height: 1.6;
min-height: 100vh;
min-height: 100dvh;
}
.container {
max-width: 640px;
margin: 0 auto;
padding: 40px 20px 60px;
}
header {
text-align: center;
margin-bottom: 32px;
}
.header-logo {
max-width: 100%;
height: auto;
margin-bottom: 8px;
}
.subtitle {
color: #ffffff;
font-size: 1.2rem;
}
.form-card {
background: var(--color-surface);
border-radius: 12px;
box-shadow: var(--shadow);
overflow: hidden;
}
/* Map Section */
.map-section {
border-bottom: 1px solid var(--color-border);
}
.map-header {
padding: 24px 24px 16px;
}
.map-label {
font-weight: 600;
font-size: 0.95rem;
margin-bottom: 4px;
display: flex;
align-items: center;
gap: 4px;
}
.required-star {
color: var(--color-error);
}
.map-hint {
font-size: 0.875rem;
color: var(--color-text-muted);
}
#map {
height: 350px;
width: 100%;
}
.map-status {
padding: 12px 24px;
background: #F5F5F4;
font-size: 0.875rem;
color: var(--color-text-muted);
display: flex;
align-items: center;
gap: 8px;
}
.map-status.selected {
background: #ECFDF5;
color: var(--color-success);
}
.map-status-icon {
width: 18px;
height: 18px;
}
/* Form Fields */
.form-fields {
padding: 24px;
display: flex;
flex-direction: column;
gap: 24px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 6px;
}
label {
font-weight: 500;
font-size: 0.95rem;
display: flex;
align-items: center;
gap: 4px;
}
.field-hint {
font-size: 0.8rem;
color: var(--color-text-muted);
font-weight: 400;
}
select, textarea, input[type="text"], input[type="email"] {
width: 100%;
padding: 12px 14px;
font-size: 1rem;
font-family: inherit;
border: 1px solid var(--color-border);
border-radius: var(--radius);
background: var(--color-surface);
color: var(--color-text);
transition: border-color 0.15s, box-shadow 0.15s;
}
select:focus, textarea:focus, input:focus {
outline: none;
border-color: var(--color-primary);
box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1);
}
select {
cursor: pointer;
appearance: none;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2357534E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 12px center;
padding-right: 40px;
}
textarea {
min-height: 120px;
resize: vertical;
}
.optional-tag {
font-size: 0.75rem;
color: var(--color-text-muted);
font-weight: 400;
margin-left: 4px;
}
/* Radio Button Styles */
.radio-group {
display: flex;
flex-direction: column;
gap: 8px;
margin-top: 8px;
}
.radio-section-label {
font-size: 1rem;
color: var(--color-text-muted);
font-weight: 500;
margin-top: 12px;
margin-bottom: 4px;
}
.radio-section-label:first-child {
margin-top: 0;
}
.radio-option {
display: flex;
align-items: center;
gap: 10px;
padding: 12px 14px;
border: 1px solid var(--color-border);
border-radius: var(--radius);
cursor: pointer;
transition: border-color 0.15s, background 0.15s;
}
.radio-option:hover {
border-color: var(--color-primary);
background: rgba(29, 78, 216, 0.02);
}
.radio-option input[type="radio"] {
width: 18px;
height: 18px;
margin: 0;
accent-color: var(--color-primary);
cursor: pointer;
}
.radio-option span {
font-size: 1rem;
color: var(--color-text);
}
.radio-option.selected {
border-color: var(--color-primary);
background: rgba(29, 78, 216, 0.05);
}
/* Error States */
.form-group.error select,
.form-group.error textarea,
.form-group.error input {
border-color: var(--color-error);
}
.form-group.error .radio-option {
border-color: var(--color-error);
}
.error-message {
font-size: 0.8rem;
color: var(--color-error);
display: none;
}
.form-group.error .error-message {
display: block;
}
/* Submit Button */
.submit-section {
padding: 0 24px 24px;
}
button[type="submit"] {
width: 100%;
padding: 14px 24px;
font-size: 1rem;
font-weight: 600;
font-family: inherit;
background: var(--color-primary);
color: white;
border: none;
border-radius: var(--radius);
cursor: pointer;
transition: background 0.15s, transform 0.1s;
}
button[type="submit"]:hover {
background: var(--color-primary-hover);
}
button[type="submit"]:active {
transform: scale(0.98);
}
button[type="submit"]:disabled {
background: #A8A29E;
cursor: not-allowed;
transform: none;
}
/* Success State */
.success-message {
display: none;
text-align: center;
padding: 60px 24px;
}
.success-message.visible {
display: block;
}
.success-icon {
width: 64px;
height: 64px;
background: #ECFDF5;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 20px;
}
.success-icon svg {
width: 32px;
height: 32px;
color: var(--color-success);
}
.success-message h2 {
font-family: 'Fraunces', Georgia, serif;
font-size: 1.5rem;
margin-bottom: 8px;
}
.success-message p {
color: var(--color-text-muted);
}
.submit-another-btn {
margin-top: 24px;
padding: 12px 24px;
font-size: 1rem;
font-weight: 500;
font-family: inherit;
background: transparent;
color: var(--color-primary);
border: 2px solid var(--color-primary);
border-radius: var(--radius);
cursor: pointer;
transition: background 0.15s, color 0.15s;
}
.submit-another-btn:hover {
background: var(--color-primary);
color: white;
}
.form-content {
display: block;
}
.form-content.hidden {
display: none;
}
/* Custom Marker */
.custom-marker {
width: 32px;
height: 40px;
cursor: pointer;
}
/* Responsive */
@media (max-width: 480px) {
.container {
padding: 24px 16px 40px;
}
#map {
height: 280px;
}
.map-header, .form-fields, .submit-section {
padding-left: 20px;
padding-right: 20px;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<img src="images/MappingManhattan600x85.png" alt="Community Mapping" class="header-logo">
<p class="subtitle">Tell us what matters in Manhattan</p>
</header>
<div class="form-card">
<form id="survey-form">
<div class="form-content" id="form-content">
<!-- Map Section -->
<div class="map-section">
<div class="map-header">
<div class="map-label">
Drop a pin on the map <span class="required-star">*</span>
</div>
<div class="map-hint">Click anywhere on the map to select a location</div>
</div>
<div id="map"></div>
<div class="map-status" id="map-status">
<svg class="map-status-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<path d="M12 6v6l4 2"/>
</svg>
<span id="map-status-text">No location selected</span>
</div>
</div>
<!-- Form Fields -->
<div class="form-fields">
<!-- Question 1 -->
<div class="form-group" id="group-map-type">
<label>
What map did you add to? <span class="required-star">*</span>
</label>
<select id="map-type" required>
<option value="">Select an option...</option>
<option value="Arts & Culture">Arts & Culture</option>
<option value="Small Businesses">Small Businesses</option>
<option value="Parks & Open Space">Parks & Open Space</option>
<option value="Streetscape">Streetscape</option>
<option value="Housing">Housing</option>
</select>
<span class="error-message">Please select a map type</span>
</div>
<!-- Question 2 (conditional) -->
<div class="form-group" id="group-pin-type" style="display: none;">
<label>
What did you pin? <span class="required-star">*</span>
</label>
<div class="radio-group" id="pin-type-radios">
<!-- Radio options populated by JavaScript -->
</div>
<span class="error-message">Please select what you pinned</span>
</div>
<!-- Question 3 -->
<div class="form-group" id="group-story">
<label>
What's the story behind what you pinned? <span class="required-star">*</span>
</label>
<textarea id="story" placeholder="Tell us about this place..." required></textarea>
<span class="error-message">Please share the story behind your pin</span>
</div>
<!-- Question 4 -->
<div class="form-group">
<label>
Name <span class="optional-tag">(optional)</span>
</label>
<input type="text" id="name" placeholder="Your name">
</div>
<!-- Question 5 -->
<div class="form-group">
<label>
Email <span class="optional-tag">(optional)</span>
</label>
<input type="email" id="email" placeholder="you@example.com">
</div>
</div>
<!-- Submit -->
<div class="submit-section">
<button type="submit" id="submit-btn">Submit</button>
</div>
</div>
<!-- Success Message -->
<div class="success-message" id="success-message">
<div class="success-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M20 6L9 17l-5-5"/>
</svg>
</div>
<h2>Thank you!</h2>
<p>Your contribution has been recorded.</p>
<button type="button" class="submit-another-btn" id="submit-another-btn">Submit another</button>
</div>
</form>
</div>
</div>
<script>
// ============================================
// CONFIGURATION - Update these values
// ============================================
// Replace with your Mapbox access token
const MAPBOX_TOKEN = 'pk.eyJ1IjoiYmV0YW55YyIsImEiOiJjbWwxOTMwYjgwNTdoM2hwemJrYmduZmt2In0.eicIosNvd4f8gK7jsVBMkA';
// Replace with your Google Apps Script web app URL
const APPS_SCRIPT_URL = 'https://script.google.com/macros/s/AKfycbx_Y-pQha4ECsD0TxT7n87DUcNbFBiWG9zhUXCkcske-3t-h6eqowxUbnKPYQMzsZi6Rw/exec';
// ============================================
// PIN TYPE OPTIONS
// ============================================
const pinTypeOptions = {
'Arts & Culture': [
'My favorite hidden gem',
'Support for an arts organization',
'New cultural spaces',
'Public art installations'
],
'Small Businesses': [
'My favorite small business',
'Empty storefronts in our borough'
],
'Parks & Open Space': [
'New open space',
'A park redesign',
'More public programming',
'Improved maintenance'
],
'Streetscape': [
'More public restrooms',
'More trees and greenery',
'Improved pedestrian safety',
'Improved lighting'
],
'Housing': [
'More new housing',
'Affordable housing preservation'
],
};
// ============================================
// MAP SETUP
// ============================================
mapboxgl.accessToken = MAPBOX_TOKEN;
// Manhattan bounds
const manhattanBounds = [
[-74.0479, 40.6829], // Southwest
[-73.9067, 40.8820] // Northeast
];
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v12',
center: [-73.985, 40.758], // Midtown Manhattan
zoom: 12,
maxBounds: manhattanBounds
});
map.addControl(new mapboxgl.NavigationControl(), 'top-right');
// Marker state
let marker = null;
let selectedLat = null;
let selectedLng = null;
// Create custom marker element
function createMarkerElement() {
const el = document.createElement('div');
el.innerHTML = `
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16 0C7.163 0 0 7.163 0 16c0 11 16 24 16 24s16-13 16-24c0-8.837-7.163-16-16-16z" fill="#1D4ED8"/>
<circle cx="16" cy="16" r="6" fill="white"/>
</svg>
`;
el.className = 'custom-marker';
return el;
}
// Handle map click
map.on('click', (e) => {
selectedLat = e.lngLat.lat;
selectedLng = e.lngLat.lng;
// Remove existing marker
if (marker) {
marker.remove();
}
// Add new marker (draggable)
marker = new mapboxgl.Marker({ element: createMarkerElement(), draggable: true })
.setLngLat([selectedLng, selectedLat])
.addTo(map);
// Update coordinates when marker is dragged
marker.on('dragend', () => {
const lngLat = marker.getLngLat();
selectedLat = lngLat.lat;
selectedLng = lngLat.lng;
document.getElementById('map-status-text').textContent = `Location selected: ${selectedLat.toFixed(5)}, ${selectedLng.toFixed(5)}`;
});
// Update status
const statusEl = document.getElementById('map-status');
const statusTextEl = document.getElementById('map-status-text');
statusEl.classList.add('selected');
statusTextEl.textContent = `Location selected: ${selectedLat.toFixed(5)}, ${selectedLng.toFixed(5)}`;
});
// ============================================
// CONDITIONAL RADIO BUTTON LOGIC
// ============================================
const mapTypeSelect = document.getElementById('map-type');
const pinTypeRadios = document.getElementById('pin-type-radios');
const pinTypeGroup = document.getElementById('group-pin-type');
// Get selected pin type value from radio buttons
function getSelectedPinType() {
const selected = document.querySelector('input[name="pin-type"]:checked');
return selected ? selected.value : '';
}
// Create a radio option element
function createRadioOption(value, index) {
const label = document.createElement('label');
label.className = 'radio-option';
label.innerHTML = `
<input type="radio" name="pin-type" value="${value}" id="pin-type-${index}">
<span>${value}</span>
`;
// Add click handler for selected state
label.addEventListener('click', () => {
document.querySelectorAll('.radio-option').forEach(opt => opt.classList.remove('selected'));
label.classList.add('selected');
});
return label;
}
// Create a section label element
function createSectionLabel(text) {
const div = document.createElement('div');
div.className = 'radio-section-label';
div.textContent = text;
return div;
}
mapTypeSelect.addEventListener('change', () => {
const selectedMapType = mapTypeSelect.value;
if (selectedMapType && pinTypeOptions[selectedMapType]) {
// Show pin type group
pinTypeGroup.style.display = 'flex';
// Clear existing radios
pinTypeRadios.innerHTML = '';
const options = pinTypeOptions[selectedMapType];
let radioIndex = 0;
if (selectedMapType === 'Arts & Culture') {
// Arts & Culture: First option, then "Or, where you'd like to see...", then rest
pinTypeRadios.appendChild(createRadioOption(options[0], radioIndex++));
pinTypeRadios.appendChild(createSectionLabel("Or, where you'd like to see..."));
for (let i = 1; i < options.length; i++) {
pinTypeRadios.appendChild(createRadioOption(options[i], radioIndex++));
}
} else if (selectedMapType === 'Small Businesses') {
// Small Businesses: Just options, no section label
options.forEach(option => {
pinTypeRadios.appendChild(createRadioOption(option, radioIndex++));
});
} else {
// Housing, Parks & Open Space, Streetscape: "Where I'd like to see..." then options
pinTypeRadios.appendChild(createSectionLabel("Where I'd like to see..."));
options.forEach(option => {
pinTypeRadios.appendChild(createRadioOption(option, radioIndex++));
});
}
} else {
// Hide pin type group
pinTypeGroup.style.display = 'none';
pinTypeRadios.innerHTML = '';
}
});
// ============================================
// FORM VALIDATION & SUBMISSION
// ============================================
const form = document.getElementById('survey-form');
const submitBtn = document.getElementById('submit-btn');
function validateForm() {
let isValid = true;
// Clear previous errors
document.querySelectorAll('.form-group').forEach(g => g.classList.remove('error'));
// Check location
if (!selectedLat || !selectedLng) {
const statusEl = document.getElementById('map-status');
statusEl.style.background = '#FEF2F2';
statusEl.style.color = '#DC2626';
document.getElementById('map-status-text').textContent = 'Please select a location on the map';
isValid = false;
}
// Check map type
if (!mapTypeSelect.value) {
document.getElementById('group-map-type').classList.add('error');
isValid = false;
}
// Check pin type (only if map type is selected)
if (mapTypeSelect.value && !getSelectedPinType()) {
document.getElementById('group-pin-type').classList.add('error');
isValid = false;
}
// Check story
if (!document.getElementById('story').value.trim()) {
document.getElementById('group-story').classList.add('error');
isValid = false;
}
return isValid;
}
form.addEventListener('submit', async (e) => {
e.preventDefault();
if (!validateForm()) {
return;
}
// Disable submit button
submitBtn.disabled = true;
submitBtn.textContent = 'Submitting...';
// Gather form data
const formData = {
latitude: selectedLat,
longitude: selectedLng,
mapType: mapTypeSelect.value,
pinType: getSelectedPinType(),
story: document.getElementById('story').value.trim(),
name: document.getElementById('name').value.trim(),
email: document.getElementById('email').value.trim(),
timestamp: new Date().toISOString()
};
try {
const response = await fetch(APPS_SCRIPT_URL, {
method: 'POST',
mode: 'no-cors', // Apps Script requires this
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData)
});
// Show success (no-cors means we can't read the response, but it usually works)
document.getElementById('form-content').classList.add('hidden');
document.getElementById('success-message').classList.add('visible');
} catch (error) {
console.error('Submission error:', error);
alert('There was an error submitting the form. Please try again.');
submitBtn.disabled = false;
submitBtn.textContent = 'Submit';
}
});
// ============================================
// SUBMIT ANOTHER
// ============================================
document.getElementById('submit-another-btn').addEventListener('click', () => {
// Reset form fields
form.reset();
// Reset map marker
if (marker) {
marker.remove();
marker = null;
}
selectedLat = null;
selectedLng = null;
// Reset map status
const statusEl = document.getElementById('map-status');
statusEl.classList.remove('selected');
statusEl.style.background = '';
statusEl.style.color = '';
document.getElementById('map-status-text').textContent = 'No location selected';
// Reset map view
map.jumpTo({ center: [-73.985, 40.758], zoom: 12 });
// Hide and clear pin type radios
pinTypeGroup.style.display = 'none';
pinTypeRadios.innerHTML = '';
// Reset submit button
submitBtn.disabled = false;
submitBtn.textContent = 'Submit';
// Clear error states
document.querySelectorAll('.form-group').forEach(g => g.classList.remove('error'));
// Show form, hide success
document.getElementById('form-content').classList.remove('hidden');
document.getElementById('success-message').classList.remove('visible');
});
</script>
</body>
</html>