Ejemplo n.º 1
0
/**
 * [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;
}
Ejemplo n.º 2
0
/**
 * [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;
}