Fork me on GitHub
#helix
<
2020-11-02
>
Christopher Stone00:11:16

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.

lilactown01:11:23

Can you paste what you’ve tried so far?

lilactown01:11:40

I’ll help as much as I can 🙂

Christopher Stone01:11:24

(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"}}) )

Christopher Stone01:11:02

its displaying as is... but if I change it to this:

Christopher Stone01:11:57

(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"}}) )

Christopher Stone01:11:55

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...

ordnungswidrig11:11:50

@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

Christopher Stone11:11:03

Thanks for your thoughtful answer, It has made clear a few distinctions, I shall explore this much more, thanks again 🙂