def reset_map_image(mapimage_param, centerlat_param, centerlng_param, northlat_param, westlng_param, zoom_param, height_param, width_param, google_data_param):
      mapimage_param.tiles_remaining = len(range(0, width_param, 256)) * len(range(0, height_param, 256))
      mapimage_param.centerlat  = centerlat_param
      mapimage_param.centerlng  = centerlng_param
      mapimage_param.northlat   = northlat_param
      mapimage_param.westlng    = westlng_param
      mapimage_param.zoom       = zoom_param
      mapimage_param.height     = height_param
      mapimage_param.width      = width_param
      mapimage_param.static_url = "http://maps.google.com/maps/api/staticmap?" + urllib.urlencode(google_data_param)
      mapimage_param.img = None
      mapimage_param.put()
    db.run_in_transaction(reset_map_image, mapimage, centerlat, centerlng, northlat, westlng, zoom, height, width, google_data)
    for offset_x_px in range(0, width, 256):
      for offset_y_px in range(0, height, 256):
        taskqueue.add(queue_name='tiles', url='/draw_static_tile/%s/%d/%f/%f/%d/%d' % (mapimage.key(), zoom, northlat, westlng, offset_x_px, offset_y_px))
  except DeadlineExceededError, err:    
    logging.error("Ran out of time before creating a map! %s" % err)

if __name__ == '__main__':
  fragments = environ['PATH_INFO'].split('/')
  fragments.pop(0)
  func = fragments.pop(0)
  user = users.get_current_user()
  try:
    if user and func == 'generate_static_map':
      assert len(fragments) == 4, "fragments should have 4 elements %s" % str(fragments)
      widthxheight, zoom, centerpoint, northwest = fragments
      generate_static_map(user, widthxheight, zoom, centerpoint, northwest)
    elif func == 'draw_static_tile':
      mapimage_key = fragments.pop(0)