mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-26 16:30:07 +08:00
@@ -454,6 +454,7 @@ let create_geomap = fun switch_fullscreen editor_frame ->
|
||||
ignore (map_menu_fact#add_item "Map of Region" ~key:GdkKeysyms._R ~callback:(map_from_region geomap));
|
||||
ignore (map_menu_fact#add_item "Dump map of Tiles" ~key:GdkKeysyms._T ~callback:(GM.map_from_tiles geomap));
|
||||
ignore (map_menu_fact#add_item "Load sector" ~callback:(Sectors.load geomap));
|
||||
ignore (map_menu_fact#add_item "Load KML" ~callback:(Sectors.load_kml geomap));
|
||||
|
||||
(** Connect Maps display to view change *)
|
||||
geomap#connect_view (fun () -> GM.update geomap);
|
||||
|
||||
@@ -39,3 +39,14 @@ let load = fun geomap () ->
|
||||
let m = sprintf "Error while loading %s:\n%s" f (Dtd.prove_error e) in
|
||||
GToolbox.message_box "Error" m
|
||||
|
||||
let load_kml = fun geomap () ->
|
||||
match GToolbox.select_file ~title:"Load KML" ~filename:(Env.flight_plans_path // "*.kml") () with
|
||||
None -> ()
|
||||
| Some f ->
|
||||
try
|
||||
let xml = Xml.parse_file f in
|
||||
MapFP.display_kml "red" geomap xml
|
||||
with
|
||||
| Dtd.Prove_error(e) ->
|
||||
let m = sprintf "Error while loading KML %s:\n%s" f (Dtd.prove_error e) in
|
||||
GToolbox.message_box "Error" m
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
val load : MapCanvas.widget -> unit -> unit
|
||||
val load_kml : MapCanvas.widget -> unit -> unit
|
||||
|
||||
@@ -202,20 +202,21 @@ let display_kml = fun ?group color geomap xml ->
|
||||
try
|
||||
let document = ExtXml.child xml "Document" in
|
||||
let rec loop = fun child ->
|
||||
match String.lowercase (Xml.tag child) with
|
||||
"placemark" ->
|
||||
let linestring = ExtXml.child child "LineString" in
|
||||
let coordinates = ExtXml.child linestring "coordinates" in
|
||||
let tag = String.lowercase (Xml.tag child) in
|
||||
match tag with
|
||||
| "linestring" | "linearring" ->
|
||||
let coordinates = ExtXml.child child "coordinates" in
|
||||
begin
|
||||
match Xml.children coordinates with
|
||||
[Xml.PCData text] ->
|
||||
let points = Str.split space_regexp text in
|
||||
let points = List.map wgs84_of_kml_point points in
|
||||
(* remove a point if polygon (first in this case) since first and last are the same *)
|
||||
let points = if tag = "linearring" && List.length points > 0 then List.tl points else points in
|
||||
ignore(display_lines ?group color geomap (Array.of_list points))
|
||||
| _ -> failwith "coordinates expected"
|
||||
end
|
||||
|
||||
| "folder" ->
|
||||
| "folder" | "placemark" | "polygon" | "outerboundaryis" ->
|
||||
List.iter loop (Xml.children child)
|
||||
| _ -> () in
|
||||
List.iter loop (Xml.children document)
|
||||
|
||||
@@ -50,3 +50,7 @@ class flight_plan :
|
||||
|
||||
(** Extracts [lat0] and [Lon0] attributes *)
|
||||
val georef_of_xml : Xml.xml -> Latlong.geographic
|
||||
|
||||
(** Display a polygon based on a kml file *)
|
||||
val display_kml : ?group:GnoCanvas.group -> string -> MapCanvas.widget -> Xml.xml -> unit
|
||||
|
||||
|
||||
Reference in New Issue
Block a user