Skip to content

Commit

Permalink
Merge pull request #7 from sagotch/lazy
Browse files Browse the repository at this point in the history
Made my_position lazy in order to use defer attribute on googlemaps js file.
  • Loading branch information
vouillon authored Sep 1, 2016
2 parents 6e41eac + 294504d commit 3869936
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions geoloc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ let coords_of_latlng ll =

(** Value containing "my position" **)
let my_position =
let opts = MarkerOptions.create
~draggable:false
~clickable:true
~title:"Ma position"
~visible:false
~z_index:17.
()
in
Marker.new_marker ~opts ()
lazy (let opts = MarkerOptions.create
~draggable:false
~clickable:true
~title:"Ma position"
~visible:false
~z_index:17.
()
in Marker.new_marker ~opts ())

let set_my_position_icon url =
Marker.set_icon my_position (Icon.create ~url ())
Marker.set_icon (Lazy.force my_position) (Icon.create ~url ())

(** Function taking a string representing the id of the div
containing the map **)
Expand Down Expand Up @@ -86,7 +85,7 @@ let show_my_position ?(interval=3.) map =
"Lng : "^(string_of_float lng)^"\n" in
let () = Firebug.console##log (Js.string str) in
let latlng = LatLng.new_lat_lng lat lng in
let () = Marker.set_position my_position latlng in
let () = Marker.set_position (Lazy.force my_position) latlng in
let%lwt () = Lwt_mutex.lock lock in
let%lwt () = Lwt_js.sleep interval in
if !showing
Expand All @@ -100,15 +99,15 @@ let show_my_position ?(interval=3.) map =
if !showing
then Lwt.return (Lwt_mutex.unlock lock)
else let () = showing := true in
let () = Marker.set_map my_position (Some(map)) in
let () = Marker.set_visible my_position true in
let () = Marker.set_map (Lazy.force my_position) (Some(map)) in
let () = Marker.set_visible (Lazy.force my_position) true in
let () = Lwt_mutex.unlock lock in
aux ()

let hide_my_position () =
let%lwt () = Lwt_mutex.lock lock in
let () = showing := false in
let () = Marker.set_visible my_position false in
let () = Marker.set_visible (Lazy.force my_position) false in
let () = Lwt_mutex.unlock lock in
Lwt.return ()

Expand Down Expand Up @@ -196,8 +195,6 @@ let coords_of_path path =
let latlngs = latlngs_of_path path in
List.map coords_of_latlng latlngs



let is_tracking = ref false
let track_lock = Lwt_mutex.create ()

Expand Down
2 changes: 1 addition & 1 deletion geoloc.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ val latlng_of_coords : float * float -> LatLng.t
val coords_of_latlng : LatLng.t -> float * float

(** Marker for "my position" **)
val my_position : Marker.t
val my_position : Marker.t Lazy.t

(** Change the icon for the "my position" marker **)
val set_my_position_icon : string -> unit
Expand Down

0 comments on commit 3869936

Please sign in to comment.