source: subversion/applications/routing/pyroute/projection.py @ 5512

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

Zoom on the map, by dragging left/right at the top of the screen

File size: 1.5 KB
Line 
1
2class Projection:
3  def __init__(self):
4    self.xyValid = 0
5    self.llValid = 0
6  def isValid(self):
7    return(self.xyValid and self.llValid)
8  def setView(self,x,y,w,h):
9    self.w = w / 2
10    self.h = h / 2
11    self.xc = x + self.w
12    self.yc = y + self.h
13    self.xyValid = 1
14  def recentre(self,lat,lon,scale):
15    self.lat = lat
16    self.lon = lon
17    self.scale = scale  # TODO: scale and scaleCosLat
18    self.findEdges()
19    self.llValid = 1
20  def findEdges(self):
21    """(S,W,E,N) are derived from (lat,lon,scale)"""
22    self.S = self.lat - self.scale
23    self.N = self.lat + self.scale
24    self.W = self.lon - self.scale
25    self.E = self.lon + self.scale
26  def nudge(self,dx,dy,scale):
27    self.lat = self.lat + dy * scale * self.scale
28    self.lon = self.lon + dx * scale * self.scale
29    self.findEdges()
30  def nudgeZoom(self,amount):
31    self.scale = self.scale * (1 + amount)
32    self.findEdges()   
33  def ll2xy(self,lat,lon):
34    px = (lon - self.lon) / self.scale
35    py = (lat - self.lat) / self.scale
36    x = self.xc + self.w * px
37    y = self.yc - self.h * py
38    return(x,y)
39  def xy2ll(self,x,y):
40    px = (x - self.xc) / self.w
41    py = (y - self.yc) / self.h
42    lon = self.lon + px * self.scale
43    lat = self.lat - py * self.scale
44    return(lat,lon)
45  def onscreen(self,x,y):
46    return(x >= 0 and x < 2 * self.w and y >= 0 and y < 2 * self.h)
47  def relXY(self,x,y):
48    return(x/(2*self.w), y/(2*self.h))
49   
Note: See TracBrowser for help on using the repository browser.