Getting better

This commit is contained in:
Simon Brooke 2020-04-11 11:44:02 +01:00
parent c791ab8ba8
commit d714dfc49e
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
3 changed files with 25 additions and 6 deletions

View file

@ -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 `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. 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 ## Setup
To get an interactive development environment run: To get an interactive development environment run:

View file

@ -110,6 +110,16 @@ crossorigin=""/ -->
</p> </p>
<div id="kml-map" <div id="kml-map"
style="height: 600px; width: 80%; border: thin solid gray;"></div> style="height: 600px; width: 80%; border: thin solid gray;"></div>
<h2>
Map using inline KML
</h2>
<p>
This is more limited than I would like, because of cross-site scripting
blocks; the URL <b>must</b> be sourced from the same host as the page.
</p>
<div id="inline-kml-map"
style="height: 600px; width: 80%; border: thin solid gray;">
</div>
<div id="doc"> <div id="doc">
<p> <p>
Use this page as a crib for how to use <b>GeoCSV Lite</b> in your projects. In order Use this page as a crib for how to use <b>GeoCSV Lite</b> in your projects. In order
@ -282,7 +292,7 @@ crossorigin=""></script -->
geocsv_lite.core.initialise_map_element("url-map", csv_url); geocsv_lite.core.initialise_map_element("url-map", csv_url);
/* Map using KML from 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");
</script> </script>
</body> </body>
</html> </html>

View file

@ -200,15 +200,22 @@
map view identified by `k`." map view identified by `k`."
[f k data-source] [f k data-source]
(let [view (get-view k)] (let [view (get-view k)]
(if-not (if-let [layer (case (:format f)
(case (:format f)
:gpx (case (:type 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) :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. :json ;; assuming geojson here, which is dodgy.
(case (:type f) (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))))) (n/error (str "Cannot yet handle " f)))))
(defn get-data (defn get-data