Map attribution WIP.

This commit is contained in:
John Wiseman 2020-07-23 16:54:42 -07:00
parent d75e557ded
commit 41d00d5707
3 changed files with 78 additions and 4 deletions

38
package-lock.json generated
View File

@ -278,6 +278,16 @@
"integrity": "sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=",
"dev": true
},
"canvas": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/canvas/-/canvas-2.6.1.tgz",
"integrity": "sha512-S98rKsPcuhfTcYbtF53UIJhcbgIAK533d1kJKMwsMwAIFgfd58MOyxRud3kktlzWiEkFliaJtvyZCBtud/XVEA==",
"requires": {
"nan": "^2.14.0",
"node-pre-gyp": "^0.11.0",
"simple-get": "^3.0.3"
}
},
"caseless": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
@ -476,6 +486,14 @@
"ms": "^2.1.1"
}
},
"decompress-response": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz",
"integrity": "sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==",
"requires": {
"mimic-response": "^2.0.0"
}
},
"deep-extend": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
@ -1026,6 +1044,11 @@
"mime-db": "1.42.0"
}
},
"mimic-response": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz",
"integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA=="
},
"minimalistic-assert": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz",
@ -1588,6 +1611,21 @@
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
},
"simple-concat": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
"integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q=="
},
"simple-get": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.0.tgz",
"integrity": "sha512-bCR6cP+aTdScaQCnQKbPKtJOKDp/hj9EDLJo3Nw4y1QksqaovlW/bnptB6/c1e+qmNIDHRK+oXFDdEqBT8WzUA==",
"requires": {
"decompress-response": "^4.2.0",
"once": "^1.3.1",
"simple-concat": "^1.0.0"
}
},
"simple-swizzle": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",

View File

@ -6,6 +6,7 @@
"shadow-cljs": "^2.8.109"
},
"dependencies": {
"canvas": "^2.6.1",
"commander": "^4.0.1",
"geolib": "^3.2.0",
"js-yaml": "^3.13.1",

View File

@ -1,5 +1,6 @@
(ns lemondronor.advisorycircular
(:require
["canvas" :as canvas]
["commander" :as commander]
["fs" :as fs]
[cljs.pprint :as pprint]
@ -636,7 +637,7 @@
(p/let [nearby (landmark config lat lon)
;;_ (log-info "WOOO %s" nearby)
ac-db-rec (if-let [ac-info-db-path (:aircraft-info-db-path config)]
(get-aircraft-info-record icao ac-info-db-path))]
(get-aircraft-info-record icao ac-info-db-path))]
(let [description (generate-description ac ac-db-rec coarse nearby)]
(log-info "%s Description: %s" (:icao ac) description)
description))])
@ -743,8 +744,18 @@
(def default-config-path "config.yaml")
(defn write-stream-to-file [stream path]
(p/promise
[resolve]
(let [out (fs/createWriteStream path)]
(.pipe stream out)
(.on out "finish" #(do (println "resolving") (resolve nil)))
(.on out "error" #(throw %)))))
(defn main [& args]
(-> commander
(-> commander
(.option "--lat <lat>" "Latitude of the circle of region of interest" parse-number)
(.option "--lon <lat>" "Longitude of the circle of the region of interest" parse-number)
(.option "--adsbx-url <url>" "ADSBX API url")
@ -767,6 +778,30 @@
(logging/set-log-prefix! (or (.-logPrefix commander) ""))
(reset! log-prefix (or (.-logPrefix commander) ""))
(p/try
(p/let [path (nth (.-argv js/process) 2)
_ (println path)
image (canvas/loadImage path)
canvas (canvas/createCanvas (.-width image) (.-height image))
ctx (.getContext canvas "2d")]
(.drawImage ctx image 0 0)
(set! (.-font ctx) "12px Impact")
(let [attribution "Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community" ;; "© OpenStreetMap contributors"
text-metrics (.measureText ctx attribution)
w (.-width text-metrics)
h 12
[mw mh] [1 1]
[pw ph] [2 2]
text-x (- (.-width image) w pw mw)
text-y (- (.-height image) h ph mh )]
(.beginPath ctx)
(set! (.-fillStyle ctx) "rgba(128,128,128,0.7)")
(.rect ctx (- text-x pw) (- text-y ph) (+ w pw pw) (+ h ph ph))
(.fill ctx)
(set! (.-fillStyle ctx) "black")
(.fillText ctx attribution text-x (+ text-y h)))
(write-stream-to-file (.createPNGStream canvas) "out.png")
(println "DONE!")
(.exit js/process 0))
(cond
(.-createAircraftInfoDbFromJson commander)
(create-aircraft-info-db (.-createAircraftInfoDbFromJson commander) (.-aircraftInfoDb commander))
@ -830,8 +865,8 @@
(map #(str (:icao %) ":" (.toFixed (:curviness %) 0)))
(string/join " "))))))))
(p/catch :default e
(log-error "%s" e)
(log-error "%s" (.-stack e))
(log-error "wee1 %s" e)
(log-error "wee2 %s" (.-stack e))
(.exit js/process 1))))