X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/983bb64fcf20abf3445f82969c33a5e679ab5f3f..b529dc9c00bbafad3671e76e719277d4deecddbc:/src/vikslippymapsource.c?ds=sidebyside diff --git a/src/vikslippymapsource.c b/src/vikslippymapsource.c index 2c878047..c04ef485 100644 --- a/src/vikslippymapsource.c +++ b/src/vikslippymapsource.c @@ -36,14 +36,14 @@ static gboolean _supports_if_modified_since (VikMapSource *self ); static gchar *_get_uri( VikSlippyMapSource *self, MapCoord *src ); static gchar *_get_hostname( VikSlippyMapSource *self ); -static DownloadOptions *_get_download_options( VikSlippyMapSource *self ); +static DownloadMapOptions *_get_download_options( VikSlippyMapSource *self ); typedef struct _VikSlippyMapSourcePrivate VikSlippyMapSourcePrivate; struct _VikSlippyMapSourcePrivate { gchar *hostname; gchar *url; - DownloadOptions options; + DownloadMapOptions options; }; #define VIK_SLIPPY_MAP_SOURCE_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIK_TYPE_SLIPPY_MAP_SOURCE, VikSlippyMapSourcePrivate)) @@ -250,13 +250,23 @@ static const gdouble scale_mpps[] = { GZ(0), GZ(1), GZ(2), GZ(3), GZ(4), GZ(5), static const gint num_scales = (sizeof(scale_mpps) / sizeof(scale_mpps[0])); +static const gdouble scale_neg_mpps[] = { 1.0/GZ(0), 1.0/GZ(1), 1.0/GZ(2), 1.0/GZ(3) }; +static const gint num_scales_neg = (sizeof(scale_neg_mpps) / sizeof(scale_neg_mpps[0])); + #define ERROR_MARGIN 0.01 -static guint8 slippy_zoom ( gdouble mpp ) { +static gint slippy_zoom ( gdouble mpp ) { gint i; for ( i = 0; i < num_scales; i++ ) { - if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN ) + if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN ) { return i; + } } + for ( i = 0; i < num_scales_neg; i++ ) { + if ( ABS(scale_neg_mpps[i] - mpp) < 0.000001 ) { + return -i; + } + } + return 255; } @@ -286,7 +296,7 @@ vik_slippy_map_source_get_hostname( VikSlippyMapSource *self ) return (*klass->get_hostname)(self); } -DownloadOptions * +DownloadMapOptions * vik_slippy_map_source_get_download_options( VikSlippyMapSource *self ) { VikSlippyMapSourceClass *klass; @@ -330,7 +340,11 @@ _coord_to_mapcoord ( VikMapSource *self, const VikCoord *src, gdouble xzoom, gdo static void _mapcoord_to_center_coord ( VikMapSource *self, MapCoord *src, VikCoord *dest ) { - gdouble socalled_mpp = GZ(src->scale); + gdouble socalled_mpp; + if (src->scale >= 0) + socalled_mpp = GZ(src->scale); + else + socalled_mpp = 1.0/GZ(-src->scale); dest->mode = VIK_COORD_LATLON; dest->east_west = ((src->x+0.5) / GZ(17) * socalled_mpp * 360) - 180; dest->north_south = DEMERCLAT(180 - ((src->y+0.5) / GZ(17) * socalled_mpp * 360)); @@ -342,7 +356,7 @@ _download ( VikMapSource *self, MapCoord *src, const gchar *dest_fn, void *handl int res; gchar *uri = vik_slippy_map_source_get_uri(VIK_SLIPPY_MAP_SOURCE(self), src); gchar *host = vik_slippy_map_source_get_hostname(VIK_SLIPPY_MAP_SOURCE(self)); - DownloadOptions *options = vik_slippy_map_source_get_download_options(VIK_SLIPPY_MAP_SOURCE(self)); + DownloadMapOptions *options = vik_slippy_map_source_get_download_options(VIK_SLIPPY_MAP_SOURCE(self)); res = a_http_download_get_url ( host, uri, dest_fn, options, handle ); g_free ( uri ); g_free ( host ); @@ -381,7 +395,7 @@ _get_hostname( VikSlippyMapSource *self ) return g_strdup( priv->hostname ); } -static DownloadOptions * +static DownloadMapOptions * _get_download_options( VikSlippyMapSource *self ) { g_return_val_if_fail (VIK_IS_SLIPPY_MAP_SOURCE(self), NULL);