Skip to content

Commit

Permalink
(ISA-537) Info click popups for esri raster layers
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Groombridge committed Jan 19, 2024
1 parent 6c61fcd commit 1144841
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions frontend/src/cljs/imas_seamap/interop/leaflet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@
(def geojson-feature L/geoJson)
(def latlng L/LatLng)
(def esri-query #(.query esri (clj->js %)))
(defn dynamic-map-layer-query
[url leaflet-map point callback]
(let [dynamic-map-layer ((-> esri .-dynamicMapLayer) (clj->js {:url url}))]
(->
dynamic-map-layer
(.identify)
(.on leaflet-map)
(.at point)
(.run callback))))

;;; Multiple basemaps:
(def layers-control (r/adapt-react-class ReactLeaflet/LayersControl))
Expand Down
26 changes: 26 additions & 0 deletions frontend/src/cljs/imas_seamap/map/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
(def ^:const INFO-FORMAT-NONE 3)
(def ^:const INFO-FORMAT-FEATURE 4)
(def ^:const INFO-FORMAT-XML 5)
(def ^:const INFO-FORMAT-RASTER 6)

(defmulti get-feature-info #(second %2))

Expand Down Expand Up @@ -166,6 +167,31 @@
:on-success [:map/got-featureinfo request-id point "text/xml" layers]
:on-failure [:map/got-featureinfo-err request-id point]}}))

(defmethod get-feature-info INFO-FORMAT-RASTER
[{:keys [db]} [_ _info-format-type layers request-id _leaflet-props {:keys [lat lng] :as point}]]
(let [layer-server-ids (mapv #(last (string/split (:server_url %) "/")) layers)
url (string/join "/" (butlast (string/split (-> layers first :server_url) "/")))
leaflet-map (get-in db [:map :leaflet-map])
leaflet-point (leaflet/latlng. lat lng)]
(leaflet/dynamic-map-layer-query
url
leaflet-map
leaflet-point
(fn [error feature-collection _response]
(if error
(re-frame/dispatch [:map/got-featureinfo-err request-id point nil])
(let [feature-collection
(as-> (js->clj feature-collection) feature-collection
(assoc
feature-collection "features"
(filterv
#(and
(some #{(str (get % "layerId"))} layer-server-ids) ; check it's a layer we're querying for (not a different layer on the server)
(not= (get-in % ["properties" "Pixel Value"]) "NoData")) ; check the layer has associated data
(get feature-collection "features"))))]
(re-frame/dispatch [:map/got-featureinfo request-id point "application/json" layers feature-collection])))))
nil))

(defmethod get-feature-info :default
[_ [_ _info-format-type layers request-id _leaflet-props point]]
{:dispatch [:map/got-featureinfo request-id point nil nil layers]})
Expand Down

0 comments on commit 1144841

Please sign in to comment.