3 # this is a very rustic script for generating png maps from a model
4 # the model is expected in /var/www/html/sites/map.png
5 # and the output is located in the same dir as livemap.png
7 # this has many drawbacks, as it needs a cylindric projection map
8 # (there's almost no such map out there) and manual calibration
9 # you want to use the kml-based googlemap applet instead
11 import Image, ImageDraw
13 ####### first - rustic - linear positioning on a map
14 def circle (image, percentX, percentY, radiusX, radiusY, colorIn, colorOut):
16 imageX, imageY = image.size
17 centerX = int(imageX*percentX)
18 centerY = int(imageY*percentY)
19 x = max (0, min (centerX,imageX))
20 y = max (0, min (centerY,imageY))
27 draw = ImageDraw.Draw (image)
28 draw.chord((x1,y1,x2,y2), 0, 360, fill=colorIn, outline=colorOut )
33 longitude={'left':-11.,
36 def render_site (site, image, sx, sy, cIn, cOut):
37 if site['longitude'] is not None and site['latitude'] is not None:
38 px=float(longitude['left']-site['longitude'])/float(longitude['left']-longitude['right'])
39 py=float(latitude['top']-site['latitude'])/float(latitude['top']-latitude['bottom'])
40 if (px<0 or py<0 or px>1 or py>1):
43 circle(image,px,py,sx,sy,cIn,cOut)
46 path = '/var/www/html/sites/'
47 original = path + 'map.png'
48 live = path + 'livemap.png'
50 # map characteristics, in degrees.
51 # latitude : positive is north
52 # longitude : positive is east
54 # circle radius in pixels
56 # circle in and out colors
57 cInLocal , cOutLocal = '#566b8a','#bbbbbb'
59 # same for federating / foreign sites
60 sxForeign,syForeign=6,6
61 cInForeign , cOutForeign = '#acb3a4', '#444444'
63 image = Image.open(original)
65 for site in GetSites({'~peer_id':None,'enabled':True}):
66 render_site (site, image, sxForeign, syForeign, cInForeign , cOutForeign)
67 # local sites go last to be more visible
68 for site in GetSites({'peer_id':None,'enabled':True}):
69 render_site (site, image, sxLocal, syLocal, cInLocal , cOutLocal)
76 if __name__ == '__main__':