source: subversion/applications/routing/pyroute/poi_base.py

Last change on this file was 5943, checked in by ojw, 12 years ago

The lists are now generic, so that things other than POIs can be displayed

File size: 1.6 KB
Line 
1import geometry
2from base import pyrouteModule
3import listable
4
5class poi:
6  def __init__(self,lat,lon):
7    self.lat = lat
8    self.lon = lon
9    self.title = 'Untitled at %1.3f, %1.3f' % (lat,lon)
10  def formatText(self):
11    return(self.title)
12  def distanceFrom(self,pos):
13    a = (pos['lat'], pos['lon'])
14    b = (self.lat,self.lon)
15    self.d = geometry.distance(a,b)
16    return(self.d)
17   
18  def __cmp__(self, other):
19    return cmp(self.d, other.d)
20
21class poiGroup(listable.listable):
22  def __init__(self,name):
23    self.items = []
24    self.name = name
25    self.sortpos = {'valid':False}
26   
27  # Functions to implement the listable interface
28  def numItems(self):
29    return(len(self.items))
30  def getItemText(self,n):
31    return(self.items[n].title)
32  def isLocation(self,n):
33    return(True)
34  def getItemLatLon(self,n):
35    item = self.items[n]
36    return(item.lat,item.lon)
37
38  def sort(self,pos):
39   
40    if(pos == self.sortpos):
41      return
42    self.sortpos = pos
43    print "Sorting"
44
45    if(pos['valid']):
46      for i in self.items:
47        i.d = i.distanceFrom(pos)
48
49    self.items.sort()
50    if(0):
51      for i in self.items:
52        print "%1.3f" % i.d
53
54   
55class poiModule(pyrouteModule):
56  def __init__(self, modules):
57    pyrouteModule.__init__(self, modules)
58    self.groups = []
59    self.draw = True
60
61  def sort(self, pos):
62    for g in self.groups:
63      g.sort(pos)
64     
65  def report(self):
66    for g in self.groups:
67      print "=== %s ===" % g.name
68      for i in g.items:
69        print "%1.3f, %1.3f = %s" % (i.lat, i.lon, i.title)
Note: See TracBrowser for help on using the repository browser.