From 96f18396809356ba05f0b2585e1c6b144b118e8d Mon Sep 17 00:00:00 2001 From: Swrup Date: Thu, 24 Nov 2022 19:21:57 +0100 Subject: [PATCH] add Icon.create_div --- src/icon.ml | 20 ++++++++++++++++++++ src/icon.mli | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/src/icon.ml b/src/icon.ml index c40305d..f8e1bb5 100644 --- a/src/icon.ml +++ b/src/icon.ml @@ -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 |] diff --git a/src/icon.mli b/src/icon.mli index 534c9d9..d7734dd 100644 --- a/src/icon.mli +++ b/src/icon.mli @@ -5,6 +5,9 @@ type t (** [to_jv o] is [o] as {!Jv.t} *) val to_jv : t -> Jv.t +(** [of_jv o] is [o] as {!Icon.t} *) +val of_jv : Jv.t -> t + (** type for icon option used to create an icon*) type opt = | Icon_retina_url of string @@ -22,3 +25,9 @@ type opt = (** [create icon_url options] Creates an icon instance with the given [options], and the required `iconUrl` option set to [icon_url] *) val create : string -> opt list -> t + +(** [create_div ~html ~bg_pos options] Creates an DivIcon instance with the + given [options], [bg_pos] is the optional relative position of the + background, in pixels [html] is custom HTML code to put inside the div + element, empty by default. *) +val create_div : html:string option -> bg_pos:Point.t option -> opt list -> t