Esempio n. 1
0
 def real_get(self):
     if not self.ts:
         return self.die(500)
     try:
         x,y = self.request.REQUEST.get('pixelxy').split(',')
         x,y = int(x),int(y)
         z = int(self.request.REQUEST.get('zoom').split(',')[0])
         tx,ty = x/256,y/256
         ox,oy = x%256,y%256
         tile = self.find_tile(z,tx,ty)
         if not tile:
             return self.die(404)
         idx = query.query(tile,px=ox,py=oy)
         if idx> 2:
             ids = self.ts.ids.ids
             ids = zlib.decompress(ids)
             id = ids.split(',')[idx-2]
             json = '{ "idx":%d,"region_id":"%s"}'%(idx,id)
             callback = self.request.REQUEST.get('callback')
             if callback:
                 json = "%s(%s)"%(callback,json)
             self.write(json)
         else: 
             return
     except:
         self.write('Sorry, there was an error')
         #return self.die(500)
         raise
Esempio n. 2
0
 def find_tile(self,z,x,y):
     if z is not None and x is not None and y is not None and self.ts:
         z,x,y = map(int,(z,x,y))
         #logging.info('Find Tile: %d+%d+%d'%(z,x,y))
         if self.get_tile(z,x,y):
             return self._tile
         elif self.valid_tile(z,x,y):
             #logging.info('Tile: %d+%d+%d Not Found, will search'%(z,x,y))
             while z:
                 z-=1
                 x_quad = x&1
                 y_quad = y&1
                 x = x>>1
                 y = y>>1
                 #logging.info('Tile: search %d+%d+%d'%(z,x,y))
                 if self.get_tile(z,x,y):
                     #logging.info('Tile: found %d+%d+%d'%(z,x,y))
                     regionID = query.query(self._tile,qx=x_quad,qy=y_quad)
                     #logging.info('Region ID: %d'%(regionID))
                     #logging.info('Quad x,y: (%d,%d)'%(x_quad,y_quad))
                     t = Tile()
                     t.dat = str(regionID)
                     if regionID == 0:
                         t.typ = 'A'
                     else:
                         t.typ = 'B'
                     self._tile = t
                     return self._tile
         else:
             #logging.info('Tile: %d+%d+%d Is Not Valid'%(z,x,y))
             return False
     else:
         #logging.info('not z,x,y or ts')
         t =Tile()
         t.dat = '0'
         t.typ = 'A'
         self._tile = t
         return self._tile
     return False