Skip to content

Commit

Permalink
(ISA-537) raster layer support
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Groombridge committed Jan 12, 2024
1 parent 2d99868 commit b53c927
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 12 additions & 0 deletions frontend/src/cljs/imas_seamap/interop/leaflet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@
#js{:opacity (.-opacity props)
:fillOpacity (.-opacity props)})))))))

(def dynamic-map-layer
(r/adapt-react-class
(ReactLeafletCore/createLayerComponent
;; Create layer fn
(fn [props context]
(let [instance ((-> esri .-dynamicMapLayer) props)]
#js{:instance instance :context context}))
;; Update layer fn
(fn [instance props prev-props]
(when (not= (.-opacity props) (.-opacity prev-props))
(.setOpacity instance (.-opacity props)))))))

(def map-container (r/adapt-react-class ReactLeaflet/MapContainer))
(def pane (r/adapt-react-class ReactLeaflet/Pane))
(def marker (r/adapt-react-class ReactLeaflet/Marker))
Expand Down
22 changes: 19 additions & 3 deletions frontend/src/cljs/imas_seamap/map/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
;;; Copyright (c) 2017, Institute of Marine & Antarctic Studies. Written by Condense Pty Ltd.
;;; Released under the Affero General Public Licence (AGPL) v3. See LICENSE file for details.
(ns imas-seamap.map.views
(:require [reagent.core :as r]
(:require [clojure.string :as string]
[reagent.core :as r]
[re-frame.core :as re-frame]
[imas-seamap.blueprint :as b]
[imas-seamap.utils :refer [copy-text handler-dispatch create-shadow-dom-element format-number] :include-macros true]
Expand Down Expand Up @@ -216,14 +217,29 @@
(defmethod layer-component :feature
[{:keys [layer-opacities layer] {:keys [server_url]} :displayed-layer}]
[leaflet/feature-layer
{:url server_url
:opacity (/ (layer-opacities layer) 100)
{:url server_url
:opacity (/ (layer-opacities layer) 100)
:eventHandlers
{:loading #(re-frame/dispatch [:map.layer/load-start layer])
:tileloadstart #(re-frame/dispatch [:map.layer/tile-load-start layer])
:tileerror #(re-frame/dispatch [:map.layer/load-error layer])
:load #(re-frame/dispatch [:map.layer/load-finished layer])}}]) ; sometimes results in tile query errors: https://github.com/PaulLeCam/react-leaflet/issues/626

(defmethod layer-component :raster
[{:keys [layer-opacities layer] {:keys [server_url]} :displayed-layer}]
(let [layer-server-id (last (string/split server_url "/"))
url (string/join "/" (butlast (string/split server_url "/")))]
[leaflet/dynamic-map-layer
{:url url
:layers [layer-server-id]
:f "image"
:opacity (/ (layer-opacities layer) 100)
:eventHandlers
{:loading #(re-frame/dispatch [:map.layer/load-start layer])
:tileloadstart #(re-frame/dispatch [:map.layer/tile-load-start layer])
:tileerror #(re-frame/dispatch [:map.layer/load-error layer])
:load #(re-frame/dispatch [:map.layer/load-finished layer])}}])) ; sometimes results in tile query errors: https://github.com/PaulLeCam/react-leaflet/issues/626

(defmethod layer-component :wms-non-tiled
[{:keys [boundary-filter layer-opacities layer] {:keys [server_url layer_name style]} :displayed-layer}]
[leaflet/non-tiled-layer
Expand Down

0 comments on commit b53c927

Please sign in to comment.