/
phoros-js.lisp
2630 lines (2518 loc) · 118 KB
/
phoros-js.lisp
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
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; PHOROS -- Photogrammetric Road Survey
;;; Copyright (C) 2010, 2011, 2012 Bert Burgemeister
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License along
;;; with this program; if not, write to the Free Software Foundation, Inc.,
;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
(in-package :phoros)
(hunchentoot:define-easy-handler (phoros.js) ()
"Serve some Javascript."
(assert-authentication)
(ps*
'(progn
(setf debug-info (@ *open-layers *console info))
(defmacro inner-html-with-id (id)
"innerHTML of element with id=\"id\"."
`(chain document (get-element-by-id ,id) inner-h-t-m-l))
(defmacro value-with-id (id)
"Value of element with id=\"id\"."
`(chain document (get-element-by-id ,id) value))
(defmacro checkbox-status-with-id (id)
"Whether checkbox with id=\"id\" is checked or not."
`(chain document (get-element-by-id ,id) checked))
(defvar *help-topics*
(create
:user-role
(who-ps-html
(:p "User role. \"Read\" can't write or modify anything.
\"Write\" may write user points and edit/delete their own
ones (and ownerless points). \"Admin\" may write user
points and edit/delete points written by anyone."))
:presentation-project-name
(who-ps-html
(:p "Presentation project name."))
:presentation-project-emptiness
(who-ps-html
(:p "This presentation project is empty. You can't do much
with it."))
:recommend-fresh-login
(who-ps-html
(:p "Sorry, but you are no longer authenticated. Your
session may have expired due to prolonged inactivity, or an
administrator has kicked you out by restarting the server.")
(:p "Please repeat the login process."))
:phoros-version
(who-ps-html
(:p "Phoros version.")
(:p "In a version string A.B.C, changes in A denote
incompatible changes in data (you can't access a database
set up by a different version of Phoros); changes in B mean
user-visible changes in feature set; changes in C denote
bug fixes and minor improvements."))
:h2-phoros-controls
(who-ps-html
(:p "Current action."))
:multiple-points-viewer
(who-ps-html
(:p "Try reading the text under mouse pointer."))
:delete-point-button
(who-ps-html
(:p "Delete current point."))
:finish-point-button
(who-ps-html
(:p "Store user point with its attributes kind,
numeric-description and description, and with its auxiliary
data into database; warn if the given set of attributes
isn't unique."))
:suggest-unique-button
(who-ps-html
(:h3 "Non-unique set of user point attributes")
(:p "Recommend a set of user point attributes that is
unique among the currently defined user points, preferably
by incrementing a portion of attribute numeric-description
that looks like a number."))
:force-duplicate-button
(who-ps-html
(:h3 "Non-unique set of user point attributes")
(:p "Store user point with its attributes kind,
numeric-description and description, and with its auxiliary
data into database; don't care whether the given set of
attributes is unique."))
:download-user-points-button
(who-ps-html
(:p "Download all user points as GeoJSON-fomatted text
file. Do this regularly if you don't want to lose your
work due to server crashes or major Phoros updates.")
(:p "Points saved this way can be fed back into your
project using the command line interface (on server or on
any other host where the database is reachable)."))
:point-kind
(who-ps-html
(:h3 "\"kind\"")
(:p "The standard ones, polygon, polyline, and solitary, are
rendered as asterisk, square, and triangle respectively.
The numbers 0 to 9, if used as values, are mapped to an
alternative set of distinct symbols. Anything else is
rendered as an X."))
:point-description
(who-ps-html
(:h3 "\"description\"")
(:p "Optional textual description of the set of user points
the current point belongs to."))
:point-numeric-description
(who-ps-html
(:h3 "\"numeric-description\"")
(:p "Optional description of the current user point. It is
occasionally used to label representations of this point in
streetmap and in images.")
(:p "It should contain a numeric part, possibly with
leading zeros, which will be incremented automatically to
make the attribute sets of points with otherwise identical
attributes unique."))
:point-creation-date
(who-ps-html
(:p "Creation date of current user point. Will be updated
when you change this point."))
:include-aux-data
(who-ps-html
(:p "Check this if the user point being created is to
include auxiliary data."))
:display-nearest-aux-data
(who-ps-html
(:p "Check this to see auxiliary data near streetmap
cursor.")
(:p "You need to uncheck this before you can select user
points in streetmap."))
:aux-point-distance
(who-ps-html
(:p "Select a set of auxiliary data by its distance (in
metres) from the current estimated position if any, or its
distance from streetmap cursor otherwise.")
(:p "Alternatively, a set of auxiliary data is also
selectable by clicking its representation in streetmap."))
:aux-data
(who-ps-html
(:p "Auxiliary data connected to this presentation project;
all the numeric values followed by all the text values if
any."))
:creator
(who-ps-html
(:p "Creator of current user point. Will be updated when
you change this point."))
:remove-work-layers-button
(who-ps-html
(:p "Discard the current, unstored user point or unselect
any selected user points. Zoom out all images. Keep
the rest of the workspace untouched."))
:blurb-button
(who-ps-html
(:p "View some info about Phoros."))
:logout-button
(who-ps-html
(:p "Finish this session after storing current streetmap
zoom status and your cursor position.")
(:p "Fresh login is required to continue."))
:streetmap
(who-ps-html
(:p "Clicking into the streetmap fetches images which most
probably feature the clicked point.")
(:p "To pan the map, drag the mouse. To zoom, spin the
mouse wheel, or hold shift down whilst dragging a box, or
double-click (shift double-click for larger zoom steps) a
point of interest."))
:image
(who-ps-html
(:p "Clicking into an image sets or resets the active point
there. Once a feature is marked by active points in more
than one image, the estimated position is calculated.")
(:p "To pan an image, drag the mouse. To zoom, spin the
mouse wheel, or hold shift down whilst dragging a box, or
double-click (shift double-click for larger zoom steps) a
point of interest."))
ol-Control-Pan-West-Item-Inactive
(who-ps-html
(:p "Move viewport left."))
ol-Control-Pan-East-Item-Inactive
(who-ps-html
(:p "Move viewport right."))
ol-Control-Pan-North-Item-Inactive
(who-ps-html
(:p "Move viewport up."))
ol-Control-Pan-South-Item-Inactive
(who-ps-html
(:p "Move viewport down."))
ol-Control-Zoom-In-Item-Inactive
(who-ps-html
(:p "Zoom in."))
ol-Control-Zoom-Out-Item-Inactive
(who-ps-html
(:p "Zoom out."))
streetmap-Zoom-To-Max-Extent-Item-Inactive
(who-ps-html
(:p "Zoom to the extent of presentation project."))
ol-Control-Zoom-To-Max-Extent-Item-Inactive
(who-ps-html
(:p "Zoom out completely, restoring the original view."))
:zoom-images-to-max-extent
(who-ps-html
(:p "Zoom all images out completely, restoring the original
view."))
:no-footprints-p
(who-ps-html
(:p "I haven't been able to display a set of images that
cover a common area because I couldn't find the necessary
information. As a fallback, I'm displaying a set of images
with points of view close to the point you selected.")
(:p "The server is probably trying to remedy this problem
but this may take some time."))
:auto-zoom
(who-ps-html
(:h3 "Auto Zoom")
(:p "Check this to automatically zoom into images once they
get an estimated position."))
:brighten-images
(who-ps-html
(:p "Check this to have underexposed images brightened up.")
(:p "Brightening starts with the next set of images and may
slow things down a bit."))
:walk-mode
(who-ps-html
(:p "Check this to snap your current position onto a line
along points of auxiliary data, and to keep streetmap
centered around current position."))
:decrease-step-size
(who-ps-html
(:p "Decrease step size. Double-click to decrease harder."))
:step-size
(who-ps-html
(:p "Step size in metres. Click to increase; double-click
to increase harder."))
:increase-step-size
(who-ps-html
(:p "Increase step size. Double-click to increase harder."))
:step-button
(who-ps-html
(:p "Move your position by one step on a line along points
of auxiliary data. Double-click to change direction."))
:image-layer-switcher
(who-ps-html
(:p "Toggle display of image."))
:image-usable
(who-ps-html
(:p "No photogrammetric survey possible as there isn't any
usable calibration data available for this image.")
(:p "This means no image footprints can be calculated
either which prevents me from selecting images covering a
common area."))
:image-trigger-time
(who-ps-html
(:p "Time this image was taken."))
base-layers-div
(who-ps-html
(:p "Choose a background streetmap."))
data-layers-div
(who-ps-html
(:p "Toggle visibility of data layers."))
:unselect-all-restrictions-button
(who-ps-html
(:h3 "Image Restrictions")
(:p "Remove all image restrictions."))
:restriction-select
(who-ps-html
(:h3 "Image Restrictions")
(:p "Select one ore more of the restrictions in order to
consider only a subset of the images available. No
selection at all means no restriction.")
(:p "Shift-click selects a range of restrictions,
control-click selects or unselects a particular
restriction, click selects a restriction unselecting
anything else."))
:streetmap-overview
(who-ps-html
(:p "Click to re-center streetmap, or drag the red
rectangle."))
:streetmap-mouse-position
(who-ps-html
(:p "Cursor position in geographic coordinates when cursor
is in streetmap."))
:h2-help
(who-ps-html
(:p "Hints on Phoros' displays and controls are shown here
while hovering over the respective elements."))))
(defun add-help-topic (topic element)
"Add mouse events to DOM element that initiate display of a
help message."
(when element
(setf (@ element onmouseover)
((lambda (x)
(lambda () (show-help x)))
topic))
(setf (@ element onmouseout) show-help)))
(defun add-help-events ()
"Add mouse events to DOM elements that initiate display of a
help message."
(for-in
(topic *help-topics*)
(add-help-topic topic (chain document (get-element-by-id topic)))
(dolist (element (chain document (get-elements-by-class-name topic)))
(add-help-topic topic element))))
(defun show-help (&optional topic)
"Put text on topic into help-display"
(setf (inner-html-with-id "help-display")
(let ((help-body (getprop *help-topics* topic)))
(if (undefined help-body)
""
help-body))))
(defvar *click-control*
(chain
*open-layers
(*class
(@ *open-layers *control)
(create
:initialize
(lambda (options)
(chain *open-layers
*control
prototype
initialize
(apply this arguments))
(setf (@ this handler)
(new (chain *open-layers
*handler
(*click this
(create
:click (@ this trigger)))))))))))
(defvar +unix-epoch+ (lisp *unix-epoch*)
"Seconds between Lisp epoch and UNIX epoch.")
(defvar +geographic+
(new (chain *open-layers (*projection "EPSG:4326"))))
(defvar +spherical-mercator+
(new (chain *open-layers (*projection "EPSG:900913"))))
(defvar +proxy-root+
(lisp *proxy-root*)
"First element of URL path; defaults to phoros but may be
turned into something different by an HTTP proxy
definition.")
(defvar +user-name+ (lisp (hunchentoot:session-value 'user-name))
"User's (short) name.")
(defvar +user-role+ (lisp (string-downcase (hunchentoot:session-value
'user-role)))
"User's permissions.")
(defvar +presentation-project-bbox-text+
(lisp (hunchentoot:session-value 'presentation-project-bbox)))
(defvar +presentation-project-bounds+
(chain (new (chain *open-layers
*bounds
(from-string
(or +presentation-project-bbox-text+
"-180,-89,180,89"))))
(transform +geographic+ +spherical-mercator+))
"Bounding box of the entire presentation project.")
(defvar +aux-data-p+
(lisp (hunchentoot:session-value 'aux-data-p)))
(defvar +aux-numeric-labels+
(lisp (when *aux-numeric-labels*
(coerce *aux-numeric-labels* 'vector))))
(defvar +aux-text-labels+
(lisp (when *aux-text-labels*
(coerce *aux-text-labels* 'vector))))
(defvar *images* (array) "Collection of the photos currently shown.")
(defvar *streetmap* undefined
"The streetmap shown to the user.")
(defvar *aux-point-distance-select* undefined
"The HTML element for selecting one of a few nearest
auxiliary points.")
(defvar *global-position* undefined
"Coordinates of the current estimated position")
(defvar *linestring-step-ratio* 4
"Look for auxiliary points to include into linestring within
a radius of *linestring-step-ratio* multilied by multiplied by
step-size.")
(defvar *current-nearest-aux-point*
(create attributes (create aux-numeric undefined
aux-text undefined))
"Attributes of currently selected point of auxiliary data.")
(defvar *bbox-strategy* (@ *open-layers *strategy *bbox*))
(setf (@ *bbox-strategy* prototype ratio) 1.5)
(setf (@ *bbox-strategy* prototype res-factor) 1.5)
(defvar *json-parser* (new (chain *open-layers *format *json*)))
(defvar *geojson-parser* (new (chain *open-layers *format *geo-j-s-o-n)))
(defvar *geojson-format* (chain *open-layers *format *geo-j-s-o-n))
(setf (@ *geojson-format* prototype ignore-extra-dims)
t) ;doesn't handle height anyway
(setf (@ *geojson-format* prototype external-projection)
+geographic+)
(setf (@ *geojson-format* prototype internal-projection)
+geographic+)
(defvar *wkt-parser*
(new (chain *open-layers
*format
(*wkt*
(create external-projection +geographic+
internal-projection +spherical-mercator+)))))
(defvar *http-protocol* (chain *open-layers *protocol *http*))
(setf (chain *http-protocol* prototype format) (new *geojson-format*))
(defvar *pristine-images-p* t
"T if none of the current images has been clicked into yet.")
(defvar *current-user-point* undefined
"The currently selected user-point.")
(defun write-permission-p (&optional (current-owner +user-name+))
"Nil if current user can't edit stuff created by
current-owner or, without arguments, new stuff."
(or (equal +user-role+ "admin")
(and (equal +user-role+ "write")
(or (equal +user-name+ current-owner)
(not current-owner)))))
(defun *image ()
"Anything necessary to deal with a photo."
(setf (@ this map)
(new
(chain
*open-layers
(*map
(create projection +spherical-mercator+
all-overlays t
controls (array (new (chain *open-layers
*control
(*navigation)))))))))
(setf (@ this dummy) false) ;TODO why? (omitting splices map components directly into *image)
)
(setf (@ *image prototype delete-photo)
delete-photo)
(setf (@ *image prototype photop)
photop)
(setf (@ *image prototype show-photo)
show-photo)
(setf (@ *image prototype draw-epipolar-line)
draw-epipolar-line)
(setf (@ *image prototype draw-active-point)
draw-active-point)
(setf (@ *image prototype draw-estimated-positions)
draw-estimated-positions)
(defun photo-path (photo-parameters)
"Create from stuff found in photo-parameters and in checkbox
brighten-images-p a path with parameters for use in an image
url."
(+ "/" +proxy-root+
"/lib/photo/"
(@ photo-parameters directory) "/"
(@ photo-parameters filename) "/"
(@ photo-parameters byte-position) ".png"
"?mounting-angle=" (@ photo-parameters mounting-angle)
"&bayer-pattern=" (@ photo-parameters bayer-pattern)
"&color-raiser=" (@ photo-parameters color-raiser)
(if (checkbox-status-with-id "brighten-images-p")
"&brightenp"
"")))
(defun has-layer-p (map layer-name)
"False if map doesn't have a layer called layer-name."
(chain map (get-layers-by-name layer-name) length))
(defun some-active-point-p ()
"False if no image in *images* has an Active Point."
(loop
for i across *images*
sum (has-layer-p (@ i map) "Active Point")))
(defun remove-layer (map layer-name)
"Destroy layer layer-name in map."
(when (has-layer-p map layer-name)
(chain map (get-layers-by-name layer-name) 0 (destroy))))
(defun remove-any-layers (layer-name)
"Destroy in all *images* and in *streetmap* the layer named layer-name."
(loop
for i across *images* do
(remove-layer (@ i map) layer-name))
(remove-layer *streetmap* layer-name))
(defun reset-controls ()
(disable-element-with-id "finish-point-button")
(disable-element-with-id "delete-point-button")
(disable-element-with-id "remove-work-layers-button")
(setf (inner-html-with-id "creator") nil)
(setf (inner-html-with-id "point-creation-date") nil)
(hide-aux-data-choice)
(setf (inner-html-with-id "aux-numeric-list") nil)
(setf (inner-html-with-id "aux-text-list") nil))
(defun disable-streetmap-nearest-aux-points-layer ()
"Get (@ *streetmap* nearest-aux-points-layer) out of the way,
i.e., remove features and disable feature select control so
it won't shadow any other control."
(chain *streetmap* nearest-aux-points-layer (remove-all-features))
(chain *streetmap* nearest-aux-points-select-control (deactivate))
(chain *streetmap* user-points-select-control (activate)))
(defun reset-layers-and-controls ()
"Destroy user-generated layers in *streetmap* and in all
*images*, and put controls into pristine state."
(remove-any-layers "Epipolar Line")
(remove-any-layers "Active Point")
(remove-any-layers "Estimated Position")
(remove-any-layers "User Point")
(chain *streetmap* user-points-select-control (unselect-all))
(when (and (not (equal undefined *current-user-point*))
(@ *current-user-point* layer))
(chain *streetmap*
user-points-select-control
(unselect *current-user-point*)))
(reset-controls)
(if +aux-data-p+
(switch-phoros-controls-to "aux-data-viewer")
(switch-phoros-controls-to "point-creator"))
(setf *pristine-images-p* t)
(if (and +aux-data-p+
(checkbox-status-with-id "display-nearest-aux-data-p"))
(request-aux-points-near-cursor 30)
(disable-streetmap-nearest-aux-points-layer))
(zoom-images-to-max-extent))
(defun enable-element-with-id (id)
"Activate HTML element with id=\"id\". Return t if element
was greyed out before."
(prog1
(chain document (get-element-by-id id) disabled)
(setf (chain document (get-element-by-id id) disabled) nil)))
(defun enable-elements-of-class (class-name)
"Activate HTML elements with class=\"class\"."
(loop
for element in (chain document
(get-elements-by-class-name class-name))
do (setf (@ element disabled) nil)))
(defun disable-element-with-id (id)
"Grey out HTML element with id=\"id\". Return t if element
was active before."
(prog1
(not (chain document (get-element-by-id id) disabled))
(setf (chain document (get-element-by-id id) disabled) t)))
(defun hide-element-with-id (id)
"Hide HTML element with id=\"id\"."
(setf (chain document (get-element-by-id id) style display)
"none"))
(defun hide-elements-of-class (class-name)
"Hide HTML elements with class=\"class\"."
(loop
for element in (chain document
(get-elements-by-class-name class-name))
do (setf (@ element style display) "none")))
(defun reveal-element-with-id (id)
"Reveal HTML element with id=\"id\"."
(setf (chain document (get-element-by-id id) style display)
""))
(defun reveal-elements-of-class (class-name)
"Reveal HTML elements with class=\"class\"."
(loop
for element in (chain document
(get-elements-by-class-name class-name))
do (setf (@ element style display) "")))
(defun switch-phoros-controls-to (class-name)
"Reveal elements of class class-name; hide anything else.
Unless there is auxiliary data available, hide the related
controls"
(let ((phoros-controls-classes
'("point-creator" "point-editor" "point-viewer"
"multiple-points-viewer" "aux-data-viewer")))
(dolist (c phoros-controls-classes)
(unless (equal c class-name) (hide-elements-of-class c))))
(reveal-elements-of-class class-name)
(unless +aux-data-p+
(hide-elements-of-class "aux-data-dependent")))
(defun hide-aux-data-choice ()
"Disable selector for auxiliary data."
(hide-element-with-id "include-aux-data")
(hide-element-with-id "aux-point-distance")
(setf (chain document
(get-element-by-id "aux-point-distance")
options
length)
0))
(defun refresh-layer (layer)
"Have layer re-request and redraw features."
(chain layer (refresh (create :force t))))
(defun present-photos ()
"Handle the response triggered by request-photos-for-point."
(let ((photo-parameters
(chain *json-parser*
(read (@ *streetmap*
photo-request-response response-text)))))
(loop
for i across *images*
do (chain i (delete-photo)))
(if (@ photo-parameters 0 footprintp)
(hide-element-with-id "no-footprints-p")
(reveal-element-with-id "no-footprints-p"))
(loop
for p across photo-parameters
for i across *images*
do
(setf (@ i photo-parameters) p)
(chain i (show-photo)))))
(defun recommend-fresh-login ()
"Notify user about invalid authentication."
(setf (inner-html-with-id "recommend-fresh-login")
"(not authenticated)")
(disable-element-with-id "download-user-points-button")
(disable-element-with-id "blurb-button")
(hide-element-with-id "phoros-controls")
(hide-element-with-id "images"))
(defun consolidate-combobox (combobox-id)
"Help faking a combobox: copy selected option into input."
(let* ((combobox-select (+ combobox-id "-select"))
(combobox-input (+ combobox-id "-input"))
(combobox-selected-index
(chain document
(get-element-by-id combobox-select)
selected-index)))
(when (< -1 combobox-selected-index)
(setf (value-with-id combobox-input)
(getprop (chain document
(get-element-by-id combobox-select)
options)
combobox-selected-index
'value)))
(chain document
(get-element-by-id combobox-input)
(focus))))
(defun unselect-combobox-selection (combobox-id)
"Help faking a combobox: unset selected option so any
selection there will trigger an onchange event."
(let ((combobox-select (+ combobox-id "-select")))
(setf (chain document
(get-element-by-id combobox-select)
selected-index)
-1)))
(defun stuff-combobox (combobox-id values &optional (selection -1))
"Stuff combobox with values. If selection is a non-negative
integer, select the respective item."
(let ((combobox-select (+ combobox-id "-select"))
(combobox-input (+ combobox-id "-input")))
(setf (chain document
(get-element-by-id combobox-select)
options
length)
0)
(loop for i in values do
(setf combobox-item
(chain document (create-element "option")))
(setf (@ combobox-item text) i)
(chain document
(get-element-by-id combobox-select)
(add combobox-item null)))
(setf (chain document
(get-element-by-id combobox-select)
selected-index)
selection)
(consolidate-combobox combobox-id)))
(defun stuff-user-point-comboboxes (&optional selectp)
"Stuff user point attribute comboboxes with sensible values.
If selectp it t, select the most frequently used one."
(let* ((response
(chain *json-parser*
(read (@ *streetmap*
user-point-choice-response response-text))))
(kinds
(chain response kinds (map (lambda (x)
(@ x kind)))))
(descriptions
(chain response descriptions (map (lambda (x)
(@ x description)))))
(best-used-kind -1)
(best-used-description -1))
(when selectp
(loop
with maximum = 0
for i across (@ response descriptions)
for k from 0
do (when (< maximum (@ i count))
(setf maximum (@ i count))
(setf best-used-description k)))
(loop
with maximum = 0
for i across (@ response kinds)
for k from 0
do (when (< maximum (@ i count))
(setf maximum (@ i count))
(setf best-used-kind k))))
(stuff-combobox
"point-kind" kinds best-used-kind)
(stuff-combobox
"point-description" descriptions best-used-description)))
(defun request-user-point-choice (&optional selectp)
"Stuff user point attribute comboboxes with sensible values.
If selectp it t, select the most frequently used one."
(setf (@ *streetmap* user-point-choice-response)
(chain
*open-layers
*request
(*post*
(create :url (+ "/" +proxy-root+
"/lib/user-point-attributes.json")
:data nil
:headers (create "Content-type" "text/plain")
:success (lambda ()
(stuff-user-point-comboboxes selectp))
:failure recommend-fresh-login)))))
(defun stuff-restriction-select ()
"Stuff available restriction IDs into restriction-select."
(let ((response
(chain *json-parser*
(read (@ *streetmap*
restriction-select-choice-response
response-text))))
(restriction-select-options
(chain document
(get-element-by-id "restriction-select")
options)))
(loop
for restriction in response
for i from 0
do (setf (elt restriction-select-options i)
(new (chain (*option restriction)))))))
(defun request-restriction-select-choice ()
"Stuff available restriction IDs into restriction-select."
(setf (@ *streetmap* restriction-select-choice-response)
(chain
*open-layers
*request
(*post*
(create :url (+ "/" +proxy-root+
"/lib/selectable-restrictions.json")
:data nil
:headers (create "Content-type" "text/plain")
:success stuff-restriction-select
:failure recommend-fresh-login)))))
(defun selected-restrictions ()
"Return list of restriction IDs selected by user."
(let ((restriction-select-options
(chain document
(get-element-by-id "restriction-select")
options)))
(loop
for restriction in restriction-select-options
when (@ restriction selected)
collect (@ restriction text))))
(defun unselect-all-restrictions ()
"Clear any selected restrictions."
(loop
for option across (chain document
(get-element-by-id "restriction-select")
options)
do (setf (@ option selected) f))
(request-photos))
(defun request-photos-after-click (event)
"Handle the response to a click into *streetmap*; fetch photo
data. Set or update streetmap cursor."
(request-photos (chain *streetmap*
(get-lon-lat-from-pixel (@ event xy)))))
(defun request-photos (&optional lonlat)
"Set streetmap cursor to lonlat if provided. Fetch photo
data for a point near streetmap cursor."
(when lonlat
(setf (@ *streetmap* clicked-lonlat) lonlat))
(if (checkbox-status-with-id "walk-p")
(request-aux-data-linestring-for-point
(@ *streetmap* clicked-lonlat))
(request-photos-for-point)))
(defun request-aux-data-linestring-for-point (lonlat-spherical-mercator)
"Fetch a linestring along auxiliary points near
lonlat-spherical-mercator."
(let ((lonlat-geographic
(chain lonlat-spherical-mercator
(clone)
(transform +spherical-mercator+ +geographic+))))
(request-aux-data-linestring (@ lonlat-geographic lon)
(@ lonlat-geographic lat)
(* *linestring-step-ratio*
(step-size-degrees))
(step-size-degrees))))
(defun request-photos-for-point ()
"Fetch photo data near (@ *streetmap* clicked-lonlat); set or
update streetmap cursor."
(remove-any-layers "Estimated Position")
(disable-streetmap-nearest-aux-points-layer)
(reset-layers-and-controls)
(let* ((lonlat-spherical-mercator
(@ *streetmap* clicked-lonlat))
(lonlat-geographic
(chain lonlat-spherical-mercator
(clone)
(transform +spherical-mercator+ +geographic+)))
(content
(chain *json-parser*
(write
(create :longitude (@ lonlat-geographic lon)
:latitude (@ lonlat-geographic lat)
:zoom (chain *streetmap* (get-zoom))
:count (lisp *number-of-images*)
:selected-restriction-ids
(selected-restrictions))))))
(chain *streetmap*
cursor-layer
(remove-all-features))
(chain *streetmap*
cursor-layer
(add-features
(new (chain *open-layers
*feature
(*vector
(new (chain
*open-layers
*geometry
(*point (@ lonlat-spherical-mercator
lon)
(@ lonlat-spherical-mercator
lat)))))))))
(chain *streetmap*
overview-cursor-layer
(remove-all-features))
(chain *streetmap*
overview-cursor-layer
(add-features
(new (chain *open-layers
*feature
(*vector
(new (chain
*open-layers
*geometry
(*point (@ lonlat-spherical-mercator
lon)
(@ lonlat-spherical-mercator
lat)))))))))
(setf (@ *streetmap* photo-request-response)
(chain
*open-layers
*request
(*post*
(create
:url (+ "/" +proxy-root+ "/lib/nearest-image-data")
:data content
:headers (create "Content-type" "text/plain"
"Content-length" (@ content length))
:success present-photos
:failure recommend-fresh-login))))))
(defun draw-epipolar-line ()
"Draw an epipolar line from response triggered by clicking
into a (first) photo."
(disable-streetmap-nearest-aux-points-layer)
(enable-element-with-id "remove-work-layers-button")
(switch-phoros-controls-to "point-creator")
(let* ((epipolar-line
(chain *json-parser*
(read
(@ this epipolar-request-response response-text))))
(points
(chain epipolar-line
(map (lambda (x)
(new (chain *open-layers
*geometry
(*point
(@ x :m) (@ x :n))))))))
(feature
(new (chain *open-layers
*feature
(*vector
(new (chain
*open-layers
*geometry
(*line-string points))))))))
(setf (@ feature render-intent) "temporary")
(chain this epipolar-layer
(add-features feature))))
(defun request-aux-points-near-cursor (count)
"Draw into streetmap the count nearest points of auxiliary
data around streetmap cursor."
(let ((lonlat-geographic
(chain (@ *streetmap* clicked-lonlat)
(clone)
(transform +spherical-mercator+ +geographic+))))
(request-nearest-aux-points
(create :longitude (@ lonlat-geographic lon)
:latitude (@ lonlat-geographic lat))
count)))
(defun request-nearest-aux-points (global-position count)
"Draw into streetmap the count nearest points of auxiliary
data around global-position."
(let ((global-position-etc global-position)
content)
(setf (@ global-position-etc count) count)
(setf content (chain *json-parser*
(write global-position-etc)))
(setf (@ *streetmap* aux-local-data-request-response)
(chain *open-layers
*request
(*post*
(create :url (+ "/" +proxy-root+
"/lib/aux-local-data")
:data content
:headers (create "Content-type" "text/plain"
"Content-length"
(@ content length))
:success draw-nearest-aux-points
:failure recommend-fresh-login))))))
(defun request-aux-data-linestring (longitude latitude radius step-size)
"Draw into streetmap a piece of linestring threaded along the
nearest points of auxiliary data inside radius."
(let* ((payload (create longitude longitude
latitude latitude
radius radius
step-size step-size
azimuth (@ *streetmap*
linestring-central-azimuth)))
(content (chain *json-parser* (write payload))))
(setf (@ *streetmap* aux-data-linestring-request-response)
(chain *open-layers
*request
(*post*
(create :url (+ "/" +proxy-root+
"/lib/aux-local-linestring.json")
:data content
:headers (create "Content-type" "text/plain"
"Content-length"
(@ content length))
:success draw-aux-data-linestring
:failure recommend-fresh-login))))))
(defun draw-estimated-positions ()
"Draw into streetmap and into all images points at Estimated
Position. Estimated Position is the point returned so far
from photogrammetric calculations that are triggered by
clicking into another photo. Also draw into streetmap the
nearest auxiliary points to Estimated Position."
(when (write-permission-p)
(setf (chain document
(get-element-by-id "finish-point-button")