change map creation

This commit is contained in:
Swrup 2022-06-18 07:53:26 +02:00
parent 2f12dc381a
commit ea061ebe66
3 changed files with 16 additions and 14 deletions

View file

@ -1,11 +1,5 @@
(* create map *) (* create map *)
let map = let map = Leaflet.Map.create_on "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
(* setup map *) (* setup map *)
let () = let () =

View file

@ -6,10 +6,13 @@ let of_jv = Fun.id
let to_jv = Fun.id let to_jv = Fun.id
let create ?(options = Jv.null) container = let create_on ?(options = Jv.null) id =
match Brr.El.at (Jstr.of_string "id") container with Jv.call Global.leaflet "map" [| Jv.of_string id; options |]
| None -> failwith "container doesn't have id"
| Some id -> Jv.call Global.leaflet "map" [| Jv.of_jstr 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 <div>"
let invalidate_size map = let invalidate_size map =
let (_ : Jv.t) = Jv.call map "invalidateSize" [| Jv.true' |] in let (_ : Jv.t) = Jv.call map "invalidateSize" [| Jv.true' |] in

View file

@ -2,9 +2,14 @@
type t type t
(** [create container] creates a map on [container]. * To have a functional map (** [create id] creates a map on the <div> with DOM id [id]. To have a
you will need to add a tile layer to it. *) functional map you will need to add a tile layer to it. *)
val create : ?options:Jv.t -> Brr.El.t -> t val create_on : ?options:Jv.t -> string -> t
(** [create_from_div container] creates a map given [container], an instance of
a <div> 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 (** [invalidate_size map] checks if the map container size changed and updates
the map if so *) the map if so *)