#include "hildon-mapper.h"
#include "utils.h"
-#include "map.h"
#include "osm.h"
#include "db.h"
#include "osm-db.h"
#include "ui-common.h"
#include "settings.h"
#include "latlon.h"
-#include "gpx.h"
#include "map-download.h"
#include "iap.h"
#include "map-repo.h"
+#include "gtkmap.h"
static guint _num_downloads=0;
static guint _curr_download=0;
if (msg->easy_handle == _autoroute_data.curl_easy) {
/* This is the autoroute download. */
/* Now, parse the autoroute and update the display. */
- if (_autoroute_data.enabled && parse_gpx(&_route, _autoroute_data.rdl_data.bytes, _autoroute_data.rdl_data.bytes_read, 0)) {
+ if (_autoroute_data.enabled && path_gpx_parse(_route, _autoroute_data.rdl_data.bytes, _autoroute_data.rdl_data.bytes_read, 0)) {
/* Find the nearest route point, if we're connected. */
- route_find_nearest_point();
- map_force_redraw();
+ path_find_nearest_point(_route, _gps->data.lat, _gps->data.lon);
}
- cancel_autoroute(TRUE); /* We're done. Clean up. */
+ route_cancel_autoroute(_route, TRUE); /* We're done. Clean up. */
} else {
ProgressUpdateInfo *pui = g_hash_table_lookup(pui_by_easy, msg->easy_handle);
g_queue_push_head(curl_easy_queue, msg->easy_handle);
}
/* Up to 1 transfer per tile. */
-while (num_transfers < (BUF_WIDTH_TILES * BUF_HEIGHT_TILES) && g_tree_nnodes(pui_tree)) {
+while (num_transfers < (4*4) && g_tree_nnodes(pui_tree)) {
ProgressUpdateInfo *pui;
g_tree_foreach(pui_tree, (GTraverseFunc)get_next_pui, &pui);
curl_easy_setopt(curl_easy, CURLOPT_URL, pui->src_str);
curl_easy_setopt(curl_easy, CURLOPT_WRITEDATA, f);
g_hash_table_insert(pui_by_easy, curl_easy, pui);
- if (!_curl_multi) {
- /* Initialize CURL. */
- _curl_multi = curl_multi_init();
- /*curl_multi_setopt(_curl_multi, CURLMOPT_PIPELINING, 1); */
- }
curl_multi_add_handle(_curl_multi, curl_easy);
num_transfers++;
} else {
while ((curr = g_queue_pop_tail(curl_easy_queue)))
curl_easy_cleanup(curr);
- curl_multi_cleanup(_curl_multi);
- _curl_multi = NULL;
-
_curl_sid = 0;
return FALSE;
}
return TRUE;
}
+#ifdef MAP_DOWNLOAD_WMS
/**
* Given a wms uri pattern, compute the coordinate transformation and
* trimming.
* 'proj' is used for the conversion
*/
+
+#define WMS_TILE_SIZE_PIXELS (256)
+
static gchar *
map_convert_wms_to_wms(gint tilex, gint tiley, gint zoomlevel, gchar * uri)
{
srs[srsstre - srsstr - 4] = 0;
/* convert to lower, as WMC is EPSG and cs2cs is epsg */
-gint dwidth = widthstr ? atoi(widthstr + 6) - TILE_SIZE_PIXELS : 0;
-gint dheight = heightstr ? atoi(heightstr + 7) - TILE_SIZE_PIXELS : 0;
+gint dwidth = widthstr ? atoi(widthstr + 6) - WMS_TILE_SIZE_PIXELS : 0;
+gint dheight = heightstr ? atoi(heightstr + 7) - WMS_TILE_SIZE_PIXELS : 0;
unit2latlon(tile2zunit(tilex, zoomlevel) - pixel2zunit(dwidth / 2, zoomlevel),
- tile2zunit(tiley + 1, zoomlevel) + pixel2zunit((dheight + 1) / 2, zoomlevel), lat1, lon1);
+ tile2zunit(tiley + 1, zoomlevel) + pixel2zunit((dheight + 1) / 2, zoomlevel), &lat1, &lon1);
unit2latlon(tile2zunit(tilex + 1, zoomlevel) + pixel2zunit((dwidth + 1) / 2, zoomlevel),
- tile2zunit(tiley, zoomlevel) - pixel2zunit(dheight / 2, zoomlevel), lat2, lon2);
+ tile2zunit(tiley, zoomlevel) - pixel2zunit(dheight / 2, zoomlevel), &lat2, &lon2);
setlocale(LC_NUMERIC, "C");
return ret;
}
-
+#endif
/**
* Given the xyz coordinates of our map coordinate system, write the qrst
switch (_curr_repo->type) {
case REPOTYPE_XYZ:
return g_strdup_printf(_curr_repo->url, tilex, tiley, zoom);
-
case REPOTYPE_XYZ_INV:
return g_strdup_printf(_curr_repo->url, 17 - zoom, tilex, tiley);
-
-case REPOTYPE_QUAD_QRST:
- {
- gchar location[MAX_ZOOM + 2];
+case REPOTYPE_QUAD_QRST: {
+ gchar location[32];
map_convert_coords_to_quadtree_string(tilex, tiley, zoom, location, 't', "qrts");
return g_strdup_printf(_curr_repo->url, location);
}
-
-case REPOTYPE_QUAD_ZERO:
- {
+case REPOTYPE_QUAD_ZERO: {
/* This is a zero-based quadtree URI. */
- gchar location[MAX_ZOOM + 2];
+ gchar location[32];
map_convert_coords_to_quadtree_string(tilex, tiley, zoom, location, '\0', "0123");
return g_strdup_printf(_curr_repo->url, location);
}
-
+#ifdef MAP_DOWNLOAD_WMD
case REPOTYPE_WMS:
return map_convert_wms_to_wms(tilex, tiley, zoom, _curr_repo->url);
-
+#endif
default:
return NULL;
}
gboolean
map_download_idle_refresh(ProgressUpdateInfo * pui)
{
+guint tmp=0;
/* Test if download succeeded (only if retries != 0). */
if (!pui->retries || g_file_test(pui->dest_str, G_FILE_TEST_EXISTS)) {
- gint zoom_diff = pui->zoom - _zoom;
+ gint zoom_diff = pui->zoom - gtk_map_get_zoom(_map);
+
+#if 0
/* Only refresh at same or "lower" (more detailed) zoom level. */
if (zoom_diff >= 0) {
+ guint tilex, tiley, tilex_end, tiley_end;
+
/* If zoom has changed since we first put in the request for
* this tile, then we may have to update more than one tile. */
- guint tilex, tiley, tilex_end, tiley_end;
for (tilex = pui->tilex << zoom_diff, tilex_end = tilex + (1 << zoom_diff); tilex < tilex_end; tilex++) {
for (tiley = pui->tiley << zoom_diff, tiley_end = tiley + (1 << zoom_diff); tiley < tiley_end; tiley++) {
- if ((tilex - _base_tilex) < BUF_WIDTH_TILES && (tiley - _base_tiley) < BUF_HEIGHT_TILES) {
- map_render_tile(tilex, tiley, ((tilex - _base_tilex) << TILE_SIZE_P2), ((tiley - _base_tiley) << TILE_SIZE_P2), TRUE);
+ tmp++;
+ if (map_render_tile(tilex, tiley, ((tilex - _base_tilex) << TILE_SIZE_P2), ((tiley - _base_tiley) << TILE_SIZE_P2), TRUE)==TRUE) {
map_render_data();
- gtk_widget_queue_draw_area
- (_map_widget,
+ gtk_widget_queue_draw_area(_map_widget,
((tilex - _base_tilex) << TILE_SIZE_P2) - _offsetx,
((tiley - _base_tiley) << TILE_SIZE_P2) - _offsety,
TILE_SIZE_PIXELS, TILE_SIZE_PIXELS);
}
}
}
+ g_debug("*** MDIR LOOP: %u", tmp);
}
+#else
+ g_debug("XXX: Add cb or signal or something to inform map widget about fresh tile");
+#endif
}
/* Else the download failed. Update retries and maybe try again. */
else {
pui->tilex = tilex;
pui->tiley = tiley;
pui->zoom = zoom;
-pui->priority = (abs((gint) tilex - unit2tile(_center.unitx)) + abs((gint) tiley - unit2tile(_center.unity)));
+pui->priority = 1;
if (!retries)
pui->priority = -pui->priority; /* "Negative" makes them lowest pri. */
pui->retries = retries;
pui_tree = g_tree_new_full((GCompareDataFunc)download_comparefunc, NULL, (GDestroyNotify) progress_update_info_free, NULL);
downloading_tree = g_tree_new_full((GCompareDataFunc)download_comparefunc, NULL, (GDestroyNotify) progress_update_info_free, NULL);
pui_by_easy = g_hash_table_new(g_direct_hash, g_direct_equal);
+_curl_multi = curl_multi_init();
+/* curl_multi_setopt(_curl_multi, CURLMOPT_PIPELINING, 1); */
}
gboolean
ProgressUpdateInfo *pui = g_hash_table_lookup(pui_by_easy, msg->easy_handle);
g_queue_push_head(curl_easy_queue, msg->easy_handle);
g_hash_table_remove(pui_by_easy, msg->easy_handle);
- fclose(pui->file);
+ if (pui->file)
+ fclose(pui->file);
curl_multi_remove_handle(_curl_multi, msg->easy_handle);
}
}
g_debug("Stopping downloads");
while ((curr = g_queue_pop_tail(curl_easy_queue)))
curl_easy_cleanup(curr);
- curl_multi_cleanup(_curl_multi);
- _curl_multi = NULL;
return TRUE;
}
g_debug("No downloads to stop");
g_hash_table_destroy(pui_by_easy);
if (curl_easy_queue)
g_queue_free(curl_easy_queue);
+ curl_multi_cleanup(_curl_multi);
+ _curl_multi = NULL;
}
if (_curl_sid) {