parameters: (self, handler, is_imagery, layer_id)
docstring: Handle requests for map imagery or vector jpeg tiles.
docstring_summary: Handle requests for map imagery or vector jpeg tiles.
docstring_tokens: Handle requests for map imagery or vector jpeg tiles .
function: def LocalMapTileHandler(self, handler, is_imagery, layer_id):
      """Handle requests for map imagery or vector jpeg tiles."""
      if not handler.IsValidRequest():
        raise tornado.web.HTTPError(404)
  
      x = int(handler.request.arguments["x"][0])
      y = int(handler.request.arguments["y"][0])
      z = int(handler.request.arguments["z"][0])
      if tornado.web.globe_.IsMbtiles() and is_imagery:
        handler.write(
            tornado.web.globe_.ReadMapImageryTile(x, y, z))
        return
  
      qtnode = self.ConvertToQtNode(x, y, z)
      channel = int(handler.request.arguments["channel"][0])
      try:
        if is_imagery:
          handler.write(
              tornado.web.globe_.ReadMapImageryPacket(qtnode, channel, layer_id))
          return
        else:
          handler.write(
              tornado.web.globe_.ReadMapVectorPacket(qtnode, channel, layer_id))
          return
      except:
        # Super-sample tiles where there is missing imagery data.
        if (not is_imagery or
            not tornado.web.globe_.IsBaseLayer(layer_id, channel)):
          return
  
        if (not pil_enabled or
            not tornado.web.globe_.config_.FillMissingMapTiles()):
          if tornado.web.globe_.IsBaseLayer(layer_id, channel):
            handler.write(self.empty_tile_)
          return
  
        length = len(qtnode)
        max_index = min(length,
                        tornado.web.globe_.config_.MaxMissingMapTileAncestor())
        index = 1
        size = 128
        xoff = 0
        yoff = 0
        # Use shift since we are moving right to left off address.
        shift = 1
        while index < max_index:
          try:
            if size > 0:
              last_node = qtnode[length - index]
              if last_node == "0":
                yoff += shift
              elif last_node == "1":
                yoff += shift
                xoff += shift
              elif last_node == "2":
                xoff += shift
              elif last_node == "3":
                pass
              else:
                raise(
                    Exception("Unexpected qtnode: %s" %  qtnode[:length - index]))
  
            parser = ImageFile.Parser()
            parser.feed(
                tornado.web.globe_.ReadMapImageryPacket(
                    qtnode[:length - index], channel, layer_id))
            image = parser.close()
            # Skip 1 x 1 placeholders
            if image.size[0] == 1:
              if tornado.web.globe_.IsBaseLayer(layer_id, channel):
                handler.write(self.empty_tile_)
              return
  
            xoffset = xoff * size
            yoffset = yoff * size
            image = image.crop((xoffset,
                                yoffset,
                                xoffset + size,
                                yoffset + size)).resize((256, 256))
            output = StringIO.StringIO()
            # If has palette, use PNG.
            if image.mode == "P":
              image.save(output, "PNG")
            else:
              image.save(output, "JPEG")
  
            content = output.getvalue()
            output.close()
            handler.write(content)
            return
          except portable_globe.UnableToFindException, e:
            index += 1
            if size > 1:
              size >>= 1   # divide by 2
              shift <<= 1  # multiply by 2
            else:
              # If we get down to a single pixel,
              # keep cutting the resolution of the
              # offset in half to grab the "best"
              # pixel.
              xoff >>= 1  # divide by 2
              yoff >>= 1  # divide by 2
  
        # Unable to find a near enough ancestor; show "no data".
        if tornado.web.globe_.IsBaseLayer(layer_id, channel):
          handler.write(self.empty_tile_)
function_tokens: def LocalMapTileHandler ( self , handler , is_imagery , layer_id ) : if not handler . IsValidRequest ( ) : raise tornado . web . HTTPError ( 404 ) x = int ( handler . request . arguments [ "x" ] [ 0 ] ) y = int ( handler . request . arguments [ "y" ] [ 0 ] ) z = int ( handler . request . arguments [ "z" ] [ 0 ] ) if tornado . web . globe_ . IsMbtiles ( ) and is_imagery : handler . write ( tornado . web . globe_ . ReadMapImageryTile ( x , y , z ) ) return qtnode = self . ConvertToQtNode ( x , y , z ) channel = int ( handler . request . arguments [ "channel" ] [ 0 ] ) try : if is_imagery : handler . write ( tornado . web . globe_ . ReadMapImageryPacket ( qtnode , channel , layer_id ) ) return else : handler . write ( tornado . web . globe_ . ReadMapVectorPacket ( qtnode , channel , layer_id ) ) return except : # Super-sample tiles where there is missing imagery data. if ( not is_imagery or not tornado . web . globe_ . IsBaseLayer ( layer_id , channel ) ) : return if ( not pil_enabled or not tornado . web . globe_ . config_ . FillMissingMapTiles ( ) ) : if tornado . web . globe_ . IsBaseLayer ( layer_id , channel ) : handler . write ( self . empty_tile_ ) return length = len ( qtnode ) max_index = min ( length , tornado . web . globe_ . config_ . MaxMissingMapTileAncestor ( ) ) index = 1 size = 128 xoff = 0 yoff = 0 # Use shift since we are moving right to left off address. shift = 1 while index < max_index : try : if size > 0 : last_node = qtnode [ length - index ] if last_node == "0" : yoff += shift elif last_node == "1" : yoff += shift xoff += shift elif last_node == "2" : xoff += shift elif last_node == "3" : pass else : raise ( Exception ( "Unexpected qtnode: %s" % qtnode [ : length - index ] ) ) parser = ImageFile . Parser ( ) parser . feed ( tornado . web . globe_ . ReadMapImageryPacket ( qtnode [ : length - index ] , channel , layer_id ) ) image = parser . close ( ) # Skip 1 x 1 placeholders if image . size [ 0 ] == 1 : if tornado . web . globe_ . IsBaseLayer ( layer_id , channel ) : handler . write ( self . empty_tile_ ) return xoffset = xoff * size yoffset = yoff * size image = image . crop ( ( xoffset , yoffset , xoffset + size , yoffset + size ) ) . resize ( ( 256 , 256 ) ) output = StringIO . StringIO ( ) # If has palette, use PNG. if image . mode == "P" : image . save ( output , "PNG" ) else : image . save ( output , "JPEG" ) content = output . getvalue ( ) output . close ( ) handler . write ( content ) return except portable_globe . UnableToFindException , e : index += 1 if size > 1 : size >>= 1 # divide by 2 shift <<= 1 # multiply by 2 else : # If we get down to a single pixel, # keep cutting the resolution of the # offset in half to grab the "best" # pixel. xoff >>= 1 # divide by 2 yoff >>= 1 # divide by 2 # Unable to find a near enough ancestor; show "no data". if tornado . web . globe_ . IsBaseLayer ( layer_id , channel ) : handler . write ( self . empty_tile_ )