From 184cb14aa803d6b073c20735bbb2d7559f132cd6 Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Thu, 7 May 2020 13:01:34 -0700 Subject: [PATCH] Added screenshot config, with zoom and layer selection. --- src/main/lemondronor/advisorycircular.cljs | 31 +++++++++++-------- .../lemondronor/advisorycircular/adsbx.cljs | 11 +++++-- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/lemondronor/advisorycircular.cljs b/src/main/lemondronor/advisorycircular.cljs index cd32d90..3846a99 100644 --- a/src/main/lemondronor/advisorycircular.cljs +++ b/src/main/lemondronor/advisorycircular.cljs @@ -175,18 +175,23 @@ (:normalized-curviness ac))) -(defn screenshot [icao lat lon now] - (p/let [image-path (str (string/join "-" [@log-prefix icao (util/format-utc-ts now)]) - ".png") - _ (adsbx/screenshot-aircraft icao lat lon - {:timeout 30000 - :output-path image-path - ;;:headless? false - ;; :viewport {:width 1600 :height 800} - ;; :clip {:width 1600 :height 800 :x 0 :y 0} - })] - (log-verbose "%s: Got screenshot" icao) - image-path)) +(defn screenshot + ([icao lat lon now] + (screenshot icao lat lon now {})) + ([icao lat lon now options] + (p/let [image-path (str (string/join "-" [@log-prefix icao (util/format-utc-ts now)]) + ".png") + _ (adsbx/screenshot-aircraft icao lat lon + {:timeout 30000 + :output-path image-path + :headless? false + :layer (:layer options) + :zoom (:zoom options) + ;; :viewport {:width 1600 :height 800} + ;; :clip {:width 1600 :height 800 :x 0 :y 0} + })] + (log-verbose "%s: Got screenshot" icao) + image-path))) (defn circling? [ac config] @@ -495,7 +500,7 @@ (let [coarse (first (:features coarse))] (log-info "%s: Reverse geocode: %s" icao (:properties coarse)) ;; Note that if we're over the ocean we get null :( - (p/then (p/all [(screenshot (:icao ac) lat lon now) + (p/then (p/all [(screenshot (:icao ac) lat lon now (:screenshot config)) (p/let [nearby (landmark config lat lon) _ (log-info "WOOO %s" nearby) sqb (if-let [sqb-path (:basestation-sqb config)] diff --git a/src/main/lemondronor/advisorycircular/adsbx.cljs b/src/main/lemondronor/advisorycircular/adsbx.cljs index 24cb5f0..d2ea177 100644 --- a/src/main/lemondronor/advisorycircular/adsbx.cljs +++ b/src/main/lemondronor/advisorycircular/adsbx.cljs @@ -72,13 +72,18 @@ (if-let [user-agent (:user-agent options)] (.setUserAgent page user-agent)) (log-debug "Navigating") - (let [url (gstring/format "https://tar1090.adsbexchange.com/?icao=%s&noIsolation&hideButtons&hideSidebar&monochromeMarkers=ffff55&monochromeTracks=010101&outlineColor=505050&zoom=14" icao)] - (log-info "Getting screenshot at url %s" url) + (let [url (gstring/format "https://tar1090.adsbexchange.com/?icao=%s&zoom=%s&noIsolation&hideButtons&hideSidebar&monochromeMarkers=ffff55&monochromeTracks=010101&outlineColor=505050" icao (get options :zoom 14))] + (log-info "Getting screenshot at url %s with zoom %s" url (get options :zoom 14)) (p/all [(.waitForNavigation page) (.goto page url (clj->js {:referer "https://adsbexchange.com/"}))])) - (timeout 3000) + (timeout 100) + (when-let [layer (:layer options)] + (.evaluate page (str "ol.control.LayerSwitcher.forEachRecursive(layers_group, l => { if (l.get('name') == '" + layer + "') { console.log(l.get('name')); ol.control.LayerSwitcher.setVisible_(OLMap, l, true); } });"))) + (timeout 2900) (delete-node page "#adsense") (p/all [(.type (.-keyboard page) "l") (timeout 2000)])