|
11 | 11 | [promesa.core :as p] |
12 | 12 | )) |
13 | 13 |
|
| 14 | + |
| 15 | +;;put your own here. |
| 16 | +(set! (.-defaultAccessToken js/Cesium.Ion) |
| 17 | + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiODFiNWRmOC02MDQ4LTRjNDktYjZmMy1kZjk0MDFjYWM4MDQiLCJpZCI6MzMyMTI0LCJpYXQiOjE3NTUyMDI3MTZ9.1L8bGdlixVLs_-YYNOBrrCkHikDAGEy7EPkSeEn3ukY") |
| 18 | + |
| 19 | +(def bounds {:default [-125.147327626 24.6163352675 -66.612171376 49.6742238918] |
| 20 | + :shifted [-115.85193175578075 23.6163352675 -66.612171376 49.6742238918] |
| 21 | + :3d-us {:position [-63215.181346188605 -9528933.76322208 6760084.984842104], :direction [0.007298723988826753 0.8268915851484712 -0.5623140003937158], :up [0.08733080420213787 0.5596533194968705 0.8241125485111495], :right [0.9961526284990382 -0.05512230389581595 -0.06812835201055821]} |
| 22 | + :3d-us-perspective {:position [-317622.8693122543 -9992858.180467833 4246834.783303648], :direction [0.031052476256112346 0.9868503489240992 -0.15862576255686647], :up [0.0037603323137679672 0.15858582933665222 0.9873380346337804], :right [0.9995106820936202 -0.03125577645796077 0.001213597444119795]} |
| 23 | + :3d-us-small {:position [-762505.075345366 -8709290.1490951 4043268.4155746778], :direction [0.09961461776873652 0.9857124352588807 -0.13582313095638476], :up [0.05184249751899356 0.1311751752861519 0.9900027418344055], :right [0.9936746365776786 -0.10566015504746376 -0.038034829532472586]} |
| 24 | + :inset-atlantic {:position [-5415797.494191807 4642953.337264422 10653133.091939844], :direction [0 0 -1], :up [-2.2204460492503126e-16 1 0], :right [1 2.2204460492503126e-16 0]} |
| 25 | + :us [-129.2 20.2 -62.7 51.1] |
| 26 | + :us-europe [-125.8 16.7 71.7 55.2] |
| 27 | + :europe [-12.6 34.7 53.8 60.3] |
| 28 | + :us-asia [88.7 5.3 -67.7 48.5] |
| 29 | + :us-hld {:position [-1.1789283742143026E7 -851171.9394538645 4220213.20184823], |
| 30 | + :direction [-0.014107715109319626 0.8223014117772767 -0.5688772807587698], |
| 31 | + :up [-0.009758438829426674 0.5687935771746235 0.8224224215307534], |
| 32 | + :right [0.9998528617981781 0.01715385536820768 2.833893553849664E-10]}}) |
| 33 | + |
14 | 34 | (def color-schemes |
15 | 35 | {:red {:colors {:equipment [255 0 0 125]}} |
16 | 36 | :orange {:colors {:equipment [255, 165, 0, 125]}} |
|
45 | 65 | #js{:url (js/Cesium.buildModuleUrl. "Assets/Textures/NaturalEarthII")}) |
46 | 66 | ;;false ;;(-> local-layers :blue-marble) |
47 | 67 | :geocoder true |
48 | | - :resolutionScale 1.0 |
| 68 | + :resolutionScale 1.0 ;;can toggle this to mess with res...hmm.. |
49 | 69 | :clockViewModel shared-clock |
50 | 70 | }) |
51 | 71 |
|
|
106 | 126 | (set! (.-clockRange shared-clock) js/Cesium.ClockRange.CLAMPED) |
107 | 127 | (swap! app-state assoc :extents [start stop])) |
108 | 128 |
|
| 129 | +(defn ^js/Cesium.DataSourceCollection |
| 130 | + get-layers! [& {:keys [id] :or {id :current}}] |
| 131 | + (-> id ces/get-view .-dataSources)) |
| 132 | + |
| 133 | +(defn imagery-layers [& {:keys [id] :or {id :current}}] |
| 134 | + (-> id ces/get-view .-imageryLayers)) |
| 135 | + |
| 136 | +(defn layer-names [& {:keys [id] :or {id :current}}] |
| 137 | + (for [^js/Cesium.DataSource v (some-> id ces/get-view .-dataSources .-_dataSources)] |
| 138 | + (.-name v))) |
| 139 | + |
| 140 | +(defn ^js/Cesium.EntityCollection |
| 141 | + get-layer! [k & {:keys [id] :or {id :current}}] |
| 142 | + (-> (get-layers! :id id) (.getByName k) first)) |
| 143 | + |
| 144 | + |
| 145 | +(defn drop-layer! [k & {:keys [id] :or {id :current}}] |
| 146 | + (let [l (get-layers! :id id) |
| 147 | + tgt (first (.getByName l k))] |
| 148 | + (.remove l tgt true))) |
| 149 | + |
| 150 | + |
| 151 | +(defn show-layer! [k & {:keys [id] :or {id :current}}] |
| 152 | + (let [l (get-layers! :id id) |
| 153 | + tgt (first (.getByName l k))] |
| 154 | + (set! (.-show tgt) true))) |
| 155 | + |
| 156 | +(defn hide-layer! [k & {:keys [id] :or {id :current}}] |
| 157 | + (let [l (get-layers! :id id) |
| 158 | + tgt (first (.getByName l k))] |
| 159 | + (set! (.-show tgt) false))) |
| 160 | + |
| 161 | +(defn toggle-layer! [k & {:keys [id] :or {id :current}}] |
| 162 | + (let [l (get-layers! :id id) |
| 163 | + tgt (first (.getByName l k))] |
| 164 | + (when tgt |
| 165 | + (set! (.-show tgt) (not (.-show tgt)))))) |
| 166 | + |
| 167 | +(defn entities-in [layer & {:keys [id] :or {id :current}}] |
| 168 | + (-> (get-layer! layer :id id) |
| 169 | + .-_entityCollection |
| 170 | + .-values |
| 171 | + )) |
| 172 | + |
| 173 | +(defn url->xyz [url] |
| 174 | + (js/Cesium.UrlTemplateImageryProvider. #js{:url url})) |
| 175 | + |
| 176 | +(defn base-layer [] |
| 177 | + (.get (imagery-layers) 0)) |
| 178 | + |
| 179 | +(defn xyz-provider [url] |
| 180 | + (url->xyz url)) |
| 181 | + |
| 182 | +(def local-layers |
| 183 | + {:blue-marble (xyz-provider "layers/bm5/{z}/{x}/{y}.png") |
| 184 | + :virtual-earth (xyz-provider "layers/bingve/{z}/{x}/{y}.png")}) |
| 185 | + |
| 186 | +(defn set-imagery [provider] |
| 187 | + (let [layers (imagery-layers) |
| 188 | + base (base-layer) |
| 189 | + _ (.remove layers base)] |
| 190 | + (.addImageryProvider layers provider))) |
| 191 | + |
| 192 | +(defn registered-moves [] |
| 193 | + (let [keyf (memoize (fn [e] (-> e meta (get "move-type"))))] |
| 194 | + (->> (get-layer! "moves") |
| 195 | + .-_entityCollection |
| 196 | + vals |
| 197 | + (group-by keyf)))) |
| 198 | + |
| 199 | +(defn present [t ents] |
| 200 | + (let [t (->jd t)] |
| 201 | + (filter (fn [^js/Cesium.Entity e] (.isAvailable e t)) ents))) |
| 202 | + |
| 203 | +;;naive stats. |
| 204 | +(defn present-on-day [d ents] |
| 205 | + (present (add-days +now+ d) ents )) |
| 206 | + |
| 207 | + |
109 | 208 | #_ |
110 | 209 | (defn simple-movement [from to start stop] |
111 | 210 | ;;just draw a straight line between from and to for now. |
|
146 | 245 | (set-finish! start stop) |
147 | 246 | :done))) |
148 | 247 |
|
149 | | -(defn demo-click! [] |
150 | | - (fire-events!)) |
151 | | -;;put your own here. |
152 | | -(set! (.-defaultAccessToken js/Cesium.Ion) |
153 | | - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiODFiNWRmOC02MDQ4LTRjNDktYjZmMy1kZjk0MDFjYWM4MDQiLCJpZCI6MzMyMTI0LCJpYXQiOjE3NTUyMDI3MTZ9.1L8bGdlixVLs_-YYNOBrrCkHikDAGEy7EPkSeEn3ukY") |
| 248 | +(defn states! [] |
| 249 | + (ces/load-geojson! "ne_10m_us_states.topojson" :style |
| 250 | + {:stroke js/Cesium.Color.BLACK |
| 251 | + :fill (js/Cesium.Color.DARKGRAY.withAlpha 0.7), |
| 252 | + :strokeWidth 20} |
| 253 | + :name "states")) |
| 254 | +#_ |
| 255 | +(defn countries! [] |
| 256 | + (ces/load-geojson! "all-countries.geo.json" :id :inset |
| 257 | + :style {:stroke js/Cesium.Color.BLACK |
| 258 | + :fill (js/Cesium.Color.GREY.withAlpha 1.0), |
| 259 | + :strokeWidth 3})) |
154 | 260 |
|
155 | | -(def bounds {:default [-125.147327626 24.6163352675 -66.612171376 49.6742238918] |
156 | | - :shifted [-115.85193175578075 23.6163352675 -66.612171376 49.6742238918] |
157 | | - :3d-us {:position [-63215.181346188605 -9528933.76322208 6760084.984842104], :direction [0.007298723988826753 0.8268915851484712 -0.5623140003937158], :up [0.08733080420213787 0.5596533194968705 0.8241125485111495], :right [0.9961526284990382 -0.05512230389581595 -0.06812835201055821]} |
158 | | - :3d-us-perspective {:position [-317622.8693122543 -9992858.180467833 4246834.783303648], :direction [0.031052476256112346 0.9868503489240992 -0.15862576255686647], :up [0.0037603323137679672 0.15858582933665222 0.9873380346337804], :right [0.9995106820936202 -0.03125577645796077 0.001213597444119795]} |
159 | | - :3d-us-small {:position [-762505.075345366 -8709290.1490951 4043268.4155746778], :direction [0.09961461776873652 0.9857124352588807 -0.13582313095638476], :up [0.05184249751899356 0.1311751752861519 0.9900027418344055], :right [0.9936746365776786 -0.10566015504746376 -0.038034829532472586]} |
160 | | - :inset-atlantic {:position [-5415797.494191807 4642953.337264422 10653133.091939844], :direction [0 0 -1], :up [-2.2204460492503126e-16 1 0], :right [1 2.2204460492503126e-16 0]} |
161 | | - :us [-129.2 20.2 -62.7 51.1] |
162 | | - :us-europe [-125.8 16.7 71.7 55.2] |
163 | | - :europe [-12.6 34.7 53.8 60.3] |
164 | | - :us-asia [88.7 5.3 -67.7 48.5] |
165 | | - :us-hld {:position [-1.1789283742143026E7 -851171.9394538645 4220213.20184823], |
166 | | - :direction [-0.014107715109319626 0.8223014117772767 -0.5688772807587698], |
167 | | - :up [-0.009758438829426674 0.5687935771746235 0.8224224215307534], |
168 | | - :right [0.9998528617981781 0.01715385536820768 2.833893553849664E-10]}}) |
| 261 | + |
| 262 | + |
| 263 | +;;Handlers |
| 264 | +(defn demo-click! [] (fire-events!)) |
| 265 | +(defn toggle-states! [] (toggle-layer! "states")) |
| 266 | + |
| 267 | + |
| 268 | +;;UI |
169 | 269 |
|
170 | 270 | (defn cesium-root |
171 | 271 | ([opts] |
|
184 | 284 | "play"] |
185 | 285 | [:button.cesium-button {:style {:flex "1"} :id "stop" :type "button" :on-click #(stop!)} |
186 | 286 | "stop"] |
| 287 | + [:button.cesium-button {:style {:flex "1"} :id "toggle states" :type "button" |
| 288 | + :on-click #(toggle-states!)} |
| 289 | + "Toggle States Layer"] |
187 | 290 | [:button.cesium-button {:style {:flex "1"} :id "demo" :type "button" :on-click demo-click!} |
188 | 291 | "Load Fires!"]]] ) |
| 292 | + |
| 293 | +(defn layers! [] |
| 294 | + (do (states!) |
| 295 | + #_ |
| 296 | + (countries!))) |
| 297 | + |
189 | 298 | ;; Initialize App |
190 | 299 | (defn main [] |
191 | | -;; (reset! app-state default-state) |
192 | 300 | (rdom/render [page app-state] |
193 | | - (.getElementById js/document "app"))) |
| 301 | + (.getElementById js/document "app")) |
| 302 | + (layers!)) |
194 | 303 |
|
195 | 304 | (main) |
196 | 305 |
|
|
0 commit comments