+void maps_layer_init ()
+{
+ VikLayerParamData tmp;
+ tmp.s = maps_layer_default_dir();
+ a_preferences_register(prefs, tmp, VIKING_PREFERENCES_GROUP_KEY);
+}
+
+/****************************************/
+/******** MAPS LAYER TYPES **************/
+/****************************************/
+
+int _get_index_for_id ( guint id )
+{
+ int index = 0 ;
+ while (params_maptypes_ids[index] != 0)
+ {
+ if (params_maptypes_ids[index] == id)
+ return index;
+ index++;
+ }
+ return -1;
+}
+
+void _add_map_source ( guint id, const char *label, VikMapSource *map )
+{
+ gsize len = 0;
+ if (params_maptypes)
+ len = g_strv_length (params_maptypes);
+ /* Add the label */
+ params_maptypes = g_realloc (params_maptypes, (len+2)*sizeof(gchar*));
+ params_maptypes[len] = g_strdup (label);
+ params_maptypes[len+1] = NULL;
+
+ /* Add the id */
+ params_maptypes_ids = g_realloc (params_maptypes_ids, (len+2)*sizeof(guint));
+ params_maptypes_ids[len] = id;
+ params_maptypes_ids[len+1] = 0;
+
+ /* We have to clone */
+ VikMapSource *clone = VIK_MAP_SOURCE(g_object_ref(map));
+ /* Register the clone in the list */
+ __map_types = g_list_append(__map_types, clone);
+
+ /* Hack
+ We have to ensure the mode LayerParam references the up-to-date
+ GLists.
+ */
+ /*
+ memcpy(&maps_layer_params[0].widget_data, ¶ms_maptypes, sizeof(gpointer));
+ memcpy(&maps_layer_params[0].extra_widget_data, ¶ms_maptypes_ids, sizeof(gpointer));
+ */
+ maps_layer_params[0].widget_data = params_maptypes;
+ maps_layer_params[0].extra_widget_data = params_maptypes_ids;
+}
+
+void _update_map_source ( const char *label, VikMapSource *map, int index )
+{
+ GList *item = g_list_nth (__map_types, index);
+ g_object_unref (item->data);
+ item->data = g_object_ref (map);
+ /* Change previous data */
+ g_free (params_maptypes[index]);
+ params_maptypes[index] = g_strdup (label);
+}
+
+void maps_layer_register_map_source ( VikMapSource *map )
+{
+ g_assert(map != NULL);
+
+ guint id = vik_map_source_get_uniq_id(map);
+ const char *label = vik_map_source_get_label(map);
+ g_assert(label != NULL);
+
+ int previous = map_uniq_id_to_index (id);
+ if (previous != NUM_MAP_TYPES)
+ {
+ _update_map_source (label, map, previous);
+ }
+ else
+ {
+ _add_map_source (id, label, map);
+ }
+}
+
+#define MAPS_LAYER_NTH_LABEL(n) (params_maptypes[n])
+#define MAPS_LAYER_NTH_ID(n) (params_maptypes_ids[n])
+#define MAPS_LAYER_NTH_TYPE(n) (VIK_MAP_SOURCE(g_list_nth_data(__map_types, (n))))
+
+gint vik_maps_layer_get_map_type(VikMapsLayer *vml)
+{
+ return(vml->maptype);
+}
+
+gchar *vik_maps_layer_get_map_label(VikMapsLayer *vml)
+{
+ return(g_strdup(MAPS_LAYER_NTH_LABEL(vml->maptype)));
+}