Lines 1-123
Link Here
|
1 |
--- src/tracks.c.orig 2014-10-24 04:57:10 UTC |
|
|
2 |
+++ src/tracks.c |
3 |
@@ -41,8 +41,10 @@ bbox_t get_track_bbox(GSList *track); |
4 |
GSList * load_log_file_into_list(char *file); |
5 |
GSList * load_gpx_file_into_list(char *file); |
6 |
GSList * load_ols_XML_file_into_list(char *file); |
7 |
+GSList * load_kml_XML_file_into_list(char *file); |
8 |
GSList * parse_gpx_nodes(xmlNode *node); |
9 |
GSList * parse_ols_XML_nodes(xmlNode *node); |
10 |
+GSList * parse_kml_XML_nodes(xmlNode *node); |
11 |
|
12 |
void * fetch_track_thread(void *ptr); |
13 |
void * fetch_openrouteservice_track_thread(void *ptr); |
14 |
@@ -662,6 +664,30 @@ load_ols_XML_string_into_list(char *ols_ |
15 |
} |
16 |
|
17 |
GSList * |
18 |
+load_kml_XML_string_into_list(char *kml_string) |
19 |
+{ |
20 |
+ GSList *list = NULL; |
21 |
+ xmlDoc *doc = NULL; |
22 |
+ xmlNode *root_element = NULL; |
23 |
+ |
24 |
+ if(!kml_string) return NULL; |
25 |
+ |
26 |
+ LIBXML_TEST_VERSION |
27 |
+ |
28 |
+ doc = xmlReadMemory(kml_string, strlen(kml_string), "noname.xml", NULL, 0); |
29 |
+ |
30 |
+ if (doc == NULL) { |
31 |
+ fprintf (stderr, _("Failed to parse document\n")); |
32 |
+ } else { |
33 |
+ root_element = xmlDocGetRootElement(doc); |
34 |
+ list = parse_kml_XML_nodes(root_element); |
35 |
+ xmlFreeDoc(doc); |
36 |
+ } |
37 |
+ |
38 |
+ return list; |
39 |
+} |
40 |
+ |
41 |
+GSList * |
42 |
parse_gpx_nodes(xmlNode *node) |
43 |
{ |
44 |
xmlNode *cur_node = NULL; |
45 |
@@ -754,6 +780,60 @@ parse_ols_XML_nodes(xmlNode *node) |
46 |
return list; |
47 |
} |
48 |
|
49 |
+GSList * |
50 |
+parse_kml_XML_nodes(xmlNode *node) |
51 |
+{ |
52 |
+ xmlNode *cur_node = NULL; |
53 |
+ GSList *list = NULL; |
54 |
+ |
55 |
+ for (cur_node = node; cur_node; cur_node = cur_node->next) |
56 |
+ { |
57 |
+ if (xmlStrEqual(cur_node->name, BAD_CAST "Placemark")) |
58 |
+ { |
59 |
+ xmlNode *geometry_node = cur_node->children; |
60 |
+ while (geometry_node != NULL) |
61 |
+ { |
62 |
+ if (xmlStrEqual(geometry_node->name, BAD_CAST "LineString")) |
63 |
+ { |
64 |
+ xmlNode *inner_cur_node = geometry_node->children; |
65 |
+ while (inner_cur_node != NULL) |
66 |
+ { |
67 |
+ if (xmlStrEqual(inner_cur_node->name, BAD_CAST "coordinates")) { |
68 |
+ char** lonlatlist; |
69 |
+ lonlatlist = g_strsplit(xmlNodeGetContent(inner_cur_node), "\n", -1); |
70 |
+ for(unsigned int i = 0; lonlatlist[i]; i++){ |
71 |
+ g_strchug(lonlatlist[i]); |
72 |
+ g_strchomp(lonlatlist[i]); |
73 |
+ char** lonlat = g_strsplit(lonlatlist[i], ",", 2); |
74 |
+ if (lonlat[0]) |
75 |
+ { |
76 |
+ double lat, lon; |
77 |
+ lon = atof(lonlat[0]); |
78 |
+ if (lonlat[1]) |
79 |
+ { |
80 |
+ trackpoint_t *tp = g_new0(trackpoint_t,1); |
81 |
+ lat = atof(lonlat[1]); |
82 |
+ tp->lat = deg2rad(lat); |
83 |
+ tp->lon = deg2rad(lon); |
84 |
+ list = g_slist_append(list, tp); |
85 |
+ } |
86 |
+ } |
87 |
+ g_strfreev (lonlat); |
88 |
+ } |
89 |
+ g_strfreev (lonlatlist); |
90 |
+ } |
91 |
+ inner_cur_node = inner_cur_node->next; |
92 |
+ } |
93 |
+ } |
94 |
+ geometry_node = geometry_node->next; |
95 |
+ } |
96 |
+ } |
97 |
+ list = g_slist_concat(list, parse_kml_XML_nodes(cur_node->children)); |
98 |
+ } |
99 |
+ |
100 |
+ return list; |
101 |
+} |
102 |
+ |
103 |
|
104 |
void |
105 |
fetch_track(GtkWidget *widget, char *service, char *start, char *end) |
106 |
@@ -796,7 +876,7 @@ void fetch_yournavigation_track(GtkWidge |
107 |
dialog10 = widget; |
108 |
printf("%s(): %s, %s\n",__PRETTY_FUNCTION__, start, end); |
109 |
|
110 |
- url = g_strdup_printf("http://www.yournavigation.org/api/dev/gosmore.php?format=gpx&flat=%s&flon=%s&tlat=%s&tlon=%s&v=motorcar&fast=1&layer=mapnik",startlatstr, startlonstr, endlatstr, endlonstr); |
111 |
+ url = g_strdup_printf("http://www.yournavigation.org/api/1.0/gosmore.php?format=kml&flat=%s&flon=%s&tlat=%s&tlon=%s&v=motorcar&fast=1&layer=mapnik",startlatstr, startlonstr, endlatstr, endlonstr); |
112 |
if (!g_thread_create(&fetch_track_thread, (void *)url, FALSE, NULL) != 0) |
113 |
g_warning("### can't create route thread\n"); |
114 |
} |
115 |
@@ -1002,7 +1082,7 @@ fetch_track_thread(void *ptr) |
116 |
|
117 |
printf("HTTP-GET: size: %d, statuscode %d \n", (int)reply->size, (int)reply->status_code); |
118 |
|
119 |
- loaded_track = load_gpx_string_into_list(reply->data); |
120 |
+ loaded_track = load_kml_XML_string_into_list(reply->data); |
121 |
process_fetched_track(reply, true); |
122 |
|
123 |
return NULL; |