1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 Handle zoom levels for stops, pois, and turns. It turns out that all three are
23 sufficiently similar that they can be processed generically.
24 """
25
27 """
28 Find the first item in item_list closer to the check_item than dist.
29
30 @param item_list: C{list} of L{Point} items to check
31 @type item_list: C{list} of L{Point}
32 @param check_item: L{Point} to check against
33 @type check_item: L{Point}
34 @param dist: threshhold distance to check for
35 @type dist: C{float}
36 """
37 for item in item_list:
38 if check_item.calculate_distance(item) <= dist:
39 return item
40
41 return None
42
44 """
45 Item referencing several non-zoomed items.
46
47 @ivar lat: latitude
48 @type lat: C{float}
49 @ivar lon: longitude
50 @type lon: C{float}
51 @ivar node_id: id of this item
52 @type node_id: C{int}
53 @ivar name: name of this item
54 @type name: C{string}
55 """
56 - def __init__(self, lat, lon, node_id, name):
57 """
58 Save the passed-in values
59
60 @param lat: latitude
61 @type lat: C{float}
62 @param lon: longitude
63 @type lon: C{float}
64 @param node_id: id
65 @type node_id: C{int}
66 @param name: name
67 @type name: C{string}
68 """
69 self.lat = lat
70 self.lon = lon
71 self.node_id = node_id
72 self.name = name
73
75 """
76 Generate a "compacted" list of items based on a full item list. This finds
77 all items that are close to eachother, within a distance of "dist", and
78 creates one item that references all of the close items. This is good when
79 a map would show a bunch of hard-to-read overlapping items at a spot, but
80 will now show one single item instead.
81
82 @param items: list of items to compact
83 @type items: C{list} of L{Point} items
84 @param dist: threshold distance between items
85 @type dist: C{float}
86 @param node_id: L{NodeId} object to get ids for zoomed items
87 @type node_id: L{NodeId}
88 """
89 zoomed_items = []
90
91
92 for index, item in enumerate(items):
93 old_item = find_close_item(zoomed_items, item, dist)
94 if old_item is not None:
95 old_item.name = "%s,%s" % (old_item.name, index+1)
96 else:
97 new_item = ZoomItem(item.lat, item.lon, node_id.next(), index+1)
98 zoomed_items.append(new_item)
99
100 return zoomed_items
101