59 |
if(id == ID_ILLEGAL) |
if(id == ID_ILLEGAL) |
60 |
str = g_strdup_printf(_("Unknown item")); |
str = g_strdup_printf(_("Unknown item")); |
61 |
else { |
else { |
62 |
str = g_strdup_printf("%s #%ld", item_str, id); |
str = g_strdup_printf("%s #" ITEM_ID_FORMAT, item_str, id); |
63 |
|
|
64 |
/* add some tags ... */ |
/* add some tags ... */ |
65 |
/* |
/* |
167 |
gint h = gdk_pixbuf_get_height(map_item->object.node->icon_buf); |
gint h = gdk_pixbuf_get_height(map_item->object.node->icon_buf); |
168 |
/* icons are technically square, so a radius slightly bigger */ |
/* icons are technically square, so a radius slightly bigger */ |
169 |
/* than sqrt(2)*MAX(w,h) should fit nicely */ |
/* than sqrt(2)*MAX(w,h) should fit nicely */ |
170 |
radius = 0.75 * map->style->icon.scale * ((w>h)?w:h); |
radius = 0.75 * map->style->icon.scale * ((w>h)?w:h); |
171 |
} |
} |
172 |
|
|
173 |
|
radius *= map->state->detail; |
174 |
map_hl_circle_new(map, CANVAS_GROUP_NODES_HL, new_map_item, |
map_hl_circle_new(map, CANVAS_GROUP_NODES_HL, new_map_item, |
175 |
x, y, radius, map->style->highlight.color); |
x, y, radius, map->style->highlight.color); |
176 |
|
|
199 |
map_statusbar(map, map_item); |
map_statusbar(map, map_item); |
200 |
icon_bar_map_item_selected(appdata, map_item, TRUE); |
icon_bar_map_item_selected(appdata, map_item, TRUE); |
201 |
gtk_widget_set_sensitive(appdata->menu_item_map_hide_sel, TRUE); |
gtk_widget_set_sensitive(appdata->menu_item_map_hide_sel, TRUE); |
202 |
|
|
203 |
gint arrow_width = (map_item->object.way->draw.flags & OSM_DRAW_FLAG_BG)? |
gint arrow_width = ((map_item->object.way->draw.flags & OSM_DRAW_FLAG_BG)? |
204 |
map->style->highlight.width + map_item->object.way->draw.bg.width/2: |
map->style->highlight.width + map_item->object.way->draw.bg.width/2: |
205 |
map->style->highlight.width + map_item->object.way->draw.width/2; |
map->style->highlight.width + map_item->object.way->draw.width/2) |
206 |
|
* map->state->detail; |
207 |
|
|
208 |
node_chain_t *node_chain = map_item->object.way->node_chain; |
node_chain_t *node_chain = map_item->object.way->node_chain; |
209 |
node_t *last = NULL; |
node_t *last = NULL; |
261 |
gint y = node_chain->node->lpos.y; |
gint y = node_chain->node->lpos.y; |
262 |
|
|
263 |
map_hl_circle_new(map, CANVAS_GROUP_NODES_IHL, new_map_item, |
map_hl_circle_new(map, CANVAS_GROUP_NODES_IHL, new_map_item, |
264 |
x, y, map->style->node.radius, |
x, y, map->style->node.radius * map->state->detail, |
265 |
map->style->highlight.node_color); |
map->style->highlight.node_color); |
266 |
} |
} |
267 |
|
|
289 |
new_map_item->highlight = TRUE; |
new_map_item->highlight = TRUE; |
290 |
|
|
291 |
map_hl_polyline_new(map, CANVAS_GROUP_WAYS_HL, new_map_item, points, |
map_hl_polyline_new(map, CANVAS_GROUP_WAYS_HL, new_map_item, points, |
292 |
(map_item->object.way->draw.flags & OSM_DRAW_FLAG_BG)? |
((map_item->object.way->draw.flags & OSM_DRAW_FLAG_BG)? |
293 |
2*map->style->highlight.width + map_item->object.way->draw.bg.width: |
2*map->style->highlight.width + map_item->object.way->draw.bg.width: |
294 |
2*map->style->highlight.width + map_item->object.way->draw.width, |
2*map->style->highlight.width + map_item->object.way->draw.width) |
295 |
map->style->highlight.color); |
* map->state->detail, map->style->highlight.color); |
296 |
|
|
297 |
canvas_points_free(points); |
canvas_points_free(points); |
298 |
} |
} |
299 |
} |
} |
301 |
void map_relation_select(appdata_t *appdata, relation_t *relation) { |
void map_relation_select(appdata_t *appdata, relation_t *relation) { |
302 |
map_t *map = appdata->map; |
map_t *map = appdata->map; |
303 |
|
|
304 |
printf("highlighting relation %ld\n", relation->id); |
printf("highlighting relation "ITEM_ID_FORMAT"\n", relation->id); |
305 |
|
|
306 |
g_assert(!map->highlight); |
g_assert(!map->highlight); |
307 |
map_highlight_t **hl = &map->highlight; |
map_highlight_t **hl = &map->highlight; |
320 |
while(member) { |
while(member) { |
321 |
canvas_item_t *item = NULL; |
canvas_item_t *item = NULL; |
322 |
|
|
323 |
switch(member->type) { |
switch(member->object.type) { |
324 |
|
|
325 |
case NODE: { |
case NODE: { |
326 |
node_t *node = member->node; |
node_t *node = member->object.node; |
327 |
printf(" -> node %ld\n", node->id); |
printf(" -> node "ITEM_ID_FORMAT"\n", node->id); |
328 |
|
|
329 |
item = canvas_circle_new(map->canvas, CANVAS_GROUP_NODES_HL, |
item = canvas_circle_new(map->canvas, CANVAS_GROUP_NODES_HL, |
330 |
node->lpos.x, node->lpos.y, |
node->lpos.x, node->lpos.y, |
333 |
} break; |
} break; |
334 |
|
|
335 |
case WAY: { |
case WAY: { |
336 |
way_t *way = member->way; |
way_t *way = member->object.way; |
337 |
/* a way needs at least 2 points to be drawn */ |
/* a way needs at least 2 points to be drawn */ |
338 |
guint nodes = osm_way_number_of_nodes(way); |
guint nodes = osm_way_number_of_nodes(way); |
339 |
if(nodes > 1) { |
if(nodes > 1) { |
474 |
else |
else |
475 |
map_item->item = canvas_image_new(map->canvas, CANVAS_GROUP_NODES, |
map_item->item = canvas_image_new(map->canvas, CANVAS_GROUP_NODES, |
476 |
node->icon_buf, |
node->icon_buf, |
477 |
node->lpos.x - map->style->icon.scale/2 * |
node->lpos.x - map->style->icon.scale/2 * map->state->detail * |
478 |
gdk_pixbuf_get_width(node->icon_buf), |
gdk_pixbuf_get_width(node->icon_buf), |
479 |
node->lpos.y - map->style->icon.scale/2 * |
node->lpos.y - map->style->icon.scale/2 * map->state->detail * |
480 |
gdk_pixbuf_get_height(node->icon_buf), |
gdk_pixbuf_get_height(node->icon_buf), |
481 |
map->style->icon.scale,map->style->icon.scale); |
map->state->detail * map->style->icon.scale, |
482 |
|
map->state->detail * map->style->icon.scale); |
483 |
|
|
484 |
canvas_item_set_zoom_max(map_item->item, node->zoom_max); |
canvas_item_set_zoom_max(map_item->item, |
485 |
|
node->zoom_max / (2 * map->state->detail)); |
486 |
|
|
487 |
/* attach map_item to nodes map_item_chain */ |
/* attach map_item to nodes map_item_chain */ |
488 |
map_item_chain_t **chain = &node->map_item_chain; |
map_item_chain_t **chain = &node->map_item_chain; |
544 |
map_item->item = canvas_polyline_new(map->canvas, group, points, width, color); |
map_item->item = canvas_polyline_new(map->canvas, group, points, width, color); |
545 |
} |
} |
546 |
|
|
547 |
canvas_item_set_zoom_max(map_item->item, way->draw.zoom_max); |
canvas_item_set_zoom_max(map_item->item, |
548 |
|
way->draw.zoom_max / (2 * map->state->detail)); |
549 |
|
|
550 |
/* a ways outline itself is never dashed */ |
/* a ways outline itself is never dashed */ |
551 |
if (group != CANVAS_GROUP_WAYS_OL) |
if (group != CANVAS_GROUP_WAYS_OL) |
595 |
} |
} |
596 |
|
|
597 |
/* draw way */ |
/* draw way */ |
598 |
|
float width = way->draw.width * map->state->detail; |
599 |
|
|
600 |
if(way->draw.flags & OSM_DRAW_FLAG_AREA) { |
if(way->draw.flags & OSM_DRAW_FLAG_AREA) { |
601 |
map_way_new(map, CANVAS_GROUP_POLYGONS, way, points, |
map_way_new(map, CANVAS_GROUP_POLYGONS, way, points, |
602 |
way->draw.width, way->draw.color, way->draw.area.color); |
width, way->draw.color, way->draw.area.color); |
603 |
} else { |
} else { |
604 |
|
|
605 |
if(way->draw.flags & OSM_DRAW_FLAG_BG) { |
if(way->draw.flags & OSM_DRAW_FLAG_BG) { |
606 |
map_way_new(map, CANVAS_GROUP_WAYS_INT, way, points, |
map_way_new(map, CANVAS_GROUP_WAYS_INT, way, points, |
607 |
way->draw.width, way->draw.color, NO_COLOR); |
width, way->draw.color, NO_COLOR); |
608 |
|
|
609 |
map_way_new(map, CANVAS_GROUP_WAYS_OL, way, points, |
map_way_new(map, CANVAS_GROUP_WAYS_OL, way, points, |
610 |
way->draw.bg.width, way->draw.bg.color, NO_COLOR); |
way->draw.bg.width * map->state->detail, |
611 |
|
way->draw.bg.color, NO_COLOR); |
612 |
|
|
613 |
} else |
} else |
614 |
map_way_new(map, CANVAS_GROUP_WAYS, way, points, |
map_way_new(map, CANVAS_GROUP_WAYS, way, points, |
615 |
way->draw.width, way->draw.color, NO_COLOR); |
width, way->draw.color, NO_COLOR); |
616 |
} |
} |
617 |
canvas_points_free(points); |
canvas_points_free(points); |
618 |
} |
} |
625 |
|
|
626 |
if(!node->ways) |
if(!node->ways) |
627 |
map_node_new(map, node, |
map_node_new(map, node, |
628 |
map->style->node.radius, |
map->style->node.radius * map->state->detail, |
629 |
map->style->node.border_radius, |
map->style->node.border_radius * map->state->detail, |
630 |
map->style->node.fill_color, |
map->style->node.fill_color, |
631 |
map->style->node.color); |
map->style->node.color); |
632 |
|
|
633 |
else if(map->style->node.show_untagged || osm_node_has_tag(node)) |
else if(map->style->node.show_untagged || osm_node_has_tag(node)) |
634 |
map_node_new(map, node, |
map_node_new(map, node, |
635 |
map->style->node.radius, 0, |
map->style->node.radius * map->state->detail, 0, |
636 |
map->style->node.color, 0); |
map->style->node.color, 0); |
637 |
} |
} |
638 |
|
|
890 |
|
|
891 |
switch(map_item->object.type) { |
switch(map_item->object.type) { |
892 |
case NODE: |
case NODE: |
893 |
printf(" item is node #%ld\n", map_item->object.node->id); |
printf(" item is node #"ITEM_ID_FORMAT"\n", map_item->object.node->id); |
894 |
break; |
break; |
895 |
case WAY: |
case WAY: |
896 |
printf(" item is way #%ld\n", map_item->object.way->id); |
printf(" item is way #"ITEM_ID_FORMAT"\n", map_item->object.way->id); |
897 |
break; |
break; |
898 |
default: |
default: |
899 |
printf(" unknown item\n"); |
printf(" unknown item\n"); |
919 |
parent = map_item->object.node->map_item_chain->map_item; |
parent = map_item->object.node->map_item_chain->map_item; |
920 |
|
|
921 |
if(parent) |
if(parent) |
922 |
printf(" using parent item node #%ld\n", parent->object.node->id); |
printf(" using parent item node #" ITEM_ID_FORMAT "\n", |
923 |
|
parent->object.node->id); |
924 |
break; |
break; |
925 |
|
|
926 |
case WAY: |
case WAY: |
928 |
parent = map_item->object.way->map_item_chain->map_item; |
parent = map_item->object.way->map_item_chain->map_item; |
929 |
|
|
930 |
if(parent) |
if(parent) |
931 |
printf(" using parent item way #%ld\n", parent->object.way->id); |
printf(" using parent item way #" ITEM_ID_FORMAT "\n", |
932 |
|
parent->object.way->id); |
933 |
break; |
break; |
934 |
|
|
935 |
default: |
default: |
1296 |
} |
} |
1297 |
|
|
1298 |
void map_way_delete(appdata_t *appdata, way_t *way) { |
void map_way_delete(appdata_t *appdata, way_t *way) { |
1299 |
printf("deleting way #%ld from map and osm\n", way->id); |
printf("deleting way #" ITEM_ID_FORMAT " from map and osm\n", way->id); |
1300 |
|
|
1301 |
/* remove it visually from the screen */ |
/* remove it visually from the screen */ |
1302 |
map_item_chain_destroy(&way->map_item_chain); |
map_item_chain_destroy(&way->map_item_chain); |
1765 |
printf("Creating new map state\n"); |
printf("Creating new map state\n"); |
1766 |
map->state = g_new0(map_state_t, 1); |
map->state = g_new0(map_state_t, 1); |
1767 |
map->state->zoom = 0.25; |
map->state->zoom = 0.25; |
1768 |
|
map->state->detail = 1.0; |
1769 |
} |
} |
1770 |
|
|
1771 |
map->state->refcount++; |
map->state->refcount++; |
1978 |
/* deleting the selected item de-selects it ... */ |
/* deleting the selected item de-selects it ... */ |
1979 |
map_item_deselect(appdata); |
map_item_deselect(appdata); |
1980 |
|
|
1981 |
undo_remember_delete(appdata, item.object.type, item.object.ptr); |
undo_remember_delete(appdata, &item.object); |
1982 |
|
|
1983 |
switch(item.object.type) { |
switch(item.object.type) { |
1984 |
case NODE: |
case NODE: |
1985 |
printf("request to delete node #%ld\n", item.object.node->id); |
printf("request to delete node #" ITEM_ID_FORMAT "\n", |
1986 |
|
item.object.node->id); |
1987 |
|
|
1988 |
/* check if this node is part of a way with two nodes only. */ |
/* check if this node is part of a way with two nodes only. */ |
1989 |
/* we cannot delete this as this would also delete the way */ |
/* we cannot delete this as this would also delete the way */ |
2044 |
break; |
break; |
2045 |
|
|
2046 |
case WAY: |
case WAY: |
2047 |
printf("request to delete way #%ld\n", item.object.way->id); |
printf("request to delete way #" ITEM_ID_FORMAT "\n", item.object.way->id); |
2048 |
map_way_delete(appdata, item.object.way); |
map_way_delete(appdata, item.object.way); |
2049 |
break; |
break; |
2050 |
|
|
2057 |
|
|
2058 |
/* ----------------------- track related stuff ----------------------- */ |
/* ----------------------- track related stuff ----------------------- */ |
2059 |
|
|
2060 |
|
static gboolean track_pos2lpos(bounds_t *bounds, pos_t *pos, lpos_t *lpos) { |
2061 |
|
pos2lpos(bounds, pos, lpos); |
2062 |
|
|
2063 |
|
/* check if point is within bounds */ |
2064 |
|
return ((lpos->x >= bounds->min.x) && (lpos->x <= bounds->max.x) && |
2065 |
|
(lpos->y >= bounds->min.y) && (lpos->y <= bounds->max.y)); |
2066 |
|
} |
2067 |
|
|
2068 |
void map_track_draw_seg(map_t *map, track_seg_t *seg) { |
void map_track_draw_seg(map_t *map, track_seg_t *seg) { |
2069 |
|
bounds_t *bounds = map->appdata->osm->bounds; |
2070 |
|
|
2071 |
/* a track_seg needs at least 2 points to be drawn */ |
/* a track_seg needs at least 2 points to be drawn */ |
2072 |
guint pnum = track_seg_points(seg); |
guint pnum = track_seg_points(seg); |
2073 |
printf("seg of length %d\n", pnum); |
printf("seg of length %d\n", pnum); |
2074 |
|
|
2075 |
if(pnum == 1) { |
if(!pnum) |
2076 |
g_assert(!seg->item); |
return; |
2077 |
|
|
2078 |
seg->item = canvas_circle_new(map->canvas, CANVAS_GROUP_TRACK, |
/* nothing should have been drawn by now ... */ |
2079 |
seg->track_point->lpos.x, seg->track_point->lpos.y, |
g_assert(!seg->item_chain); |
2080 |
map->style->track.width/2.0, 0, map->style->track.color, NO_COLOR); |
|
2081 |
} |
track_item_chain_t **itemP = &seg->item_chain; |
2082 |
|
track_point_t *track_point = seg->track_point; |
2083 |
|
while(track_point) { |
2084 |
|
lpos_t lpos; |
2085 |
|
|
2086 |
|
/* skip all points not on screen */ |
2087 |
|
track_point_t *last = NULL; |
2088 |
|
while(track_point && !track_pos2lpos(bounds, &track_point->pos, &lpos)) { |
2089 |
|
last = track_point; |
2090 |
|
track_point = track_point->next; |
2091 |
|
} |
2092 |
|
|
2093 |
|
int visible = 0; |
2094 |
|
|
2095 |
|
/* count nodes that _are_ on screen */ |
2096 |
|
track_point_t *tmp = track_point; |
2097 |
|
while(tmp && track_pos2lpos(bounds, &tmp->pos, &lpos)) { |
2098 |
|
tmp = tmp->next; |
2099 |
|
visible++; |
2100 |
|
} |
2101 |
|
|
2102 |
|
/* actually start drawing with the last position that was offscreen */ |
2103 |
|
/* so the track nicely enters the viewing area */ |
2104 |
|
if(last) { |
2105 |
|
track_point = last; |
2106 |
|
visible++; |
2107 |
|
} |
2108 |
|
|
2109 |
|
/* also use last one that's offscreen to nicely leave the visible area */ |
2110 |
|
if(tmp && tmp->next) |
2111 |
|
visible++; |
2112 |
|
|
|
if(pnum > 1) { |
|
|
|
|
2113 |
/* allocate space for nodes */ |
/* allocate space for nodes */ |
2114 |
canvas_points_t *points = canvas_points_new(pnum); |
canvas_points_t *points = canvas_points_new(visible); |
2115 |
|
|
2116 |
int point = 0; |
printf("visible are %d\n", visible); |
2117 |
track_point_t *track_point = seg->track_point; |
int point; |
2118 |
while(track_point) { |
for(point=0;point<visible;point++) { |
2119 |
points->coords[point++] = track_point->lpos.x; |
track_pos2lpos(bounds, &track_point->pos, &lpos); |
2120 |
points->coords[point++] = track_point->lpos.y; |
|
2121 |
|
points->coords[2*point+0] = lpos.x; |
2122 |
|
points->coords[2*point+1] = lpos.y; |
2123 |
track_point = track_point->next; |
track_point = track_point->next; |
2124 |
} |
} |
|
|
|
|
/* there may be a circle (one point line) */ |
|
|
if(seg->item) |
|
|
canvas_item_destroy(seg->item); |
|
2125 |
|
|
2126 |
seg->item = canvas_polyline_new(map->canvas, CANVAS_GROUP_TRACK, |
*itemP = g_new0(track_item_chain_t, 1); |
2127 |
points, map->style->track.width, map->style->track.color); |
(*itemP)->item = canvas_polyline_new(map->canvas, CANVAS_GROUP_TRACK, |
2128 |
|
points, map->style->track.width, map->style->track.color); |
2129 |
|
itemP = &(*itemP)->next; |
2130 |
|
|
2131 |
canvas_points_free(points); |
canvas_points_free(points); |
2132 |
} |
} |
2133 |
} |
} |
2134 |
|
|
2135 |
|
/* update the last visible fragment of this segment since a */ |
2136 |
|
/* gps position may have been added */ |
2137 |
void map_track_update_seg(map_t *map, track_seg_t *seg) { |
void map_track_update_seg(map_t *map, track_seg_t *seg) { |
2138 |
|
bounds_t *bounds = map->appdata->osm->bounds; |
2139 |
|
|
2140 |
|
printf("-- APPENDING TO TRACK --\n"); |
2141 |
|
|
2142 |
/* a track_seg needs at least 2 points to be drawn */ |
/* a track_seg needs at least 2 points to be drawn */ |
2143 |
guint pnum = track_seg_points(seg); |
guint pnum = track_seg_points(seg); |
2144 |
printf("seg of length %d\n", pnum); |
printf("seg of length %d\n", pnum); |
2145 |
|
|
2146 |
if(pnum > 1) { |
/* there are two cases: either the second last point was on screen */ |
2147 |
|
/* or it wasn't. We'll have to start a new screen item if the latter */ |
2148 |
|
/* is the case */ |
2149 |
|
|
2150 |
|
/* search last point */ |
2151 |
|
track_point_t *begin = seg->track_point, *second_last = seg->track_point; |
2152 |
|
lpos_t lpos; |
2153 |
|
while(second_last && second_last->next && second_last->next->next) { |
2154 |
|
if(!track_pos2lpos(bounds, &second_last->pos, &lpos)) |
2155 |
|
begin = second_last; |
2156 |
|
|
2157 |
|
second_last = second_last->next; |
2158 |
|
} |
2159 |
|
track_point_t *last = second_last->next; |
2160 |
|
|
2161 |
|
/* since we are updating an existing track, it sure has at least two */ |
2162 |
|
/* points, second_last must be valid and its "next" (last) also */ |
2163 |
|
g_assert(second_last); |
2164 |
|
g_assert(last); |
2165 |
|
|
2166 |
|
/* check if the last and second_last points are visible */ |
2167 |
|
gboolean last_is_visible = |
2168 |
|
track_pos2lpos(bounds, &last->pos, &lpos); |
2169 |
|
gboolean second_last_is_visible = |
2170 |
|
track_pos2lpos(bounds, &second_last->pos, &lpos); |
2171 |
|
|
2172 |
|
/* if both are invisible, then nothing has changed on screen */ |
2173 |
|
if(!last_is_visible && !second_last_is_visible) { |
2174 |
|
printf("second_last and last entry are invisible -> doing nothing\n"); |
2175 |
|
return; |
2176 |
|
} |
2177 |
|
|
2178 |
|
/* search last element in item chain */ |
2179 |
|
track_item_chain_t *item = seg->item_chain; |
2180 |
|
while(item && item->next) |
2181 |
|
item = item->next; |
2182 |
|
|
2183 |
|
if(second_last_is_visible) { |
2184 |
|
/* there must be something already on the screen and there must */ |
2185 |
|
/* be visible nodes in the chain */ |
2186 |
|
g_assert(item); |
2187 |
|
g_assert(begin); |
2188 |
|
|
2189 |
|
printf("second_last is visible -> append\n"); |
2190 |
|
|
2191 |
/* allocate space for nodes */ |
/* count points to be placed */ |
2192 |
canvas_points_t *points = canvas_points_new(pnum); |
int npoints = 0; |
2193 |
|
track_point_t *tmp = begin; |
2194 |
|
while(tmp) { |
2195 |
|
tmp = tmp->next; |
2196 |
|
npoints++; |
2197 |
|
} |
2198 |
|
|
2199 |
|
printf("updating last segment to %d points\n", npoints); |
2200 |
|
|
2201 |
|
canvas_points_t *points = canvas_points_new(npoints); |
2202 |
|
|
2203 |
|
gint point = 0; |
2204 |
|
while(begin) { |
2205 |
|
track_pos2lpos(bounds, &begin->pos, &lpos); |
2206 |
|
canvas_point_set_pos(points, point++, &lpos); |
2207 |
|
begin = begin->next; |
2208 |
|
} |
2209 |
|
|
2210 |
int point = 0; |
canvas_item_set_points(item->item, points); |
2211 |
track_point_t *track_point = seg->track_point; |
canvas_points_free(points); |
2212 |
while(track_point) { |
|
2213 |
canvas_point_set_pos(points, point++, &track_point->lpos); |
} else { |
2214 |
track_point = track_point->next; |
printf("second last is invisible -> start new screen segment\n"); |
2215 |
|
|
2216 |
|
/* the search for the "begin" ends with the second_last item */ |
2217 |
|
/* verify the last one also */ |
2218 |
|
if(begin->next && !track_pos2lpos(bounds, &begin->next->pos, &lpos)) |
2219 |
|
begin = begin->next; |
2220 |
|
|
2221 |
|
item->next = g_new0(track_item_chain_t, 1); |
2222 |
|
item = item->next; |
2223 |
|
|
2224 |
|
/* count points to be placed */ |
2225 |
|
int npoints = 0; |
2226 |
|
track_point_t *tmp = begin; |
2227 |
|
while(tmp) { |
2228 |
|
tmp = tmp->next; |
2229 |
|
npoints++; |
2230 |
|
} |
2231 |
|
|
2232 |
|
printf("attaching new segment with %d points\n", npoints); |
2233 |
|
|
2234 |
|
canvas_points_t *points = canvas_points_new(npoints); |
2235 |
|
|
2236 |
|
gint point = 0; |
2237 |
|
while(begin) { |
2238 |
|
track_pos2lpos(bounds, &begin->pos, &lpos); |
2239 |
|
canvas_point_set_pos(points, point++, &lpos); |
2240 |
|
begin = begin->next; |
2241 |
} |
} |
2242 |
|
|
2243 |
g_assert(seg->item); |
item->item = canvas_polyline_new(map->canvas, CANVAS_GROUP_TRACK, |
2244 |
canvas_item_set_points(seg->item, points); |
points, map->style->track.width, map->style->track.color); |
2245 |
|
|
2246 |
canvas_points_free(points); |
canvas_points_free(points); |
2247 |
} |
} |
2248 |
|
|
2249 |
} |
} |
2250 |
|
|
2251 |
void map_track_draw(map_t *map, track_t *track) { |
void map_track_draw(map_t *map, track_t *track) { |
2268 |
/* remove all segments */ |
/* remove all segments */ |
2269 |
track_seg_t *seg = track->track_seg; |
track_seg_t *seg = track->track_seg; |
2270 |
while(seg) { |
while(seg) { |
2271 |
if(seg->item) { |
track_item_chain_t *item = seg->item_chain; |
2272 |
canvas_item_destroy(seg->item); |
while(item) { |
2273 |
seg->item = NULL; |
track_item_chain_t *next = item->next; |
2274 |
|
canvas_item_destroy(item->item); |
2275 |
|
item = next; |
2276 |
} |
} |
2277 |
|
|
2278 |
|
seg->item_chain = NULL; |
2279 |
seg = seg->next; |
seg = seg->next; |
2280 |
} |
} |
2281 |
} |
} |
2282 |
|
|
2283 |
void map_track_pos(appdata_t *appdata, lpos_t *lpos) { |
void map_track_pos(appdata_t *appdata, pos_t *pos) { |
2284 |
if(appdata->track.gps_item) { |
if(appdata->track.gps_item) { |
2285 |
canvas_item_destroy(appdata->track.gps_item); |
canvas_item_destroy(appdata->track.gps_item); |
2286 |
appdata->track.gps_item = NULL; |
appdata->track.gps_item = NULL; |
2287 |
} |
} |
2288 |
|
|
2289 |
if(lpos) |
if(pos) { |
2290 |
|
lpos_t lpos; |
2291 |
|
pos2lpos(appdata->osm->bounds, pos, &lpos); |
2292 |
|
|
2293 |
appdata->track.gps_item = |
appdata->track.gps_item = |
2294 |
canvas_circle_new(appdata->map->canvas, CANVAS_GROUP_GPS, |
canvas_circle_new(appdata->map->canvas, CANVAS_GROUP_GPS, |
2295 |
lpos->x, lpos->y, appdata->map->style->track.width/2.0, 0, |
lpos.x, lpos.y, appdata->map->style->track.width/2.0, 0, |
2296 |
appdata->map->style->track.gps_color, NO_COLOR); |
appdata->map->style->track.gps_color, NO_COLOR); |
2297 |
|
} |
2298 |
} |
} |
2299 |
|
|
2300 |
/* ------------------- map background ------------------ */ |
/* ------------------- map background ------------------ */ |
2355 |
} |
} |
2356 |
|
|
2357 |
way_t *way = map->selected.object.way; |
way_t *way = map->selected.object.way; |
2358 |
printf("hiding way #%ld\n", way->id); |
printf("hiding way #" ITEM_ID_FORMAT "\n", way->id); |
2359 |
|
|
2360 |
map_item_deselect(appdata); |
map_item_deselect(appdata); |
2361 |
way->flags |= OSM_FLAG_HIDDEN; |
way->flags |= OSM_FLAG_HIDDEN; |
2381 |
gtk_widget_set_sensitive(appdata->menu_item_map_show_all, FALSE); |
gtk_widget_set_sensitive(appdata->menu_item_map_show_all, FALSE); |
2382 |
} |
} |
2383 |
|
|
2384 |
|
static void map_detail_change(map_t *map, float detail) { |
2385 |
|
appdata_t *appdata = map->appdata; |
2386 |
|
|
2387 |
|
/* deselecting anything allows us not to care about automatic deselection */ |
2388 |
|
/* as well as items becoming invisible by the detail change */ |
2389 |
|
map_item_deselect(appdata); |
2390 |
|
|
2391 |
|
map->state->detail = detail; |
2392 |
|
printf("changing detail factor to %f\n", map->state->detail); |
2393 |
|
|
2394 |
|
banner_busy_start(appdata, 1, "Redrawing..."); |
2395 |
|
map_clear(appdata, MAP_LAYER_OBJECTS_ONLY); |
2396 |
|
map_paint(appdata); |
2397 |
|
banner_busy_stop(appdata); |
2398 |
|
} |
2399 |
|
|
2400 |
|
#define DETAIL_STEP 1.5 |
2401 |
|
|
2402 |
|
void map_detail_increase(map_t *map) { |
2403 |
|
if(!map) return; |
2404 |
|
map_detail_change(map, map->state->detail * DETAIL_STEP); |
2405 |
|
} |
2406 |
|
|
2407 |
|
void map_detail_decrease(map_t *map) { |
2408 |
|
if(!map) return; |
2409 |
|
map_detail_change(map, map->state->detail / DETAIL_STEP); |
2410 |
|
} |
2411 |
|
|
2412 |
|
void map_detail_normal(map_t *map) { |
2413 |
|
if(!map) return; |
2414 |
|
map_detail_change(map, 1.0); |
2415 |
|
} |
2416 |
|
|
2417 |
// vim:et:ts=8:sw=2:sts=2:ai |
// vim:et:ts=8:sw=2:sts=2:ai |