add Icon.create_div

This commit is contained in:
Swrup 2022-11-24 19:21:57 +01:00
parent 7effdcc577
commit ce8dcba87a
2 changed files with 29 additions and 0 deletions

View file

@ -4,6 +4,8 @@ type t = Jv.t
let to_jv = Fun.id
let of_jv = Fun.id
type opt =
| Icon_retina_url of string
| Icon_size of Point.t
@ -47,3 +49,21 @@ let create icon_url options =
let l = List.map (fun o -> (to_string o, opt_to_jv o)) options in
let l = Array.of_list @@ (("iconUrl", Jv.of_string icon_url) :: l) in
Jv.call Global.leaflet "icon" [| Jv.obj l |]
let create_div ~html ~bg_pos options =
let l = List.map (fun o -> (to_string o, opt_to_jv o)) options in
let div_options =
let html =
match html with
| None -> []
| Some html -> [ ("html", Jv.of_string html) ]
in
let bg_pos =
match bg_pos with
| None -> []
| Some bg_pos -> [ ("bgPos", Point.to_jv bg_pos) ]
in
html @ bg_pos
in
let l = Array.of_list @@ div_options @ l in
Jv.call Global.leaflet "divIcon" [| Jv.obj l |]