static void roadmap_square_get_tiles (RoadMapArea *area, int min_scale) { RoadMapPosition position; RoadMapPosition corner; RoadMapPosition origin; int scale; int step; int max_scale = roadmap_tile_get_max_scale (); corner.longitude = area->west; corner.latitude = area->south; if (max_scale > min_scale + 1) { max_scale = min_scale + 1; } for (scale = min_scale; scale <= max_scale; scale++) { roadmap_tile_get_origin (scale, &corner, &origin); step = roadmap_tile_get_size (scale); for (position.longitude = origin.longitude; position.longitude <= area->east; position.longitude += step) { for (position.latitude = origin.latitude; position.latitude <= area->north; position.latitude += step) { roadmap_tile_request (roadmap_tile_get_id_from_position (scale, &position), ROADMAP_TILE_STATUS_PRIORITY_NONE, 0, NULL); } } } }
static int editor_line_interpolate_request_tiles (int from_tile, int to_tile, RoadMapPosition *from_pos, RoadMapPosition *to_pos, int min_update) { int mid_tile; RoadMapPosition mid_pos; int tile_update; if (roadmap_tile_is_adjacent (from_tile, to_tile)) { return min_update; } mid_pos.longitude = (from_pos->longitude + to_pos->longitude) / 2; mid_pos.latitude = (from_pos->latitude + to_pos->latitude) / 2; if ((mid_pos.longitude == from_pos->longitude && mid_pos.latitude == from_pos->latitude) || (mid_pos.longitude == to_pos->longitude && mid_pos.latitude == to_pos->latitude)) { return min_update; } mid_tile = roadmap_tile_get_id_from_position (0, &mid_pos); if (mid_tile != from_tile && mid_tile != to_tile) { roadmap_tile_request (mid_tile, 0, 1, NULL); tile_update = (int)roadmap_square_timestamp (mid_tile); if (tile_update < min_update) { min_update = tile_update; } } if (mid_tile != from_tile) { min_update = editor_line_interpolate_request_tiles (from_tile, mid_tile, from_pos, &mid_pos, min_update); } if (mid_tile != to_tile) { min_update = editor_line_interpolate_request_tiles (mid_tile, to_tile, &mid_pos, to_pos, min_update); } return min_update; }
int editor_line_get_update_time (int line_id) { RoadMapPosition pos; RoadMapPosition last_pos; int shape; int last_tile = -1; int tile; editor_db_line *line_db; int min_update = 0x7fffffff; int tile_update; int first_shape; int last_shape; int from_point; line_db = (editor_db_line *) editor_db_get_item (ActiveLinesDB, line_id, 0, NULL); if (line_db == NULL) return min_update; editor_trkseg_get (line_db->trkseg, &from_point, &first_shape, &last_shape, NULL); if (first_shape == -1) { last_shape = -1; } for (shape = first_shape - 1; shape <= last_shape; shape++) { if (shape == -2) { editor_point_position (line_db->point_from, &pos); } else if (shape < first_shape) { editor_point_position (from_point, &pos); } else if (shape >= 0) { editor_shape_position (shape, &pos); } else { editor_point_position (line_db->point_to, &pos); } tile = roadmap_tile_get_id_from_position (0, &pos); if (tile != last_tile) { roadmap_tile_request (tile, 0, 1, NULL); tile_update = (int)roadmap_square_timestamp (tile); if (tile_update < min_update) { min_update = tile_update; } if (last_tile != -1) { min_update = editor_line_interpolate_request_tiles (last_tile, tile, &last_pos, &pos, min_update); } last_tile = tile; } last_pos = pos; } return min_update; }
int roadmap_square_view (int *square, int size, RoadMapArea *squares_area) { RoadMapPosition origin; RoadMapPosition position; RoadMapArea screen; RoadMapArea peripheral; int count; int index; int step; int slot; int filter_count = 0; if (RoadMapSquareActive == NULL) return 0; roadmap_math_screen_edges (&screen); position.longitude = screen.west; position.latitude = screen.south; roadmap_tile_get_origin (RoadMapScaleCurrent, &position, &origin); if (squares_area) { squares_area->west = origin.longitude; squares_area->south = origin.latitude; } step = roadmap_tile_get_size (RoadMapScaleCurrent); count = 0; peripheral.west = (screen.west * 9 - screen.east) / 8; peripheral.east = (screen.east * 9 - screen.west) / 8; peripheral.south = (screen.south * 9 - screen.north) / 8; peripheral.north = (screen.north * 9 - screen.south) / 8; for (position.longitude = origin.longitude; position.longitude < screen.east; position.longitude += step) { for (position.latitude = origin.latitude; position.latitude <= screen.north; position.latitude += step) { RoadMapArea edges; RoadMapPosition topleft, topright; RoadMapPosition bottomright, bottomleft; RoadMapGuiPoint points[4]; int i, il, ir; index = roadmap_tile_get_id_from_position (RoadMapScaleCurrent, &position); // roadmap_log(ROADMAP_ERROR, "%d %d %d", position.latitude, position.longitude, RoadMapScaleCurrent); slot = roadmap_square_find (index); if (slot >= 0) roadmap_square_edges (index, &edges); else roadmap_tile_edges(index, &edges.west, &edges.east, &edges.south, &edges.north); topleft.longitude = edges.west; topright.longitude = edges.east; topleft.latitude = edges.north; topright.latitude = edges.north; bottomleft.longitude = edges.west; bottomright.longitude = edges.east; bottomleft.latitude = edges.south; bottomright.latitude = edges.south; roadmap_math_coordinate (&topleft, points); roadmap_math_coordinate (&bottomright, points+1); roadmap_math_coordinate (&topright, points+2); roadmap_math_coordinate (&bottomleft, points+3); for (i=0; i< 4; ++i) { roadmap_math_rotate_project_coordinate(points+i); } if ((abs(points[0].x - points[1].x) < 30 && abs(points[0].y - points[1].y) < 30)) { filter_count++; continue; } for (il=0; il< 4; ++il) { if (points[il].x>= 0) break; } if (il==4) { filter_count++; continue; } for (ir=0; ir< 4; ++ir) { if (points[ir].x<= roadmap_canvas_width()) break; } if (ir==4) { filter_count++; continue; } if (slot < 0) { roadmap_tile_request (index, ROADMAP_TILE_STATUS_PRIORITY_ON_SCREEN, 0, NULL); if (roadmap_square_set_current (index)) { slot = roadmap_square_find (index); } } if (slot >= 0) { if (RoadMapSquareForceUpdateMode || ((*roadmap_tile_status_get (index)) & ROADMAP_TILE_STATUS_FLAG_ROUTE)) { // force new version of route tiles when on screen roadmap_tile_request (index, ROADMAP_TILE_STATUS_PRIORITY_ON_SCREEN, 1, NULL); } if (count < size) { square[count] = index; } count += 1; if (size > 0 && count > size) { roadmap_log (ROADMAP_ERROR, "too many square are visible: %d is not enough", size); } } } } if (squares_area) { squares_area->east = position.longitude; squares_area->north = position.latitude; } #ifndef J2ME roadmap_square_get_tiles (&peripheral, RoadMapScaleCurrent); #endif RoadMapSquareForceUpdateMode = 0; //printf("count: %d filter: %d \n", count, filter_count); return count; }
static int roadmap_square_location (const RoadMapPosition *position, int scale_index) { return roadmap_tile_get_id_from_position (scale_index, position); }
/** * [IN] alert_position - the position of the alert * [IN] alert_location_info - The old location_info of the alert. Will be updated if necessary * [OUT] pNew_Info - the location_info of this alert, to be calculated. * returns TRUE iff successful in finding relevant location info for this alert * - D.F. */ BOOL get_alert_location_info(const RoadMapPosition *alert_position,roadmap_alerter_location_info *pNew_Info, roadmap_alerter_location_info *alert_location_info){ int alert_square_time_stamp; int layers_count; int count; int layers[128]; RoadMapNeighbour neighbours; int square; int context_save_zoom; RoadMapPosition context_save_pos; if (alert_location_info){ // check if this alert was tagged as invalid in the past - Could locate a street next to it, eventhough // its tile already exists. if (alert_location_info->square_id == ALERTER_SQUARE_ID_INVALID) return FALSE; // if alert info is already initialized and has an up to date timestamp, use its info. if(alert_location_info->square_id!=ALERTER_SQUARE_ID_UNINITIALIZED){ alert_square_time_stamp = roadmap_square_version(alert_location_info->square_id); if(alert_square_time_stamp==alert_location_info->time_stamp){ pNew_Info->line_id = alert_location_info->line_id; pNew_Info->square_id = alert_location_info->square_id; pNew_Info->time_stamp = alert_location_info->time_stamp; return TRUE; } } } // did not return so far - so no cached valid location info was found, need to cacluate it. layers_count = roadmap_layer_all_roads (layers, 128); if (layers_count > 0) { square = roadmap_tile_get_id_from_position(0,alert_position); if(!roadmap_square_set_current(square)){ return FALSE; // do no have this alert's tile, return FALSE; } roadmap_math_get_context(&context_save_pos, &context_save_zoom); roadmap_math_set_context((RoadMapPosition *)alert_position, 20); count = roadmap_street_get_closest(alert_position, 0, layers, layers_count, 1, &neighbours, 1); roadmap_math_set_context(&context_save_pos, context_save_zoom); if(count>0&&neighbours.distance <= MAX_DISTANCE_FROM_ROAD){ // found valid information pNew_Info->line_id = neighbours.line.line_id; pNew_Info->square_id = neighbours.line.square; pNew_Info->time_stamp = roadmap_square_version(pNew_Info->square_id); }else{ // We have the alert's tile, yet still we could not locate it satisfactorily on // a street. Tag this alert so it will not be checked in the future. if(alert_location_info){ alert_location_info->square_id = ALERTER_SQUARE_ID_INVALID; } return FALSE; } } if(alert_location_info){ // update the information of the alert, for future calls. alert_location_info->line_id = pNew_Info->line_id; alert_location_info->square_id = pNew_Info->square_id; alert_location_info->time_stamp = pNew_Info->time_stamp; } return TRUE; }
/** * [IN] alert_position - the position of the alert * [IN] alert_location_info - The old location_info of the alert. Will be updated if necessary * [OUT] pNew_Info - the location_info of this alert, to be calculated. * returns TRUE iff successful in finding relevant location info for this alert * - D.F. */ BOOL get_alert_location_info(const RoadMapPosition *alert_position, int alert_streering, roadmap_alerter_location_info *pNew_Info, roadmap_alerter_location_info *alert_location_info){ int alert_square_time_stamp; int layers_count; int count; int layers[128]; RoadMapNeighbour neighbours[2]; int square; zoom_t context_save_zoom; RoadMapPosition context_save_pos; if (alert_location_info){ // check if this alert was tagged as invalid in the past - Could locate a street next to it, eventhough // its tile already exists. if (alert_location_info->square_id == ALERTER_SQUARE_ID_INVALID) return FALSE; // if alert info is already initialized and has an up to date timestamp, use its info. if(alert_location_info->square_id!=ALERTER_SQUARE_ID_UNINITIALIZED){ alert_square_time_stamp = roadmap_square_version(alert_location_info->square_id); if(alert_square_time_stamp==alert_location_info->time_stamp){ pNew_Info->line_id = alert_location_info->line_id; pNew_Info->square_id = alert_location_info->square_id; pNew_Info->time_stamp = alert_location_info->time_stamp; return TRUE; } } } // did not return so far - so no cached valid location info was found, need to cacluate it. layers_count = roadmap_layer_all_roads (layers, 128); if (layers_count > 0) { square = roadmap_tile_get_id_from_position(0,alert_position); if(!roadmap_square_set_current(square)){ return FALSE; // do no have this alert's tile, return FALSE; } roadmap_math_get_context(&context_save_pos, &context_save_zoom); roadmap_math_set_context((RoadMapPosition *)alert_position, 2); count = roadmap_street_get_closest(alert_position, 0, layers, layers_count, 1, &neighbours[0], 2); roadmap_math_set_context(&context_save_pos, context_save_zoom); if(count>0&&neighbours[0].distance <= MAX_DISTANCE_FROM_ROAD){ if (count > 1){ int direction; roadmap_square_set_current(neighbours[0].line.line_id); direction = roadmap_line_route_get_direction (neighbours[0].line.line_id, ROUTE_CAR_ALLOWED); if (direction == ROUTE_DIRECTION_WITH_LINE || direction == ROUTE_DIRECTION_AGAINST_LINE){ int line_azymuth; int delta; if (direction == ROUTE_DIRECTION_WITH_LINE) line_azymuth = roadmap_math_azymuth (&neighbours[0].from, &neighbours[0].to); else line_azymuth = roadmap_math_azymuth (&neighbours[0].to, &neighbours[0].from); delta = azymuth_delta(line_azymuth, alert_streering); if (delta > AZYMUTH_DELTA || delta < (0-AZYMUTH_DELTA)) { pNew_Info->line_id = neighbours[1].line.line_id; pNew_Info->square_id = neighbours[1].line.square; pNew_Info->time_stamp = roadmap_square_version(pNew_Info->square_id); } else{ pNew_Info->line_id = neighbours[0].line.line_id; pNew_Info->square_id = neighbours[0].line.square; pNew_Info->time_stamp = roadmap_square_version(pNew_Info->square_id); } } else{ pNew_Info->line_id = neighbours[0].line.line_id; pNew_Info->square_id = neighbours[0].line.square; pNew_Info->time_stamp = roadmap_square_version(pNew_Info->square_id); } } else{ // found valid information pNew_Info->line_id = neighbours[0].line.line_id; pNew_Info->square_id = neighbours[0].line.square; pNew_Info->time_stamp = roadmap_square_version(pNew_Info->square_id); } }else{ // We have the alert's tile, yet still we could not locate it satisfactorily on // a street. Tag this alert so it will not be checked in the future. if(alert_location_info){ alert_location_info->square_id = ALERTER_SQUARE_ID_INVALID; } return FALSE; } } if(alert_location_info){ // update the information of the alert, for future calls. alert_location_info->line_id = pNew_Info->line_id; alert_location_info->square_id = pNew_Info->square_id; alert_location_info->time_stamp = pNew_Info->time_stamp; } return TRUE; }