From e0ca0443af9b65b88612a8e092fc10f1481231b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kom=D1=8Fpa?= Date: Thu, 24 Jun 2010 14:11:40 +0300 Subject: [PATCH] fixed GUI resize and zoomlevel calculation --- src/kothic.py | 21 ++++++++++----------- src/mapcss/__init__.py | 13 ++++++++++++- src/render.py | 11 ++++++----- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/kothic.py b/src/kothic.py index 9059548..9681643 100644 --- a/src/kothic.py +++ b/src/kothic.py @@ -28,7 +28,8 @@ import Queue from debug import debug, Timer from vtiles_backend import QuadTileBackend as DataBackend -from style import Styling +#from style import Styling +from mapcss import MapCSS as Styling from render import RasterTile @@ -52,7 +53,7 @@ class Renderer(threading.Thread): if(self.comm[0].empty): break #debug (" got request:", request) - res = RasterTile(request.size[0], request.size[1], request.zoomlevel, request.data_backend) + res = RasterTile(request.size[0], request.size[1], request.zoom, request.data_backend) res.update_surface_by_center(request.center_lonlat, request.zoom, request.style) comm[1].put(res) comm[0].task_done() @@ -63,9 +64,8 @@ class Navigator: self.comm = comm self.center_coord = (27.6749791, 53.8621394) self.width, self.height = 800, 480 - self.zoomlevel = 15. + self.zoom = 15. self.data_projection = "EPSG:4326" - self.zoom = self.width/0.02; self.request_d = (0,0) self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.data = DataBackend() @@ -133,13 +133,13 @@ class Navigator: def scroll_ev(self, widget, event): # Zoom test :3 if event.direction == gtk.gdk.SCROLL_UP: - self.zoom *= 2.**0.5 - self.zoomlevel += 0.5 + #self.zoom *= 2.**0.5 + self.zoom += 0.5 debug("Zoom in") elif event.direction == gtk.gdk.SCROLL_DOWN: - if self.zoomlevel >= 0: ## negative zooms are nonsense - self.zoom /= 2.**0.5 - self.zoomlevel -= 0.5 + if self.zoom >= 0: ## negative zooms are nonsense + #self.zoom /= 2.**0.5 + self.zoom -= 0.5 debug("Zoom out") self.redraw() # widget.queue_draw() @@ -150,7 +150,6 @@ class Navigator: com = MessageContainer() com.center_lonlat = self.center_coord com.data_backend = self.data - com.zoomlevel = self.zoomlevel com.zoom = self.zoom com.size = (self.width*3, self.height*3) com.style = self.style @@ -166,7 +165,7 @@ class Navigator: self.height = widget.allocation.height self.rastertile = None if self.rastertile is None: - self.rastertile = RasterTile(self.width*3, self.height*3, self.zoomlevel, self.data) + self.rastertile = RasterTile(self.width*3, self.height*3, self.zoom, self.data) self.rastertile.update_surface_by_center(self.center_coord, self.zoom, self.style, None) nrt = None while(not self.comm[1].empty()): diff --git a/src/mapcss/__init__.py b/src/mapcss/__init__.py index 0e24924..0636415 100644 --- a/src/mapcss/__init__.py +++ b/src/mapcss/__init__.py @@ -75,15 +75,24 @@ CENTER = re.compile(r'^center$/i') HEX = re.compile(r'^#([0-9a-f]+)$/i') +builtin_style = """ +canvas {fill-color: #ccc} +way {width: 1} +""" + + ## ** also needs to support @import rules class MapCSS(): - def __init__(self,minscale,maxscale): + def __init__(self,minscale=0,maxscale=19): """ """ self.minscale=minscale self.maxscale=maxscale self.choosers = [] + self.style_loaded = False + self.parse(builtin_style) + self.style_loaded = False #override one after loading def parseZoom(self, s): @@ -112,6 +121,8 @@ class MapCSS(): """ Parses MapCSS given as string """ + if not self.style_loaded: + self.choosers = [] log = logging.getLogger('mapcss.parser') previous = 0 # what was the previous CSS word? sc=StyleChooser() #currently being assembled diff --git a/src/render.py b/src/render.py index 4aaf9b2..63b9088 100644 --- a/src/render.py +++ b/src/render.py @@ -62,8 +62,8 @@ class RasterTile: self.zoom = zoom #self.zoom = 0.1 xy = projections.from4326(lonlat, self.proj) - xy1 = projections.to4326((xy[0]-self.w/2/self.zoom, xy[1]-self.h/2/self.zoom), self.proj) - xy2 = projections.to4326((xy[0]+self.w/2/self.zoom, xy[1]+self.h/2/self.zoom), self.proj) + xy1 = projections.to4326((xy[0]-40075016*0.5**self.zoom/256*self.w, xy[1]-40075016*0.5**self.zoom/256*self.h), self.proj) + xy2 = projections.to4326((xy[0]+40075016*0.5**self.zoom/256*self.w, xy[1]+40075016*0.5**self.zoom/256*self.h), self.proj) bbox = (xy1[0],xy1[1],xy2[0],xy2[1]) debug (bbox) return self.update_surface(bbox, zoom, style, lock) @@ -76,11 +76,12 @@ class RasterTile: print self.zoom, self.zoomlevel self.bbox = bbox self.bbox_p = projections.from4326(bbox,self.proj) - - + debug(zoom) + bgs = style.get_style("canvas", {}, self.zoom)[0] cr = cairo.Context(self.surface) cr.rectangle(0, 0, self.w, self.h) - cr.set_source_rgb(0.7, 0.7, 0.7) + color = bgs.get("fill-color",(0.7, 0.7, 0.7)) + cr.set_source_rgba(color[0], color[1], color[2], bgs.get("fill-opacity", 1)) #cr.set_source_rgb(0, 0, 0) cr.fill() datatimer = Timer("Asking backend and styling")