Branch data Line data Source code
1 : : /* 2 : : * Copyright (C) 2023 James Westman <james@jwestman.net> 3 : : * 4 : : * This library is free software; you can redistribute it and/or 5 : : * modify it under the terms of the GNU Lesser General Public 6 : : * License as published by the Free Software Foundation; either 7 : : * version 2.1 of the License, or (at your option) any later version. 8 : : * 9 : : * This library is distributed in the hope that it will be useful, 10 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : : * Lesser General Public License for more details. 13 : : * 14 : : * You should have received a copy of the GNU Lesser General Public 15 : : * License along with this library; if not, see <https://www.gnu.org/licenses/>. 16 : : */ 17 : : 18 : : #include "shumate-vector-reader-private.h" 19 : : #ifdef SHUMATE_HAS_VECTOR_RENDERER 20 : : #include "vector/vector_tile.pb-c.h" 21 : : #endif 22 : : 23 : : /** 24 : : * ShumateVectorReader: 25 : : * 26 : : * Provides low-level access to the contents of a vector tile. 27 : : * 28 : : * To create a new [class@VectorReader], use [ctor@VectorReader.new] and pass 29 : : * the bytes of a vector tile, which you might get from a [class@DataSource]. 30 : : * Then, use [method@VectorReader.iterate] to get a [class@VectorReaderIter] 31 : : * and iterate over the features in the tile. You can create multiple 32 : : * [class@VectorReaderIter]s from the same [class@VectorReader]. 33 : : * 34 : : * Since: 1.2 35 : : */ 36 : : 37 [ + + + - ]: 100 : G_DEFINE_TYPE (ShumateVectorReader, shumate_vector_reader, G_TYPE_OBJECT) 38 : : 39 : : static void 40 : 21 : shumate_vector_reader_finalize (GObject *object) 41 : : { 42 : 21 : ShumateVectorReader *self = SHUMATE_VECTOR_READER (object); 43 : : 44 : : #ifdef SHUMATE_HAS_VECTOR_RENDERER 45 : 21 : vector_tile__tile__free_unpacked (self->tile, NULL); 46 : 21 : self->tile = NULL; 47 : : #endif 48 : : 49 : 21 : G_OBJECT_CLASS (shumate_vector_reader_parent_class)->finalize (object); 50 : 21 : } 51 : : 52 : : static void 53 : 13 : shumate_vector_reader_class_init (ShumateVectorReaderClass *klass) 54 : : { 55 : 13 : GObjectClass *object_class = G_OBJECT_CLASS (klass); 56 : : 57 : 13 : object_class->finalize = shumate_vector_reader_finalize; 58 : : } 59 : : 60 : : static void 61 : 21 : shumate_vector_reader_init (ShumateVectorReader *self) 62 : : { 63 : 21 : } 64 : : 65 : : /** 66 : : * shumate_vector_reader_new: 67 : : * @bytes: (transfer none): A tile in Mapbox Vector Tile format 68 : : * 69 : : * Creates a new [class@VectorReader] from @bytes. 70 : : * 71 : : * Returns: (transfer full): A new [class@VectorReader] 72 : : * 73 : : * Since: 1.2 74 : : */ 75 : : ShumateVectorReader * 76 : 21 : shumate_vector_reader_new (GBytes *bytes) 77 : : { 78 : : #ifdef SHUMATE_HAS_VECTOR_RENDERER 79 : 21 : g_autoptr(ShumateVectorReader) self = g_object_new(SHUMATE_TYPE_VECTOR_READER, NULL); 80 : 21 : gconstpointer data; 81 : 21 : gsize len; 82 : : 83 : 21 : data = g_bytes_get_data (bytes, &len); 84 : 21 : self->tile = vector_tile__tile__unpack (NULL, len, data); 85 : : 86 [ - + ]: 21 : if (self->tile == NULL) 87 : 0 : return NULL; 88 : : 89 : : return g_steal_pointer (&self); 90 : : #else 91 : : g_warning ("Vector tile support is not enabled"); 92 : : return NULL; 93 : : #endif 94 : : } 95 : : 96 : : /** 97 : : * shumate_vector_reader_iterate: 98 : : * @self: A [class@VectorReader] 99 : : * 100 : : * Creates a new [class@VectorReaderIter] for @self. 101 : : * 102 : : * Returns: (transfer full): A new [class@VectorReaderIter] 103 : : * 104 : : * Since: 1.2 105 : : */ 106 : : ShumateVectorReaderIter * 107 : 39 : shumate_vector_reader_iterate (ShumateVectorReader *self) 108 : : { 109 : : #ifdef SHUMATE_HAS_VECTOR_RENDERER 110 : 39 : return shumate_vector_reader_iter_new (self); 111 : : #else 112 : : g_warning ("Vector tile support is not enabled"); 113 : : return NULL; 114 : : #endif 115 : : }