| 1 |
(in-package :bos.web) |
|---|
| 2 |
|
|---|
| 3 |
(enable-interpol-syntax) |
|---|
| 4 |
|
|---|
| 5 |
(defun map-navigator (x y base-url &key formcheck) |
|---|
| 6 |
(labels ((pfeil-image (name) |
|---|
| 7 |
(html ((:img :border "0" :width "16" :height "16" :src (format nil "/images/~:[trans.gif~;~:*pfeil-~A.gif~]" name))))) |
|---|
| 8 |
(td-link-to (x y name &optional (link-format (concatenate 'string base-url "~D/~D"))) |
|---|
| 9 |
(html (:td (if (or (minusp x) |
|---|
| 10 |
(minusp y) |
|---|
| 11 |
(>= (+ 270 x) 10800) |
|---|
| 12 |
(>= (+ 270 y) 10800)) |
|---|
| 13 |
(pfeil-image nil) |
|---|
| 14 |
(html ((:a :href (format nil link-format x y)) |
|---|
| 15 |
(pfeil-image name)))))))) |
|---|
| 16 |
(html |
|---|
| 17 |
((:form :id "mapnavigator" :name "mapnavigator") |
|---|
| 18 |
((:table :border "1") |
|---|
| 19 |
(:tr (:th "Navigate") (:th "Coordinates") (:th "Layers")) |
|---|
| 20 |
(:tr ((:td :align "center") |
|---|
| 21 |
((:table :cellspacing "1" :cellpadding "1" :border "0") |
|---|
| 22 |
(:tr (td-link-to (- x 90) (- y 90) "ol") |
|---|
| 23 |
(td-link-to x (- y 90) "o") |
|---|
| 24 |
(td-link-to (+ x 90) (- y 90) "or")) |
|---|
| 25 |
(:tr (td-link-to (- x 90) y "l") |
|---|
| 26 |
:td |
|---|
| 27 |
(td-link-to (+ x 90) y "r")) |
|---|
| 28 |
(:tr (td-link-to (- x 90) (+ y 90) "ul") |
|---|
| 29 |
(td-link-to x (+ y 90) "u") |
|---|
| 30 |
(td-link-to (+ x 90) (+ y 90) "ur")))) |
|---|
| 31 |
(:td |
|---|
| 32 |
((:table) |
|---|
| 33 |
(:tr (:td "X:") (:td (text-field "xcoord" :size "5" :value x))) |
|---|
| 34 |
(:tr (:td "Y:") (:td (text-field "ycoord" :size "5" :value y))) |
|---|
| 35 |
(:tr ))) |
|---|
| 36 |
(:td |
|---|
| 37 |
(with-query-params (background areas contracts) |
|---|
| 38 |
;; xxx should use tile-layers |
|---|
| 39 |
(unless (or background areas contracts) |
|---|
| 40 |
(setq background t |
|---|
| 41 |
areas t |
|---|
| 42 |
contracts t)) |
|---|
| 43 |
(html |
|---|
| 44 |
((:table) |
|---|
| 45 |
(:tr (:td (checkbox-field "background" "sat image" :checked background))) |
|---|
| 46 |
(:tr (:td (checkbox-field "areas" "allocation areas" :checked areas))) |
|---|
| 47 |
(:tr (:td (checkbox-field "contracts" "contracts" :checked contracts)))))))) |
|---|
| 48 |
(:tr ((:td :align "center" :colspan "3") |
|---|
| 49 |
(submit-button "view" "view" :formcheck formcheck) |
|---|
| 50 |
(submit-button "save" "save")))))))) |
|---|
| 51 |
|
|---|
| 52 |
(defclass image-tile-handler (cachable-handler object-handler) |
|---|
| 53 |
()) |
|---|
| 54 |
|
|---|
| 55 |
(defmethod object-handler-get-object ((handler image-tile-handler)) |
|---|
| 56 |
(destructuring-bind (x y &rest operations) (decoded-handler-path handler) |
|---|
| 57 |
(declare (ignore operations)) |
|---|
| 58 |
(setf x (parse-integer x)) |
|---|
| 59 |
(setf y (parse-integer y)) |
|---|
| 60 |
(ensure-map-tile x y))) |
|---|
| 61 |
|
|---|
| 62 |
(defmethod handle-object ((handler image-tile-handler) (tile (eql nil))) |
|---|
| 63 |
(error-404)) |
|---|
| 64 |
|
|---|
| 65 |
(defun parse-operations (&rest operation-strings) |
|---|
| 66 |
(mapcar #'(lambda (operation-string) |
|---|
| 67 |
(destructuring-bind (operation &rest arguments) (split "," operation-string) |
|---|
| 68 |
(apply #'list (make-keyword-from-string operation) arguments))) |
|---|
| 69 |
operation-strings)) |
|---|
| 70 |
|
|---|
| 71 |
(defmethod handle-object ((handler image-tile-handler) tile) |
|---|
| 72 |
;; xxx parse url another time - the parse result of |
|---|
| 73 |
;; object-handler-get-object should really be kept in the request |
|---|
| 74 |
(destructuring-bind (x y &rest operation-strings) (decoded-handler-path handler) |
|---|
| 75 |
(declare (ignore x y)) |
|---|
| 76 |
(let ((changed-time (image-tile-changed-time tile))) |
|---|
| 77 |
(hunchentoot:handle-if-modified-since changed-time) |
|---|
| 78 |
(let ((image (image-tile-image tile (apply #'parse-operations operation-strings)))) |
|---|
| 79 |
(emit-image-to-browser image :png |
|---|
| 80 |
:date changed-time |
|---|
| 81 |
:max-age 60) |
|---|
| 82 |
(cl-gd:destroy-image image))))) |
|---|
| 83 |
|
|---|
| 84 |
(defclass enlarge-tile-handler (image-tile-handler) |
|---|
| 85 |
()) |
|---|
| 86 |
|
|---|
| 87 |
(defun tile-active-layers-from-request-params (tile) |
|---|
| 88 |
(let (active-layers |
|---|
| 89 |
(all-layer-names (mapcar #'symbol-name (image-tile-layers tile)))) |
|---|
| 90 |
(dolist (layer-name all-layer-names) |
|---|
| 91 |
(when (query-param layer-name) |
|---|
| 92 |
(push layer-name active-layers))) |
|---|
| 93 |
(or (reverse active-layers) all-layer-names))) |
|---|
| 94 |
|
|---|
| 95 |
(defun tile-url (tile x y) |
|---|
| 96 |
(format nil "/overview/~D/~D~(~{/~A~}~)" |
|---|
| 97 |
x y |
|---|
| 98 |
(tile-active-layers-from-request-params tile))) |
|---|
| 99 |
|
|---|
| 100 |
(defmethod handle-object ((handler enlarge-tile-handler) tile) |
|---|
| 101 |
(let ((ismap-coords (decode-ismap-query-string)) |
|---|
| 102 |
(tile-x (tile-nw-x tile)) |
|---|
| 103 |
(tile-y (tile-nw-y tile))) |
|---|
| 104 |
(if ismap-coords |
|---|
| 105 |
(let* ((x (+ (floor (first ismap-coords) 4) tile-x)) |
|---|
| 106 |
(y (+ (floor (second ismap-coords) 4) tile-y)) |
|---|
| 107 |
(m2 (get-m2 x y)) |
|---|
| 108 |
(contract-id (and m2 (m2-contract m2) (store-object-id (m2-contract m2))))) |
|---|
| 109 |
(if contract-id |
|---|
| 110 |
(redirect #?"/contract/$(contract-id)") |
|---|
| 111 |
(with-bos-cms-page (:title "Not sold") |
|---|
| 112 |
(html (:h2 "this square meter has not been sold yet"))))) |
|---|
| 113 |
(with-bos-cms-page (:title "Browsing tile") |
|---|
| 114 |
(:a ((:a :href (hunchentoot:request-uri*)) |
|---|
| 115 |
((:img :width "360" :ismap "ismap" :height "360" :border "0" :src (tile-url tile tile-x tile-y))))) |
|---|
| 116 |
(map-navigator tile-x tile-y "/enlarge-overview/"))))) |
|---|