void RealTimeBonus_SegmentChangedCB (PluginLine *current, int direction){ int line_length; RoadMapPosition pos; line_length = roadmap_line_length(current->line_id); if (line_length < 75) return; roadmap_square_set_current(current->square); if (direction == ROUTE_DIRECTION_WITH_LINE){ roadmap_street_extend_line_ends(current, NULL, &pos, FLAG_EXTEND_TO, NULL, NULL); } else{ roadmap_street_extend_line_ends(current, &pos, NULL, FLAG_EXTEND_FROM, NULL, NULL); } if (g_CustomIndex == -1) return; if (gBonusTable.bonus[g_CustomIndex] == NULL) return; printf("CustomBonusCB %s",gBonusTable.bonus[g_CustomIndex]->pIconName); gBonusTable.bonus[g_CustomIndex]->position.latitude = pos.latitude; gBonusTable.bonus[g_CustomIndex]->position.longitude = pos.longitude; //Adding the custom bonus if (roadmap_map_settings_road_goodies()){ static RoadMapSoundList list; if (!list) { list = roadmap_sound_list_create (SOUND_LIST_NO_FREE); roadmap_sound_list_add (list, "ping2"); roadmap_res_get (RES_SOUND, 0, "ping2"); } roadmap_sound_play_list (list); AddBonusToMap(gBonusTable.bonus[g_CustomIndex], TRUE); } g_CustomIndex = -1; roadmap_navigate_unregister_segment_changed(RealTimeBonus_SegmentChangedCB); }
static int find_segment_extension (int square, int seg_line_id, int is_seg_reversed, struct successor *successors) { PluginLine line; int flag = is_seg_reversed ? FLAG_EXTEND_FROM : FLAG_EXTEND_TO; line.square = square; line.line_id = seg_line_id; line.plugin_id = ROADMAP_PLUGIN_ID; return roadmap_street_extend_line_ends (&line, NULL, NULL, flag, extend_segment, successors); }
int editor_line_copy (PluginLine *line, int street) { editor_line_copy_points copy_points; RoadMapPosition from_pos; RoadMapPosition to_pos; int trkseg; int from_point; int to_point; int line_id; int direction; int id_from; int id_to; // collect shape points for trkseg roadmap_plugin_line_from (line, ©_points.last_position); copy_points.first_shape = -1; copy_points.last_shape = -1; // we assume that in case of a line broken because of tiles, // we begin with the original "from" segment handle_segment (line, ©_points, FLAG_EXTEND_TO); roadmap_street_extend_line_ends (line, &from_pos, &to_pos, FLAG_EXTEND_TO, handle_segment, ©_points); if (line->plugin_id == EditorPluginID) { editor_line_get_points (line->line_id, &from_point, &to_point); } else { roadmap_square_set_current (line->square); roadmap_line_point_ids (line->line_id, &id_from, &id_to); from_point = editor_point_add (&from_pos, id_from); to_point = editor_point_add (&to_pos, id_to); } trkseg = editor_trkseg_add (-1, -1, from_point, copy_points.first_shape, copy_points.last_shape, -1, -1, ED_TRKSEG_FAKE); direction = roadmap_plugin_get_direction (line, ROUTE_DIRECTION_ANY); line_id = editor_line_add (from_point, to_point, trkseg, line->cfcc, direction, street, ED_LINE_DIRTY); return line_id; }
int roadmap_plugin_same_db_line (const PluginLine *line1, const PluginLine *line2) { PluginLine temp_line; if (roadmap_plugin_same_line (line1, line2)) return 1; if (line1->plugin_id != ROADMAP_PLUGIN_ID || line1->plugin_id != line2->plugin_id) { return 0; } temp_line = *line2; temp_line.plugin_id = 0; // using this for count roadmap_street_extend_line_ends (line1, NULL, NULL, FLAG_EXTEND_BOTH, check_same_line, &temp_line); return temp_line.plugin_id; }
static void roadmap_address_done (RoadMapGeocode *selected, RoadMapAddressDialog *context, address_info_ptr ai) { PluginStreet street; PluginLine line; RoadMapPosition from; RoadMapPosition to; roadmap_locator_activate (selected->fips); roadmap_log (ROADMAP_DEBUG, "selected address at %d.%06d %c, %d.%06d %c", abs(selected->position.longitude)/1000000, abs(selected->position.longitude)%1000000, selected->position.longitude >= 0 ? 'E' : 'W', abs(selected->position.latitude)/1000000, abs(selected->position.latitude)%1000000, selected->position.latitude >= 0 ? 'N' : 'S'); roadmap_math_adjust_zoom (selected->square); roadmap_plugin_set_line (&line, ROADMAP_PLUGIN_ID, selected->line, -1, selected->square, selected->fips); roadmap_trip_set_point ("Selection", &selected->position); roadmap_trip_set_point ("Address", &selected->position); if (!context->navigate || !RoadMapAddressNavigate) { roadmap_trip_set_focus ("Address"); roadmap_display_activate ("Selected Street", &line, &selected->position, &street); roadmap_street_extend_line_ends (&line, &from, &to, FLAG_EXTEND_BOTH, NULL, NULL); roadmap_display_update_points ("Selected Street", &from, &to); roadmap_screen_refresh (); } else { if ((*RoadMapAddressNavigate) (&selected->position, &line, 0, ai) != -1) { } } }
RoadMapFuzzy roadmap_fuzzy_connected (const RoadMapNeighbour *street, const RoadMapNeighbour *reference, int prev_direction, int direction, RoadMapPosition *connection) { /* The logic for the connection membership function is that * the line is the most connected to itself, is well connected * to lines to which it share a common point and is not well * connected to other lines. * The weight of each state is a matter fine tuning. */ RoadMapPosition line_point[2]; RoadMapPosition reference_point[2]; int allowed; int i, j; if (roadmap_plugin_same_db_line (&street->line, &reference->line)) { *connection = street->from; return (FUZZY_TRUTH_MAX * 4) / 4; } allowed = allowed_turn (reference, prev_direction, street, direction); if (allowed == 1) { //printf("==>found valid turn\n"); if (prev_direction == ROUTE_DIRECTION_AGAINST_LINE) *connection = street->from; else *connection = street->to; return (FUZZY_TRUTH_MAX * 4) / 4; } else if (allowed == -1) { //printf("--> found shared node\n"); if (prev_direction == ROUTE_DIRECTION_AGAINST_LINE) *connection = street->from; else *connection = street->to; return (FUZZY_TRUTH_MAX * 3) / 4; } roadmap_street_extend_line_ends (&street->line,&(line_point[0]), &(line_point[1]), FLAG_EXTEND_BOTH, NULL, NULL); roadmap_street_extend_line_ends (&reference->line,&(reference_point[0]), &(reference_point[1]), FLAG_EXTEND_BOTH, NULL, NULL); if (direction == ROUTE_DIRECTION_AGAINST_LINE) { i = 1; } else { i = 0; } if (prev_direction == ROUTE_DIRECTION_AGAINST_LINE) { j = 0; } else { j = 1; } if ((line_point[i].latitude == reference_point[j].latitude) && (line_point[i].longitude == reference_point[j].longitude)) { *connection = line_point[i]; return (FUZZY_TRUTH_MAX * 4) / 4; } else if ((line_point[!i].latitude == reference_point[j].latitude) && (line_point[!i].longitude == reference_point[j].longitude)) { *connection = line_point[!i]; return FUZZY_TRUTH_MAX / 2; } else { RoadMapPosition pos1; RoadMapPosition pos2; pos1 = line_point[i]; pos2 = reference_point[j]; if (roadmap_math_distance (&pos1, &pos2) < 50) { connection->latitude = 0; connection->longitude = 0; return FUZZY_TRUTH_MAX * 2 / 3; } } connection->latitude = 0; connection->longitude = 0; return FUZZY_TRUTH_MAX / 3; }
int editor_track_known_end_segment (PluginLine *previous_line, int last_point_id, PluginLine *line, RoadMapTracking *street, int is_new_track) { //TODO: add stuff //Notice that previous_line may not be valid (only at first) // //check for low confidence & in static update, do not use a trkseg with low confidence! RoadMapPosition from; RoadMapPosition to; RoadMapPosition *current; int trkseg; int trkseg_line_id; int trkseg_plugin_id; int trkseg_square; int line_length; int segment_length; int percentage; int flags = 0; editor_log_push ("editor_track_end_known_segment"); assert (last_point_id != 0); if (!last_point_id) return 0; if (editor_db_activate (line->fips) == -1) { editor_db_create (line->fips); if (editor_db_activate (line->fips) == -1) { editor_log_pop (); return 0; } } roadmap_street_extend_line_ends (line, &from, &to, FLAG_EXTEND_BOTH, NULL, NULL); trkseg_plugin_id = roadmap_plugin_get_id (line); trkseg_line_id = roadmap_plugin_get_line_id (line); trkseg_square = roadmap_plugin_get_square (line); line_length = editor_track_util_get_line_length (line); segment_length = editor_track_util_length (0, last_point_id); editor_log (ROADMAP_INFO, "Ending line %d (plugin_id:%d). Line length:%d, Segment length:%d", trkseg_line_id, trkseg_plugin_id, line_length, segment_length); /* End current segment if we really passed through it * and not only touched a part of it. */ /*SRUL*: avoid this problem, see above comment assert (line_length > 0); if (line_length == 0) { editor_log (ROADMAP_ERROR, "line %d (plugin_id:%d) has length of zero.", trkseg_line_id, trkseg_plugin_id); editor_log_pop (); return 0; } */ if (line_length <= 0) line_length = 1; current = track_point_pos (last_point_id); if (roadmap_math_distance (current, &to) > roadmap_math_distance (current, &from)) { flags = ED_TRKSEG_OPPOSITE_DIR; #if DEBUG_TRACKS printf ("Closing trkseg from %d.%06d,%d.%06d to %d.%06d,%d.%06d", to.longitude / 1000000, to.longitude % 1000000, to.latitude / 1000000, to.latitude % 1000000, from.longitude / 1000000, from.longitude % 1000000, from.latitude / 1000000, from.latitude % 1000000); } else { printf ("Closing trkseg from %d.%06d,%d.%06d to %d.%06d,%d.%06d", from.longitude / 1000000, from.longitude % 1000000, from.latitude / 1000000, from.latitude % 1000000, to.longitude / 1000000, to.longitude % 1000000, to.latitude / 1000000, to.latitude % 1000000); #endif } #if DEBUG_TRACKS printf (" %d/%d", segment_length, line_length); #endif if (is_new_track) { flags |= ED_TRKSEG_NEW_TRACK; #if DEBUG_TRACKS printf (" NEW"); #endif } if (!editor_ignore_new_roads ()) { flags |= ED_TRKSEG_RECORDING_ON; } percentage = 100 * segment_length / line_length; if (percentage < 70) { editor_log (ROADMAP_INFO, "segment is too small to consider: %d%%", percentage); if (segment_length > (editor_track_point_distance ()*1.5)) { trkseg = editor_track_util_create_trkseg (trkseg_square, trkseg_line_id, trkseg_plugin_id, 0, last_point_id, flags|ED_TRKSEG_LOW_CONFID); editor_track_add_trkseg (line, trkseg, ROUTE_DIRECTION_NONE, ROUTE_CAR_ALLOWED); editor_log_pop (); #if DEBUG_TRACKS printf (" LOW (percentage)\n"); #endif return 1; } else { trkseg = editor_track_util_create_trkseg (trkseg_square, trkseg_line_id, trkseg_plugin_id, 0, last_point_id, flags|ED_TRKSEG_IGNORE); editor_track_add_trkseg (line, trkseg, ROUTE_DIRECTION_NONE, ROUTE_CAR_ALLOWED); editor_log_pop (); #if DEBUG_TRACKS printf (" IGNORE\n"); #endif return 0; } } #if 0 if (!roadmap_fuzzy_is_good (street->entry_fuzzyfied) || !roadmap_fuzzy_is_good (street->cur_fuzzyfied)) { flags |= ED_TRKSEG_LOW_CONFID; #if DEBUG_TRACKS printf (" LOW"); if (!roadmap_fuzzy_is_good (street->entry_fuzzyfied)) printf (" (entry)"); if (!roadmap_fuzzy_is_good (street->cur_fuzzyfied)) printf (" (cur)"); #endif } #endif if (trkseg_plugin_id != ROADMAP_PLUGIN_ID) flags |= ED_TRKSEG_LOW_CONFID; trkseg = editor_track_util_create_trkseg (trkseg_square, trkseg_line_id, trkseg_plugin_id, 0, last_point_id, flags); if (flags & ED_TRKSEG_OPPOSITE_DIR) { editor_log (ROADMAP_INFO, "Updating route direction: to -> from"); editor_track_add_trkseg (line, trkseg, ROUTE_DIRECTION_AGAINST_LINE, ROUTE_CAR_ALLOWED); } else { editor_log (ROADMAP_INFO, "Updating route direction: from -> to"); editor_track_add_trkseg (line, trkseg, ROUTE_DIRECTION_WITH_LINE, ROUTE_CAR_ALLOWED); } editor_log_pop (); #if DEBUG_TRACKS printf ("\n"); #endif return 1; }
/** * Finds a line ID given 2 GPS points * @param pTrafficInfo - pointer to traffic info * @param start - first node point * @param end - second node point * @param Line - point to line to return the found line * @param allowedDeviation - allowed deviation when searching the nodes * @return TRUE - If a line is found */ static BOOL RTTrafficInfo_Get_LineId(RTTrafficInfo *pTrafficInfo, RoadMapPosition *start, RoadMapPosition *end, char *name, PluginLine *Line, int allowedDeviation){ RoadMapNeighbour neighbours_start[6], neighbours_end[6]; int count_start, count_end = 0; int layers[128]; int layers_count; RoadMapPosition context_save_pos; int context_save_zoom; RoadMapPosition from; RoadMapPosition to; int i; roadmap_math_get_context(&context_save_pos, &context_save_zoom); layers_count = roadmap_layer_all_roads(layers, 128); roadmap_math_set_context(start, 20); count_start = roadmap_street_get_closest(start, 0, layers, layers_count, 1, &neighbours_start[0], 5); // first try to find it in the same segment for (i=0; i<count_start; i++){ RoadMapStreetProperties properties; const char *street_name; roadmap_square_set_current(neighbours_start[i].line.square); roadmap_street_get_properties(neighbours_start[i].line.line_id, &properties); street_name = roadmap_street_get_street_fename(&properties); if (strcmp(street_name, pTrafficInfo->sStreet)) continue; roadmap_plugin_line_from (&neighbours_start[i].line, &from); roadmap_plugin_line_to (&neighbours_start[i].line, &to); if ( ( samePosition(&from, start,allowedDeviation) && samePosition(&to, end,allowedDeviation)) || (samePosition(&from, end,allowedDeviation) && samePosition(&to, start,allowedDeviation)) ){ if (samePosition(&from, start,allowedDeviation)) pTrafficInfo->iDirection = ROUTE_DIRECTION_WITH_LINE; else pTrafficInfo->iDirection = ROUTE_DIRECTION_AGAINST_LINE; roadmap_math_set_context(&context_save_pos, context_save_zoom); *Line = neighbours_start[i].line; return TRUE; } } //if not try to extend the line on the starting point for (i=0; i<count_start; i++){ RoadMapStreetProperties properties; const char *street_name; roadmap_square_set_current(neighbours_start[i].line.square); roadmap_street_get_properties(neighbours_start[i].line.line_id, &properties); street_name = roadmap_street_get_street_fename(&properties); if (strcmp(street_name, pTrafficInfo->sStreet)){ continue; } roadmap_street_extend_line_ends (&neighbours_start[i].line, &from, &to, FLAG_EXTEND_BOTH, NULL, NULL); if ( ( samePosition(&from, start,allowedDeviation) && samePosition(&to, end,allowedDeviation)) || (samePosition(&from, end,allowedDeviation) && samePosition(&to, start,allowedDeviation)) ){ if (samePosition(&from, start,allowedDeviation)) pTrafficInfo->iDirection = ROUTE_DIRECTION_WITH_LINE; else pTrafficInfo->iDirection = ROUTE_DIRECTION_AGAINST_LINE; roadmap_street_extend_line_ends (&neighbours_start[i].line, &from, &to, FLAG_EXTEND_BOTH, extendCallBack, (void *)pTrafficInfo); roadmap_math_set_context(&context_save_pos, context_save_zoom); *Line = neighbours_start[i].line; return TRUE; } } roadmap_math_set_context(end, 20); count_end = roadmap_street_get_closest(end, 0, layers, layers_count, 1, &neighbours_end[0], 4); for (i=0; i<count_end; i++){ RoadMapStreetProperties properties; const char *street_name; roadmap_square_set_current(neighbours_end[i].line.square); roadmap_street_get_properties(neighbours_end[i].line.line_id, &properties); street_name = roadmap_street_get_street_fename(&properties); if (strcmp(street_name, pTrafficInfo->sStreet)){ continue; } roadmap_street_extend_line_ends (&neighbours_end[i].line, &from, &to, FLAG_EXTEND_BOTH, NULL, NULL); if ( ( samePosition(&from, start,allowedDeviation) && samePosition(&to, end,allowedDeviation)) || (samePosition(&from, end,allowedDeviation) && samePosition(&to, start,allowedDeviation)) ){ if (samePosition(&to, end,allowedDeviation)) pTrafficInfo->iDirection = ROUTE_DIRECTION_WITH_LINE; else pTrafficInfo->iDirection = ROUTE_DIRECTION_AGAINST_LINE; roadmap_street_extend_line_ends (&neighbours_end[i].line, &from, &to, FLAG_EXTEND_BOTH, extendCallBack, (void *)pTrafficInfo); roadmap_math_set_context(&context_save_pos, context_save_zoom); *Line = neighbours_end[i].line; return TRUE; } } roadmap_math_set_context(&context_save_pos, context_save_zoom); return FALSE; }
static void track_rec_locate_point(int point_id, int point_type) { int i; int count; TrackNewSegment new_segments[10]; assert (!(point_type & POINT_UNKNOWN) || cur_active_line); //track_verify_square (point_id); if (!cur_active_line) { RoadMapTracking new_street; RoadMapNeighbour new_line; do { int prev_square = -1; int prev_line = -1; if (TrackConfirmedStreet.valid) { prev_square = TrackConfirmedLine.line.square; prev_line = TrackConfirmedLine.line.line_id; } count = editor_track_known_locate_point (point_id, &TrackLastPosition, &TrackConfirmedStreet, &TrackConfirmedLine, &new_street, &new_line); if (count) { if (count == -1) { /* Error, graceful end track */ TrackConfirmedLine = new_line; TrackConfirmedStreet = new_street; cur_node.id = -1; is_new_track = 1; } else { int consumed = end_known_segment (count, &new_street, &new_line); if (new_street.valid && (new_line.line.plugin_id == ROADMAP_PLUGIN_ID) && editor_screen_gray_scale()){ int points; roadmap_square_set_current (TrackConfirmedLine.line.square); points = roadmap_line_length (TrackConfirmedLine.line.line_id); if ((!roadmap_line_route_is_low_weight (TrackConfirmedLine.line.line_id)) || editor_override_exists(TrackConfirmedLine.line.line_id, TrackConfirmedLine.line.square )){ editor_points_hide(); } } else{ editor_points_hide(); } if (!new_street.valid) { /* the current point does not belong to a known street */ assert(!editor_track_known_num_candidates()); editor_track_known_reset_resolve(); cur_active_line = 1; for (i=0; i<points_count; i++) { track_rec_locate_point (i, POINT_UNKNOWN|point_type); } break; } if (count > consumed) { /* In case of a resolver, the resolver already assumes * about the number of points which match each segment. * So here we make it be. */ track_reset_points(count - consumed); } else if (consumed > count) { assert(!editor_track_known_num_candidates()); count = consumed; } point_id -= count; } } else if ((prev_square != -1) && (prev_square != TrackConfirmedLine.line.square)) { /*printf ("crossed from tile %d line %d to tile %d line %d\n", prev_square, prev_line, TrackConfirmedLine.line.square, TrackConfirmedLine.line.line_id); */ if (TrackConfirmedStreet.valid && (TrackConfirmedLine.line.plugin_id == ROADMAP_PLUGIN_ID) && editor_screen_gray_scale()){ int low_weight; roadmap_square_set_current(prev_square); low_weight = roadmap_line_route_is_low_weight (prev_line); if (low_weight){ int length; RoadMapPosition line_from; RoadMapPosition line_to; int flags; if (editor_override_line_get_flags(prev_line, prev_square, &flags) == -1){ length = roadmap_line_length (prev_line); if (length > 0){ editor_points_add(length); roadmap_line_from (prev_line, &line_from); roadmap_line_to (prev_line, &line_to); roadmap_square_set_current (prev_square); editor_override_line_set_flag (prev_line, prev_square, ED_LINE_NEW_DIRECTION); roadmap_street_extend_line_ends (&TrackConfirmedLine.line, &line_from, &line_to, FLAG_EXTEND_BOTH, handle_new_direction, NULL); } } } } } } while (points_count && count && editor_track_known_resolve()); } else { count = editor_track_unknown_locate_point (point_id, &TrackLastPosition, &TrackConfirmedStreet, &TrackConfirmedLine, new_segments, sizeof(new_segments) / sizeof(new_segments[0]), point_type); if (count) { int num_points; if ((point_id == 0) && TrackConfirmedStreet.valid) { cur_active_line = 0; return; } assert (point_id > 0); end_unknown_segments (new_segments, count); if (TrackConfirmedStreet.valid) { /* the current point is a known street */ cur_active_line = 0; } /* After creating a new line, we need to check if the current * point_is still unknown. */ num_points = points_count; for (i=0; i<points_count; i++) { track_rec_locate_point (i, point_type); if (points_count != num_points) { // The inner call has created a new line and further processed // all existing points. break; } } } } }