Source

xJs / gmaps / mymap.ml

Full commit
open Spotlib_js.Spot
open XJs
open XJs.Std

let drawMap () = 
  let maps = GMaps.get () in
  (* The variable "google" must be referred in the function. 
     Map API is loaded lazyily
     and the variable google is not available before the loading is finished. *)

  let latlng = GMaps.latlng maps in

  let mapOptions = 
    let open GMaps.MapOptions in
    run &  center (latlng 1.306044 103.9047)
        ++ zoom 15
        ++ mapTypeId GMaps.MapTypeId.ROADMAP
  in
      
  let div = match getElementById "map_canvas" with
    | None -> assert false
    | Some div -> div
  in
  let themap = GMaps.map maps div mapOptions in

  let markerOptions = 
    let open GMaps.MarkerOptions in
    run &  position (latlng 1.306044 103.9047)
        ++ map themap
        ++ title (!$ "hello world")
  in
  let marker = GMaps.marker maps markerOptions in 
  ignore marker

let () = Unsafe.set_variable "initialize" drawMap

let () = set_onload (fun () ->
  GMaps.load 
    ~callback:"initialize" 
    ~sensor:false 
    ~key:"AIzaSyCzkJ0D1W9_nZROV296_TMnpbGEZa4hGcE" ())