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); } }
//return the street name given a GPS position static int get_street(const RoadMapPosition *position, const char **street_name, const char **city_name) { int count = 0; int layers[128]; int layers_count; RoadMapNeighbour neighbours; layers_count = roadmap_layer_all_roads (layers, 128); if (layers_count > 0) { count = roadmap_street_get_closest (position, 0, layers, layers_count, &neighbours, 1); if (count > 0) { get_street_from_line (neighbours.line.square, neighbours.line.line_id, street_name, city_name); return 0; } else return -1; } return -1; }
static int alert_is_on_route (const RoadMapPosition *point_position, int steering) { int count = 0; int layers[128]; int layers_count; RoadMapNeighbour neighbours; int rc = 0; int from; int to; RoadMapPosition from_position; RoadMapPosition to_position; int road_azymuth; int delta; int square_current = roadmap_square_active (); layers_count = roadmap_layer_all_roads (layers, 128); if (layers_count > 0) { count = roadmap_street_get_closest (point_position, 0, layers, layers_count, &neighbours, 1); if (count > 0) { roadmap_square_set_current (neighbours.line.square); roadmap_line_points (neighbours.line.line_id, &from, &to); roadmap_point_position (from, &from_position); roadmap_point_position (to, &to_position); road_azymuth = roadmap_math_azymuth (&from_position, &to_position); delta = azymuth_delta (steering, road_azymuth); if (delta >= -90 && delta < 90) rc = navigate_is_line_on_route (neighbours.line.square, neighbours.line.line_id, from, to); else rc = navigate_is_line_on_route (neighbours.line.square, neighbours.line.line_id, to, from); } } roadmap_square_set_current (square_current); return rc; }
/** * 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 const char *editor_segments_find_city (int line, int plugin_id, int square) { int i; int count; int layers_count; int layers[128]; RoadMapPosition point; RoadMapNeighbour neighbours[50]; if (plugin_id == EditorPluginID) { editor_line_get (line, &point, NULL, NULL, NULL, NULL); } else { roadmap_square_set_current (square); roadmap_line_from (line, &point); } layers_count = roadmap_layer_all_roads (layers, 128); count = roadmap_street_get_closest (&point, 0, layers, layers_count, 1, neighbours, sizeof(neighbours) / sizeof(RoadMapNeighbour)); count = roadmap_plugin_get_closest (&point, layers, layers_count, 1, neighbours, count, sizeof(neighbours) / sizeof(RoadMapNeighbour)); for (i = 0; i < count; ++i) { const char *city; if (roadmap_plugin_get_id (&neighbours[i].line) == EditorPluginID) { int street_id = -1; editor_line_get_street (roadmap_plugin_get_line_id (&neighbours[i].line), &street_id); city = editor_street_get_street_city (street_id); } else if (roadmap_plugin_get_id (&neighbours[i].line) == ROADMAP_PLUGIN_ID) { RoadMapStreetProperties properties; roadmap_square_set_current (roadmap_plugin_get_square (&neighbours[i].line)); roadmap_street_get_properties (roadmap_plugin_get_line_id (&neighbours[i].line), &properties); city = roadmap_street_get_street_city (&properties, ROADMAP_STREET_LEFT_SIDE); } else { city = ""; } if (strlen(city)) { return city; } } return ""; }
/** * [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; }