diff --git a/src/layer.ml b/src/layer.ml index 85a9ce8..f98de08 100644 --- a/src/layer.ml +++ b/src/layer.ml @@ -118,7 +118,30 @@ let create_geojson : Jv.t -> geojson_opt list -> [ `Geojson ] t = let jv_t = Jv.call Global.leaflet "geoJSON" [| geojson; Jv.obj l |] in Geojson jv_t +(** Tile layers *) + +let create_tile_osm : string option -> [ `Tile ] t = + fun url -> + let url = + Option.value url + ~default:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" + in + let jv_t = + Jv.call Global.leaflet "tileLayer" + [| Jv.of_string url + ; Jv.obj + [| ( "attribution" + , Jv.of_string + "© OpenStreetMap \ + contributors" ) + |] + |] + in + Tile jv_t + (** Marker layers *) +(* TODO make a Marker module? *) type marker_opt = | Icon of Icon.t @@ -168,24 +191,28 @@ let create_marker : Latlng.t -> marker_opt list -> [ `Marker ] t = in Marker jv_t -(** Tile layers *) +let get_latlng : [ `Marker ] t -> Latlng.t = function + | Marker marker -> Jv.call marker "getLatLng" [||] |> Latlng.of_jv -let create_tile_osm : string option -> [ `Tile ] t = - fun url -> - let url = - Option.value url - ~default:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" - in - let jv_t = - Jv.call Global.leaflet "tileLayer" - [| Jv.of_string url - ; Jv.obj - [| ( "attribution" - , Jv.of_string - "© OpenStreetMap \ - contributors" ) - |] - |] - in - Tile jv_t +let set_latlng latlng : [ `Marker ] t -> unit = function + | Marker marker -> + let (_ : Jv.t) = Jv.call marker "setLatLng" [| Latlng.to_jv latlng |] in + () + +let set_z_index_offset z_index : [ `Marker ] t -> unit = function + | Marker marker -> + let (_ : Jv.t) = Jv.call marker "setZIndexOffset" [| Jv.of_int z_index |] in + () + +let get_icon : [ `Marker ] t -> Icon.t = function + | Marker marker -> Jv.call marker "getIcon" [||] |> Icon.of_jv + +let set_icon icon : [ `Marker ] t -> unit = function + | Marker marker -> + let (_ : Jv.t) = Jv.call marker "setIcon" [| Icon.to_jv icon |] in + () + +let set_opacity opacity : [ `Marker ] t -> unit = function + | Marker marker -> + let (_ : Jv.t) = Jv.call marker "setOpacity" [| Jv.of_int opacity |] in + () diff --git a/src/layer.mli b/src/layer.mli index e819d2e..84586d7 100644 --- a/src/layer.mli +++ b/src/layer.mli @@ -62,6 +62,13 @@ type geojson_opt = (** [create_geojson geojson] is a new geojson layer *) val create_geojson : Jv.t -> geojson_opt list -> [ `Geojson ] t +(** Tile layers *) + +(** [create_tile_osm Some(url)] is a new tile layer with tile server specified + by [url]. Tile server default to [openstreetmap.org]. See + {:https://wiki.openstreetmap.org/wiki/Tile_servers} *) +val create_tile_osm : string option -> [ `Tile ] t + (** Marker layers *) (** type for marker option, used to create marker *) @@ -83,9 +90,20 @@ type marker_opt = [latlng] and with options set to [options] *) val create_marker : Latlng.t -> marker_opt list -> [ `Marker ] t -(** Tile layers *) +(** Returns the current geographical position of the marker. *) +val get_latlng : [ `Marker ] t -> Latlng.t -(** [create_tile_osm Some(url)] is a new tile layer with tile server specified - by [url]. Tile server default to [openstreetmap.org]. See - {:https://wiki.openstreetmap.org/wiki/Tile_servers} *) -val create_tile_osm : string option -> [ `Tile ] t +(** Changes the marker position to the given point. *) +val set_latlng : Latlng.t -> [ `Marker ] t -> unit + +(** Changes the zIndex offset of the marker. *) +val set_z_index_offset : int -> [ `Marker ] t -> unit + +(** Returns the current icon used by the marker *) +val get_icon : [ `Marker ] t -> Icon.t + +(** Changes the marker icon. *) +val set_icon : Icon.t -> [ `Marker ] t -> unit + +(** Changes the opacity of the marker. *) +val set_opacity : int -> [ `Marker ] t -> unit