CL-MAPSCRIPT provides CFFI-based Common Lisp bindings for MapServer. Distribution provides C glue code that is compiled into a shared library and wrapped into CFFI-based common lisp bindings.
Loading the library:
(asdf:oos 'asdf:load-op :cffi)
;; define proper location of the C glue
(cffi:define-foreign-library libmapscript
(:unix (:or "./libmapscript.so")))
(asdf:oos 'asdf:load-op :cl-mapscript)
Basic operations:
;; creating a new point object
(new_pointObj ox oy 0.0d0 0.0d0)
;; loading a MAP file where mapFile is a string with MAP file name
(new_mapObj mapFile)
CL-MAPSCRIPT distribution contains a RENDER-POINT function that is used to render a point with given geographical coordinates using the settings of a given MAP file. Rendered coordinates can then be used to put a graphical mark on top of a rendered map image in HTML pages or elsewhere to create interactive graphics.
For example lets consider several cities in Kyiv oblast, Ukraine: Kyiv, Dymer, and Brovary and place clickable marks on a map of the Kyiv oblast:
(multiple-value-bind (pixelX pixelY relX relY)
(render-point 30.523611121111d0 50.45000001d0 "kyiv.map")
(format t "Kyiv: pixelX=~5F, pixelY=~5F, relX=~5F, relY=~5F~%" pixelX pixelY relX relY))
(multiple-value-bind (pixelX pixelY relX relY)
(render-point 30.309166676667d0 50.787222232222d0 "kyiv.map")
(format t "Dymer: pixelX=~5F, pixelY=~5F, relX=~5F, relY=~5F~%" pixelX pixelY relX relY))
(multiple-value-bind (pixelX pixelY relX relY)
(render-point 30.790277787778d0 50.511388898889d0 "kyiv.map")
(format t "Brovary: pixelX=~5F, pixelY=~5F, relX=~5F, relY=~5F~%" pixelX pixelY relX relY))
After the calculations we will obtain:
Kyiv: pixelX=171.5, pixelY=141.0, relX=42.88, relY=46.99
Dymer: pixelX=136.1, pixelY=105.4, relX=34.03, relY=35.14
Brovary: pixelX=210.4, pixelY=133.5, relX= 52.6, relY=44.49
The "pixelX
" and "pixelY
" values
provide information necessary to place corresponding clickable
marks over the map using the relative positioning scheme inside
the image-containing div
block.
Library provides most basic means to interact with the MapServer/MapScript functionality.
Code is distributed under the terms of the BSD License:
Copyright (c) 2012, Victor Anyakin <anyakinvictor@yahoo.com> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of thenor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.