diff --git a/src/kothic.py b/src/kothic.py index 9149e53..90e44da 100644 --- a/src/kothic.py +++ b/src/kothic.py @@ -173,9 +173,15 @@ class Navigator: ort = self.rastertile #nrt = self.comm[1].get() lonlat = ort.screen2lonlat(ort.w/2, ort.h/2) - ox, oy = nrt.lonlat2screen(lonlat) + debug(lonlat) + debug(self.center_coord) + ox, oy = nrt.lonlat2screen(lonlat, epsg4326=True) + ox, oy = int(ox),int(oy) ox -= nrt.w/2 oy -= nrt.h/2 + debug(ox) + debug(oy) + self.drag_x += ox self.drag_y += oy self.dx -= ox diff --git a/src/render.py b/src/render.py index 82d0273..0ad2dc5 100644 --- a/src/render.py +++ b/src/render.py @@ -50,13 +50,17 @@ class RasterTile: self.zoom = None self.data = data_backend self.proj = raster_proj - def screen2lonlat(self, lon, lat): + def screen2lonlat(self, x, y): lo1, la1, lo2, la2 = self.bbox_p - #debug ("%s %s %s"%(lon, lat, repr(self.bbox_p))) - return projections.to4326(((lon)/(self.w-1)*(lo2-lo1)+lo2, la2+((lat)/(self.h-1)*(la2-la1))),self.proj) + debug ("%s %s - %s %s"%(x,y,self.w, self.h)) + debug(self.bbox_p) + debug((1.*x/self.w*(lo2-lo1)+lo1, la1+(1.*y/(self.h)*(la2-la1)))) + return projections.to4326( (1.*x/self.w*(lo2-lo1)+lo1, la1+(1.*y/(self.h)*(la2-la1))),self.proj) # return (x - self.w/2)/(math.cos(self.center_coord[1]*math.pi/180)*self.zoom) + self.center_coord[0], -(y - self.h/2)/self.zoom + self.center_coord[1] - def lonlat2screen(self, (lon, lat)): + def lonlat2screen(self, (lon, lat), epsg4326=False): + if epsg4326: + lon, lat = projections.from4326((lon,lat),self.proj) lo1, la1, lo2, la2 = self.bbox_p return ((lon-lo1)*(self.w-1)/abs(lo2-lo1), ((la2-lat)*(self.h-1)/(la2-la1))) # return (lon - self.center_coord[0])*self.lcc*self.zoom + self.w/2, -(lat - self.center_coord[1])*self.zoom + self.h/2