diff --git a/example/main.ml b/example/main.ml index 9e685c4..43b9fcd 100644 --- a/example/main.ml +++ b/example/main.ml @@ -1,11 +1,5 @@ (* create map *) -let map = - 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 +let map = Leaflet.Map.create_on "map" (* setup map *) let () = diff --git a/src/map.ml b/src/map.ml index bbd5da3..2f2db23 100644 --- a/src/map.ml +++ b/src/map.ml @@ -6,10 +6,13 @@ let of_jv = Fun.id let to_jv = Fun.id -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 create_on ?(options = Jv.null) id = + Jv.call Global.leaflet "map" [| Jv.of_string id; options |] + +let create_from_div ?(options = Jv.null) container = + if Brr.El.has_tag_name Brr.El.Name.div container then + Jv.call Global.leaflet "map" [| Brr.El.to_jv container; options |] + else failwith "container is not a