Moved web root into root of project; this makes deployment easier.

Also deleted 'docs', which is now redundant.
This commit is contained in:
Simon Brooke 2020-02-27 14:18:29 +00:00
parent a5204c66b9
commit 743d8a1740
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
1592 changed files with 53626 additions and 139250 deletions

View file

@ -0,0 +1,37 @@
(ns geocsv-lite.core
(:require
[clojure.browser.dom :as dom]
[clojure.string :as cs]
[geocsv-lite.data :refer [get-csv-url get-data get-query-part-as-map]]
[geocsv-lite.map :as m]
[geocsv-lite.notify :as n]))
(defn ^:export initialise-map-element
"Create a map view in the element with this `id` and decorate it with
pins showing locations from this `data-source`. If `data-source` is nil
or an empty string, the content of the element will be used, if present."
[id data-source]
(let [sid (str id)
kid (keyword sid)
v (m/add-view sid 55 -4 10)]
(.whenReady v (fn [] (get-data kid data-source)))))
(defn ^:export initialise-map-element-from-content
[id]
(let [sid (str id)
kid (keyword sid)
v (m/add-view sid 55 -4 10)]
(.whenReady
v
(fn
[]
(get-data kid (.innerText (.getElementById js/document id)))))))
(defn on-js-reload []
;; optionally touch your app-state to force rerendering depending on
;; your application
;; (swap! app-state update-in [:__figwheel_counter] inc)
)

View file

@ -0,0 +1 @@
["^ ","~:rename-macros",["^ "],"~:renames",["^ "],"~:externs",["^ ","~$document",["^ ","~$getElementById",["^ "]],"~$Object",["^ ","~$innerText",["^ "]]],"~:use-macros",["^ "],"~:excludes",["~#set",[]],"~:name","~$geocsv-lite.core","~:imports",null,"~:requires",["^ ","~$dom","~$clojure.browser.dom","^?","^?","~$n","~$geocsv-lite.notify","~$m","~$geocsv-lite.map","~$cs","~$clojure.string","^A","^A","~$geocsv-lite.data","^D","^@","^@","^C","^C"],"~:cljs.spec/speced-vars",[],"~:uses",["^ ","~$get-data","^D","~$get-csv-url","^D","~$get-query-part-as-map","^D"],"~:defs",["^ ","~$initialise-map-element",["^ ","~:protocol-inline",null,"~:meta",["^ ","~:file","/home/simon/workspace/geocsv-lite/src/geocsv_lite/core.cljs","~:line",10,"~:column",16,"~:end-line",10,"~:end-column",38,"~:export",true,"~:arglists",["~#list",["~$quote",["^U",[["~$id","~$data-source"]]]]],"~:doc","Create a map view in the element with this `id` and decorate it with\n pins showing locations from this `data-source`. If `data-source` is nil\n or an empty string, the content of the element will be used, if present."],"^:","~$geocsv-lite.core/initialise-map-element","^N","src/geocsv_lite/core.cljs","^R",38,"~:method-params",["^U",[["^W","^X"]]],"~:protocol-impl",null,"^S",true,"~:arglists-meta",["^U",[null,null]],"^P",1,"~:variadic?",false,"^O",10,"~:ret-tag","~$any","^Q",10,"~:max-fixed-arity",2,"~:fn-var",true,"^T",["^U",["^V",["^U",[["^W","^X"]]]]],"^Y","Create a map view in the element with this `id` and decorate it with\n pins showing locations from this `data-source`. If `data-source` is nil\n or an empty string, the content of the element will be used, if present."],"~$initialise-map-element-from-content",["^ ","^L",null,"^M",["^ ","^N","/home/simon/workspace/geocsv-lite/src/geocsv_lite/core.cljs","^O",20,"^P",16,"^Q",20,"^R",51,"^S",true,"^T",["^U",["^V",["^U",[["^W"]]]]]],"^:","~$geocsv-lite.core/initialise-map-element-from-content","^N","src/geocsv_lite/core.cljs","^R",51,"^[",["^U",[["^W"]]],"^10",null,"^S",true,"^11",["^U",[null,null]],"^P",1,"^12",false,"^O",20,"^13","^14","^Q",20,"^15",1,"^16",true,"^T",["^U",["^V",["^U",[["^W"]]]]]],"~$on-js-reload",["^ ","^L",null,"^M",["^ ","^N","/home/simon/workspace/geocsv-lite/src/geocsv_lite/core.cljs","^O",33,"^P",7,"^Q",33,"^R",19,"^T",["^U",["^V",["^U",[[]]]]]],"^:","~$geocsv-lite.core/on-js-reload","^N","src/geocsv_lite/core.cljs","^R",19,"^[",["^U",[[]]],"^10",null,"^11",["^U",[null,null]],"^P",1,"^12",false,"^O",33,"^13","~$clj-nil","^Q",33,"^15",0,"^16",true,"^T",["^U",["^V",["^U",[[]]]]]]],"~:cljs.spec/registry-ref",[],"~:require-macros",null,"^Y",null]

View file

@ -0,0 +1,40 @@
// Compiled by ClojureScript 1.10.520 {}
goog.provide('geocsv_lite.core');
goog.require('cljs.core');
goog.require('clojure.browser.dom');
goog.require('clojure.string');
goog.require('geocsv_lite.data');
goog.require('geocsv_lite.map');
goog.require('geocsv_lite.notify');
/**
* Create a map view in the element with this `id` and decorate it with
* pins showing locations from this `data-source`. If `data-source` is nil
* or an empty string, the content of the element will be used, if present.
*/
geocsv_lite.core.initialise_map_element = (function geocsv_lite$core$initialise_map_element(id,data_source){
var sid = cljs.core.str.cljs$core$IFn$_invoke$arity$1(id);
var kid = cljs.core.keyword.call(null,sid);
var v = geocsv_lite.map.add_view.call(null,sid,(55),(-4),(10));
return v.whenReady(((function (sid,kid,v){
return (function (){
return geocsv_lite.data.get_data.call(null,kid,data_source);
});})(sid,kid,v))
);
});
goog.exportSymbol('geocsv_lite.core.initialise_map_element', geocsv_lite.core.initialise_map_element);
geocsv_lite.core.initialise_map_element_from_content = (function geocsv_lite$core$initialise_map_element_from_content(id){
var sid = cljs.core.str.cljs$core$IFn$_invoke$arity$1(id);
var kid = cljs.core.keyword.call(null,sid);
var v = geocsv_lite.map.add_view.call(null,sid,(55),(-4),(10));
return v.whenReady(((function (sid,kid,v){
return (function (){
return geocsv_lite.data.get_data.call(null,kid,document.getElementById(id).innerText());
});})(sid,kid,v))
);
});
goog.exportSymbol('geocsv_lite.core.initialise_map_element_from_content', geocsv_lite.core.initialise_map_element_from_content);
geocsv_lite.core.on_js_reload = (function geocsv_lite$core$on_js_reload(){
return null;
});
//# sourceMappingURL=core.js.map?rel=1582812678933

View file

