1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
5 * Copyright (C) 2013, Rob Norris <rw_norris@hotmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 // World Scale: VIK_GZ(17)
26 // Submeter scale: 1/VIK_GZ(5)
27 // No map provider is going to have tiles at the highest zoom in level - but we can interpolate to that.
29 static const gdouble scale_mpps[] = { VIK_GZ(0), VIK_GZ(1), VIK_GZ(2), VIK_GZ(3), VIK_GZ(4), VIK_GZ(5),
30 VIK_GZ(6), VIK_GZ(7), VIK_GZ(8), VIK_GZ(9), VIK_GZ(10), VIK_GZ(11),
31 VIK_GZ(12), VIK_GZ(13), VIK_GZ(14), VIK_GZ(15), VIK_GZ(16), VIK_GZ(17) };
32 static const gint num_scales = (sizeof(scale_mpps) / sizeof(scale_mpps[0]));
34 static const gdouble scale_neg_mpps[] = { 1.0/VIK_GZ(0), 1.0/VIK_GZ(1), 1.0/VIK_GZ(2),
35 1.0/VIK_GZ(3), 1.0/VIK_GZ(4), 1.0/VIK_GZ(5) };
36 static const gint num_scales_neg = (sizeof(scale_neg_mpps) / sizeof(scale_neg_mpps[0]));
38 #define ERROR_MARGIN 0.01
40 * map_utils_mpp_to_scale:
41 * @mpp: The so called 'mpp'
43 * Returns: the zoom scale value which may be negative.
45 gint map_utils_mpp_to_scale ( gdouble mpp ) {
47 for ( i = 0; i < num_scales; i++ ) {
48 if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN ) {
52 for ( i = 0; i < num_scales_neg; i++ ) {
53 if ( ABS(scale_neg_mpps[i] - mpp) < 0.000001 ) {
62 * map_utils_mpp_to_zoom_level:
63 * @mpp: The so called 'mpp'
65 * Returns: a Zoom Level
66 * See: http://wiki.openstreetmap.org/wiki/Zoom_levels
68 guint8 map_utils_mpp_to_zoom_level ( gdouble mpp )
70 gint answer = 17 - map_utils_mpp_to_scale ( mpp );