diff --git a/README.md b/README.md index 7937b95..5df9828 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ Note that, unlike in **geocsv**, *THERE IS NO DEFAULT PIN*, as there is no serve `geocsv-lite` now experimentally displays GPX and KML formated XML, by using [leaflet-omnivore](https://github.com/mapbox/leaflet-omnivore). While `leaflet-omnivore` also parses CSV, it doesn't handle the CSV as richly as GeoCSV does natively, so we don't use Omnivore to parse CSV. +Having said that, while omnivore correctly extracts and renders boundaries from KML there's a lot of other data in KML that it doesn't (e.g. it doesn't render the requested `Style` on elements, including the rather important `BallonStyle`), so I'm not entirely satisfied and might revisit this to do my own parse/render engine. + ## Setup To get an interactive development environment run: diff --git a/resources/public/index.html b/resources/public/index.html index a989e53..d9b368e 100644 --- a/resources/public/index.html +++ b/resources/public/index.html @@ -110,6 +110,16 @@ crossorigin=""/ -->

+

+ Map using inline KML +

+

+ This is more limited than I would like, because of cross-site scripting + blocks; the URL must be sourced from the same host as the page. +

+
+

Use this page as a crib for how to use GeoCSV Lite in your projects. In order @@ -282,7 +292,7 @@ crossorigin=""> geocsv_lite.core.initialise_map_element("url-map", csv_url); /* Map using KML from URL */ - geocsv_lite.core.initialise_map_element("kml-map", url + "data/wild-lands/doc.kml"); + geocsv_lite.core.initialise_map_element("kml-map", url + "data/wild-lands/doc-with-balloons.kml"); diff --git a/src/geocsv_lite/data.cljs b/src/geocsv_lite/data.cljs index 3e6bd2e..1e29e57 100644 --- a/src/geocsv_lite/data.cljs +++ b/src/geocsv_lite/data.cljs @@ -200,15 +200,22 @@ map view identified by `k`." [f k data-source] (let [view (get-view k)] - (if-not - (case (:format f) + (if-let [layer (case (:format f) :gpx (case (:type f) - :url (.addTo (.gpx js/omnivore data-source) view)) + :url (.gpx js/omnivore data-source) + :inline (.gpx.parse js/omnivore data-source)) :kml (case (:type f) - :url (.addTo (.kml js/omnivore data-source) view)) + :url (.kml js/omnivore data-source) + :inline (.kml.parse js/omnivore data-source)) :json ;; assuming geojson here, which is dodgy. (case (:type f) - :url (.addTo (.kml js/omnivore data-source) view))) + :url (.addTo (.geojson js/omnivore data-source) view)))] + (do + (.addTo layer view) + ;; zoom and pan the view to the bounds of the layer. + ;; map.fitBounds(runLayer.getBounds()); + (.fitBounds view (.getBounds layer)) + (n/message (str "Added " (:format f) " layer"))) (n/error (str "Cannot yet handle " f))))) (defn get-data