]> git.street.me.uk Git - andy/viking.git/blame - src/osm-map-type.gob
Add Terraserver
[andy/viking.git] / src / osm-map-type.gob
CommitLineData
1eda0c35 1%headertop{
2#ifdef HAVE_CONFIG_H
3#include "config.h"
4#endif
5
6#include "vikcoord.h"
7#include "mapcoord.h"
8#include "vik-map-type.h"
9%}
10
11%{
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include <glib/gi18n.h>
17#include <gtk/gtk.h>
18#include <math.h>
19#include <string.h>
20#include "coords.h"
21#include "vikcoord.h"
22#include "mapcoord.h"
23#include "download.h"
24#include "curl_download.h"
25#include "globals.h"
26#include "google.h"
27#include "vikmapslayer.h"
28%}
29
30%h{
31
32%}
33
34%{
35
36static DownloadOptions osm_options = { NULL, 0, a_check_map_file };
37
38/* 1 << (x) is like a 2**(x) */
39#define GZ(x) (1<<(x))
40
41static const gdouble scale_mpps[] = { GZ(0), GZ(1), GZ(2), GZ(3), GZ(4), GZ(5), GZ(6), GZ(7), GZ(8), GZ(9),
42 GZ(10), GZ(11), GZ(12), GZ(13), GZ(14), GZ(15), GZ(16), GZ(17) };
43
44static const gint num_scales = (sizeof(scale_mpps) / sizeof(scale_mpps[0]));
45
46#define ERROR_MARGIN 0.01
47guint8 osm_zoom ( gdouble mpp ) {
48 gint i;
49 for ( i = 0; i < num_scales; i++ ) {
50 if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN )
51 return i;
52 }
53 return 255;
54}
55
56%}
57
58class Osm:Map:Type from Vik:Map:Type {
59 private gchar *hostname;
60
61 private gchar *filename_format;
62
63 override (Vik:Map:Type) gboolean
64 coord_to_mapcoord ( Vik:Map:Type *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
65 {
66 g_assert ( src->mode == VIK_COORD_LATLON );
67
68 if ( xzoom != yzoom )
69 return FALSE;
70
71 dest->scale = osm_zoom ( xzoom );
72 if ( dest->scale == 255 )
73 return FALSE;
74
75 dest->x = (src->east_west + 180) / 360 * GZ(17) / xzoom;
76 dest->y = (180 - MERCLAT(src->north_south)) / 360 * GZ(17) / xzoom;
77 dest->z = 0;
78 return TRUE;
79 }
80
81 override (Vik:Map:Type) void
82 mapcoord_to_center_coord ( Vik:Map:Type *self, MapCoord *src, VikCoord *dest )
83 {
84 gdouble socalled_mpp = GZ(src->scale);
85 dest->mode = VIK_COORD_LATLON;
86 dest->east_west = ((src->x+0.5) / GZ(17) * socalled_mpp * 360) - 180;
87 dest->north_south = DEMERCLAT(180 - ((src->y+0.5) / GZ(17) * socalled_mpp * 360));
88 }
89
90 override (Vik:Map:Type) int
91 download ( Vik:Map:Type *self, MapCoord *src, const gchar *dest_fn )
92 {
93 int res = -1;
94 gchar *uri = g_strdup_printf ( OSM_MAP_TYPE(self)->_priv->filename_format,
95 17 - src->scale, src->x, src->y );
96 res = a_http_download_get_url ( OSM_MAP_TYPE(self)->_priv->hostname,
97 uri, dest_fn, &osm_options );
98 g_free ( uri );
99 return res;
100 }
101}