|
xquery version "1.0-ml"; |
|
|
|
declare namespace ns = "http://www.marklogic.com/MLU/logbook"; |
|
declare variable $bbox as xs:string? := xdmp:get-request-field("BBOX", ()); |
|
|
|
xdmp:set-response-content-type("text/kml; charset=utf-8"), |
|
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2"> |
|
<Document> |
|
{ |
|
|
|
(: If the bounding box was provided by Google Earth, use it for a geo query :) |
|
let $pointQuery := |
|
if ($bbox) then |
|
let $lon1 := fn:number(fn:tokenize($bbox, ",")[1]) |
|
let $lon2 := fn:number(fn:tokenize($bbox, ",")[3]) |
|
let $lat1 := fn:number(fn:tokenize($bbox, ",")[2]) |
|
let $lat2 := fn:number(fn:tokenize($bbox, ",")[4]) |
|
let $west := fn:min(($lon1, $lon2)) |
|
let $east := fn:max(($lon1, $lon2)) |
|
let $north := fn:max(($lat1, $lat2)) |
|
let $south := fn:min(($lat1, $lat2)) |
|
|
|
let $boundingBox := cts:box($south, $west, $north, $east) |
|
return cts:element-pair-geospatial-query( xs:QName("ns:Place"), |
|
xs:QName("ns:Lat"), |
|
xs:QName("ns:Lon"), |
|
$boundingBox) |
|
else |
|
() |
|
|
|
(: Perform the search - only geo search for simplicity :) |
|
let $docs := cts:search(fn:doc(), $pointQuery, "unfiltered") |
|
|
|
(: KML is Lon, Lat, Alt :) |
|
for $doc in $docs |
|
return |
|
<Placemark> |
|
<name>{$doc//ns:Site/text()}</name> |
|
<description> |
|
{$doc//ns:DiverLName/text()}, {$doc//ns:DiverFName/text()}: |
|
{$doc//ns:Divedate/text()}<p>{$doc//ns:Comments/text()} |
|
</description> |
|
<Point> |
|
<coordinates>{$doc//ns:Lon/text()}, {$doc//ns:Lat/text()}</coordinates> |
|
</Point> |
|
</Placemark> |
|
} |
|
</Document> |
|
</kml> |