[libshumate/tintou/map-source-registry] map-source-registry: Replaces map-source-factory and cleanup unused types
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libshumate/tintou/map-source-registry] map-source-registry: Replaces map-source-factory and cleanup unused types
- Date: Thu, 10 Jun 2021 11:23:46 +0000 (UTC)
commit 028997968a3a62514e93051c1722cd15dbd49eeb
Author: Corentin Noël <corentin noel collabora com>
Date: Thu Jun 10 13:04:52 2021 +0200
map-source-registry: Replaces map-source-factory and cleanup unused types
ShumateMapSourceDesc is now gone as it wasn't providing any value.
The ShumateMapSourceRegistry is now a GListModel implementation.
demos/shumate-demo-window.c | 37 ++-
demos/shumate-demo-window.ui | 7 -
demos/shumate-test-tile-source.c | 5 +-
demos/shumate-test-tile-source.h | 2 +
docs/reference/libshumate-docs.sgml | 6 +-
shumate/meson.build | 6 +-
shumate/shumate-map-source-desc.c | 570 ----------------------------------
shumate/shumate-map-source-desc.h | 76 -----
shumate/shumate-map-source-factory.c | 325 -------------------
shumate/shumate-map-source-factory.h | 111 -------
shumate/shumate-map-source-registry.c | 367 ++++++++++++++++++++++
shumate/shumate-map-source-registry.h | 78 +++++
shumate/shumate-view.c | 8 +-
shumate/shumate.h | 2 +-
tests/coordinate.c | 10 +-
15 files changed, 485 insertions(+), 1125 deletions(-)
---
diff --git a/demos/shumate-demo-window.c b/demos/shumate-demo-window.c
index 6011bfc..102d2fd 100644
--- a/demos/shumate-demo-window.c
+++ b/demos/shumate-demo-window.c
@@ -29,6 +29,7 @@ struct _ShumateDemoWindow
ShumateScale *scale;
ShumateLicense *license;
GtkDropDown *layers_dropdown;
+ ShumateMapSourceRegistry *registry;
ShumateMapLayer *tile_layer;
ShumateMarkerLayer *marker_layer;
@@ -73,8 +74,7 @@ set_map_source (ShumateDemoWindow *self, ShumateMapSource *new_source)
shumate_license_remove_map_source (self->license, self->current_source);
}
- g_clear_object (&self->current_source);
- self->current_source = new_source;
+ g_set_object (&self->current_source, new_source);
shumate_viewport_set_reference_map_source (viewport, new_source);
shumate_view_set_map_source (self->view, new_source);
@@ -92,28 +92,19 @@ set_map_source (ShumateDemoWindow *self, ShumateMapSource *new_source)
static void
on_layers_dropdown_notify_selected (ShumateDemoWindow *self, GParamSpec *pspec, GtkDropDown *dropdown)
{
- g_autoptr(ShumateMapSourceFactory) factory = NULL;
-
- switch (gtk_drop_down_get_selected (dropdown)) {
- case 0:
- factory = shumate_map_source_factory_dup_default ();
- set_map_source (self, shumate_map_source_factory_create (factory, SHUMATE_MAP_SOURCE_OSM_MAPNIK));
- break;
- case 1:
- set_map_source (self, SHUMATE_MAP_SOURCE (shumate_test_tile_source_new ()));
- break;
- }
+ set_map_source (self, gtk_drop_down_get_selected_item (dropdown));
}
static void
-shumate_demo_window_finalize (GObject *object)
+shumate_demo_window_dispose (GObject *object)
{
ShumateDemoWindow *self = SHUMATE_DEMO_WINDOW (object);
g_clear_object (&self->current_source);
+ g_clear_object (&self->registry);
- G_OBJECT_CLASS (shumate_demo_window_parent_class)->finalize (object);
+ G_OBJECT_CLASS (shumate_demo_window_parent_class)->dispose (object);
}
@@ -123,7 +114,7 @@ shumate_demo_window_class_init (ShumateDemoWindowClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- object_class->finalize = shumate_demo_window_finalize;
+ object_class->dispose = shumate_demo_window_dispose;
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/Shumate/Demo/ui/shumate-demo-window.ui");
gtk_widget_class_bind_template_child (widget_class, ShumateDemoWindow, view);
@@ -134,14 +125,28 @@ shumate_demo_window_class_init (ShumateDemoWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, on_layers_dropdown_notify_selected);
}
+static gchar *
+get_map_source_name (ShumateMapSource *map_source)
+{
+ return g_strdup (shumate_map_source_get_name (map_source));
+}
static void
shumate_demo_window_init (ShumateDemoWindow *self)
{
ShumateViewport *viewport;
+ GtkExpression *expression;
gtk_widget_init_template (GTK_WIDGET (self));
+ self->registry = shumate_map_source_registry_new_with_defaults ();
+ shumate_map_source_registry_add (self->registry, SHUMATE_MAP_SOURCE (shumate_test_tile_source_new ()));
+ expression = gtk_cclosure_expression_new (G_TYPE_STRING, NULL, 0, NULL,
+ (GCallback)get_map_source_name, NULL, NULL);
+ gtk_drop_down_set_expression (self->layers_dropdown, expression);
+ gtk_drop_down_set_model (self->layers_dropdown, G_LIST_MODEL (self->registry));
+
+
viewport = shumate_view_get_viewport (self->view);
/* Set the map source */
diff --git a/demos/shumate-demo-window.ui b/demos/shumate-demo-window.ui
index 2fabff7..9191aca 100644
--- a/demos/shumate-demo-window.ui
+++ b/demos/shumate-demo-window.ui
@@ -10,7 +10,6 @@
<object class="GtkHeaderBar">
<child>
<object class="GtkDropDown" id="layers_dropdown">
- <property name="model">layers</property>
<signal name="notify::selected" handler="on_layers_dropdown_notify_selected" swapped="true" />
</object>
</child>
@@ -38,10 +37,4 @@
</object>
</child>
</template>
- <object class="GtkStringList" id="layers">
- <items>
- <item translatable="yes">Mapnik (OSM)</item>
- <item translatable="yes">Test Pattern</item>
- </items>
- </object>
</interface>
diff --git a/demos/shumate-test-tile-source.c b/demos/shumate-test-tile-source.c
index c0a458a..3c970a9 100644
--- a/demos/shumate-test-tile-source.c
+++ b/demos/shumate-test-tile-source.c
@@ -29,7 +29,10 @@ G_DEFINE_TYPE (ShumateTestTileSource, shumate_test_tile_source, SHUMATE_TYPE_TIL
ShumateTestTileSource *
shumate_test_tile_source_new (void)
{
- return g_object_new (SHUMATE_TYPE_TEST_TILE_SOURCE, NULL);
+ return g_object_new (SHUMATE_TYPE_TEST_TILE_SOURCE,
+ "id", SHUMATE_MAP_SOURCE_TEST,
+ "name", "Test Pattern",
+ NULL);
}
diff --git a/demos/shumate-test-tile-source.h b/demos/shumate-test-tile-source.h
index 8a17d44..83956b5 100644
--- a/demos/shumate-test-tile-source.h
+++ b/demos/shumate-test-tile-source.h
@@ -29,4 +29,6 @@ G_DECLARE_FINAL_TYPE (ShumateTestTileSource, shumate_test_tile_source, SHUMATE,
ShumateTestTileSource *shumate_test_tile_source_new (void);
+#define SHUMATE_MAP_SOURCE_TEST "test-source"
+
G_END_DECLS
diff --git a/docs/reference/libshumate-docs.sgml b/docs/reference/libshumate-docs.sgml
index d99d7c2..493a36e 100644
--- a/docs/reference/libshumate-docs.sgml
+++ b/docs/reference/libshumate-docs.sgml
@@ -73,6 +73,7 @@
<part>
<title>Map Source API</title>
<xi:include href="xml/shumate-map-source.xml"/>
+ <xi:include href="xml/shumate-map-source-registry.xml"/>
<chapter>
<title>Tile Sources</title>
<xi:include href="xml/shumate-tile-source.xml"/>
@@ -83,11 +84,6 @@
<xi:include href="xml/shumate-file-cache.xml"/>
<xi:include href="xml/shumate-memory-cache.xml"/>
</chapter>
- <chapter>
- <title>Map Source Utilities</title>
- <xi:include href="xml/shumate-map-source-factory.xml"/>
- <xi:include href="xml/shumate-map-source-desc.xml"/>
- </chapter>
</part>
<part>
<title>Others</title>
diff --git a/shumate/meson.build b/shumate/meson.build
index 61cd055..80c19f4 100644
--- a/shumate/meson.build
+++ b/shumate/meson.build
@@ -5,8 +5,7 @@ libshumate_public_h = [
'shumate-license.h',
'shumate-location.h',
'shumate-map-layer.h',
- 'shumate-map-source-desc.h',
- 'shumate-map-source-factory.h',
+ 'shumate-map-source-registry.h',
'shumate-map-source.h',
'shumate-marker-layer.h',
'shumate-marker.h',
@@ -35,8 +34,7 @@ libshumate_sources = [
'shumate-license.c',
'shumate-location.c',
'shumate-map-layer.c',
- 'shumate-map-source-desc.c',
- 'shumate-map-source-factory.c',
+ 'shumate-map-source-registry.c',
'shumate-map-source.c',
'shumate-marker-layer.c',
'shumate-marker.c',
diff --git a/shumate/shumate-map-source-registry.c b/shumate/shumate-map-source-registry.c
new file mode 100644
index 0000000..e14cef0
--- /dev/null
+++ b/shumate/shumate-map-source-registry.c
@@ -0,0 +1,367 @@
+#include "shumate-map-source-registry.h"
+
+#include <gio/gio.h>
+
+#include "shumate-network-tile-source.h"
+
+struct _ShumateMapSourceRegistry
+{
+ GObject parent_instance;
+
+ GPtrArray *map_sources;
+};
+
+static void shumate_map_source_registry_list_model_init (GListModelInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (ShumateMapSourceRegistry, shumate_map_source_registry, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE(G_TYPE_LIST_MODEL,
shumate_map_source_registry_list_model_init))
+
+static gboolean
+shumate_map_source_registry_find_by_id (ShumateMapSource *map_source,
+ const gchar *id)
+{
+ return g_strcmp0 (shumate_map_source_get_id (map_source), id) == 0;
+}
+
+static void
+shumate_map_source_registry_dispose (GObject *object)
+{
+ ShumateMapSourceRegistry *self = (ShumateMapSourceRegistry *)object;
+
+ g_clear_pointer (&self->map_sources, g_ptr_array_unref);
+
+ G_OBJECT_CLASS (shumate_map_source_registry_parent_class)->dispose (object);
+}
+
+static void
+shumate_map_source_registry_class_init (ShumateMapSourceRegistryClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = shumate_map_source_registry_dispose;
+}
+
+static void
+shumate_map_source_registry_init (ShumateMapSourceRegistry *self)
+{
+ self->map_sources = g_ptr_array_new_with_free_func (g_object_unref);
+}
+
+static GType
+shumate_map_source_registry_get_item_type (GListModel *list)
+{
+ return SHUMATE_TYPE_MAP_SOURCE;
+}
+
+static guint
+shumate_map_source_registry_get_n_items (GListModel *list)
+{
+ ShumateMapSourceRegistry *self = SHUMATE_MAP_SOURCE_REGISTRY (list);
+
+ return self->map_sources->len;
+}
+
+static gpointer
+shumate_map_source_registry_get_item (GListModel *list,
+ guint position)
+{
+ ShumateMapSourceRegistry *self = SHUMATE_MAP_SOURCE_REGISTRY (list);
+
+ if (position >= self->map_sources->len)
+ return NULL;
+ else
+ return g_object_ref (g_ptr_array_index (self->map_sources, position));
+}
+
+static void
+shumate_map_source_registry_list_model_init (GListModelInterface *iface)
+{
+ iface->get_item_type = shumate_map_source_registry_get_item_type;
+ iface->get_n_items = shumate_map_source_registry_get_n_items;
+ iface->get_item = shumate_map_source_registry_get_item;
+}
+
+/**
+ * shumate_map_source_registry_new:
+ *
+ * Create a new #ShumateMapSourceRegistry.
+ *
+ * Returns: (transfer full): a newly created #ShumateMapSourceRegistry
+ */
+ShumateMapSourceRegistry *
+shumate_map_source_registry_new (void)
+{
+ return g_object_new (SHUMATE_TYPE_MAP_SOURCE_REGISTRY, NULL);
+}
+
+/**
+ * shumate_map_source_registry_new_with_defaults:
+ *
+ * Create a new #ShumateMapSourceRegistry with defaults map sources.
+ * This is identical to calling shumate_map_source_registry_populate_defaults()
+ * after shumate_map_source_registry_new().
+ *
+ * Returns: (transfer full): a newly created #ShumateMapSourceRegistry
+ */
+ShumateMapSourceRegistry *
+shumate_map_source_registry_new_with_defaults (void)
+{
+ ShumateMapSourceRegistry *registry = shumate_map_source_registry_new ();
+
+ shumate_map_source_registry_populate_defaults (registry);
+
+ return registry;
+}
+
+/**
+ * shumate_map_source_registry_populate_defaults:
+ * @self: a #ShumateMapSourceRegistry
+ *
+ * Populates the #ShumateMapSourceRegistry with a default set of sources.
+ */
+void
+shumate_map_source_registry_populate_defaults (ShumateMapSourceRegistry *self)
+{
+ uint n_items;
+
+ g_return_if_fail (SHUMATE_IS_MAP_SOURCE_REGISTRY (self));
+
+ n_items = self->map_sources->len;
+
+ if (!shumate_map_source_registry_get_by_id (self, SHUMATE_MAP_SOURCE_OSM_MAPNIK))
+ {
+ g_ptr_array_add (self->map_sources,
+ shumate_network_tile_source_new_full (
+ SHUMATE_MAP_SOURCE_OSM_MAPNIK,
+ "OpenStreetMap Mapnik",
+ "Map Data ODBL OpenStreetMap Contributors, Map Imagery CC-BY-SA 2.0 OpenStreetMap",
+ "http://creativecommons.org/licenses/by-sa/2.0/",
+ 0,
+ 18,
+ 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ "https://tile.openstreetmap.org/#Z#/#X#/#Y#.png"
+ )
+ );
+ }
+
+ if (!shumate_map_source_registry_get_by_id (self, SHUMATE_MAP_SOURCE_OSM_CYCLE_MAP))
+ {
+ g_ptr_array_add (self->map_sources,
+ shumate_network_tile_source_new_full (
+ SHUMATE_MAP_SOURCE_OSM_CYCLE_MAP,
+ "OpenStreetMap Cycle Map",
+ "Map data is CC-BY-SA 2.0 OpenStreetMap contributors",
+ "http://creativecommons.org/licenses/by-sa/2.0/",
+ 0,
+ 18,
+ 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ "http://tile.opencyclemap.org/cycle/#Z#/#X#/#Y#.png"
+ )
+ );
+ }
+
+ if (!shumate_map_source_registry_get_by_id (self, SHUMATE_MAP_SOURCE_OSM_TRANSPORT_MAP))
+ {
+ g_ptr_array_add (self->map_sources,
+ shumate_network_tile_source_new_full (
+ SHUMATE_MAP_SOURCE_OSM_TRANSPORT_MAP,
+ "OpenStreetMap Transport Map",
+ "Map data is CC-BY-SA 2.0 OpenStreetMap contributors",
+ "http://creativecommons.org/licenses/by-sa/2.0/",
+ 0,
+ 18,
+ 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ "http://tile.xn--pnvkarte-m4a.de/tilegen/#Z#/#X#/#Y#.png"
+ )
+ );
+ }
+
+ if (!shumate_map_source_registry_get_by_id (self, SHUMATE_MAP_SOURCE_MFF_RELIEF))
+ {
+ g_ptr_array_add (self->map_sources,
+ shumate_network_tile_source_new_full (
+ SHUMATE_MAP_SOURCE_MFF_RELIEF,
+ "Maps for Free Relief",
+ "Map data available under GNU Free Documentation license, Version 1.2 or later",
+ "http://www.gnu.org/copyleft/fdl.html",
+ 0,
+ 11,
+ 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ "http://maps-for-free.com/layer/relief/z#Z#/row#Y#/#Z#_#X#-#Y#.jpg"
+ )
+ );
+ }
+
+ if (!shumate_map_source_registry_get_by_id (self, SHUMATE_MAP_SOURCE_OWM_CLOUDS))
+ {
+ g_ptr_array_add (self->map_sources,
+ shumate_network_tile_source_new_full (
+ SHUMATE_MAP_SOURCE_OWM_CLOUDS,
+ "OpenWeatherMap cloud layer",
+ "Map data is CC-BY-SA 2.0 OpenWeatherMap contributors",
+ "http://creativecommons.org/licenses/by-sa/2.0/",
+ 0,
+ 18,
+ 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ "http://tile.openweathermap.org/map/clouds/#Z#/#X#/#Y#.png"
+ )
+ );
+ }
+
+ if (!shumate_map_source_registry_get_by_id (self, SHUMATE_MAP_SOURCE_OWM_WIND))
+ {
+ g_ptr_array_add (self->map_sources,
+ shumate_network_tile_source_new_full (
+ SHUMATE_MAP_SOURCE_OWM_WIND,
+ "OpenWeatherMap wind layer",
+ "Map data is CC-BY-SA 2.0 OpenWeatherMap contributors",
+ "http://creativecommons.org/licenses/by-sa/2.0/",
+ 0,
+ 18,
+ 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ "http://tile.openweathermap.org/map/wind/#Z#/#X#/#Y#.png"
+ )
+ );
+ }
+
+ if (!shumate_map_source_registry_get_by_id (self, SHUMATE_MAP_SOURCE_OWM_TEMPERATURE))
+ {
+ g_ptr_array_add (self->map_sources,
+ shumate_network_tile_source_new_full (
+ SHUMATE_MAP_SOURCE_OWM_TEMPERATURE,
+ "OpenWeatherMap temperature layer",
+ "Map data is CC-BY-SA 2.0 OpenWeatherMap contributors",
+ "http://creativecommons.org/licenses/by-sa/2.0/",
+ 0,
+ 18,
+ 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ "http://tile.openweathermap.org/map/temp/#Z#/#X#/#Y#.png"
+ )
+ );
+ }
+
+ if (!shumate_map_source_registry_get_by_id (self, SHUMATE_MAP_SOURCE_OWM_PRECIPITATION))
+ {
+ g_ptr_array_add (self->map_sources,
+ shumate_network_tile_source_new_full (
+ SHUMATE_MAP_SOURCE_OWM_PRECIPITATION,
+ "OpenWeatherMap precipitation layer",
+ "Map data is CC-BY-SA 2.0 OpenWeatherMap contributors",
+ "http://creativecommons.org/licenses/by-sa/2.0/",
+ 0,
+ 18,
+ 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ "http://tile.openweathermap.org/map/precipitation/#Z#/#X#/#Y#.png"
+ )
+ );
+ }
+
+ if (!shumate_map_source_registry_get_by_id (self, SHUMATE_MAP_SOURCE_OWM_PRESSURE))
+ {
+ g_ptr_array_add (self->map_sources,
+ shumate_network_tile_source_new_full (
+ SHUMATE_MAP_SOURCE_OWM_PRESSURE,
+ "OpenWeatherMap sea level pressure layer",
+ "Map data is CC-BY-SA 2.0 OpenWeatherMap contributors",
+ "http://creativecommons.org/licenses/by-sa/2.0/",
+ 0,
+ 18,
+ 256,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ "http://tile.openweathermap.org/map/pressure/#Z#/#X#/#Y#.png"
+ )
+ );
+ }
+
+ if (self->map_sources->len - n_items > 0) {
+ g_list_model_items_changed (G_LIST_MODEL (self), n_items, self->map_sources->len - n_items, 0);
+ }
+}
+
+/**
+ * shumate_map_source_registry_get_by_id:
+ * @self: a #ShumateMapSourceRegistry
+ * @id: the id of the #ShumateMapSource
+ *
+ * Find the #ShumateMapSource with the corresponding id
+ *
+ * Returns: (transfer none) (nullable): the #ShumateMapSource or %NULL if no
+ * map source has been found
+ */
+ShumateMapSource *
+shumate_map_source_registry_get_by_id (ShumateMapSourceRegistry *self,
+ const gchar *id)
+{
+ guint index;
+
+ g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE_REGISTRY (self), NULL);
+ g_return_val_if_fail (id != NULL, NULL);
+
+ if (g_ptr_array_find_with_equal_func (self->map_sources, id,
+ (GEqualFunc) shumate_map_source_registry_find_by_id,
+ &index))
+ {
+ return g_ptr_array_index (self->map_sources, index);
+ }
+
+ return NULL;
+}
+
+/**
+ * shumate_map_source_registry_add:
+ * @self: a #ShumateMapSourceRegistry
+ * @map_source: (transfer full): a #ShumateMapSource
+ *
+ * Adds the #ShumateMapSource to the #ShumateMapSourceRegistry
+ */
+void shumate_map_source_registry_add (ShumateMapSourceRegistry *self,
+ ShumateMapSource *map_source)
+{
+ guint n_items;
+
+ g_return_if_fail (SHUMATE_IS_MAP_SOURCE_REGISTRY (self));
+ g_return_if_fail (SHUMATE_IS_MAP_SOURCE (map_source));
+
+ if (!g_ptr_array_find_with_equal_func (self->map_sources, shumate_map_source_get_id (map_source),
+ (GEqualFunc) shumate_map_source_registry_find_by_id,
+ NULL))
+ {
+ n_items = self->map_sources->len;
+ g_ptr_array_add (self->map_sources, map_source);
+
+ g_list_model_items_changed (G_LIST_MODEL (self), n_items, 0, 1);
+ }
+}
+
+/**
+ * shumate_map_source_registry_remove:
+ * @self: a #ShumateMapSourceRegistry
+ * @id: a #ShumateMapSource id
+ *
+ * Removes the corresponding #ShumateMapSource from the registry.
+ * If the source doesn't exist in the registry, this function does nothing.
+ */
+void shumate_map_source_registry_remove (ShumateMapSourceRegistry *self,
+ const gchar *id)
+{
+ guint index;
+
+ g_return_if_fail (SHUMATE_IS_MAP_SOURCE_REGISTRY (self));
+ g_return_if_fail (id != NULL);
+
+ if (g_ptr_array_find_with_equal_func (self->map_sources, id,
+ (GEqualFunc) shumate_map_source_registry_find_by_id,
+ &index))
+ {
+ g_ptr_array_remove_index (self->map_sources, index);
+ g_list_model_items_changed (G_LIST_MODEL (self), index, 1, 0);
+ }
+}
diff --git a/shumate/shumate-map-source-registry.h b/shumate/shumate-map-source-registry.h
new file mode 100644
index 0000000..2d3f6f3
--- /dev/null
+++ b/shumate/shumate-map-source-registry.h
@@ -0,0 +1,78 @@
+#pragma once
+
+#include <glib-object.h>
+
+#include <shumate/shumate-map-source.h>
+
+G_BEGIN_DECLS
+
+#define SHUMATE_TYPE_MAP_SOURCE_REGISTRY (shumate_map_source_registry_get_type())
+
+G_DECLARE_FINAL_TYPE (ShumateMapSourceRegistry, shumate_map_source_registry, SHUMATE, MAP_SOURCE_REGISTRY,
GObject)
+
+ShumateMapSourceRegistry *shumate_map_source_registry_new (void);
+ShumateMapSourceRegistry *shumate_map_source_registry_new_with_defaults (void);
+void shumate_map_source_registry_populate_defaults (ShumateMapSourceRegistry *self);
+ShumateMapSource *shumate_map_source_registry_get_by_id (ShumateMapSourceRegistry *self,
+ const gchar *id);
+void shumate_map_source_registry_add (ShumateMapSourceRegistry *self,
+ ShumateMapSource *map_source);
+void shumate_map_source_registry_remove (ShumateMapSourceRegistry *self,
+ const gchar *id);
+
+/**
+ * SHUMATE_MAP_SOURCE_OSM_MAPNIK:
+ *
+ * OpenStreetMap Mapnik
+ */
+#define SHUMATE_MAP_SOURCE_OSM_MAPNIK "osm-mapnik"
+/**
+ * SHUMATE_MAP_SOURCE_OSM_CYCLE_MAP:
+ *
+ * OpenStreetMap Cycle Map
+ */
+#define SHUMATE_MAP_SOURCE_OSM_CYCLE_MAP "osm-cyclemap"
+/**
+ * SHUMATE_MAP_SOURCE_OSM_TRANSPORT_MAP:
+ *
+ * OpenStreetMap Transport Map
+ */
+#define SHUMATE_MAP_SOURCE_OSM_TRANSPORT_MAP "osm-transportmap"
+/**
+ * SHUMATE_MAP_SOURCE_MFF_RELIEF:
+ *
+ * Maps for Free Relief
+ */
+#define SHUMATE_MAP_SOURCE_MFF_RELIEF "mff-relief"
+/**
+ * SHUMATE_MAP_SOURCE_OWM_CLOUDS:
+ *
+ * OpenWeatherMap clouds layer
+ */
+#define SHUMATE_MAP_SOURCE_OWM_CLOUDS "owm-clouds"
+/**
+ * SHUMATE_MAP_SOURCE_OWM_PRECIPITATION:
+ *
+ * OpenWeatherMap precipitation
+ */
+#define SHUMATE_MAP_SOURCE_OWM_PRECIPITATION "owm-precipitation"
+/**
+ * SHUMATE_MAP_SOURCE_OWM_PRESSURE:
+ *
+ * OpenWeatherMap sea level pressure
+ */
+#define SHUMATE_MAP_SOURCE_OWM_PRESSURE "owm-pressure"
+/**
+ * SHUMATE_MAP_SOURCE_OWM_WIND:
+ *
+ * OpenWeatherMap wind
+ */
+#define SHUMATE_MAP_SOURCE_OWM_WIND "owm-wind"
+/**
+ * SHUMATE_MAP_SOURCE_OWM_TEMPERATURE:
+ *
+ * OpenWeatherMap temperature
+ */
+#define SHUMATE_MAP_SOURCE_OWM_TEMPERATURE "owm-temperature"
+
+G_END_DECLS
diff --git a/shumate/shumate-view.c b/shumate/shumate-view.c
index c01b59d..9090c92 100644
--- a/shumate/shumate-view.c
+++ b/shumate/shumate-view.c
@@ -56,7 +56,7 @@
#include "shumate-marshal.h"
#include "shumate-map-layer.h"
#include "shumate-map-source.h"
-#include "shumate-map-source-factory.h"
+#include "shumate-map-source-registry.h"
#include "shumate-tile.h"
#include "shumate-license.h"
#include "shumate-location.h"
@@ -967,14 +967,14 @@ ShumateView *
shumate_view_new_simple (void)
{
ShumateView *view = g_object_new (SHUMATE_TYPE_VIEW, NULL);
- ShumateMapSourceFactory *factory;
+ g_autoptr(ShumateMapSourceRegistry) registry = NULL;
ShumateMapSource *source;
ShumateMapLayer *map_layer;
ShumateViewport *viewport;
viewport = shumate_view_get_viewport (view);
- factory = shumate_map_source_factory_dup_default ();
- source = shumate_map_source_factory_create (factory, SHUMATE_MAP_SOURCE_OSM_MAPNIK);
+ registry = shumate_map_source_registry_new_with_defaults ();
+ source = shumate_map_source_registry_get_by_id (registry, SHUMATE_MAP_SOURCE_OSM_MAPNIK);
shumate_viewport_set_reference_map_source (viewport, source);
map_layer = shumate_map_layer_new (source, viewport);
shumate_view_add_layer (view, SHUMATE_LAYER (map_layer));
diff --git a/shumate/shumate.h b/shumate/shumate.h
index 71f1650..591d40c 100644
--- a/shumate/shumate.h
+++ b/shumate/shumate.h
@@ -43,7 +43,7 @@
#include "shumate/shumate-map-source.h"
#include "shumate/shumate-tile-source.h"
-#include "shumate/shumate-map-source-factory.h"
+#include "shumate/shumate-map-source-registry.h"
#include "shumate/shumate-network-tile-source.h"
diff --git a/tests/coordinate.c b/tests/coordinate.c
index 9fa1960..6f2e1d7 100644
--- a/tests/coordinate.c
+++ b/tests/coordinate.c
@@ -6,17 +6,17 @@
static void
test_coordinate_convert (void)
{
- ShumateMapSourceFactory *factory;
+ ShumateMapSourceRegistry *registry;
ShumateMapSource *source;
double latitude = -73.75f;
double longitude = 45.466f;
double zoom_level;
- factory = shumate_map_source_factory_dup_default ();
+ registry = shumate_map_source_registry_new_with_defaults ();
- g_assert_nonnull (factory);
+ g_assert_nonnull (registry);
- source = shumate_map_source_factory_create (factory, SHUMATE_MAP_SOURCE_OSM_MAPNIK);
+ source = shumate_map_source_registry_get_by_id (registry, SHUMATE_MAP_SOURCE_OSM_MAPNIK);
g_assert_nonnull (source);
@@ -35,7 +35,7 @@ test_coordinate_convert (void)
}
g_object_unref (source);
- g_object_unref (factory);
+ g_object_unref (registry);
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]