Working production build in docs subdirectory.

This commit is contained in:
Simon Brooke 2020-02-27 09:35:17 +00:00
parent bb7be028e6
commit a5204c66b9
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
644 changed files with 134256 additions and 53616 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",["^ ","~$HTMLDocument",["^ ","~$prototype",["^ ","~$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","^B","^B","~$geocsv-lite.data","^E","^A","^A","^D","^D"],"~:cljs.spec/speced-vars",[],"~:uses",["^ ","~$get-data","^E","~$get-csv-url","^E","~$get-query-part-as-map","^E"],"~: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",["^V",[["~$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","^O","src/geocsv_lite/core.cljs","^S",38,"~:method-params",["^V",[["^X","^Y"]]],"~:protocol-impl",null,"^T",true,"~:arglists-meta",["^V",[null,null]],"^Q",1,"~:variadic?",false,"^P",10,"~:ret-tag","~$any","^R",10,"~:max-fixed-arity",2,"~:fn-var",true,"^U",["^V",["^W",["^V",[["^X","^Y"]]]]],"^Z","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",["^ ","^M",null,"^N",["^ ","^O","/home/simon/workspace/geocsv-lite/src/geocsv_lite/core.cljs","^P",20,"^Q",16,"^R",20,"^S",51,"^T",true,"^U",["^V",["^W",["^V",[["^X"]]]]]],"^;","~$geocsv-lite.core/initialise-map-element-from-content","^O","src/geocsv_lite/core.cljs","^S",51,"^10",["^V",[["^X"]]],"^11",null,"^T",true,"^12",["^V",[null,null]],"^Q",1,"^13",false,"^P",20,"^14","^15","^R",20,"^16",1,"^17",true,"^U",["^V",["^W",["^V",[["^X"]]]]]],"~$on-js-reload",["^ ","^M",null,"^N",["^ ","^O","/home/simon/workspace/geocsv-lite/src/geocsv_lite/core.cljs","^P",33,"^Q",7,"^R",33,"^S",19,"^U",["^V",["^W",["^V",[[]]]]]],"^;","~$geocsv-lite.core/on-js-reload","^O","src/geocsv_lite/core.cljs","^S",19,"^10",["^V",[[]]],"^11",null,"^12",["^V",[null,null]],"^Q",1,"^13",false,"^P",33,"^14","~$clj-nil","^R",33,"^16",0,"^17",true,"^U",["^V",["^W",["^V",[[]]]]]]],"~:cljs.spec/registry-ref",[],"~:require-macros",null,"^Z",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

View file

