[libshumate] vector-renderer: Read data source info from style



commit b5f4da8b62f649f58f81fe39ca913ca764db6de1
Author: James Westman <james jwestman net>
Date:   Tue Apr 26 22:20:46 2022 -0500

    vector-renderer: Read data source info from style
    
    Get tile URLs, min/maxzoom, etc. from the style JSON rather than
    supplied separately. Stylesheets should already contain this
    information, so it's better to not duplicate it.
    
    Removed ShumateVectorRenderer:data-source, since styles can potentially
    have multiple data sources (although it's not supported yet).

 demos/map-style.json                          |  12 ++
 demos/shumate-demo-window.c                   |  11 +-
 shumate/shumate-vector-renderer.c             | 295 ++++++++++++--------------
 shumate/shumate-vector-renderer.h             |  34 +--
 shumate/vector/shumate-vector-utils-private.h |  34 ++-
 shumate/vector/shumate-vector-utils.c         |  95 +++++++++
 tests/vector-style.c                          |   2 +-
 7 files changed, 280 insertions(+), 203 deletions(-)
---
diff --git a/demos/map-style.json b/demos/map-style.json
index 52dc5c0..76a09dc 100644
--- a/demos/map-style.json
+++ b/demos/map-style.json
@@ -1,4 +1,16 @@
 {
+  "version": 8,
+  "name": "Vector Tiles",
+  "sources": {
+    "vector-tiles": {
+      "type": "vector",
+      "tiles": [
+        "https://jwestman.pages.gitlab.gnome.org/vector-tile-test-data/world_overview/{z}/{x}/{y}.pbf";
+      ],
+      "minzoom": 0,
+      "maxzoom": 5
+    }
+  },
   "layers": [
     {
       "id": "background",
diff --git a/demos/shumate-demo-window.c b/demos/shumate-demo-window.c
index f6475b9..1b1feaf 100644
--- a/demos/shumate-demo-window.c
+++ b/demos/shumate-demo-window.c
@@ -149,12 +149,8 @@ shumate_demo_window_init (ShumateDemoWindow *self)
 
   if (shumate_vector_renderer_is_supported ())
     {
-      ShumateVectorRenderer *renderer = shumate_vector_renderer_new_full_from_url (
+      ShumateVectorRenderer *renderer = shumate_vector_renderer_new (
         "vector-tiles",
-        "Vector Tiles",
-        "© OpenStreetMap contributors", NULL, 0, 5, 512,
-        SHUMATE_MAP_PROJECTION_MERCATOR,
-        "https://jwestman.pages.gitlab.gnome.org/vector-tile-test-data/world_overview/{z}/{x}/{y}.pbf";,
         style_json,
         &error
       );
@@ -165,7 +161,10 @@ shumate_demo_window_init (ShumateDemoWindow *self)
           g_clear_error (&error);
         }
       else
-        shumate_map_source_registry_add (self->registry, SHUMATE_MAP_SOURCE (renderer));
+        {
+          shumate_map_source_set_license (SHUMATE_MAP_SOURCE (renderer), "© OpenStreetMap contributors");
+          shumate_map_source_registry_add (self->registry, SHUMATE_MAP_SOURCE (renderer));
+        }
     }
 
   viewport = shumate_simple_map_get_viewport (self->map);
diff --git a/shumate/shumate-vector-renderer.c b/shumate/shumate-vector-renderer.c
index 59d3c37..1b9046a 100644
--- a/shumate/shumate-vector-renderer.c
+++ b/shumate/shumate-vector-renderer.c
@@ -37,6 +37,7 @@ struct _ShumateVectorRenderer
 {
   ShumateMapSource parent_instance;
 
+  char *source_name;
   ShumateDataSource *data_source;
   GPtrArray *tiles;
 
@@ -52,7 +53,6 @@ G_DEFINE_TYPE_WITH_CODE (ShumateVectorRenderer, shumate_vector_renderer, SHUMATE
 
 enum {
   PROP_0,
-  PROP_DATA_SOURCE,
   PROP_STYLE_JSON,
   N_PROPS
 };
@@ -62,153 +62,31 @@ static GParamSpec *properties [N_PROPS];
 
 /**
  * shumate_vector_renderer_new:
- * @data_source: a [class@DataSource] to provide tile image data
+ * @id: an ID for the map source
  * @style_json: a vector style
  * @error: return location for a #GError, or %NULL
  *
- * Creates a new [class@VectorRenderer] to render vector tiles from @data_source.
+ * Creates a new [class@VectorRenderer] from the given JSON style.
  *
- * Returns: (transfer full): a newly constructed [class@VectorRenderer]
- */
-ShumateVectorRenderer *
-shumate_vector_renderer_new (ShumateDataSource  *data_source,
-                             const char         *style_json,
-                             GError            **error)
-{
-  g_return_val_if_fail (SHUMATE_IS_DATA_SOURCE (data_source), NULL);
-  return g_initable_new (SHUMATE_TYPE_VECTOR_RENDERER, NULL, error,
-                         "data-source", data_source,
-                         "style-json", style_json,
-                         NULL);
-}
-
-
-/**
- * shumate_vector_renderer_new_from_url:
- * @url_template: a URL template to fetch tiles from
- * @style_json: a vector style
- * @error: return location for a #GError, or %NULL
- *
- * Creates a new [class@VectorRenderer] that fetches tiles from the given URL
- * using a [class@TileDownloader] data source.
- *
- * Equivalent to:
- *
- * ```c
- * g_autoptr(ShumateTileDownloader) source = shumate_tile_downloader_new (url_template);
- * ShumateVectorRenderer *renderer = shumate_vector_renderer_new (source);
- * ```
- *
- * Returns: (transfer full): a newly constructed [class@VectorRenderer]
- */
-ShumateVectorRenderer *
-shumate_vector_renderer_new_from_url (const char  *url_template,
-                                      const char  *style_json,
-                                      GError     **error)
-{
-  g_autoptr(ShumateDataSource) data_source = NULL;
-
-  g_return_val_if_fail (url_template != NULL, NULL);
-
-  data_source = SHUMATE_DATA_SOURCE (shumate_tile_downloader_new (url_template));
-  return shumate_vector_renderer_new (data_source, style_json, error);
-}
-
-
-/**
- * shumate_vector_renderer_new_full:
- * @id: the map source's id
- * @name: the map source's name
- * @license: the map source's license
- * @license_uri: the map source's license URI
- * @min_zoom: the map source's minimum zoom level
- * @max_zoom: the map source's maximum zoom level
- * @tile_size: the map source's tile size (in pixels)
- * @projection: the map source's projection
- * @data_source: a [class@DataSource] to provide tile image data
- * @error: (nullable): a return location for a #GError, or %NULL
- *
- * Creates a new [class@VectorRenderer] to render vector tiles from @data_source.
- *
- * Returns: a newly constructed [class@VectorRenderer] object
- */
-ShumateVectorRenderer *
-shumate_vector_renderer_new_full (const char            *id,
-                                  const char            *name,
-                                  const char            *license,
-                                  const char            *license_uri,
-                                  guint                  min_zoom,
-                                  guint                  max_zoom,
-                                  guint                  tile_size,
-                                  ShumateMapProjection   projection,
-                                  ShumateDataSource     *data_source,
-                                  const char            *style_json,
-                                  GError               **error)
-{
-  g_return_val_if_fail (SHUMATE_IS_DATA_SOURCE (data_source), NULL);
-
-  return g_initable_new (SHUMATE_TYPE_VECTOR_RENDERER, NULL, error,
-                         "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,
-                         "data-source", data_source,
-                         "style-json", style_json,
-                         NULL);
-}
-
-
-/**
- * shumate_vector_renderer_new_full_from_url:
- * @id: the map source's id
- * @name: the map source's name
- * @license: the map source's license
- * @license_uri: the map source's license URI
- * @min_zoom: the map source's minimum zoom level
- * @max_zoom: the map source's maximum zoom level
- * @tile_size: the map source's tile size (in pixels)
- * @projection: the map source's projection
- * @url_template: a template for the URL to fetch tiles from
- * @error: (nullable): a return location for a #GError, or %NULL
+ * The stylesheet should contain a list of tile sources. Tiles will be
+ * downloaded using [class@TileDownloader]s.
  *
- * Creates a new [class@VectorRenderer] that fetches tiles from the given URL
- * using a [class@TileDownloader] data source.
+ * See the [MapLibre Style Specification](https://maplibre.org/maplibre-gl-js-docs/style-spec/)
+ * for details on @style_json, but be aware that libshumate does not support
+ * every feature of the specification.
  *
- * Returns: a newly constructed [class@VectorRenderer] object
+ * Returns: (transfer full): a newly constructed [class@VectorRenderer], or %NULL if @error is set
  */
 ShumateVectorRenderer *
-shumate_vector_renderer_new_full_from_url (const char            *id,
-                                           const char            *name,
-                                           const char            *license,
-                                           const char            *license_uri,
-                                           guint                  min_zoom,
-                                           guint                  max_zoom,
-                                           guint                  tile_size,
-                                           ShumateMapProjection   projection,
-                                           const char            *url_template,
-                                           const char            *style_json,
-                                           GError               **error)
+shumate_vector_renderer_new (const char  *id,
+                             const char  *style_json,
+                             GError     **error)
 {
-  g_autoptr(ShumateTileDownloader) data_source = NULL;
-
-  g_return_val_if_fail (url_template != NULL, NULL);
-
-  data_source = shumate_tile_downloader_new (url_template);
+  g_return_val_if_fail (id != NULL, NULL);
+  g_return_val_if_fail (style_json != NULL, NULL);
 
   return g_initable_new (SHUMATE_TYPE_VECTOR_RENDERER, NULL, error,
                          "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,
-                         "data-source", data_source,
                          "style-json", style_json,
                          NULL);
 }
@@ -243,15 +121,6 @@ on_data_source_received_data (ShumateVectorRenderer *self,
                               ShumateDataSource     *data_source);
 
 
-static void
-shumate_vector_renderer_constructed (GObject *object)
-{
-  ShumateVectorRenderer *self = SHUMATE_VECTOR_RENDERER (object);
-
-  g_signal_connect_object (self->data_source, "received-data", (GCallback)on_data_source_received_data, 
self, G_CONNECT_SWAPPED);
-}
-
-
 static void
 shumate_vector_renderer_finalize (GObject *object)
 {
@@ -259,6 +128,7 @@ shumate_vector_renderer_finalize (GObject *object)
 
   g_clear_pointer (&self->layers, g_ptr_array_unref);
   g_clear_pointer (&self->style_json, g_free);
+  g_clear_pointer (&self->source_name, g_free);
   g_clear_object (&self->data_source);
   g_clear_pointer (&self->tiles, g_ptr_array_unref);
 
@@ -275,9 +145,6 @@ shumate_vector_renderer_get_property (GObject    *object,
 
   switch (prop_id)
     {
-    case PROP_DATA_SOURCE:
-      g_value_set_object (value, self->data_source);
-      break;
     case PROP_STYLE_JSON:
       g_value_set_string (value, self->style_json);
       break;
@@ -296,9 +163,6 @@ shumate_vector_renderer_set_property (GObject      *object,
 
   switch (prop_id)
     {
-    case PROP_DATA_SOURCE:
-      g_set_object (&self->data_source, g_value_get_object (value));
-      break;
     case PROP_STYLE_JSON:
       /* Property is construct only, so it should only be set once */
       g_assert (self->style_json == NULL);
@@ -325,7 +189,6 @@ shumate_vector_renderer_class_init (ShumateVectorRendererClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   ShumateMapSourceClass *map_source_class = SHUMATE_MAP_SOURCE_CLASS (klass);
 
-  object_class->constructed = shumate_vector_renderer_constructed;
   object_class->finalize = shumate_vector_renderer_finalize;
   object_class->get_property = shumate_vector_renderer_get_property;
   object_class->set_property = shumate_vector_renderer_set_property;
@@ -333,19 +196,6 @@ shumate_vector_renderer_class_init (ShumateVectorRendererClass *klass)
   map_source_class->fill_tile_async = shumate_vector_renderer_fill_tile_async;
   map_source_class->fill_tile_finish = shumate_vector_renderer_fill_tile_finish;
 
-  /**
-   * ShumateVectorRenderer:data-source:
-   *
-   * The data source that provides image tiles to display. In most cases,
-   * a [class@TileDownloader] is sufficient.
-   */
-  properties[PROP_DATA_SOURCE] =
-    g_param_spec_object ("data-source",
-                         "Data source",
-                         "Data source",
-                         SHUMATE_TYPE_DATA_SOURCE,
-                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-
   /**
    * ShumateVectorRenderer:style-json:
    *
@@ -374,7 +224,9 @@ shumate_vector_renderer_initable_init (GInitable     *initable,
   ShumateVectorRenderer *self = (ShumateVectorRenderer *)initable;
   g_autoptr(JsonNode) node = NULL;
   JsonNode *layers_node;
+  JsonNode *sources_node;
   JsonObject *object;
+  const char *style_name;
 
   g_return_val_if_fail (SHUMATE_IS_VECTOR_RENDERER (self), FALSE);
   g_return_val_if_fail (self->style_json != NULL, FALSE);
@@ -385,6 +237,116 @@ shumate_vector_renderer_initable_init (GInitable     *initable,
   if (!shumate_vector_json_get_object (node, &object, error))
     return FALSE;
 
+  if (!shumate_vector_json_get_string_member (object, "name", &style_name, error))
+    return FALSE;
+  if (style_name != NULL)
+    shumate_map_source_set_name (SHUMATE_MAP_SOURCE (self), style_name);
+
+  if ((sources_node = json_object_get_member (object, "sources")) == NULL)
+    {
+      g_set_error (error,
+                   SHUMATE_STYLE_ERROR,
+                   SHUMATE_STYLE_ERROR_UNSUPPORTED,
+                   "a data source is required");
+      return FALSE;
+    }
+  else
+    {
+      JsonObject *sources;
+      JsonObjectIter iter;
+      const char *source_name;
+      JsonNode *source_node;
+      int minzoom = 30, maxzoom = 0;
+
+      if (!shumate_vector_json_get_object (sources_node, &sources, error))
+        return FALSE;
+
+      if (json_object_get_size (sources) > 1)
+        {
+          /* TODO: Support multiple data sources */
+          g_set_error (error,
+                       SHUMATE_STYLE_ERROR,
+                       SHUMATE_STYLE_ERROR_UNSUPPORTED,
+                       "ShumateVectorRenderer does not currently support multiple data sources");
+          return FALSE;
+        }
+      else if (json_object_get_size (object) == 0)
+        {
+          g_set_error (error,
+                       SHUMATE_STYLE_ERROR,
+                       SHUMATE_STYLE_ERROR_UNSUPPORTED,
+                       "a data source is required");
+          return FALSE;
+        }
+
+      json_object_iter_init (&iter, sources);
+      while (json_object_iter_next (&iter, &source_name, &source_node))
+        {
+          JsonObject *source_object;
+          const char *source_type;
+          const char *url;
+          JsonArray *tiles;
+          const char *url_template;
+          ShumateDataSource *data_source;
+
+          if (!shumate_vector_json_get_object (source_node, &source_object, error))
+            return FALSE;
+
+          if (!shumate_vector_json_get_string_member (source_object, "type", &source_type, error)
+              || !shumate_vector_json_get_string_member (source_object, "url", &url, error)
+              || !shumate_vector_json_get_array_member (source_object, "tiles", &tiles, error))
+            return FALSE;
+
+          if (g_strcmp0 (source_type, "vector") != 0)
+            {
+              g_set_error (error,
+                           SHUMATE_STYLE_ERROR,
+                           SHUMATE_STYLE_ERROR_UNSUPPORTED,
+                           "ShumateVectorRenderer currently only supports vector sources.");
+              return FALSE;
+            }
+
+          if (url != NULL)
+            {
+              g_set_error (error,
+                           SHUMATE_STYLE_ERROR,
+                           SHUMATE_STYLE_ERROR_UNSUPPORTED,
+                           "ShumateVectorRenderer does not currently support TileJSON links. "
+                           "Please embed the TileJSON data directly into the style.");
+              return FALSE;
+            }
+
+          if (tiles == NULL || json_array_get_length (tiles) == 0)
+            {
+              g_set_error (error,
+                           SHUMATE_STYLE_ERROR,
+                           SHUMATE_STYLE_ERROR_MALFORMED_STYLE,
+                           "Expected 'tiles' array to contain at least one element");
+              return FALSE;
+            }
+
+          if (!shumate_vector_json_get_string (json_array_get_element (tiles, 0),
+                                               &url_template,
+                                               error))
+            return FALSE;
+
+          minzoom = MIN (minzoom, json_object_get_int_member_with_default (source_object, "minzoom", 0));
+          maxzoom = MAX (maxzoom, json_object_get_int_member_with_default (source_object, "maxzoom", 30));
+
+          data_source = SHUMATE_DATA_SOURCE (shumate_tile_downloader_new (url_template));
+          g_signal_connect_object (data_source, "received-data", (GCallback)on_data_source_received_data, 
self, G_CONNECT_SWAPPED);
+
+          self->source_name = g_strdup (source_name);
+          self->data_source = data_source;
+        }
+
+      if (minzoom < maxzoom)
+        {
+          shumate_map_source_set_min_zoom_level (SHUMATE_MAP_SOURCE (self), minzoom);
+          shumate_map_source_set_max_zoom_level (SHUMATE_MAP_SOURCE (self), maxzoom);
+        }
+    }
+
   self->layers = g_ptr_array_new_with_free_func (g_object_unref);
   if ((layers_node = json_object_get_member (object, "layers")))
     {
@@ -412,6 +374,9 @@ shumate_vector_renderer_initable_init (GInitable     *initable,
         }
     }
 
+  /* According to the style spec, this is not configurable for vector tiles */
+  shumate_map_source_set_tile_size (SHUMATE_MAP_SOURCE (self), 512);
+
   return TRUE;
 #else
   g_set_error (error,
diff --git a/shumate/shumate-vector-renderer.h b/shumate/shumate-vector-renderer.h
index 1583e15..1e62f2b 100644
--- a/shumate/shumate-vector-renderer.h
+++ b/shumate/shumate-vector-renderer.h
@@ -31,35 +31,9 @@ G_DECLARE_FINAL_TYPE (ShumateVectorRenderer, shumate_vector_renderer, SHUMATE, V
 gboolean shumate_vector_renderer_is_supported (void);
 
 
-ShumateVectorRenderer *shumate_vector_renderer_new (ShumateDataSource  *data_source,
-                                                    const char         *style_json,
-                                                    GError            **error);
-ShumateVectorRenderer *shumate_vector_renderer_new_from_url (const char  *url_template,
-                                                             const char  *style_json,
-                                                             GError     **error);
-
-ShumateVectorRenderer *shumate_vector_renderer_new_full (const char            *id,
-                                                         const char            *name,
-                                                         const char            *license,
-                                                         const char            *license_uri,
-                                                         guint                  min_zoom,
-                                                         guint                  max_zoom,
-                                                         guint                  tile_size,
-                                                         ShumateMapProjection   projection,
-                                                         ShumateDataSource     *data_source,
-                                                         const char            *style_json,
-                                                         GError               **error);
-ShumateVectorRenderer *shumate_vector_renderer_new_full_from_url (const char            *id,
-                                                                  const char            *name,
-                                                                  const char            *license,
-                                                                  const char            *license_uri,
-                                                                  guint                  min_zoom,
-                                                                  guint                  max_zoom,
-                                                                  guint                  tile_size,
-                                                                  ShumateMapProjection   projection,
-                                                                  const char            *url_template,
-                                                                  const char            *style_json,
-                                                                  GError               **error);
+ShumateVectorRenderer *shumate_vector_renderer_new (const char  *id,
+                                                    const char  *style_json,
+                                                    GError     **error);
 
 
 /**
@@ -78,6 +52,7 @@ GQuark shumate_style_error_quark (void);
  * @SHUMATE_STYLE_ERROR_UNSUPPORTED_LAYER: An unsupported layer type was encountered.
  * @SHUMATE_STYLE_ERROR_INVALID_EXPRESSION: An invalid or unrecognized expression was encountered.
  * @SHUMATE_STYLE_ERROR_SUPPORT_OMITTED: Libshumate was compiled without vector tile support.
+ * @SHUMATE_STYLE_ERROR_UNSUPPORTED: An unsupported style spec feature was encountered.
  *
  * Error codes that occurs while parsing the style in [class@VectorRenderer].
  */
@@ -87,6 +62,7 @@ typedef enum {
   SHUMATE_STYLE_ERROR_UNSUPPORTED_LAYER,
   SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
   SHUMATE_STYLE_ERROR_SUPPORT_OMITTED,
+  SHUMATE_STYLE_ERROR_UNSUPPORTED,
 } ShumateStyleError;
 
 G_END_DECLS
diff --git a/shumate/vector/shumate-vector-utils-private.h b/shumate/vector/shumate-vector-utils-private.h
index f0b783f..c4743ae 100644
--- a/shumate/vector/shumate-vector-utils-private.h
+++ b/shumate/vector/shumate-vector-utils-private.h
@@ -21,5 +21,35 @@
 #include "shumate-vector-renderer.h"
 
 
-gboolean shumate_vector_json_get_object (JsonNode *node, JsonObject **dest, GError **error);
-gboolean shumate_vector_json_get_array (JsonNode *node, JsonArray **dest, GError **error);
+gboolean shumate_vector_json_get_object (JsonNode    *node,
+                                         JsonObject **dest,
+                                         GError     **error);
+gboolean shumate_vector_json_get_array (JsonNode   *node,
+                                        JsonArray **dest,
+                                        GError    **error);
+gboolean shumate_vector_json_get_string (JsonNode    *node,
+                                         const char **dest,
+                                         GError     **error);
+
+gboolean shumate_vector_json_get_object_member (JsonObject  *object,
+                                                const char  *name,
+                                                JsonObject **dest,
+                                                GError     **error);
+gboolean shumate_vector_json_get_array_member (JsonObject  *object,
+                                               const char  *name,
+                                               JsonArray  **dest,
+                                               GError     **error);
+gboolean shumate_vector_json_get_string_member (JsonObject  *object,
+                                                const char  *name,
+                                                const char **dest,
+                                                GError     **error);
+
+const char *shumate_vector_json_read_string_member (JsonReader *reader,
+                                                    const char *name);
+
+gboolean shumate_vector_json_read_int_member (JsonReader *reader,
+                                              const char *name,
+                                              int        *dest);
+gboolean shumate_vector_json_read_double_member (JsonReader *reader,
+                                                 const char *name,
+                                                 double     *dest);
diff --git a/shumate/vector/shumate-vector-utils.c b/shumate/vector/shumate-vector-utils.c
index 39e8584..72c5da5 100644
--- a/shumate/vector/shumate-vector-utils.c
+++ b/shumate/vector/shumate-vector-utils.c
@@ -57,3 +57,98 @@ shumate_vector_json_get_array (JsonNode *node, JsonArray **dest, GError **error)
   *dest = json_node_get_array (node);
   return TRUE;
 }
+
+gboolean
+shumate_vector_json_get_string (JsonNode    *node,
+                                const char **dest,
+                                GError     **error)
+{
+  g_assert (node != NULL);
+  g_assert (dest != NULL);
+
+  if (!JSON_NODE_HOLDS_VALUE (node) || json_node_get_value_type (node) != G_TYPE_STRING)
+    {
+      g_set_error (error,
+                   SHUMATE_STYLE_ERROR,
+                   SHUMATE_STYLE_ERROR_MALFORMED_STYLE,
+                   "Expected string, got %s",
+                   json_node_type_name (node));
+      return FALSE;
+    }
+
+  *dest = json_node_get_string (node);
+  return TRUE;
+}
+
+
+JsonNode *
+get_member (JsonObject *object,
+            const char *name)
+{
+  if (object == NULL)
+    return FALSE;
+  return json_object_get_member (object, name);
+}
+
+
+gboolean
+shumate_vector_json_get_object_member (JsonObject  *object,
+                                       const char  *name,
+                                       JsonObject **dest,
+                                       GError     **error)
+{
+  JsonNode *node;
+
+  g_assert (dest != NULL);
+
+  node = get_member (object, name);
+  if (node == NULL)
+    {
+      *dest = NULL;
+      return TRUE;
+    }
+
+  return shumate_vector_json_get_object (node, dest, error);
+}
+
+
+gboolean
+shumate_vector_json_get_array_member (JsonObject  *object,
+                                      const char  *name,
+                                      JsonArray  **dest,
+                                      GError     **error)
+{
+  JsonNode *node;
+
+  g_assert (dest != NULL);
+
+  node = get_member (object, name);
+  if (node == NULL)
+    {
+      *dest = NULL;
+      return TRUE;
+    }
+
+  return shumate_vector_json_get_array (node, dest, error);
+}
+
+
+gboolean
+shumate_vector_json_get_string_member (JsonObject  *object,
+                                       const char  *name,
+                                       const char **dest,
+                                       GError     **error)
+{
+  JsonNode *node;
+
+  g_assert (dest != NULL);
+
+  node = get_member (object, name);
+  if (node == NULL)
+    {
+      *dest = NULL;
+      return TRUE;
+    }
+
+  return shumate_vector_json_get_string (node, dest, error);
+}
diff --git a/tests/vector-style.c b/tests/vector-style.c
index 05869c6..c99ea9c 100644
--- a/tests/vector-style.c
+++ b/tests/vector-style.c
@@ -11,7 +11,7 @@ test_vector_style_create (void)
   style_json = g_resources_lookup_data ("/org/gnome/shumate/Tests/style.json", G_RESOURCE_LOOKUP_FLAGS_NONE, 
NULL);
   g_assert_no_error (error);
 
-  renderer = shumate_vector_renderer_new_from_url ("", g_bytes_get_data (style_json, NULL), &error);
+  renderer = shumate_vector_renderer_new ("", g_bytes_get_data (style_json, NULL), &error);
   g_assert_no_error (error);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]