[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[paparazzi-commits] [4206] Add option to use OSM tiles
From: |
Pascal Brisset |
Subject: |
[paparazzi-commits] [4206] Add option to use OSM tiles |
Date: |
Tue, 29 Sep 2009 07:34:36 +0000 |
Revision: 4206
http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=4206
Author: hecto
Date: 2009-09-29 07:34:36 +0000 (Tue, 29 Sep 2009)
Log Message:
-----------
Add option to use OSM tiles
Modified Paths:
--------------
paparazzi3/trunk/sw/ground_segment/cockpit/gcs.ml
paparazzi3/trunk/sw/lib/ocaml/gm.ml
paparazzi3/trunk/sw/lib/ocaml/gm.mli
Modified: paparazzi3/trunk/sw/ground_segment/cockpit/gcs.ml
===================================================================
--- paparazzi3/trunk/sw/ground_segment/cockpit/gcs.ml 2009-09-29 02:02:59 UTC
(rev 4205)
+++ paparazzi3/trunk/sw/ground_segment/cockpit/gcs.ml 2009-09-29 07:34:36 UTC
(rev 4206)
@@ -326,6 +326,7 @@
"-no_alarm", Arg.Set no_alarm, "Disables alarm page";
"-no_google_http", Arg.Set Gm.no_http, "Switch off Google Maps downloading";
"-ortho", Arg.Set_string get_bdortho, "IGN tiles path";
+ "-osm", Arg.Unit (fun () -> Gm.maps_source := Gm.OSM), "Use OpenStreetMap
database (default is Google)";
"-particules", Arg.Set display_particules, "Display particules";
"-plugin", Arg.Set_string plugin_window, "External X application
(launched with the id of the plugin window as argument)";
"-ref", Arg.Set_string geo_ref, "Geographic ref (e.g. 'WGS84 43.605
1.443')";
Modified: paparazzi3/trunk/sw/lib/ocaml/gm.ml
===================================================================
--- paparazzi3/trunk/sw/lib/ocaml/gm.ml 2009-09-29 02:02:59 UTC (rev 4205)
+++ paparazzi3/trunk/sw/lib/ocaml/gm.ml 2009-09-29 07:34:36 UTC (rev 4206)
@@ -40,6 +40,14 @@
height : float (* Latitude difference *)
}
+type maps_source = Google | OSM
+
+let maps_source = ref Google
+
+let mkdir = fun d ->
+ if not (Sys.file_exists d) then
+ Unix.mkdir d 0o755
+
let (/.=) r x = r := !r /. x
let (+.=) r x = r := !r +. x
@@ -140,8 +148,9 @@
a = String.sub b 0 (String.length a)
-let get_from_cache = fun f ->
- let files = Sys.readdir !cache_path in
+(** Get the tile or one which contains it from the cache *)
+let get_from_cache = fun dir f ->
+ let files = Sys.readdir dir in
let rec loop = fun i ->
if i < Array.length files then
let fi = files.(i) in
@@ -172,10 +181,17 @@
done;
(!x, !y, n-1)
-let google_maps_url = fun s ->
+let url_of_tile_key = fun maps_source s ->
let (x, y, z) = xyz_of_qsrt s in
- sprintf "http://khm0.google.com/kh/v=45&x=%d&s=&y=%d&z=%d" x y z
+ match maps_source with
+ Google -> sprintf "http://khm0.google.com/kh/v=45&x=%d&s=&y=%d&z=%d" x y z
+ | OSM -> sprintf "http://tile.openstreetmap.org/%d/%d/%d.png" z x y
+let get_cache_dir = function
+ Google -> !cache_path (* Historic ! Should be // Google *)
+ | OSM -> !cache_path // "OSM"
+
+
exception Not_available
let no_http = ref false
@@ -184,13 +200,15 @@
let get_image = fun key ->
- try get_from_cache key with
+ let cache_dir = get_cache_dir !maps_source in
+ mkdir cache_dir;
+ try get_from_cache cache_dir key with
Not_found ->
if !no_http then raise Not_available;
let rec loop = fun k ->
if String.length k >= 1 then
- let url = google_maps_url k in
- let jpg_file = !cache_path // (k ^ ".jpg") in
+ let url = url_of_tile_key !maps_source k in
+ let jpg_file = cache_dir // (k ^ ".jpg") in
try
ignore (Http.file_of_url ~dest:jpg_file url);
tile_of_key k, jpg_file
Modified: paparazzi3/trunk/sw/lib/ocaml/gm.mli
===================================================================
--- paparazzi3/trunk/sw/lib/ocaml/gm.mli 2009-09-29 02:02:59 UTC (rev
4205)
+++ paparazzi3/trunk/sw/lib/ocaml/gm.mli 2009-09-29 07:34:36 UTC (rev
4206)
@@ -34,6 +34,8 @@
width : float; (* Longitude difference *)
height : float (* Latitude difference *)
}
+
+type maps_source = Google | OSM
val tile_of_geo : Latlong.geographic -> int -> tile_t
(** [tile_string geo zoom] Returns the tile description containing a
@@ -47,6 +49,9 @@
val no_http : bool ref
(** Initialized to false. Set to use only the cache *)
+val maps_source : maps_source ref
+(** Initialized to Google *)
+
exception Not_available
val get_image : string -> tile_t * string
@@ -55,6 +60,3 @@
val get_tile : Latlong.geographic -> int -> tile_t*string
(** [get_tile geo zoom] May raise [Not_available] *)
-
-
-
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [paparazzi-commits] [4206] Add option to use OSM tiles,
Pascal Brisset <=