@ -0,0 +1 @@
{"version":3,"file":"\/home\/simon\/workspace\/geocsv-lite\/target\/cljsbuild-compiler-1\/geocsv_lite\/core.js","sources":["core.cljs"],"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__25894_SHARP_){
return clojure.string.split.call(null,p1__25894_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__25895_SHARP_){
return cljs.core._EQ_.call(null,cljs.core.count.call(null,p1__25895_SHARP_),(2));
});})(query_nvs))
,query_nvs)){
return cljs.core.zipmap.call(null,cljs.core.map.call(null,((function (query_nvs){
return (function (p1__25896_SHARP_){
return cljs.core.keyword.call(null,cljs.core.first.call(null,p1__25896_SHARP_));
});})(query_nvs))
,query_nvs),cljs.core.map.call(null,((function (query_nvs){
return (function (p1__25897_SHARP_){
return cljs.core.nth.call(null,p1__25897_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__25898_SHARP_){
var n = ((cljs.core.empty_QMARK_.call(null,p1__25898_SHARP_))?null:((typeof p1__25898_SHARP_ === 'string')?clojure.string.lower_case.call(null,clojure.string.replace.call(null,clojure.string.trim.call(null,p1__25898_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__23644__auto__ = cljs.core.async.chan.call(null,(1));
cljs.core.async.impl.dispatch.run.call(null,((function (c__23644__auto__){
return (function (){
var f__23645__auto__ = (function (){var switch__23549__auto__ = ((function (c__23644__auto__){
return (function (state_25907){
var state_val_25908 = (state_25907[(1)]);
if((state_val_25908 === (1))){
var inst_25899 = [new cljs.core.Keyword(null,"with-credentials?","with-credentials?",-1773202222)];
var inst_25900 = ["false"];
var inst_25901 = cljs.core.PersistentHashMap.fromArrays(inst_25899,inst_25900);
var inst_25902 = cljs_http.client.get.call(null,uri,inst_25901);
var state_25907__$1 = state_25907;
return cljs.core.async.impl.ioc_helpers.take_BANG_.call(null,state_25907__$1,(2),inst_25902);
} else {
if((state_val_25908 === (2))){
var inst_25904 = (state_25907[(2)]);
var inst_25905 = geocsv_lite.data.default_handler.call(null,inst_25904,k);
var state_25907__$1 = state_25907;
return cljs.core.async.impl.ioc_helpers.return_chan.call(null,state_25907__$1,inst_25905);
} else {
return null;
}
}
});})(c__23644__auto__))
;
return ((function (switch__23549__auto__,c__23644__auto__){
return (function() {
var geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto__ = null;
var geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto____0 = (function (){
var statearr_25909 = [null,null,null,null,null,null,null];
(statearr_25909[(0)] = geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto__);
(statearr_25909[(1)] = (1));
return statearr_25909;
});
var geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto____1 = (function (state_25907){
while(true){
var ret_value__23551__auto__ = (function (){try{while(true){
var result__23552__auto__ = switch__23549__auto__.call(null,state_25907);
if(cljs.core.keyword_identical_QMARK_.call(null,result__23552__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
continue;
} else {
return result__23552__auto__;
}
break;
}
}catch (e25910){if((e25910 instanceof Object)){
var ex__23553__auto__ = e25910;
var statearr_25911_25913 = state_25907;
(statearr_25911_25913[(5)] = ex__23553__auto__);
cljs.core.async.impl.ioc_helpers.process_exception.call(null,state_25907);
return new cljs.core.Keyword(null,"recur","recur",-437573268);
} else {
throw e25910;
}
}})();
if(cljs.core.keyword_identical_QMARK_.call(null,ret_value__23551__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
var G__25914 = state_25907;
state_25907 = G__25914;
continue;
} else {
return ret_value__23551__auto__;
}
break;
}
});
geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto__ = function(state_25907){
switch(arguments.length){
case 0:
return geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto____0.call(this);
case 1:
return geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto____1.call(this,state_25907);
}
throw(new Error('Invalid arity: ' + arguments.length));
};
geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto__.cljs$core$IFn$_invoke$arity$0 = geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto____0;
geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto__.cljs$core$IFn$_invoke$arity$1 = geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto____1;
return geocsv_lite$data$get_data_from_uri_$_state_machine__23550__auto__;
})()
;})(switch__23549__auto__,c__23644__auto__))
})();
var state__23646__auto__ = (function (){var statearr_25912 = f__23645__auto__.call(null);
(statearr_25912[(6)] = c__23644__auto__);
return statearr_25912;
})();
return cljs.core.async.impl.ioc_helpers.run_state_machine_wrapped.call(null,state__23646__auto__);
});})(c__23644__auto__))
);
return c__23644__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 (e25915){var _ = e25915;
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__23644__auto__ = cljs.core.async.chan.call(null,(1));
cljs.core.async.impl.dispatch.run.call(null,((function (c__23644__auto__){
return (function (){
var f__23645__auto__ = (function (){var switch__23549__auto__ = ((function (c__23644__auto__){
return (function (state_25923){
var state_val_25924 = (state_25923[(1)]);
if((state_val_25924 === (1))){
var inst_25916 = cljs_http.client.get.call(null,uri);
var state_25923__$1 = state_25923;
return cljs.core.async.impl.ioc_helpers.take_BANG_.call(null,state_25923__$1,(2),inst_25916);
} else {
if((state_val_25924 === (2))){
var inst_25918 = (state_25923[(2)]);
var inst_25919 = (new cljs.core.List(null,k,null,(1),null));
var inst_25920 = (new cljs.core.List(null,inst_25918,inst_25919,(2),null));
var inst_25921 = cljs.core.apply.call(null,handler_fn,inst_25920);
var state_25923__$1 = state_25923;
return cljs.core.async.impl.ioc_helpers.return_chan.call(null,state_25923__$1,inst_25921);
} else {
return null;
}
}
});})(c__23644__auto__))
;
return ((function (switch__23549__auto__,c__23644__auto__){
return (function() {
var geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto__ = null;
var geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto____0 = (function (){
var statearr_25925 = [null,null,null,null,null,null,null];
(statearr_25925[(0)] = geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto__);
(statearr_25925[(1)] = (1));
return statearr_25925;
});
var geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto____1 = (function (state_25923){
while(true){
var ret_value__23551__auto__ = (function (){try{while(true){
var result__23552__auto__ = switch__23549__auto__.call(null,state_25923);
if(cljs.core.keyword_identical_QMARK_.call(null,result__23552__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
continue;
} else {
return result__23552__auto__;
}
break;
}
}catch (e25926){if((e25926 instanceof Object)){
var ex__23553__auto__ = e25926;
var statearr_25927_25929 = state_25923;
(statearr_25927_25929[(5)] = ex__23553__auto__);
cljs.core.async.impl.ioc_helpers.process_exception.call(null,state_25923);
return new cljs.core.Keyword(null,"recur","recur",-437573268);
} else {
throw e25926;
}
}})();
if(cljs.core.keyword_identical_QMARK_.call(null,ret_value__23551__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
var G__25930 = state_25923;
state_25923 = G__25930;
continue;
} else {
return ret_value__23551__auto__;
}
break;
}
});
geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto__ = function(state_25923){
switch(arguments.length){
case 0:
return geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto____0.call(this);
case 1:
return geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto____1.call(this,state_25923);
}
throw(new Error('Invalid arity: ' + arguments.length));
};
geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto__.cljs$core$IFn$_invoke$arity$0 = geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto____0;
geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto__.cljs$core$IFn$_invoke$arity$1 = geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto____1;
return geocsv_lite$data$get_data_with_uri_and_handler_$_state_machine__23550__auto__;
})()
;})(switch__23549__auto__,c__23644__auto__))
})();
var state__23646__auto__ = (function (){var statearr_25928 = f__23645__auto__.call(null);
(statearr_25928[(6)] = c__23644__auto__);
return statearr_25928;
})();
return cljs.core.async.impl.ioc_helpers.run_state_machine_wrapped.call(null,state__23646__auto__);
});})(c__23644__auto__))
);
return c__23644__auto__;
});
//# sourceMappingURL=data.js.map

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 (e25882){if((e25882 instanceof Object)){
var any = e25882;
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 e25882;
}
}});
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__25883_SHARP_){
return ["<dt>",cljs.core.name.call(null,p1__25883_SHARP_),"</dt><dd>",cljs.core.str.cljs$core$IFn$_invoke$arity$1(record.call(null,p1__25883_SHARP_)),"</dd>"].join('');
}),cljs.core.filter.call(null,(function (p1__25884_SHARP_){
return record.call(null,p1__25884_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__25885_SHARP_){
return ["<tr><th>",cljs.core.name.call(null,p1__25885_SHARP_),"</th><td>",cljs.core.str.cljs$core$IFn$_invoke$arity$1(record.call(null,p1__25885_SHARP_)),"</td></tr>"].join('');
}),cljs.core.sort.call(null,cljs.core.filter.call(null,(function (p1__25886_SHARP_){
return record.call(null,p1__25886_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__25887_SHARP_){
if((p1__25887_SHARP_ instanceof L.Marker)){
return view.removeLayer(p1__25887_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__25888_SHARP_){
if((cljs.core.reduce.call(null,cljs.core._STAR_,cljs.core.repeat.call(null,(2),p1__25888_SHARP_)) > n)){
return p1__25888_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 (e25889){var error = e25889;
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__25890_SHARP_,p2__25891_SHARP_){
return geocsv_lite.gis.add_map_pin.call(null,p1__25890_SHARP_,p2__25891_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

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__25685 = geocsv_lite.map._STAR_map_provider_STAR_;
var G__25685__$1 = (((G__25685 instanceof cljs.core.Keyword))?G__25685.fqn:null);
switch (G__25685__$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__25685__$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

View file

@ -0,0 +1 @@
{"version":3,"file":"\/home\/simon\/workspace\/geocsv-lite\/target\/cljsbuild-compiler-1\/geocsv_lite\/map.js","sources":["map.cljs"],"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__25685","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",["^ ","~$HTMLDocument",["^ ","~$prototype",["^ ","~$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",["^K",[["~$msg"]]]]]],"^9","~$geocsv-lite.notify/message","^E","/home/simon/workspace/geocsv-lite/src/geocsv_lite/notify.cljs","^I",14,"~:method-params",["^K",[["^M"]]],"~:protocol-impl",null,"~:arglists-meta",["^K",[null,null]],"^G",1,"~:variadic?",false,"^F",4,"~:ret-tag","~$any","^H",4,"~:max-fixed-arity",1,"~:fn-var",true,"^J",["^K",["^L",["^K",[["^M"]]]]]],"~$error",["^ ","^C",null,"^D",["^ ","^E","/home/simon/workspace/geocsv-lite/src/geocsv_lite/notify.cljs","^F",10,"^G",7,"^H",10,"^I",12,"^J",["^K",["^L",["^K",[["~$err"]]]]]],"^9","~$geocsv-lite.notify/error","^E","/home/simon/workspace/geocsv-lite/src/geocsv_lite/notify.cljs","^I",12,"^O",["^K",[["^X"]]],"^P",null,"^Q",["^K",[null,null]],"^G",1,"^R",false,"^F",10,"^S","^T","^H",10,"^U",1,"^V",true,"^J",["^K",["^L",["^K",[["^X"]]]]]]],"~: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

View file

@ -0,0 +1 @@
{"version":3,"file":"\/home\/simon\/workspace\/geocsv-lite\/target\/cljsbuild-compiler-1\/geocsv_lite\/notify.js","sources":["notify.cljs"],"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"]}