[libshumate] vector: Add line layer



commit 98916ec5c21dc5a2d3d40533de63f3d3367199d1
Author: James Westman <james jwestman net>
Date:   Tue Aug 24 01:47:22 2021 -0500

    vector: Add line layer

 demos/map-style.json                               | 10 +++
 shumate/meson.build                                |  2 +
 shumate/vector/shumate-vector-layer.c              |  3 +
 shumate/vector/shumate-vector-line-layer-private.h | 32 +++++++++
 shumate/vector/shumate-vector-line-layer.c         | 81 ++++++++++++++++++++++
 5 files changed, 128 insertions(+)
---
diff --git a/demos/map-style.json b/demos/map-style.json
index 0e6e5ed..453ce79 100644
--- a/demos/map-style.json
+++ b/demos/map-style.json
@@ -14,6 +14,16 @@
       "paint": {
         "fill-color": "#3584e4"
       }
+    },
+    {
+      "id": "boundary",
+      "type": "line",
+      "source-layer": "boundary",
+      "paint": {
+        "line-color": "#9a9996",
+        "line-opacity": 0.5,
+        "line-width": 0.9
+      }
     }
   ]
 }
diff --git a/shumate/meson.build b/shumate/meson.build
index 75b3224..53ce659 100644
--- a/shumate/meson.build
+++ b/shumate/meson.build
@@ -29,6 +29,7 @@ libshumate_private_h = [
   'vector/shumate-vector-background-layer-private.h',
   'vector/shumate-vector-fill-layer-private.h',
   'vector/shumate-vector-layer-private.h',
+  'vector/shumate-vector-line-layer-private.h',
   'vector/shumate-vector-render-scope-private.h',
   'vector/shumate-vector-utils-private.h',
   'vector/vector_tile.pb-c.h',
@@ -60,6 +61,7 @@ libshumate_sources = [
   'vector/shumate-vector-background-layer.c',
   'vector/shumate-vector-fill-layer.c',
   'vector/shumate-vector-layer.c',
+  'vector/shumate-vector-line-layer.c',
   'vector/shumate-vector-render-scope.c',
   'vector/shumate-vector-utils.c',
   'vector/vector_tile.pb-c.c',
diff --git a/shumate/vector/shumate-vector-layer.c b/shumate/vector/shumate-vector-layer.c
index f109a8e..8bacdc6 100644
--- a/shumate/vector/shumate-vector-layer.c
+++ b/shumate/vector/shumate-vector-layer.c
@@ -19,6 +19,7 @@
 #include "shumate-vector-background-layer-private.h"
 #include "shumate-vector-fill-layer-private.h"
 #include "shumate-vector-layer-private.h"
+#include "shumate-vector-line-layer-private.h"
 
 typedef struct
 {
@@ -49,6 +50,8 @@ shumate_vector_layer_create_from_json (JsonObject *object, GError **error)
     layer = shumate_vector_background_layer_create_from_json (object, error);
   else if (g_strcmp0 (type, "fill") == 0)
     layer = shumate_vector_fill_layer_create_from_json (object, error);
+  else if (g_strcmp0 (type, "line") == 0)
+    layer = shumate_vector_line_layer_create_from_json (object, error);
   else
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unsupported layer type \"%s\"", type);
diff --git a/shumate/vector/shumate-vector-line-layer-private.h 
b/shumate/vector/shumate-vector-line-layer-private.h
new file mode 100644
index 0000000..89b4586
--- /dev/null
+++ b/shumate/vector/shumate-vector-line-layer-private.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2021 James Westman <james jwestman net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <json-glib/json-glib.h>
+
+#include "shumate-vector-layer-private.h"
+
+G_BEGIN_DECLS
+
+#define SHUMATE_TYPE_VECTOR_LINE_LAYER (shumate_vector_line_layer_get_type())
+
+G_DECLARE_FINAL_TYPE (ShumateVectorLineLayer, shumate_vector_line_layer, SHUMATE, VECTOR_LINE_LAYER, 
ShumateVectorLayer)
+
+ShumateVectorLayer *shumate_vector_line_layer_create_from_json (JsonObject *object, GError **error);
+
+G_END_DECLS
diff --git a/shumate/vector/shumate-vector-line-layer.c b/shumate/vector/shumate-vector-line-layer.c
new file mode 100644
index 0000000..0c3ca5c
--- /dev/null
+++ b/shumate/vector/shumate-vector-line-layer.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2021 James Westman <james jwestman net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <gtk/gtk.h>
+#include "shumate-vector-line-layer-private.h"
+#include "shumate-vector-utils-private.h"
+
+struct _ShumateVectorLineLayer
+{
+  ShumateVectorLayer parent_instance;
+
+  GdkRGBA color;
+  double opacity;
+  double width;
+};
+
+G_DEFINE_TYPE (ShumateVectorLineLayer, shumate_vector_line_layer, SHUMATE_TYPE_VECTOR_LAYER)
+
+
+ShumateVectorLayer *
+shumate_vector_line_layer_create_from_json (JsonObject *object, GError **error)
+{
+  ShumateVectorLineLayer *layer = g_object_new (SHUMATE_TYPE_VECTOR_LINE_LAYER, NULL);
+  JsonNode *paint_node;
+
+  if ((paint_node = json_object_get_member (object, "paint")))
+    {
+      JsonObject *paint;
+
+      if (!shumate_vector_json_get_object (paint_node, &paint, error))
+        return NULL;
+
+      gdk_rgba_parse (&layer->color, json_object_get_string_member_with_default (paint, "line-color", 
"#000000"));
+      layer->opacity = json_object_get_double_member_with_default (paint, "line-opacity", 1.0);
+      layer->width = json_object_get_double_member_with_default (paint, "line-width", 1.0);
+    }
+
+  return (ShumateVectorLayer *)layer;
+}
+
+
+static void
+shumate_vector_line_layer_render (ShumateVectorLayer *layer, ShumateVectorRenderScope *scope)
+{
+  ShumateVectorLineLayer *self = SHUMATE_VECTOR_LINE_LAYER (layer);
+
+  shumate_vector_render_scope_exec_geometry (scope);
+
+  cairo_set_source_rgba (scope->cr, self->color.red, self->color.green, self->color.blue, self->opacity);
+  cairo_set_line_width (scope->cr, self->width * scope->scale);
+  cairo_stroke (scope->cr);
+}
+
+
+static void
+shumate_vector_line_layer_class_init (ShumateVectorLineLayerClass *klass)
+{
+  ShumateVectorLayerClass *layer_class = SHUMATE_VECTOR_LAYER_CLASS (klass);
+
+  layer_class->render = shumate_vector_line_layer_render;
+}
+
+
+static void
+shumate_vector_line_layer_init (ShumateVectorLineLayer *self)
+{
+}


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