@ -0,0 +1 @@
{"version":3,"file":"\/home\/simon\/workspace\/geocsv-lite\/js\/compiled\/out\/geocsv_lite\/core.js","sources":["core.cljs?rel=1582812678933"],"lineCount":40,"mappings":";AAAA;;;;;;;AASA;;;;;0CAAA,1CAAeA,4FAIZC,GAAGC;AAJN,AAKE,IAAMC,MAAI,4CAAKF;IACTG,MAAI,AAACC,4BAAQF;IACbG,IAAE,uCAAA,KAAA,KAAA,jDAACC,mCAAWJ;AAFpB,AAGE,OAAYG,YAAE;;AAAA,AAAO,OAACE,oCAASJ,IAAIF;;;;;AAEvC,uDAAA,vDAAeO,sHACZR;AADH,AAEI,IAAME,MAAI,4CAAKF;IACXG,MAAI,AAACC,4BAAQF;IACbG,IAAE,uCAAA,KAAA,KAAA,jDAACC,mCAAWJ;AAFlB,AAGA,OACEG,YACA;;AAAA,AAEE,OAACE,oCAASJ,IAAI,AAAY,AAAiBM,wBAAYT;;;;;AAI\/D,gCAAA,hCAAMU;AAAN,AAAA","names":["geocsv-lite.core\/initialise-map-element","id","data-source","sid","kid","cljs.core\/keyword","v","geocsv-lite.map\/add-view","geocsv-lite.data\/get-data","geocsv-lite.core\/initialise-map-element-from-content","js\/document","geocsv-lite.core\/on-js-reload"]}

View file

