This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-02
Channels
- # announcements (1)
- # babashka (19)
- # beginners (85)
- # calva (1)
- # cider (23)
- # clara (19)
- # clj-kondo (28)
- # clojars (4)
- # clojure (60)
- # clojure-australia (8)
- # clojure-dev (14)
- # clojure-europe (117)
- # clojure-nl (3)
- # clojure-uk (11)
- # clojurescript (68)
- # conjure (2)
- # core-async (39)
- # cryogen (11)
- # cursive (7)
- # data-science (1)
- # datomic (9)
- # emacs (10)
- # etaoin (1)
- # events (1)
- # fulcro (1)
- # helix (10)
- # jobs (4)
- # kaocha (2)
- # keechma (3)
- # leiningen (1)
- # malli (6)
- # pathom (15)
- # pedestal (10)
- # re-frame (5)
- # reitit (1)
- # remote-jobs (1)
- # rum (3)
- # shadow-cljs (18)
- # tools-deps (30)
- # vim (6)
I feel a bit awkward asking you for help again. But once again I am stuck; I am able to display a map, but, I am unsure on how to create an instance of that map so that I can access methods on it after it has been created. Every time i try to store an instance of it as a let binding, and try to pass that to use-effect I get an error asking me if I meant to pass it a function instead of a symbol? I really don't know what to do, please advise.
(defnc customer-map [] (let [osm-layer (L/tileLayer osm-url copy-osm) home-marker (L/marker default-center) collection-points @(rf/subscribe [:collection-points]) collection-point-markers (for [point collection-points] (L/marker (:latlng point))) layers (L/layerGroup [home-marker collection-point-markers]) map-element (js/document.getElementById "map")] (prn (obj->clj layers)) (use-effect :once (L/map "map" (clj->js {:center default-center :zoom 9 :zoomControl false :layers [osm-layer layers] })))) (d/div {:id "map" :style {:min-height "300px"}}) )
its displaying as is... but if I change it to this:
(defnc customer-map [] (let [osm-layer (L/tileLayer osm-url copy-osm) home-marker (L/marker default-center) collection-points @(rf/subscribe [:collection-points]) collection-point-markers (for [point collection-points] (L/marker (:latlng point))) layers (L/layerGroup [home-marker collection-point-markers]) map-element (js/document.getElementById "map") the-map (L/map "map" (clj->js {:center default-center :zoom 9 :zoomControl false :layers [osm-layer layers] }))] (prn (obj->clj layers)) (use-effect :once the-map)) (d/div {:id "map" :style {:min-height "300px"}}) )
I have problems
I need to be able to store the map as an instance because it has methods to do things like flyTo another location or addTo, to add things to the map... etc...
@alpha_command I think you need the ref
attribute off react. This allows you to actually access the instance. See https://github.com/reagent-project/reagent/blob/master/doc/FAQ/UsingRefs.md
Thanks for your thoughtful answer, It has made clear a few distinctions, I shall explore this much more, thanks again 🙂