···1+open Js_of_ocaml
2+3+let fetch url =
4+ let x = XmlHttpRequest.create () in
5+ x##.responseType := Js.string "arraybuffer";
6+ x##_open (Js.string "GET") (Js.string url) Js._false;
7+ x##send Js.null;
8+ match x##.status with
9+ | 200 ->
10+ Js.Opt.case
11+ (File.CoerceTo.arrayBuffer x##.response)
12+ (fun () -> failwith ("Failed to read response from " ^ url))
13+ (fun b -> Typed_array.String.of_arrayBuffer b)
14+ | code ->
15+ failwith (Printf.sprintf "HTTP %d fetching %s" code url)
16+17+let fetch_mosaic ?base_url ?version ~year bbox =
18+ Geotessera.fetch_mosaic_sync ~fetch ?base_url ?version ~year bbox
+15
tessera-geotessera-jsoo/lib/geotessera_jsoo.mli
···000000000000000
···1+(** Browser-compatible fetch for GeoTessera tiles.
2+3+ Provides synchronous HTTP GET via XMLHttpRequest for use in web workers,
4+ and a convenience wrapper around {!Geotessera.fetch_mosaic_sync}. *)
5+6+val fetch : string -> string
7+(** Synchronous HTTP GET via XMLHttpRequest.
8+ Returns the response body as a string.
9+ @raise Failure on non-200 status or if response cannot be read. *)
10+11+val fetch_mosaic : ?base_url:string -> ?version:string -> year:int ->
12+ Geotessera.bbox -> Linalg.mat * int * int
13+(** Fetch and assemble tiles for a bounding box using browser XHR.
14+ Convenience wrapper around {!Geotessera.fetch_mosaic_sync}
15+ with {!fetch} as the fetch function. *)