]> git.street.me.uk Git - andy/viking.git/blame - src/vikmaptype.c
Add and use preference for height units.
[andy/viking.git] / src / vikmaptype.c
CommitLineData
357695f1
GB
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2/*
3 * viking
4 * Copyright (C) Guilhem Bonnefille 2009 <guilhem.bonnefille@gmail.com>
5 *
6 * viking is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * viking is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include "vikmaptype.h"
24#include "vikmapslayer_compat.h"
25
608d87ec
GB
26static guint8 map_type_get_uniq_id (VikMapSource *self);
27static const gchar *map_type_get_label (VikMapSource *self);
28static guint16 map_type_get_tilesize_x (VikMapSource *self);
29static guint16 map_type_get_tilesize_y (VikMapSource *self);
30static VikViewportDrawMode map_type_get_drawmode (VikMapSource *self);
357695f1
GB
31static gboolean map_type_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest );
32static void map_type_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest);
825413ba
SW
33static int map_type_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void * handle);
34static void * map_type_download_handle_init (VikMapSource * self);
35static void map_type_download_handle_cleanup (VikMapSource * self, void * handle);
357695f1
GB
36
37typedef struct _VikMapTypePrivate VikMapTypePrivate;
38struct _VikMapTypePrivate
39{
db03733a 40 gchar *label;
357695f1
GB
41 VikMapsLayer_MapType map_type;
42};
43
44#define VIK_MAP_TYPE_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIK_TYPE_MAP_TYPE, VikMapTypePrivate))
45
46
47G_DEFINE_TYPE (VikMapType, vik_map_type, VIK_TYPE_MAP_SOURCE);
48
49static void
50vik_map_type_init (VikMapType *object)
51{
db03733a
GB
52 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(object);
53 priv->label = NULL;
357695f1
GB
54}
55
56VikMapType *
db03733a 57vik_map_type_new_with_id (VikMapsLayer_MapType map_type, const char *label)
357695f1
GB
58{
59 VikMapType *ret = (VikMapType *)g_object_new(vik_map_type_get_type(), NULL);
60 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(ret);
61 priv->map_type = map_type;
db03733a 62 priv->label = g_strdup (label);
357695f1
GB
63 return ret;
64}
65
66static void
67vik_map_type_finalize (GObject *object)
68{
db03733a
GB
69 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(object);
70 g_free (priv->label);
71 priv->label = NULL;
357695f1
GB
72
73 G_OBJECT_CLASS (vik_map_type_parent_class)->finalize (object);
74}
75
76static void
77vik_map_type_class_init (VikMapTypeClass *klass)
78{
79 GObjectClass* object_class = G_OBJECT_CLASS (klass);
80 VikMapSourceClass* parent_class = VIK_MAP_SOURCE_CLASS (klass);
81
82 /* Overiding methods */
608d87ec
GB
83 parent_class->get_uniq_id = map_type_get_uniq_id;
84 parent_class->get_label = map_type_get_label;
85 parent_class->get_tilesize_x = map_type_get_tilesize_x;
86 parent_class->get_tilesize_y = map_type_get_tilesize_y;
87 parent_class->get_drawmode = map_type_get_drawmode;
357695f1
GB
88 parent_class->coord_to_mapcoord = map_type_coord_to_mapcoord;
89 parent_class->mapcoord_to_center_coord = map_type_mapcoord_to_center_coord;
90 parent_class->download = map_type_download;
825413ba
SW
91 parent_class->download_handle_init = map_type_download_handle_init;
92 parent_class->download_handle_cleanup = map_type_download_handle_cleanup;
357695f1
GB
93
94 g_type_class_add_private (klass, sizeof (VikMapTypePrivate));
95
96 object_class->finalize = vik_map_type_finalize;
97}
98
608d87ec
GB
99static guint8
100map_type_get_uniq_id (VikMapSource *self)
101{
102 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self);
103 g_return_val_if_fail (priv != NULL, (guint8)0);
104
105 return priv->map_type.uniq_id;
106}
107
108static const gchar *
109map_type_get_label (VikMapSource *self)
110{
111 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self);
112 g_return_val_if_fail (priv != NULL, FALSE);
113
114 return priv->label;
115}
116
117static guint16
118map_type_get_tilesize_x (VikMapSource *self)
119{
120 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self);
121 g_return_val_if_fail (priv != NULL, (guint16)0);
122
123 return priv->map_type.tilesize_x;
124}
125
126static guint16
127map_type_get_tilesize_y (VikMapSource *self)
128{
129 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self);
130 g_return_val_if_fail (priv != NULL, (guint16)0);
131
132 return priv->map_type.tilesize_y;
133}
134
135static VikViewportDrawMode
136map_type_get_drawmode (VikMapSource *self)
137{
138 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self);
139 g_return_val_if_fail (priv != NULL, (VikViewportDrawMode)0);
140
141 return priv->map_type.drawmode;
142}
143
357695f1
GB
144static gboolean
145map_type_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
146{
147 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self);
148 g_return_val_if_fail (priv != NULL, FALSE);
149
150 return (priv->map_type.coord_to_mapcoord)(src, xzoom, yzoom, dest);
151}
152
153static void
154map_type_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest)
155{
156 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self);
157 g_return_if_fail (self != NULL);
158
159 return (priv->map_type.mapcoord_to_center_coord)(src, dest);
160}
161
162static int
825413ba 163map_type_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void * handle)
357695f1
GB
164{
165 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self);
166 g_return_val_if_fail (priv != NULL, 0);
167
825413ba
SW
168 return (priv->map_type.download)(src, dest_fn, handle);
169}
170
171static void *
172map_type_download_handle_init (VikMapSource * self)
173{
174 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self);
175 g_return_val_if_fail (priv != NULL, 0);
176
177 return (priv->map_type.download_handle_init)();
178}
179
180static void
181map_type_download_handle_cleanup (VikMapSource * self, void * handle)
182{
183 VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self);
184 g_return_val_if_fail (priv != NULL, 0);
185
186 return (priv->map_type.download_handle_cleanup)(handle);
357695f1
GB
187}
188