···11+open Js_of_ocaml
22+33+let fetch url =
44+ let x = XmlHttpRequest.create () in
55+ x##.responseType := Js.string "arraybuffer";
66+ x##_open (Js.string "GET") (Js.string url) Js._false;
77+ x##send Js.null;
88+ match x##.status with
99+ | 200 ->
1010+ Js.Opt.case
1111+ (File.CoerceTo.arrayBuffer x##.response)
1212+ (fun () -> failwith ("Failed to read response from " ^ url))
1313+ (fun b -> Typed_array.String.of_arrayBuffer b)
1414+ | code ->
1515+ failwith (Printf.sprintf "HTTP %d fetching %s" code url)
1616+1717+let fetch_mosaic ?base_url ?version ~year bbox =
1818+ Geotessera.fetch_mosaic_sync ~fetch ?base_url ?version ~year bbox
+15
tessera-geotessera-jsoo/lib/geotessera_jsoo.mli
···11+(** Browser-compatible fetch for GeoTessera tiles.
22+33+ Provides synchronous HTTP GET via XMLHttpRequest for use in web workers,
44+ and a convenience wrapper around {!Geotessera.fetch_mosaic_sync}. *)
55+66+val fetch : string -> string
77+(** Synchronous HTTP GET via XMLHttpRequest.
88+ Returns the response body as a string.
99+ @raise Failure on non-200 status or if response cannot be read. *)
1010+1111+val fetch_mosaic : ?base_url:string -> ?version:string -> year:int ->
1212+ Geotessera.bbox -> Linalg.mat * int * int
1313+(** Fetch and assemble tiles for a bounding box using browser XHR.
1414+ Convenience wrapper around {!Geotessera.fetch_mosaic_sync}
1515+ with {!fetch} as the fetch function. *)