/**
 * champlain_map_source_factory_create_cached_source:
 * @factory: the Factory
 * @id: the wanted map source id
 *
 * Creates a cached map source.
 *
 * Returns: (transfer none): a ready to use #ChamplainMapSourceChain consisting of
 * #ChamplainMemoryCache, #ChamplainFileCache, #ChamplainMapSource matching the given name, and
 * an error tile source created with champlain_map_source_factory_create_error_source ().
 *
 * Since: 0.6
 */
ChamplainMapSource *
champlain_map_source_factory_create_cached_source (ChamplainMapSourceFactory *factory,
    const gchar *id)
{
  ChamplainMapSourceChain *source_chain;
  ChamplainMapSource *tile_source;
  ChamplainMapSource *error_source;
  ChamplainMapSource *memory_cache;
  ChamplainMapSource *file_cache;
  guint tile_size;
  ChamplainRenderer *renderer;

  tile_source = champlain_map_source_factory_create (factory, id);

  tile_size = champlain_map_source_get_tile_size (tile_source);
  error_source = champlain_map_source_factory_create_error_source (factory, tile_size);

  renderer = CHAMPLAIN_RENDERER (champlain_image_renderer_new ());
  file_cache = CHAMPLAIN_MAP_SOURCE (champlain_file_cache_new_full (100000000, NULL, renderer));

  renderer = CHAMPLAIN_RENDERER (champlain_image_renderer_new ());
  memory_cache = CHAMPLAIN_MAP_SOURCE (champlain_memory_cache_new_full (100, renderer));

  source_chain = champlain_map_source_chain_new ();
  champlain_map_source_chain_push (source_chain, error_source);
  champlain_map_source_chain_push (source_chain, tile_source);
  champlain_map_source_chain_push (source_chain, file_cache);
  champlain_map_source_chain_push (source_chain, memory_cache);

  return CHAMPLAIN_MAP_SOURCE (source_chain);
}
static ChamplainMapSource *
champlain_map_source_new_generic (ChamplainMapSourceDesc *desc)
{
  ChamplainMapSource *map_source;
  ChamplainRenderer *renderer;
  const gchar *id, *name, *license, *license_uri, *uri_format;
  guint min_zoom, max_zoom, tile_size;
  ChamplainMapProjection projection;

  id = champlain_map_source_desc_get_id (desc);
  name = champlain_map_source_desc_get_name (desc);
  license = champlain_map_source_desc_get_license (desc);
  license_uri = champlain_map_source_desc_get_license_uri (desc);
  min_zoom = champlain_map_source_desc_get_min_zoom_level (desc);
  max_zoom = champlain_map_source_desc_get_max_zoom_level (desc);
  tile_size = champlain_map_source_desc_get_tile_size (desc);
  projection = champlain_map_source_desc_get_projection (desc);
  uri_format = champlain_map_source_desc_get_uri_format (desc);

  renderer = CHAMPLAIN_RENDERER (champlain_image_renderer_new ());

  map_source = CHAMPLAIN_MAP_SOURCE (champlain_network_tile_source_new_full (
            id,
            name,
            license,
            license_uri,
            min_zoom,
            max_zoom,
            tile_size,
            projection,
            uri_format,
            renderer));

  return map_source;
}
/**
 * champlain_map_source_factory_create_error_source:
 * @factory: the Factory
 * @tile_size: the size of the error tile
 *
 * Creates a map source generating error tiles.
 *
 * Returns: (transfer none): a ready to use map source generating error tiles.
 *
 * Since: 0.8
 */
