Changeset 2562

Show
Ignore:
Timestamp:
02/19/08 17:42:05 (9 months ago)
Author:
ksprotte
Message:

added demo-kml function to generate the fat demo file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/bos/projects/bos/web/kml-handlers.lisp

    r2425 r2562  
    4747    (with-element "Document" 
    4848      (dolist (c (contract-neighbours contract 50)) 
    49        (let ((polygon (m2s-polygon-lon-lat (contract-m2s c))) 
    50              (name (user-full-name (contract-sponsor c)))) 
    51          (with-element "Placemark" 
    52            (with-element "name" (utf-8-text (format nil "~A ~Dm²" 
    53                                                     (if name name "anonymous") 
    54                                                     (length (contract-m2s c))))) 
    55            (with-element "description" (utf-8-text (contract-description c :de))) 
    56            (with-element "Style" 
    57              (attribute "id" "#region") 
    58              (with-element "LineStyle" 
    59                (with-element "color" (text "ffff3500"))) 
    60              (with-element "PolyStyle" 
    61                (with-element "color" (text (kml-format-color (contract-color c) 175))))) 
    62            (with-element "Polygon" 
    63              (with-element "styleUrl" "#region") 
    64              (with-element "tessellate" (text "1")) 
    65              (with-element "outerBoundaryIs" 
    66                (with-element "LinearRing" 
    67                  (with-element "coordinates" 
    68                    (text (kml-format-points polygon))))))) 
    69          ;; the center contract 
    70          (when (eq c contract) 
    71            (with-element "Placemark" 
    72              (with-element "name" (utf-8-text (format nil "~A ~Dm²" 
    73                                                       (if name name "anonymous") 
    74                                                       (length (contract-m2s c))))) 
    75              (with-element "description" (utf-8-text (contract-description c :de))) 
    76              (with-element "Point" 
    77                (with-element "coordinates" 
    78                  (text (kml-format-points (list (contract-center-lon-lat c))))))))))))) 
     49        (let ((polygon (m2s-polygon-lon-lat (contract-m2s c))) 
     50              (name (user-full-name (contract-sponsor c)))) 
     51          (with-element "Placemark" 
     52            (with-element "name" (utf-8-text (format nil "~A ~Dm²" 
     53                                                     (if name name "anonymous") 
     54                                                     (length (contract-m2s c))))) 
     55            (with-element "description" (utf-8-text (contract-description c :de))) 
     56            (with-element "Style" 
     57              (attribute "id" "#region") 
     58              (with-element "LineStyle" 
     59                (with-element "color" (text "ffff3500"))) 
     60              (with-element "PolyStyle" 
     61                (with-element "color" (text (kml-format-color (contract-color c) 175))))) 
     62            (with-element "Polygon" 
     63              (with-element "styleUrl" "#region") 
     64              (with-element "tessellate" (text "1")) 
     65              (with-element "outerBoundaryIs" 
     66                (with-element "LinearRing" 
     67                  (with-element "coordinates" 
     68                    (text (kml-format-points polygon))))))) 
     69          ;; the center contract 
     70          (when (eq c contract) 
     71            (with-element "Placemark" 
     72              (with-element "name" (utf-8-text (format nil "~A ~Dm²" 
     73                                                       (if name name "anonymous") 
     74                                                       (length (contract-m2s c))))) 
     75              (with-element "description" (utf-8-text (contract-description c :de))) 
     76              (with-element "Point" 
     77                (with-element "coordinates" 
     78                  (text (kml-format-points (list (contract-center-lon-lat c))))))))))))) 
    7979 
    8080(defmethod handle-object ((handle-object contract-kml-handler) (object null) req) 
    8181  (error "Contract not found.")) 
     82 
     83;;; static kml file demo generator 
     84(defun demo-kml (&optional (path #p"/tmp/demo.kml")) 
     85  (with-open-file (out path :direction :output :if-exists :supersede 
     86                       :element-type '(unsigned-byte 8)) 
     87    (write-line "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" out) 
     88    (write-line "<kml xmlns=\"http://earth.google.com/kml/2.2\">" out) 
     89    (cxml:with-xml-output (cxml:make-octet-stream-sink out) 
     90      (with-element "Document" 
     91        (dolist (c (subseq (class-instances 'contract) 0 10)) 
     92          (let ((polygon (m2s-polygon-lon-lat (contract-m2s c))) 
     93                (name (user-full-name (contract-sponsor c)))) 
     94            (with-element "Placemark" 
     95              (with-element "name" (utf-8-text (format nil "~A ~Dm²" 
     96                                                       (if name name "anonymous") 
     97                                                       (length (contract-m2s c))))) 
     98              (with-element "description" (utf-8-text (contract-description c :de))) 
     99              (with-element "Style" 
     100                (attribute "id" "#region") 
     101                (with-element "LineStyle" 
     102                  (with-element "color" (text "ffff3500"))) 
     103                (with-element "PolyStyle" 
     104                  (with-element "color" (text (kml-format-color (contract-color c) 175))))) 
     105              (with-element "Polygon" 
     106                (with-element "styleUrl" "#region") 
     107                (with-element "tessellate" (text "1")) 
     108                (with-element "outerBoundaryIs" 
     109                  (with-element "LinearRing" 
     110                    (with-element "coordinates" 
     111                      (text (kml-format-points polygon))))))))) 
     112        (dolist (poi (class-instances 'poi)) 
     113          (when (and (poi-area poi) 
     114                     (gethash "en" (poi-title poi))) 
     115            (destructuring-bind (poi-x poi-y) (poi-area poi) 
     116              (let ((utm-x (+ +nw-utm-x+ poi-x)) 
     117                    (utm-y (- +nw-utm-y+ poi-y)))      
     118                (with-element "Placemark" 
     119                  (with-element "name" (text (gethash "en" (poi-title poi)))) 
     120                  (when (gethash "en" (poi-description poi)) 
     121                    (with-element "description" (text (gethash "en" (poi-description poi))))) 
     122                  (with-element "Point" 
     123                    (with-element "coordinates" 
     124                      (text (kml-format-points (list (geo-utm:utm-x-y-to-lon-lat utm-x utm-y +utm-zone+ t))))))))))))) 
     125    (write-line "</kml>" out))) 
     126 
     127(demo-kml) 
     128