Changeset 2775

Show
Ignore:
Timestamp:
03/20/08 14:20:00 (10 months ago)
Author:
ksprotte
Message:

finished poi xml and kml handlers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/projects/bos/m2/packages.lisp

    r2632 r2775  
    209209           #:poi-center-x 
    210210           #:poi-center-y 
     211           #:poi-center-lon-lat 
    211212           #:make-poi-javascript 
    212  
     213           #:write-poi-xml 
     214           #:write-poi-kml 
     215            
    213216           ;; news 
    214217           #:news-item 
  • trunk/projects/bos/m2/poi.lisp

    r2147 r2775  
    121121(defmethod poi-center-y ((poi poi)) 
    122122  (second (poi-area poi))) 
     123 
     124(defun poi-center-lon-lat (poi) 
     125  (geo-utm:utm-x-y-to-lon-lat (+ +nw-utm-x+ (poi-center-x poi)) (- +nw-utm-y+ (poi-center-y poi)) +utm-zone+ t)) 
    123126 
    124127(defun make-poi-javascript (language) 
     
    177180        (format t "poi['thumbnail'] = 0;~%") 
    178181        (format t "pois.push(poi);~%"))))) 
     182 
     183(defun write-poi-xml (poi &optional prefix) 
     184  (macrolet ((with-element (qname &body body) 
     185               `(with-element* (prefix ,qname) ,@body))) 
     186    (labels ((format-hash-table (element-name hash-table) 
     187               (with-element element-name 
     188                 (maphash (lambda (k v)                         
     189                            (with-element "content" 
     190                              (attribute "lang" k) 
     191                              (text v))) 
     192                          hash-table))) 
     193             (format-store-image (element-name store-image) 
     194               (with-element element-name 
     195                 (with-element "id" (text (princ-to-string (store-object-id store-image)))) 
     196                 (with-element "name" (text (store-image-name store-image))) 
     197                 (with-element "width" (text (princ-to-string (store-image-width store-image)))) 
     198                 (with-element "height" (text (princ-to-string (store-image-height store-image))))))) 
     199      (with-accessors ((id store-object-id) 
     200                       (name poi-name) 
     201                       (title poi-title) 
     202                       (subtitle poi-subtitle) 
     203                       (description poi-description) 
     204                       (airals poi-airals) 
     205                       (images poi-images) 
     206                       (panoramas poi-panoramas) 
     207                       (movies poi-movies)) poi 
     208        (with-element "poi" 
     209          (with-element "id" (text (princ-to-string id))) 
     210          (with-element "name" (text name)) 
     211          (format-hash-table "title" title) 
     212          (format-hash-table "subtitle" subtitle) 
     213          (format-hash-table "description" description)         
     214          (with-element "airals" 
     215            (mapc (alexandria:curry #'format-store-image "airal") airals)) 
     216          (with-element "images" 
     217            (mapc (alexandria:curry #'format-store-image "image") images)) 
     218          (with-element "panoramas" 
     219            (mapc (alexandria:curry #'format-store-image "panorama") panoramas)) 
     220          (with-element "movies" 
     221            (dolist (url movies) 
     222              (with-element "movie" 
     223                (with-element "url" (text url)))))))))) 
     224 
     225(defun write-poi-kml (poi) 
     226  (with-element "Placemark" 
     227    (with-element "name" (text (poi-name poi))) 
     228    (with-element "description" 
     229      (with-namespace ("bos" "http://headcraft.de/bos") 
     230        (write-poi-xml poi "bos"))) 
     231    (with-element "Point" 
     232      (with-element "coordinates" 
     233        (text (format nil "~{~F,~}0" (poi-center-lon-lat poi))))))) 
  • trunk/projects/bos/web/poi-handlers.lisp

    r2763 r2775  
    395395 
    396396(defmethod handle-object ((handler poi-xml-handler) poi) 
    397   (labels ((format-hash-table (element-name hash-table) 
    398              (with-element element-name 
    399                (maphash (lambda (k v)                         
    400                           (with-element "content" 
    401                             (attribute "lang" k) 
    402                             (text v))) 
    403                         hash-table))) 
    404            (format-store-image (element-name store-image) 
    405              (with-element element-name 
    406                (with-element "id" (text (princ-to-string (store-object-id store-image)))) 
    407                (with-element "name" (text (store-image-name store-image))) 
    408                (with-element "width" (text (princ-to-string (store-image-width store-image)))) 
    409                (with-element "height" (text (princ-to-string (store-image-height store-image))))))) 
    410     (with-accessors ((id store-object-id) 
    411                      (name poi-name) 
    412                      (title poi-title) 
    413                      (subtitle poi-subtitle) 
    414                      (description poi-description) 
    415                      (airals poi-airals) 
    416                      (images poi-images) 
    417                      (panoramas poi-panoramas) 
    418                      (movies poi-movies)) poi 
    419       (with-xml-response (:root-element "poi") 
    420         (with-element "id" (text (princ-to-string id))) 
    421         (with-element "name" (text name)) 
    422         (format-hash-table "title" title) 
    423         (format-hash-table "subtitle" subtitle) 
    424         (format-hash-table "description" description)         
    425         (with-element "airals" 
    426           (mapc (alexandria:curry #'format-store-image "airal") airals)) 
    427         (with-element "images" 
    428           (mapc (alexandria:curry #'format-store-image "image") images)) 
    429         (with-element "panoramas" 
    430           (mapc (alexandria:curry #'format-store-image "panorama") panoramas)) 
    431         (with-element "movies" 
    432           (dolist (url movies) 
    433             (with-element "movie" 
    434               (with-element "url" (text url))))))))) 
    435  
     397  (with-xml-response () 
     398    (write-poi-xml poi))) 
     399 
     400(defclass poi-kml-handler (object-handler) 
     401  () 
     402  (:default-initargs :object-class 'poi :query-function #'find-poi)) 
     403 
     404 
     405(defmethod handle-object ((handler poi-kml-handler) poi) 
     406  (with-xml-response () 
     407    (sax:processing-instruction cxml::*sink* "xml-stylesheet" "href=\"/static/trivial.xsl\" type=\"text/xsl\"") 
     408    (with-namespace (nil "http://earth.google.com/kml/2.1") 
     409      (with-element "kml" 
     410        (write-poi-kml poi))))) 
     411 
     412(defclass poi-kml-all-handler (page-handler) 
     413  ()) 
     414 
     415(defmethod handle ((handler poi-kml-all-handler)) 
     416  (with-xml-response () 
     417    ;; (sax:processing-instruction cxml::*sink* "xml-stylesheet" "href=\"/static/tri.xsl\" type=\"text/xsl\"") 
     418    (with-namespace (nil "http://earth.google.com/kml/2.1") 
     419      (with-element "kml" 
     420        (with-element "Document" 
     421          (mapc #'write-poi-kml (remove-if-not #'poi-area (class-instances 'poi)))))))) 
     422 
  • trunk/projects/bos/web/webserver.lisp

    r2763 r2775  
    212212                                        ("/poi-image" poi-image-handler) 
    213213                                        ("/poi-xml" poi-xml-handler) 
     214                                        ("/poi-kml-all" poi-kml-all-handler) 
     215                                        ("/poi-kml" poi-kml-handler) 
    214216                                        ("/map-browser" map-browser-handler) 
    215217                                        ("/poi-javascript" poi-javascript-handler)