ChamplainMapSource *
champlain_map_source_factory_create_error_source (ChamplainMapSourceFactory *factory,
    guint tile_size)
{
  ChamplainMapSource *null_source;
  ChamplainRenderer *renderer;

  renderer = CHAMPLAIN_RENDERER (champlain_error_tile_renderer_new (tile_size));
  null_source = CHAMPLAIN_MAP_SOURCE (champlain_null_tile_source_new_full (renderer));

  return null_source;
}
static ChamplainMapSource *
champlain_map_source_new_memphis (ChamplainMapSourceDesc *desc)
{
  ChamplainMapSource *map_source;
  ChamplainRenderer *renderer;
  gchar *id, *name, *license, *license_uri;
  guint min_zoom, max_zoom, tile_size;
  ChamplainMapProjection projection;

  g_object_get (G_OBJECT (desc),
      "id", &id,
      "name", &name,
      "license", &license,
      "license-uri", &license_uri,
      "min-zoom-level", &min_zoom,
      "max-zoom-level", &max_zoom,
      "tile-size", &tile_size,
      "projection", &projection,
      NULL);

  renderer = CHAMPLAIN_RENDERER (champlain_memphis_renderer_new_full (tile_size));

  if (g_strcmp0 (id, CHAMPLAIN_MAP_SOURCE_MEMPHIS_LOCAL) == 0)
    {
      map_source = CHAMPLAIN_MAP_SOURCE (champlain_file_tile_source_new_full (
                id,
                name,
                license,
                license_uri,
                min_zoom,
                max_zoom,
                tile_size,
                projection,
                renderer));
    }
  else
    {
      map_source = CHAMPLAIN_MAP_SOURCE (champlain_network_bbox_tile_source_new_full (
                id,
                name,
                license,
                license_uri,
                min_zoom,
                max_zoom,
                tile_size,
                projection,
                renderer));
    }

  return map_source;
}
static ChamplainMapSource *
champlain_map_source_new_memphis (ChamplainMapSourceDesc *desc)
{
  ChamplainMapSource *map_source;
  ChamplainRenderer *renderer;
  const gchar *id, *name, *license, *license_uri;
  guint min_zoom, max_zoom, tile_size;
  ChamplainMapProjection projection;

  id = champlain_map_source_desc_get_id (desc);
  name = champlain_map_source_desc_get_name (desc);
  license = champlain_map_source_desc_get_license (desc);
  license_uri = champlain_map_source_desc_get_license_uri (desc);
  min_zoom = champlain_map_source_desc_get_min_zoom_level (desc);
  max_zoom = champlain_map_source_desc_get_max_zoom_level (desc);
  tile_size = champlain_map_source_desc_get_tile_size (desc);
  projection = champlain_map_source_desc_get_projection (desc);

  renderer = CHAMPLAIN_RENDERER (champlain_memphis_renderer_new_full (tile_size));

  if (g_strcmp0 (id, CHAMPLAIN_MAP_SOURCE_MEMPHIS_LOCAL) == 0)
    {
      map_source = CHAMPLAIN_MAP_SOURCE (champlain_file_tile_source_new_full (
                id,
                name,
                license,
                license_uri,
                min_zoom,
                max_zoom,
                tile_size,
                projection,
                renderer));
    }
  else
    {
      map_source = CHAMPLAIN_MAP_SOURCE (champlain_network_bbox_tile_source_new_full (
                id,
                name,
                license,
                license_uri,
                min_zoom,
                max_zoom,
                tile_size,
                projection,
                renderer));
    }

  return map_source;
}
static ChamplainMapSource *
champlain_map_source_new_generic (ChamplainMapSourceDesc *desc)
{
  ChamplainMapSource *map_source;
  ChamplainRenderer *renderer;
  gchar *id, *name, *license, *license_uri, *uri_format;
  guint min_zoom, max_zoom, tile_size;
  ChamplainMapProjection projection;

  g_object_get (G_OBJECT (desc),
      "id", &id,
      "name", &name,
      "license", &license,
      "license-uri", &license_uri,
      "min-zoom-level", &min_zoom,
      "max-zoom-level", &max_zoom,
      "tile-size", &tile_size,
      "projection", &projection,
      "uri-format", &uri_format,
      NULL);

  renderer = CHAMPLAIN_RENDERER (champlain_image_renderer_new ());

  map_source = CHAMPLAIN_MAP_SOURCE (champlain_network_tile_source_new_full (
            id,
            name,
            license,
            license_uri,
            min_zoom,
            max_zoom,
            tile_size,
            projection,
            uri_format,
            renderer));

  return map_source;
}