From 83527f5caefc1c72c05833b14cf45391c6f5a9b4 Mon Sep 17 00:00:00 2001 From: Swrup Date: Sat, 18 Jun 2022 07:53:26 +0200 Subject: [PATCH] change map creation --- example/main.ml | 8 +------- src/map.ml | 11 +++++++---- src/map.mli | 11 ++++++++--- 3 files changed, 16 insertions(+), 14 deletions(-) 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
" 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 d027da4..c1a7770 100644 --- a/src/map.mli +++ b/src/map.mli @@ -2,9 +2,14 @@ type t -(** [create container] creates a map on [container]. * To have a functional map - you will need to add a tile layer to it. *) -val create : ?options:Jv.t -> Brr.El.t -> t +(** [create id] creates a map on the
with DOM id [id]. To have a + functional map you will need to add a tile layer to it. *) +val create_on : ?options:Jv.t -> string -> t + +(** [create_from_div container] creates a map given [container], an instance of + a
HTML element. To have a functional map you will need to add a tile + layer to it. *) +val create_from_div : ?options:Jv.t -> Brr.El.t -> t (** [invalidate_size map] checks if the map container size changed and updates the map if so *)