void roadmap_reminder_add_at_position(RoadMapPosition *position, BOOL isReminder, BOOL default_reminder){ int number; int layers[128]; int layers_count; PluginStreetProperties properties; RoadMapNeighbour neighbours[2]; RoadMapPosition context_save_pos; int context_save_zoom; if (!position) return; roadmap_math_get_context(&context_save_pos, &context_save_zoom); layers_count = roadmap_layer_all_roads(layers, 128); roadmap_math_set_context(position, 20); number = roadmap_street_get_closest(position, 0, layers, layers_count, 1, &neighbours[0], 1); roadmap_math_set_context(&context_save_pos, context_save_zoom); if (number > 0){ roadmap_plugin_get_street_properties (&neighbours[0].line, &properties, 0); reminder_add_dlg(&properties, position, isReminder, default_reminder); } else{ reminder_add_dlg(NULL, position, isReminder,default_reminder); } }
static void track_rec_point (time_t gps_time, const RoadMapGpsPrecision *dilution, const RoadMapGpsPosition* gps_position) { static struct GPSFilter *filter; static time_t last_gps_time; const RoadMapGpsPosition *filtered_gps_point; RoadMapPosition context_save_pos; int context_save_zoom; int res; if (filter == NULL) { filter = editor_track_filter_new (roadmap_math_distance_convert ("1000m", NULL), 600, /* 10 minutes */ 60, /* 1 minute */ roadmap_math_distance_convert ("10m", NULL)); } if (points_count == 0) last_gps_time = 0; roadmap_math_get_context (&context_save_pos, &context_save_zoom); roadmap_math_set_context ((RoadMapPosition *)gps_position, 20); res = editor_track_filter_add (filter, gps_time, dilution, gps_position); if (res == ED_TRACK_END) { /* The current point is too far from the previous point, or * the time from the previous point is too long. * This is probably a new GPS track. */ track_end (); goto restore; } if (last_gps_time && (last_gps_time + GPS_TIME_GAP < gps_time)) { track_end (); } last_gps_time = gps_time; while ((filtered_gps_point = editor_track_filter_get (filter)) != NULL) { TrackLastPosition = *filtered_gps_point; add_point (&TrackLastPosition, gps_time); } restore: roadmap_math_set_context (&context_save_pos, context_save_zoom); }
static void track_rec_locate(time_t gps_time, const RoadMapGpsPrecision *dilution, const RoadMapGpsPosition* gps_position) { const RoadMapGpsPosition *filtered_gps_point; RoadMapPosition context_save_pos; int context_save_zoom; int point_id; int res; LastGpsUpdate = gps_time; track_filter_init (); roadmap_math_get_context (&context_save_pos, &context_save_zoom); roadmap_math_set_context ((RoadMapPosition *)gps_position, 20); editor_track_util_set_focus ((RoadMapPosition *)gps_position); res = editor_track_filter_add (TrackFilter, gps_time, dilution, gps_position); if (res == ED_TRACK_END) { /* The current point is too far from the previous point, or * the time from the previous point is too long. * This is probably a new GPS track. */ editor_track_end (); } if (!EditorAllowNewRoads) editor_track_set_fuzzy (); while ((filtered_gps_point = editor_track_filter_get (TrackFilter)) != NULL) { TrackLastPosition = *filtered_gps_point; point_id = editor_track_add_point(&TrackLastPosition, gps_time); roadmap_fuzzy_set_cycle_params (40, 150); track_rec_locate_point (point_id, 0); } if (!EditorAllowNewRoads) roadmap_fuzzy_reset_cycle (); editor_track_util_release_focus (); roadmap_math_set_context (&context_save_pos, context_save_zoom); }
/** * 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; }
//checks whether an alert is within range static int is_alert_in_range(const RoadMapGpsPosition *gps_position, const PluginLine *line){ int i; int j; unsigned int speed; int distance; // will hold the distance of the alert RoadMapPosition gps_pos; int square; int squares[9]; int count_squares; const char * street_name; // the current street name. char current_street_name[512]; RoadMapPosition context_save_pos; int context_save_zoom; int alert_index; // will hold the index in the provider of the alert int priorities [] = {ALERTER_PRIORITY_HIGH,ALERTER_PRIORITY_MEDIUM,ALERTER_PRIORITY_LOW}; int num_priorities = sizeof(priorities)/sizeof(int); int alert_providor_ind; int square_ind; BOOL found_alert = FALSE; gps_pos.latitude = gps_position->latitude; gps_pos.longitude = gps_position->longitude; roadmap_math_get_context(&context_save_pos, &context_save_zoom); roadmap_math_set_context((RoadMapPosition *)&gps_pos, 20); count_squares = roadmap_square_find_neighbours (&gps_pos, 0, squares); // get the street infromation of the current position. get_street_from_line(line->square,line->line_id, &street_name); strncpy_safe (current_street_name, street_name, sizeof (current_street_name)); // go over priorities one by one from highest to lowest. for (j=0; (j< num_priorities); j++){ if ( found_alert ) // Removed from the "for" condition due to some problem in android gcc AGA break; // loop all the providers for an alert for (i = 0 ; ((i < RoadMapAlertProviders.count)&&(!found_alert)); i++){ // if provider doesn't have a high enough priority skip him, we'll get to him later. if(RoadMapAlertProviders.provider[i]->get_priority()!=priorities[j]) continue; /* * If not enough distance has been passed from last check, provider can order to ignore * if alert is active, always perform check, so distance will be updated */ if(!alert_should_be_visible){ if(!(* (RoadMapAlertProviders.provider[i]->distance_check))(gps_pos)) continue; } if ((* (RoadMapAlertProviders.provider[i]->is_square_dependent))()){ /* * This provider has different alerts for each square, so we need to loop over all * these squares and check. (Speed cams in tiles for example, as opposed to RealTimeAlerts). */ for (square = 0; ((square < count_squares)&&(!found_alert)); square++) { roadmap_square_set_current(squares[square]); if(is_alert_in_range_provider(RoadMapAlertProviders.provider[i], gps_position, line, &alert_index,&distance, current_street_name)) { square_ind = square; alert_providor_ind = i; found_alert = TRUE; } } } else { if(is_alert_in_range_provider(RoadMapAlertProviders.provider[i], gps_position, line, &alert_index,&distance,current_street_name)) { square_ind = square; alert_providor_ind = i; found_alert = TRUE; } } } } if(found_alert){ speed = (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_speed))(alert_index); // if driving speed is over the speed limit - it's an ALERT, otherwise it's a WARNING if ((unsigned int)roadmap_math_to_speed_unit(gps_position->speed) < speed) { the_active_alert.alert_type = WARN; the_active_alert.distance_to_alert = distance; the_active_alert.active_alert_id = (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_id))(alert_index); the_active_alert.alert_provider = alert_providor_ind; the_active_alert.square = squares[square_ind]; roadmap_math_set_context(&context_save_pos, context_save_zoom); return TRUE; } else{ the_active_alert.alert_type = ALERT; the_active_alert.distance_to_alert = distance; the_active_alert.active_alert_id = (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_id))(alert_index); the_active_alert.alert_provider = alert_providor_ind; the_active_alert.square = squares[square_ind]; roadmap_math_set_context(&context_save_pos, context_save_zoom); return TRUE; } } roadmap_math_set_context(&context_save_pos, context_save_zoom); return FALSE; }
/** * [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; }