diff --git a/example/dune b/example/dune index 80423a9..1b81cc6 100644 --- a/example/dune +++ b/example/dune @@ -1,7 +1,7 @@ (executable (name main) (modules main) - (libraries leaflet) + (libraries brr leaflet) (modes js) (preprocess (pps js_of_ocaml-ppx))) diff --git a/example/main.ml b/example/main.ml index 9b8e97d..9e685c4 100644 --- a/example/main.ml +++ b/example/main.ml @@ -1,7 +1,11 @@ (* create map *) let map = - let container_id = "map" in - Leaflet.Map.create container_id + let container = + match Brr.Document.find_el_by_id Brr.G.document (Jstr.of_string "map") with + | None -> failwith "map container not found" + | Some el -> el + in + Leaflet.Map.create container (* setup map *) let () = diff --git a/src/map.ml b/src/map.ml index 259efeb..8277a9a 100644 --- a/src/map.ml +++ b/src/map.ml @@ -6,8 +6,10 @@ let of_jv = Fun.id let to_jv = Fun.id -let create ?(options = Jv.null) container_id = - Jv.call Global.leaflet "map" [| Jv.of_string container_id; options |] +let create ?(options = Jv.null) container = + match Brr.El.at (Jstr.of_string "id") container with + | None -> failwith "container doesn't have id" + | Some id -> Jv.call Global.leaflet "map" [| Jv.of_jstr id; options |] let invalidate_size map = let (_ : Jv.t) = Jv.call map "invalidateSize" [| Jv.true' |] in diff --git a/src/map.mli b/src/map.mli index 96795cb..15c1f2b 100644 --- a/src/map.mli +++ b/src/map.mli @@ -2,7 +2,7 @@ type t -val create : ?options:Jv.t -> string -> t +val create : ?options:Jv.t -> Brr.El.t -> t val invalidate_size : t -> unit