@ -0,0 +1,148 @@
(ns geocsv-lite.data
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [clojure.browser.dom :as dom]
[clojure.string :as cs]
[cljs-http.client :as http]
[cljs.core.async :refer [<!]]
[geocsv-lite.gis :as gis]
[geocsv-lite.map :refer [get-view]]
[geocsv-lite.notify :as n]))
(defn get-query-part-as-map
"Returns the query part of the current document URL as a keyword-string map."
;; not actually used in the current incarnation
[]
(let [query-nvs (map #(cs/split % "=") (cs/split (subs js/window.location.search 1) "&"))]
(when (every? #(= (count %) 2) query-nvs)
(zipmap (map #(keyword (first %)) query-nvs)(map #(nth % 1) query-nvs)))))
(defn get-csv-url
"`query` is expected a keyword-string map which may have keys:
* `:docid` whose value is a Google Sheets document id;
* `:uri` whose value is the URI of a JSON or CSV file.
If either of these keys is found, returns an appropriate URL, else nil."
;; not actually used in the current incarnation
[query]
(when (map? query)
(cond
(:docid query) (str
"https://docs.google.com/spreadsheets/d/"
(:docid query)
"/export?format=csv")
(:uri query) (:uri query))))
(defn prepare-records
"`data` is expected to be a vector of vectors, where the first vector
contains column headers and the remaining vectors contain records.
Return this as a vector of maps, with each map having keys taken from
the first vector and values taken from one of the subsequent vectors."
[data]
(let [cols (map
#(let [n (when-not
(empty? %)
(when (string? %)
(cs/lower-case
(cs/replace
(cs/trim %)
#"[^\w\d]+" "-"))))]
(keyword
(if (empty? n)
(gensym)
n)))
(first data))]
(map
(fn [r] (zipmap cols r))
(rest data))))
(defn default-handler
"When data is received from a URL, it is received asynchronously. This
is the default callback called with the `response` of the HTTP request,
and the keyword `k` identifying the map view, to populate the map with
data."
[response k]
(if
(= (:status response) 200)
(let [content (:body response)
records (prepare-records
(:data
(js->clj
(.parse js/Papa content
(clj->js {:dynamicTyping true}))
:keywordize-keys true)))]
(gis/refresh-map-pins (get-view k) records))
(n/error (str "Bad response from server: " (:status response)))))
(defn get-data-from-uri
"Get data for the view identified by this keyword `k` from this `uri`."
[k uri]
(go (let [response (<! (http/get uri {:with-credentials? "false"}))]
(default-handler response k))))
(defn get-data
"Get data for the view identified by this keyword `k` from this `data-source`.
The data source may be a URL, or a CSV or JSON formatted string."
[k data-source]
(js/console.debug (str "get-data: k = `" k "`; data-source = `" data-source "`"))
(let [p (js->clj (.parse js/Papa data-source) :keywordize-keys true)
data (if
(empty? (:errors p))
(:data p)
;; otherwise, is it JSON?
(try
(js->clj (.parse js/JSON data-source))
(catch :default _ nil)))]
;; almost anything can be a valid URL, so it's hard to verify that a given
;; string is not one. So we will assume that what we've been passed is a
;; URL unless we've been able to parse valid data out of it.
(js/console.debug "Found records: " (clj->js data))
(if
;; it looks like valid data if it's a vector of vectors.
(and (vector? data) (every? vector? data))
(let [records (prepare-records data)]
(n/message (str "Found " (count records) " records of inline data for map `" k "`"))
(gis/refresh-map-pins (get-view k) (prepare-records data)))
; else
(get-data-from-uri k data-source))))
(defn get-data-with-uri-and-handler
[uri handler-fn k]
(go (let [response (<! (http/get uri))]
(apply handler-fn (list response k)))))
;; (def data-source "Name, Latitude, Longitude
;; Nether Hazelfield Cottage, 54.816274, -3.887435
;; Over Hazelfield Cottage, 54.823192, -3.899516
;; Winter Palace, 54.822260, -3.920147
;; Craignair, 54.842321, -3.872055
;; Carlinscraig, 54.843224,-3.8730822
;; Orchardton, 54.859129, -3.854212
;; Elderslie, 54.845596, -3.866432")
;; (prepare-records
;; (:data (js->clj (.parse js/Papa data-source)
;; :keywordize-keys true)))
;; (get-data :inline-csv-map "http://localhost:3449/data/data.csv")
;; (get-data :inline-csv-map data-source)
;; (every? (fn [r] (and (vector? r) (every? vector? r))) (:data (js->clj (.parse js/Papa data-source)
;; :keywordize-keys true)))
;; (every? vector? (:data (js->clj (.parse js/Papa data-source)
;; :keywordize-keys true)))
;; (vector? (first (:data (js->clj (.parse js/Papa data-source)
;; :keywordize-keys true))))
;; (def p (:data (js->clj (.parse js/Papa data-source)
;; :keywordize-keys true)))
;; (every? vector? p)
;; (vector? p)
;; (every? vector? p)

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,313 @@
// Compiled by ClojureScript 1.10.520 {}
goog.provide('geocsv_lite.data');
goog.require('cljs.core');
goog.require('clojure.browser.dom');
goog.require('clojure.string');
goog.require('cljs_http.client');
goog.require('cljs.core.async');
goog.require('geocsv_lite.gis');
goog.require('geocsv_lite.map');
goog.require('geocsv_lite.notify');
/**
* Returns the query part of the current document URL as a keyword-string map.
*/
geocsv_lite.data.get_query_part_as_map = (function geocsv_lite$data$get_query_part_as_map(){
var query_nvs = cljs.core.map.call(null,(function (p1__25201_SHARP_){
return clojure.string.split.call(null,p1__25201_SHARP_,"=");
}),clojure.string.split.call(null,cljs.core.subs.call(null,window.location.search,(1)),"&"));
if(cljs.core.every_QMARK_.call(null,((function (query_nvs){
return (function (p1__25202_SHARP_){
return cljs.core._EQ_.call(null,cljs.core.count.call(null,p1__25202_SHARP_),(2));
});})(query_nvs))
,query_nvs)){
return cljs.core.zipmap.call(null,cljs.core.map.call(null,((function (query_nvs){
return (function (p1__25203_SHARP_){
return cljs.core.keyword.call(null,cljs.core.first.call(null,p1__25203_SHARP_));
});})(query_nvs))
,query_nvs),cljs.core.map.call(null,((function (query_nvs){
return (function (p1__25204_SHARP_){
return cljs.core.nth.call(null,p1__25204_SHARP_,(1));
});})(query_nvs))
,query_nvs));
} else {
return null;
}
});
/**
* `query` is expected a keyword-string map which may have keys:
*
* * `:docid` whose value is a Google Sheets document id;
* * `:uri` whose value is the URI of a JSON or CSV file.
*
* If either of these keys is found, returns an appropriate URL, else nil.
*/
geocsv_lite.data.get_csv_url = (function geocsv_lite$data$get_csv_url(query){
if(cljs.core.map_QMARK_.call(null,query)){
if(cljs.core.truth_(new cljs.core.Keyword(null,"docid","docid",832763997).cljs$core$IFn$_invoke$arity$1(query))){
return ["https://docs.google.com/spreadsheets/d/",cljs.core.str.cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"docid","docid",832763997).cljs$core$IFn$_invoke$arity$1(query)),"/export?format=csv"].join('');
} else {
if(cljs.core.truth_(new cljs.core.Keyword(null,"uri","uri",-774711847).cljs$core$IFn$_invoke$arity$1(query))){
return new cljs.core.Keyword(null,"uri","uri",-774711847).cljs$core$IFn$_invoke$arity$1(query);
} else {
return null;
}
}
} else {
return null;
}
});
/**
* `data` is expected to be a vector of vectors, where the first vector
* contains column headers and the remaining vectors contain records.
* Return this as a vector of maps, with each map having keys taken from
* the first vector and values taken from one of the subsequent vectors.
*/
geocsv_lite.data.prepare_records = (function geocsv_lite$data$prepare_records(data){
var cols = cljs.core.map.call(null,(function (p1__25205_SHARP_){
var n = ((cljs.core.empty_QMARK_.call(null,p1__25205_SHARP_))?null:((typeof p1__25205_SHARP_ === 'string')?clojure.string.lower_case.call(null,clojure.string.replace.call(null,clojure.string.trim.call(null,p1__25205_SHARP_),/[^\w\d]+/,"-")):null));
return cljs.core.keyword.call(null,((cljs.core.empty_QMARK_.call(null,n))?cljs.core.gensym.call(null):n));
}),cljs.core.first.call(null,data));
return cljs.core.map.call(null,((function (cols){
return (function (r){
return cljs.core.zipmap.call(null,cols,r);
});})(cols))
,cljs.core.rest.call(null,data));
});
/**
* When data is received from a URL, it is received asynchronously. This
* is the default callback called with the `response` of the HTTP request,
* and the keyword `k` identifying the map view, to populate the map with
* data.
*/
geocsv_lite.data.default_handler = (function geocsv_lite$data$default_handler(response,k){
if(cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"status","status",-1997798413).cljs$core$IFn$_invoke$arity$1(response),(200))){
var content = new cljs.core.Keyword(null,"body","body",-2049205669).cljs$core$IFn$_invoke$arity$1(response);
var records = geocsv_lite.data.prepare_records.call(null,new cljs.core.Keyword(null,"data","data",-232669377).cljs$core$IFn$_invoke$arity$1(cljs.core.js__GT_clj.call(null,Papa.parse(content,cljs.core.clj__GT_js.call(null,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"dynamicTyping","dynamicTyping",1380929723),true], null))),new cljs.core.Keyword(null,"keywordize-keys","keywordize-keys",1310784252),true)));
return geocsv_lite.gis.refresh_map_pins.call(null,geocsv_lite.map.get_view.call(null,k),records);
} else {
return geocsv_lite.notify.error.call(null,["Bad response from server: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"status","status",-1997798413).cljs$core$IFn$_invoke$arity$1(response))].join(''));
}
});
/**
* Get data for the view identified by this keyword `k` from this `uri`.
*/
geocsv_lite.data.get_data_from_uri = (function geocsv_lite$data$get_data_from_uri(k,uri){
var c__22951__auto__ = cljs.core.async.chan.call(null,(1));
cljs.core.async.impl.dispatch.run.call(null,((function (c__22951__auto__){
return (function (){
var f__22952__auto__ = (function (){var switch__22856__auto__ = ((function (c__22951__auto__){
return (function (state_25214){
var state_val_25215 = (state_25214[(1)]);
if((state_val_25215 === (1))){
var inst_25206 = [new cljs.core.Keyword(null,"with-credentials?","with-credentials?",-1773202222)];
var inst_25207 = ["false"];
var inst_25208 = cljs.core.PersistentHashMap.fromArrays(inst_25206,inst_25207);
var inst_25209 = cljs_http.client.get.call(null,uri,inst_25208);
var state_25214__$1 = state_25214;
return cljs.core.async.impl.ioc_helpers.take_BANG_.call(null,state_25214__$1,(2),inst_25209);
} else {
if((state_val_25215 === (2))){
var inst_25211 = (state_25214[(2)]);
var inst_25212 = geocsv_lite.data.default_handler.call(null,inst_25211,k);
var state_25214__$1 = state_25214;
return cljs.core.async.impl.ioc_helpers.return_chan.call(null,state_25214__$1,inst_25212);
} else {
return null;
}
}
});})(c__22951__auto__))
;
return ((function (switch__22856__auto__,c__22951__auto__){
return (function() {
var geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto__ = null;
var geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto____0 = (function (){
var statearr_25216 = [null,null,null,null,null,null,null];
(statearr_25216[(0)] = geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto__);
(statearr_25216[(1)] = (1));
return statearr_25216;
});
var geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto____1 = (function (state_25214){
while(true){
var ret_value__22858__auto__ = (function (){try{while(true){
var result__22859__auto__ = switch__22856__auto__.call(null,state_25214);
if(cljs.core.keyword_identical_QMARK_.call(null,result__22859__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
continue;
} else {
return result__22859__auto__;
}
break;
}
}catch (e25217){if((e25217 instanceof Object)){
var ex__22860__auto__ = e25217;
var statearr_25218_25220 = state_25214;
(statearr_25218_25220[(5)] = ex__22860__auto__);
cljs.core.async.impl.ioc_helpers.process_exception.call(null,state_25214);
return new cljs.core.Keyword(null,"recur","recur",-437573268);
} else {
throw e25217;
}
}})();
if(cljs.core.keyword_identical_QMARK_.call(null,ret_value__22858__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
var G__25221 = state_25214;
state_25214 = G__25221;
continue;
} else {
return ret_value__22858__auto__;
}
break;
}
});
geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto__ = function(state_25214){
switch(arguments.length){
case 0:
return geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto____0.call(this);
case 1:
return geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto____1.call(this,state_25214);
}
throw(new Error('Invalid arity: ' + arguments.length));
};
geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto__.cljs$core$IFn$_invoke$arity$0 = geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto____0;
geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto__.cljs$core$IFn$_invoke$arity$1 = geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto____1;
return geocsv_lite$data$get_data_from_uri_$_state_machine__22857__auto__;
})()
;})(switch__22856__auto__,c__22951__auto__))
})();
var state__22953__auto__ = (function (){var statearr_25219 = f__22952__auto__.call(null);
(statearr_25219[(6)] = c__22951__auto__);
return statearr_25219;
})();
return cljs.core.async.impl.ioc_helpers.run_state_machine_wrapped.call(null,state__22953__auto__);
});})(c__22951__auto__))
);
return c__22951__auto__;
});
/**
* Get data for the view identified by this keyword `k` from this `data-source`.
* The data source may be a URL, or a CSV or JSON formatted string.
*/
geocsv_lite.data.get_data = (function geocsv_lite$data$get_data(k,data_source){
console.debug(["get-data: k = `",cljs.core.str.cljs$core$IFn$_invoke$arity$1(k),"`; data-source = `",cljs.core.str.cljs$core$IFn$_invoke$arity$1(data_source),"`"].join(''));
var p = cljs.core.js__GT_clj.call(null,Papa.parse(data_source),new cljs.core.Keyword(null,"keywordize-keys","keywordize-keys",1310784252),true);
var data = ((cljs.core.empty_QMARK_.call(null,new cljs.core.Keyword(null,"errors","errors",-908790718).cljs$core$IFn$_invoke$arity$1(p)))?new cljs.core.Keyword(null,"data","data",-232669377).cljs$core$IFn$_invoke$arity$1(p):(function (){try{return cljs.core.js__GT_clj.call(null,JSON.parse(data_source));
}catch (e25222){var _ = e25222;
return null;
}})());
console.debug("Found records: ",cljs.core.clj__GT_js.call(null,data));
if(((cljs.core.vector_QMARK_.call(null,data)) && (cljs.core.every_QMARK_.call(null,cljs.core.vector_QMARK_,data)))){
var records = geocsv_lite.data.prepare_records.call(null,data);
geocsv_lite.notify.message.call(null,["Found ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.count.call(null,records))," records of inline data for map `",cljs.core.str.cljs$core$IFn$_invoke$arity$1(k),"`"].join(''));
return geocsv_lite.gis.refresh_map_pins.call(null,geocsv_lite.map.get_view.call(null,k),geocsv_lite.data.prepare_records.call(null,data));
} else {
return geocsv_lite.data.get_data_from_uri.call(null,k,data_source);
}
});
geocsv_lite.data.get_data_with_uri_and_handler = (function geocsv_lite$data$get_data_with_uri_and_handler(uri,handler_fn,k){
var c__22951__auto__ = cljs.core.async.chan.call(null,(1));
cljs.core.async.impl.dispatch.run.call(null,((function (c__22951__auto__){
return (function (){
var f__22952__auto__ = (function (){var switch__22856__auto__ = ((function (c__22951__auto__){
return (function (state_25230){
var state_val_25231 = (state_25230[(1)]);
if((state_val_25231 === (1))){
var inst_25223 = cljs_http.client.get.call(null,uri);
var state_25230__$1 = state_25230;
return cljs.core.async.impl.ioc_helpers.take_BANG_.call(null,state_25230__$1,(2),inst_25223);
} else {
if((state_val_25231 === (2))){
var inst_25225 = (state_25230[(2)]);
var inst_25226 = (new cljs.core.List(null,k,null,(1),null));
var inst_25227 = (new cljs.core.List(null,inst_25225,inst_25226,(2),null));
var inst_25228 = cljs.core.apply.call(null,handler_fn,inst_25227);
var state_25230__$1 = state_25230;
return cljs.core.async.impl.ioc_helpers.return_chan.call(null,state_25230__$1,inst_25228);
} else {
return null;
}
}
});})(c__22951__auto__))
;
return ((function (switch__22856__auto__,c__22951__auto__){
return (function() {
var geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto__ = null;
var geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto____0 = (function (){
var statearr_25232 = [null,null,null,null,null,null,null];
(statearr_25232[(0)] = geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto__);
(statearr_25232[(1)] = (1));
return statearr_25232;
});
var geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto____1 = (function (state_25230){
while(true){
var ret_value__22858__auto__ = (function (){try{while(true){
var result__22859__auto__ = switch__22856__auto__.call(null,state_25230);
if(cljs.core.keyword_identical_QMARK_.call(null,result__22859__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
continue;
} else {
return result__22859__auto__;
}
break;
}
}catch (e25233){if((e25233 instanceof Object)){
var ex__22860__auto__ = e25233;
var statearr_25234_25236 = state_25230;
(statearr_25234_25236[(5)] = ex__22860__auto__);
cljs.core.async.impl.ioc_helpers.process_exception.call(null,state_25230);
return new cljs.core.Keyword(null,"recur","recur",-437573268);
} else {
throw e25233;
}
}})();
if(cljs.core.keyword_identical_QMARK_.call(null,ret_value__22858__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
var G__25237 = state_25230;
state_25230 = G__25237;
continue;
} else {
return ret_value__22858__auto__;
}
break;
}
});
geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto__ = function(state_25230){
switch(arguments.length){
case 0:
return geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto____0.call(this);
case 1:
return geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto____1.call(this,state_25230);
}
throw(new Error('Invalid arity: ' + arguments.length));
};
geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto__.cljs$core$IFn$_invoke$arity$0 = geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto____0;
geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto__.cljs$core$IFn$_invoke$arity$1 = geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto____1;
return geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__22857__auto__;
})()
;})(switch__22856__auto__,c__22951__auto__))
})();
var state__22953__auto__ = (function (){var statearr_25235 = f__22952__auto__.call(null);
(statearr_25235[(6)] = c__22951__auto__);
return statearr_25235;
})();
return cljs.core.async.impl.ioc_helpers.run_state_machine_wrapped.call(null,state__22953__auto__);
});})(c__22951__auto__))
);
return c__22951__auto__;
});
//# sourceMappingURL=data.js.map?rel=1582812678925

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,212 @@
(ns ^{:doc "geocsv app map stuff."
:author "Simon Brooke"}
geocsv-lite.gis
(:require [cljs.reader :refer [read-string]]
[clojure.string :as cs]
[geocsv-lite.notify :as n]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
;;;; geocsv.gis: stuff to do with maps.
;;;;
;;;; This program is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU General Public License
;;;; as published by the Free Software Foundation; either version 2
;;;; of the License, or (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
;;;; USA.
;;;;
;;;; Copyright (C) 2016 Simon Brooke for Radical Independence Campaign
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; map stuff.
(defn get-current-location [view]
"Return the current location from the device, setting it in the database and
returning the locality. `view` is expected to be a Leaflet view."
(try
(if (.-geolocation js/navigator)
(.getCurrentPosition
(.-geolocation js/navigator)
(fn [position]
(let [lat (.-latitude (.-coords position))
lng (.-longitude (.-coords position))]
(n/message (str "Current location is: " lat ", " lng))
(if
(and view (float? lat) (float? lng))
(do
(.panTo view (.latLng js/L lat lng)))
(do
(n/message
(if view
(str "Geolocation failed lat: '" lat "'; lng '" lng "'")
"No value for subscription to [:view]"))
0)))))
(do
(n/message "Geolocation not available")
0))
(catch js/Object any
(n/error (str "Exception while trying to access location: " any))
0)))
(defn map-pin-click-handler
[id]
(n/message (str "Click handler for record #" id)))
(defn pin-image
"Return the name of a suitable pin image for this `record`."
[record]
(let [n (cs/capitalize
(cs/replace
(cs/lower-case
(str (:category record)))
#"[^a-z0-9]" "-"))]
(str
(if
(empty? n) "Unknown"
n)
"-pin")))
(defn popup-content
"Appropriate content for the popup of a map pin for this `record`."
[record]
(if
(map? record) ;; which it should be!
(str
"<h5>"
(:name record)
"</h5><dl>"
(apply
str
(map
#(str "<dt>" (name %) "</dt><dd>" (record %) "</dd>")
(filter #(record %) (keys record))))
"</dl>")))
(defn popup-table-content
"Appropriate content for the popup of a map pin for this `record`, as a
table. Obviously this is semantically wrong, but for styling reasons it's
worth trying."
[record]
(if
(map? record) ;; which it should be!
(str
"<h5>"
(:name record)
"</h5><table>"
(apply
str
(map
#(str "<tr><th>" (name %) "</th><td>" (record %) "</td></tr>")
(sort (filter #(record %) (keys record)))))
"</table>")))
(defn add-map-pin
"Add an appropriate map-pin for this `record` in this map `view`, if it
has a valid `:latitude` and `:longitude`."
[record index view]
(let [lat (js/Number (:latitude record))
lng (js/Number (:longitude record))]
(if
(and
(number? lat)
(number? lng)
(not (zero? lat))
(not (zero? lng)))
(let [pin (.icon js/L
(clj->js
{:iconAnchor [16 41]
:iconSize [32 42]
:iconUrl (str "img/map-pins/" (pin-image record) ".png")
:riseOnHover true
:shadowAnchor [16 23]
:shadowSize [57 24]
:shadowUrl "img/map-pins/shadow_pin.png"}))
marker (.marker js/L
(.latLng js/L lat lng)
(clj->js {:icon pin
:title (:name record)}))]
(.bindPopup marker (popup-table-content record))
(.addTo marker view)
(n/message (str "Added `"(:name record)"` in at " lat ", " lng))
marker))))
(defn map-remove-pins
"Remove all pins from this map `view`. Side-effecty; liable to be
problematic."
[view]
(if view
(.eachLayer view
#(if
(instance? js/L.Marker %)
(.removeLayer view %)))
view))
(defn compute-zoom
"See [explanation here](https://leafletjs.com/examples/zoom-levels/). Brief
summary: it's hard, but it doesn't need to be precise."
[min-lat max-lat min-lng max-lng]
(let [n (min (/ 360 (- max-lng min-lng)) (/ 180 (- max-lat min-lat)))]
(first
(remove
nil?
(map
#(if (> (reduce * (repeat 2 %)) n) %)
(range))))))
(defn compute-centre
"Compute, and return as a map with keys `:latitude` and `:longitude`, the
centre of the locations of these records as indicated by the values of their
`:latitude` and `:longitude` keys."
[records]
(try
(let [lats (remove zero?
(filter number? (map js/Number (map :latitude records))))
min-lat (apply min lats)
max-lat (apply max lats)
lngs (remove zero?
(filter number? (map js/Number (map :longitude records))))
min-lng (apply min lngs)
max-lng (apply max lngs)]
(if-not
(or (empty? lats) (empty? lngs))
{:latitude (+ min-lat (/ (- max-lat min-lat) 2))
:longitude (+ min-lng (/ (- max-lng min-lng) 2))
:zoom (compute-zoom min-lat max-lat min-lng max-lng)}
{}))
(catch :default
error
(n/error (str "Failed to compute centre because " error))
{})))
(defn refresh-map-pins
"Refresh the map pins on the current map. Side-effecty; liable to be
problematic."
[view records]
(let [view (map-remove-pins view)
centre (compute-centre records)]
(if
view
(do
(n/message
(str
"Mapped "
(count
(remove nil? (map #(add-map-pin %1 %2 view) records (range))))
" records, centre at " centre))
(if
(:latitude centre)
(.setView view (clj->js [(:latitude centre) (:longitude centre)]) (:zoom centre))))
(do (n/error "View is not yet ready")))))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,187 @@
// Compiled by ClojureScript 1.10.520 {}
goog.provide('geocsv_lite.gis');
goog.require('cljs.core');
goog.require('cljs.reader');
goog.require('clojure.string');
goog.require('geocsv_lite.notify');
geocsv_lite.gis.get_current_location = (function geocsv_lite$gis$get_current_location(view){
try{if(cljs.core.truth_(navigator.geolocation)){
return navigator.geolocation.getCurrentPosition((function (position){
var lat = position.coords.latitude;
var lng = position.coords.longitude;
geocsv_lite.notify.message.call(null,["Current location is: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(lat),", ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(lng)].join(''));
if(cljs.core.truth_((function (){var and__4120__auto__ = view;
if(cljs.core.truth_(and__4120__auto__)){
return ((cljs.core.float_QMARK_.call(null,lat)) && (cljs.core.float_QMARK_.call(null,lng)));
} else {
return and__4120__auto__;
}
})())){
return view.panTo(L.latLng(lat,lng));
} else {
geocsv_lite.notify.message.call(null,(cljs.core.truth_(view)?["Geolocation failed lat: '",cljs.core.str.cljs$core$IFn$_invoke$arity$1(lat),"'; lng '",cljs.core.str.cljs$core$IFn$_invoke$arity$1(lng),"'"].join(''):"No value for subscription to [:view]"));
return (0);
}
}));
} else {
geocsv_lite.notify.message.call(null,"Geolocation not available");
return (0);
}
}catch (e25189){if((e25189 instanceof Object)){
var any = e25189;
geocsv_lite.notify.error.call(null,["Exception while trying to access location: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(any)].join(''));
return (0);
} else {
throw e25189;
}
}});
geocsv_lite.gis.map_pin_click_handler = (function geocsv_lite$gis$map_pin_click_handler(id){
return geocsv_lite.notify.message.call(null,["Click handler for record #",cljs.core.str.cljs$core$IFn$_invoke$arity$1(id)].join(''));
});
/**
* Return the name of a suitable pin image for this `record`.
*/
geocsv_lite.gis.pin_image = (function geocsv_lite$gis$pin_image(record){
var n = clojure.string.capitalize.call(null,clojure.string.replace.call(null,clojure.string.lower_case.call(null,cljs.core.str.cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"category","category",-593092832).cljs$core$IFn$_invoke$arity$1(record))),/[^a-z0-9]/,"-"));
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(((cljs.core.empty_QMARK_.call(null,n))?"Unknown":n)),"-pin"].join('');
});
/**
* Appropriate content for the popup of a map pin for this `record`.
*/
geocsv_lite.gis.popup_content = (function geocsv_lite$gis$popup_content(record){
if(cljs.core.map_QMARK_.call(null,record)){
return ["<h5>",cljs.core.str.cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"name","name",1843675177).cljs$core$IFn$_invoke$arity$1(record)),"</h5><dl>",cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.apply.call(null,cljs.core.str,cljs.core.map.call(null,(function (p1__25190_SHARP_){
return ["<dt>",cljs.core.name.call(null,p1__25190_SHARP_),"</dt><dd>",cljs.core.str.cljs$core$IFn$_invoke$arity$1(record.call(null,p1__25190_SHARP_)),"</dd>"].join('');
}),cljs.core.filter.call(null,(function (p1__25191_SHARP_){
return record.call(null,p1__25191_SHARP_);
}),cljs.core.keys.call(null,record))))),"</dl>"].join('');
} else {
return null;
}
});
/**
* Appropriate content for the popup of a map pin for this `record`, as a
* table. Obviously this is semantically wrong, but for styling reasons it's
* worth trying.
*/
geocsv_lite.gis.popup_table_content = (function geocsv_lite$gis$popup_table_content(record){
if(cljs.core.map_QMARK_.call(null,record)){
return ["<h5>",cljs.core.str.cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"name","name",1843675177).cljs$core$IFn$_invoke$arity$1(record)),"</h5><table>",cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.apply.call(null,cljs.core.str,cljs.core.map.call(null,(function (p1__25192_SHARP_){
return ["<tr><th>",cljs.core.name.call(null,p1__25192_SHARP_),"</th><td>",cljs.core.str.cljs$core$IFn$_invoke$arity$1(record.call(null,p1__25192_SHARP_)),"</td></tr>"].join('');
}),cljs.core.sort.call(null,cljs.core.filter.call(null,(function (p1__25193_SHARP_){
return record.call(null,p1__25193_SHARP_);
}),cljs.core.keys.call(null,record)))))),"</table>"].join('');
} else {
return null;
}
});
/**
* Add an appropriate map-pin for this `record` in this map `view`, if it
* has a valid `:latitude` and `:longitude`.
*/
geocsv_lite.gis.add_map_pin = (function geocsv_lite$gis$add_map_pin(record,index,view){
var lat = Number(new cljs.core.Keyword(null,"latitude","latitude",394867543).cljs$core$IFn$_invoke$arity$1(record));
var lng = Number(new cljs.core.Keyword(null,"longitude","longitude",-1268876372).cljs$core$IFn$_invoke$arity$1(record));
if(((typeof lat === 'number') && (typeof lng === 'number') && ((!((lat === (0))))) && ((!((lng === (0))))))){
var pin = L.icon(cljs.core.clj__GT_js.call(null,new cljs.core.PersistentArrayMap(null, 7, [new cljs.core.Keyword(null,"iconAnchor","iconAnchor",970343173),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(16),(41)], null),new cljs.core.Keyword(null,"iconSize","iconSize",253109071),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(32),(42)], null),new cljs.core.Keyword(null,"iconUrl","iconUrl",-1868537869),["img/map-pins/",geocsv_lite.gis.pin_image.call(null,record),".png"].join(''),new cljs.core.Keyword(null,"riseOnHover","riseOnHover",1575955733),true,new cljs.core.Keyword(null,"shadowAnchor","shadowAnchor",643451688),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(16),(23)], null),new cljs.core.Keyword(null,"shadowSize","shadowSize",-1015046863),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(57),(24)], null),new cljs.core.Keyword(null,"shadowUrl","shadowUrl",1986496437),"img/map-pins/shadow_pin.png"], null)));
var marker = L.marker(L.latLng(lat,lng),cljs.core.clj__GT_js.call(null,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"icon","icon",1679606541),pin,new cljs.core.Keyword(null,"title","title",636505583),new cljs.core.Keyword(null,"name","name",1843675177).cljs$core$IFn$_invoke$arity$1(record)], null)));
marker.bindPopup(geocsv_lite.gis.popup_table_content.call(null,record));
marker.addTo(view);
geocsv_lite.notify.message.call(null,["Added `",cljs.core.str.cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"name","name",1843675177).cljs$core$IFn$_invoke$arity$1(record)),"` in at ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(lat),", ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(lng)].join(''));
return marker;
} else {
return null;
}
});
/**
* Remove all pins from this map `view`. Side-effecty; liable to be
* problematic.
*/
geocsv_lite.gis.map_remove_pins = (function geocsv_lite$gis$map_remove_pins(view){
if(cljs.core.truth_(view)){
return view.eachLayer((function (p1__25194_SHARP_){
if((p1__25194_SHARP_ instanceof L.Marker)){
return view.removeLayer(p1__25194_SHARP_);
} else {
return null;
}
}));
} else {
return view;
}
});
/**
* See [explanation here](https://leafletjs.com/examples/zoom-levels/). Brief
* summary: it's hard, but it doesn't need to be precise.
*/
geocsv_lite.gis.compute_zoom = (function geocsv_lite$gis$compute_zoom(min_lat,max_lat,min_lng,max_lng){
var n = (function (){var x__4222__auto__ = ((360) / (max_lng - min_lng));
var y__4223__auto__ = ((180) / (max_lat - min_lat));
return ((x__4222__auto__ < y__4223__auto__) ? x__4222__auto__ : y__4223__auto__);
})();
return cljs.core.first.call(null,cljs.core.remove.call(null,cljs.core.nil_QMARK_,cljs.core.map.call(null,((function (n){
return (function (p1__25195_SHARP_){
if((cljs.core.reduce.call(null,cljs.core._STAR_,cljs.core.repeat.call(null,(2),p1__25195_SHARP_)) > n)){
return p1__25195_SHARP_;
} else {
return null;
}
});})(n))
,cljs.core.range.call(null))));
});
/**
* Compute, and return as a map with keys `:latitude` and `:longitude`, the
* centre of the locations of these records as indicated by the values of their
* `:latitude` and `:longitude` keys.
*/
geocsv_lite.gis.compute_centre = (function geocsv_lite$gis$compute_centre(records){
try{var lats = cljs.core.remove.call(null,cljs.core.zero_QMARK_,cljs.core.filter.call(null,cljs.core.number_QMARK_,cljs.core.map.call(null,Number,cljs.core.map.call(null,new cljs.core.Keyword(null,"latitude","latitude",394867543),records))));
var min_lat = cljs.core.apply.call(null,cljs.core.min,lats);
var max_lat = cljs.core.apply.call(null,cljs.core.max,lats);
var lngs = cljs.core.remove.call(null,cljs.core.zero_QMARK_,cljs.core.filter.call(null,cljs.core.number_QMARK_,cljs.core.map.call(null,Number,cljs.core.map.call(null,new cljs.core.Keyword(null,"longitude","longitude",-1268876372),records))));
var min_lng = cljs.core.apply.call(null,cljs.core.min,lngs);
var max_lng = cljs.core.apply.call(null,cljs.core.max,lngs);
if((!(((cljs.core.empty_QMARK_.call(null,lats)) || (cljs.core.empty_QMARK_.call(null,lngs)))))){
return new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"latitude","latitude",394867543),(min_lat + ((max_lat - min_lat) / (2))),new cljs.core.Keyword(null,"longitude","longitude",-1268876372),(min_lng + ((max_lng - min_lng) / (2))),new cljs.core.Keyword(null,"zoom","zoom",-1827487038),geocsv_lite.gis.compute_zoom.call(null,min_lat,max_lat,min_lng,max_lng)], null);
} else {
return cljs.core.PersistentArrayMap.EMPTY;
}
}catch (e25196){var error = e25196;
geocsv_lite.notify.error.call(null,["Failed to compute centre because ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(error)].join(''));
return cljs.core.PersistentArrayMap.EMPTY;
}});
/**
* Refresh the map pins on the current map. Side-effecty; liable to be
* problematic.
*/
geocsv_lite.gis.refresh_map_pins = (function geocsv_lite$gis$refresh_map_pins(view,records){
var view__$1 = geocsv_lite.gis.map_remove_pins.call(null,view);
var centre = geocsv_lite.gis.compute_centre.call(null,records);
if(cljs.core.truth_(view__$1)){
geocsv_lite.notify.message.call(null,["Mapped ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.count.call(null,cljs.core.remove.call(null,cljs.core.nil_QMARK_,cljs.core.map.call(null,((function (view__$1,centre){
return (function (p1__25197_SHARP_,p2__25198_SHARP_){
return geocsv_lite.gis.add_map_pin.call(null,p1__25197_SHARP_,p2__25198_SHARP_,view__$1);
});})(view__$1,centre))
,records,cljs.core.range.call(null)))))," records, centre at ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(centre)].join(''));
if(cljs.core.truth_(new cljs.core.Keyword(null,"latitude","latitude",394867543).cljs$core$IFn$_invoke$arity$1(centre))){
return view__$1.setView(cljs.core.clj__GT_js.call(null,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"latitude","latitude",394867543).cljs$core$IFn$_invoke$arity$1(centre),new cljs.core.Keyword(null,"longitude","longitude",-1268876372).cljs$core$IFn$_invoke$arity$1(centre)], null)),new cljs.core.Keyword(null,"zoom","zoom",-1827487038).cljs$core$IFn$_invoke$arity$1(centre));
} else {
return null;
}
} else {
return geocsv_lite.notify.error.call(null,"View is not yet ready");
}
});
//# sourceMappingURL=gis.js.map?rel=1582812678901

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,91 @@
(ns geocsv-lite.map
(:require [geocsv-lite.notify :as n]))
;;; Cribbed heavily from
;;; https://github.com/reagent-project/reagent-cookbook/tree/master/recipes/leaflet
;;; but using OSM data because we can't afford commercial, so also cribbed from
;;; https://switch2osm.org/using-tiles/getting-started-with-leaflet/
;;; Note that this is raw reagent stylee; it should be refactoed into re-frame stylee
;;; when I understand it better.
;; which provider to use
(def ^:dynamic *map-provider* :osm)
(def osm-url "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png")
(def osm-attrib "Map data &copy; <a href='http://openstreetmap.org'>OpenStreetMap</a> contributors")
;; My gods mapbox is user-hostile!
(defn map-did-mount-mapbox
"Did-mount function loading map tile data from MapBox (proprietary).
Arguments are:
* `id` the element id of the HTML element to occupy (string);
* `lat` the latitude of the centre of the view (real number);
* `lng` the longitude of the centre of the view (real number);
* `zoom` the initial zoom level of the view (real number)."
[id lat lng zoom]
(let [view (.setView
(.map js/L id (clj->js {:zoomControl "false"}))
#js [lat lng]
zoom)]
;; NEED TO REPLACE FIXME with your mapID!
(.addTo (.tileLayer js/L "http://{s}.tiles.mapbox.com/v3/FIXME/{z}/{x}/{y}.png"
(clj->js {:attribution "Map data &copy; [...]"
:maxZoom 18})))
view))
(defn map-did-mount-osm
"Did-mount function loading map tile data from Open Street Map.
Arguments are:
* `id` the element id of the HTML element to occupy (string);
* `lat` the latitude of the centre of the view (real number);
* `lng` the longitude of the centre of the view (real number);
* `zoom` the initial zoom level of the view (real number)."
[id lat lng zoom]
(let [view (.setView
(.map js/L
id
(clj->js {:zoomControl false}))
#js [lat lng]
zoom)]
(.addTo (.tileLayer js/L osm-url
(clj->js {:attribution osm-attrib
:maxZoom 18}))
view)
view))
(defn map-did-mount
"Select the actual map provider to use. Arguments are:
* `id` the element id of the HTML element to occupy (string);
* `lat` the latitude of the centre of the view (real number);
* `lng` the longitude of the centre of the view (real number);
* `zoom` the initial zoom level of the view (real number)."
[id lat lng zoom]
(case *map-provider*
:mapbox (map-did-mount-mapbox id lat lng zoom)
:osm (map-did-mount-osm id lat lng zoom)
;; potentially others
))
(def views (atom {}))
(defn add-view
[id lat lng zoom]
(let [k (keyword id)
v (or
(@views k)
(map-did-mount id lat lng zoom))]
(n/message (str "Added Leaflet view to element with id `" id "`"))
(swap! views assoc k v)
v))
(defn get-view
[k]
(when-not (keyword? k) (n/message (str "Key `" k "` passed to get-view is not a keyword")))
(when-not (k @views) (n/message (str "Key `" k "` does not identify a known view")))
(k @views))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,90 @@
// Compiled by ClojureScript 1.10.520 {}
goog.provide('geocsv_lite.map');
goog.require('cljs.core');
goog.require('geocsv_lite.notify');
geocsv_lite.map._STAR_map_provider_STAR_ = new cljs.core.Keyword(null,"osm","osm",855693280);
geocsv_lite.map.osm_url = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
geocsv_lite.map.osm_attrib = "Map data &copy; <a href='http://openstreetmap.org'>OpenStreetMap</a> contributors";
/**
* Did-mount function loading map tile data from MapBox (proprietary).
* Arguments are:
* * `id` the element id of the HTML element to occupy (string);
* * `lat` the latitude of the centre of the view (real number);
* * `lng` the longitude of the centre of the view (real number);
* * `zoom` the initial zoom level of the view (real number).
*/
geocsv_lite.map.map_did_mount_mapbox = (function geocsv_lite$map$map_did_mount_mapbox(id,lat,lng,zoom){
var view = L.map(id,cljs.core.clj__GT_js.call(null,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"zoomControl","zoomControl",-2137430217),"false"], null))).setView([lat,lng],zoom);
L.tileLayer("http://{s}.tiles.mapbox.com/v3/FIXME/{z}/{x}/{y}.png",cljs.core.clj__GT_js.call(null,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"attribution","attribution",1937239286),"Map data &copy; [...]",new cljs.core.Keyword(null,"maxZoom","maxZoom",566190639),(18)], null))).addTo();
return view;
});
/**
* Did-mount function loading map tile data from Open Street Map.
* Arguments are:
* * `id` the element id of the HTML element to occupy (string);
* * `lat` the latitude of the centre of the view (real number);
* * `lng` the longitude of the centre of the view (real number);
* * `zoom` the initial zoom level of the view (real number).
*/
geocsv_lite.map.map_did_mount_osm = (function geocsv_lite$map$map_did_mount_osm(id,lat,lng,zoom){
var view = L.map(id,cljs.core.clj__GT_js.call(null,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"zoomControl","zoomControl",-2137430217),false], null))).setView([lat,lng],zoom);
L.tileLayer(geocsv_lite.map.osm_url,cljs.core.clj__GT_js.call(null,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"attribution","attribution",1937239286),geocsv_lite.map.osm_attrib,new cljs.core.Keyword(null,"maxZoom","maxZoom",566190639),(18)], null))).addTo(view);
return view;
});
/**
* Select the actual map provider to use. Arguments are:
* * `id` the element id of the HTML element to occupy (string);
* * `lat` the latitude of the centre of the view (real number);
* * `lng` the longitude of the centre of the view (real number);
* * `zoom` the initial zoom level of the view (real number).
*/
geocsv_lite.map.map_did_mount = (function geocsv_lite$map$map_did_mount(id,lat,lng,zoom){
var G__24992 = geocsv_lite.map._STAR_map_provider_STAR_;
var G__24992__$1 = (((G__24992 instanceof cljs.core.Keyword))?G__24992.fqn:null);
switch (G__24992__$1) {
case "mapbox":
return geocsv_lite.map.map_did_mount_mapbox.call(null,id,lat,lng,zoom);
break;
case "osm":
return geocsv_lite.map.map_did_mount_osm.call(null,id,lat,lng,zoom);
break;
default:
throw (new Error(["No matching clause: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__24992__$1)].join('')));
}
});
geocsv_lite.map.views = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);
geocsv_lite.map.add_view = (function geocsv_lite$map$add_view(id,lat,lng,zoom){
var k = cljs.core.keyword.call(null,id);
var v = (function (){var or__4131__auto__ = cljs.core.deref.call(null,geocsv_lite.map.views).call(null,k);
if(cljs.core.truth_(or__4131__auto__)){
return or__4131__auto__;
} else {
return geocsv_lite.map.map_did_mount.call(null,id,lat,lng,zoom);
}
})();
geocsv_lite.notify.message.call(null,["Added Leaflet view to element with id `",cljs.core.str.cljs$core$IFn$_invoke$arity$1(id),"`"].join(''));
cljs.core.swap_BANG_.call(null,geocsv_lite.map.views,cljs.core.assoc,k,v);
return v;
});
geocsv_lite.map.get_view = (function geocsv_lite$map$get_view(k){
if((k instanceof cljs.core.Keyword)){
} else {
geocsv_lite.notify.message.call(null,["Key `",cljs.core.str.cljs$core$IFn$_invoke$arity$1(k),"` passed to get-view is not a keyword"].join(''));
}
if(cljs.core.truth_(k.call(null,cljs.core.deref.call(null,geocsv_lite.map.views)))){
} else {
geocsv_lite.notify.message.call(null,["Key `",cljs.core.str.cljs$core$IFn$_invoke$arity$1(k),"` does not identify a known view"].join(''));
}
return k.call(null,cljs.core.deref.call(null,geocsv_lite.map.views));
});
//# sourceMappingURL=map.js.map?rel=1582812678780

View file

@ -0,0 +1 @@
{"version":3,"file":"\/home\/simon\/workspace\/geocsv-lite\/js\/compiled\/out\/geocsv_lite\/map.js","sources":["map.cljs?rel=1582812678781"],"lineCount":90,"mappings":";AAAA;;;AAWA,2CAAA,3CAAeA;AAEf,0BAAA,1BAAKC;AACL,6BAAA,7BAAKC;AAGL;;;;;;;;uCAAA,vCAAMC,sFAOHC,GAAGC,IAAIC,IAAIC;AAPd,AAQE,IAAMC,OAAK,iLAAA,jLACE,AAAMC,MAAKL,GAAG,+BAAA,2CAAA,oEAAA,9IAACM,yKACVL,IAAIC,KACTC;AAHb,AAKE,AAAQ,YAAA,ZAAYE,mEACA,+BAAA,2CAAA,mEAAA,wBAAA,0DAAA,\/NAACC;;AAErBF;;AAEJ;;;;;;;;oCAAA,pCAAMG,gFAOHP,GAAGC,IAAIC,IAAIC;AAPd,AAQE,IAAMC,OAAK,+KAAA,\/KACE,AAAMC,MACAL,GACA,+BAAA,2CAAA,oEAAA,9IAACM,uKACFL,IAAIC,KACTC;AALb,AAME,AAAQ,AAAYE,YAAKR,wBACL,+BAAA,2CAAA,8FAAA,0DAAA,lOAACS,6IAAsBR,0GAEnCM;;AACRA;;AAEJ;;;;;;;gCAAA,hCAAMI,wEAMHR,GAAGC,IAAIC,IAAIC;AANd,AAOE,IAAAM,WAAMb;IAANa,eAAA,EAAA,CAAAA,oBAAAC,oBAAA,AAAAD,aAAA;AAAA,AAAA,QAAAA;KAAA;AACU,OAACV,+CAAqBC,GAAGC,IAAIC,IAAIC;;;KAD3C;AAEO,OAACI,4CAAkBP,GAAGC,IAAIC,IAAIC;;;;AAFrC,MAAA,KAAAQ,MAAA,CAAA,mEAAAF;;;;AAOF,AAAKG,wBAAM,yBAAA,zBAACC;AAGZ,2BAAA,3BAAMC,8DACHd,GAAGC,IAAIC,IAAIC;AADd,AAEE,IAAMY,IAAE,AAACC,4BAAQhB;IACXiB,IAAE,iBAAAC,mBACE,AAAA,AAAAC,0BAAEP,iCAAMG;AADV,AAAA,oBAAAG;AAAAA;;AAEE,OAACV,wCAAcR,GAAGC,IAAIC,IAAIC;;;AAHpC,AAIE,AAACiB,qCAAU,CAAA,0FAAA,JAA+CpB;;AAC1D,AAACqB,+BAAMT,sBAAMU,gBAAMP,EAAEE;;AACrBA;;AAGJ,2BAAA,3BAAMM,8DACHR;AADH,AAEE,GAAU,cAAAL,bAAUK;AAApB;AAAA,AAAuB,AAACK,qCAAU,CAAA,uDAAA,HAAaL;;;AAC\/C,oBAAU,YAAA,AAAAI,ZAACJ,sCAAGH;AAAd;AAAA,AAAqB,AAACQ,qCAAU,CAAA,uDAAA,HAAaL;;;AAC7C,mBAAA,AAAAI,ZAACJ,sCAAGH","names":["geocsv-lite.map\/*map-provider*","geocsv-lite.map\/osm-url","geocsv-lite.map\/osm-attrib","geocsv-lite.map\/map-did-mount-mapbox","id","lat","lng","zoom","view","js\/L","cljs.core\/clj->js","geocsv-lite.map\/map-did-mount-osm","geocsv-lite.map\/map-did-mount","G__24992","cljs.core\/Keyword","js\/Error","geocsv-lite.map\/views","cljs.core\/atom","geocsv-lite.map\/add-view","k","cljs.core\/keyword","v","or__4131__auto__","cljs.core\/deref","geocsv-lite.notify\/message","cljs.core\/swap!","cljs.core\/assoc","geocsv-lite.map\/get-view"]}

View file

@ -0,0 +1,13 @@
(ns geocsv-lite.notify
(:require [clojure.browser.dom :as dom]))
(defn message
[msg]
(js/console.log msg)
(dom/set-text (.getElementById js/document "message") msg))
(defn error
[err]
(js/console.error err)
(dom/set-text (.getElementById js/document "error") err))

View file

@ -0,0 +1 @@
["^ ","~:rename-macros",["^ "],"~:renames",["^ "],"~:externs",["^ ","~$console",["^ ","~$log",["^ "],"~$error",["^ "]],"~$document",["^ ","~$getElementById",["^ "]]],"~:use-macros",["^ "],"~:excludes",["~#set",[]],"~:name","~$geocsv-lite.notify","~:imports",null,"~:requires",["^ ","~$dom","~$clojure.browser.dom","^@","^@"],"~:cljs.spec/speced-vars",[],"~:uses",null,"~:defs",["^ ","~$message",["^ ","~:protocol-inline",null,"~:meta",["^ ","~:file","/home/simon/workspace/geocsv-lite/src/geocsv_lite/notify.cljs","~:line",4,"~:column",7,"~:end-line",4,"~:end-column",14,"~:arglists",["~#list",["~$quote",["^M",[["~$msg"]]]]]],"^;","~$geocsv-lite.notify/message","^G","/home/simon/workspace/geocsv-lite/src/geocsv_lite/notify.cljs","^K",14,"~:method-params",["^M",[["^O"]]],"~:protocol-impl",null,"~:arglists-meta",["^M",[null,null]],"^I",1,"~:variadic?",false,"^H",4,"~:ret-tag","~$any","^J",4,"~:max-fixed-arity",1,"~:fn-var",true,"^L",["^M",["^N",["^M",[["^O"]]]]]],"^5",["^ ","^E",null,"^F",["^ ","^G","/home/simon/workspace/geocsv-lite/src/geocsv_lite/notify.cljs","^H",10,"^I",7,"^J",10,"^K",12,"^L",["^M",["^N",["^M",[["~$err"]]]]]],"^;","~$geocsv-lite.notify/error","^G","/home/simon/workspace/geocsv-lite/src/geocsv_lite/notify.cljs","^K",12,"^Q",["^M",[["^Y"]]],"^R",null,"^S",["^M",[null,null]],"^I",1,"^T",false,"^H",10,"^U","^V","^J",10,"^W",1,"^X",true,"^L",["^M",["^N",["^M",[["^Y"]]]]]]],"~:cljs.spec/registry-ref",[],"~:require-macros",null,"~:doc",null]

View file

@ -0,0 +1,16 @@
// Compiled by ClojureScript 1.10.520 {}
goog.provide('geocsv_lite.notify');
goog.require('cljs.core');
goog.require('clojure.browser.dom');
geocsv_lite.notify.message = (function geocsv_lite$notify$message(msg){
console.log(msg);
return clojure.browser.dom.set_text.call(null,document.getElementById("message"),msg);
});
geocsv_lite.notify.error = (function geocsv_lite$notify$error(err){
console.error(err);
return clojure.browser.dom.set_text.call(null,document.getElementById("error"),err);
});
//# sourceMappingURL=notify.js.map?rel=1582812678772

View file

@ -0,0 +1 @@
{"version":3,"file":"\/home\/simon\/workspace\/geocsv-lite\/js\/compiled\/out\/geocsv_lite\/notify.js","sources":["notify.cljs?rel=1582812678772"],"lineCount":16,"mappings":";AAAA;;;AAGA,6BAAA,7BAAMA,kEACHC;AADH,AAEE,AAACC,YAAeD;;AAChB,OAACE,uCAAc,wBAAA,xBAAiBC,mCAAuBH;;AAGzD,2BAAA,3BAAMI,8DACHC;AADH,AAEE,AAACC,cAAiBD;;AAClB,OAACH,uCAAc,wBAAA,xBAAiBC,iCAAqBE","names":["geocsv-lite.notify\/message","msg","js\/console.log","clojure.browser.dom\/set-text","js\/document","geocsv-lite.notify\/error","err","js\/console.error"]}