Beispiel #1
0
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);
   		}
   	}
   }
}
Beispiel #2
0
void	roadmap_tile_get_origin (int scale, const RoadMapPosition *position, RoadMapPosition *origin) {

	int tile_size = roadmap_tile_get_size (scale);
	
	origin->longitude = (position->longitude + 180000000) / tile_size * tile_size - 180000000;
	origin->latitude = (position->latitude + 90000000) / tile_size * tile_size - 90000000;
}
Beispiel #3
0
void roadmap_square_request_location (const RoadMapPosition *position) {

	static int last_requested[5] = {-1, -1, -1, -1, -1};
	int tile_size;
	int square;
	RoadMapPosition neighbour;

	if (RoadMapSquareActive == NULL) return;
	square = roadmap_square_location (position, 0);

	tile_size = roadmap_tile_get_size (0);
	if (square != last_requested[0]) {
		roadmap_square_request (square, ROADMAP_TILE_STATUS_PRIORITY_GPS, 0); // original position
		last_requested[0] = square;
	}

	neighbour = *position;

	neighbour.longitude += tile_size / 4;
	neighbour.latitude += tile_size / 4;
	square = roadmap_square_location (&neighbour, 0);
	if (square != last_requested[1]) {
		roadmap_square_request (square, ROADMAP_TILE_STATUS_PRIORITY_NEIGHBOURS, 0); // north-east
		last_requested[1] = square;
	}

	neighbour.longitude -= tile_size / 2;
	square = roadmap_square_location (&neighbour, 0);
	if (square != last_requested[2]) {
		roadmap_square_request (square, ROADMAP_TILE_STATUS_PRIORITY_NEIGHBOURS, 0); // north-west
		last_requested[2] = square;
	}

	neighbour.latitude -= tile_size / 2;
	square = roadmap_square_location (&neighbour, 0);
	if (square != last_requested[3]) {
		roadmap_square_request (square, ROADMAP_TILE_STATUS_PRIORITY_NEIGHBOURS, 0); // south-west
		last_requested[3] = square;
	}

	neighbour.longitude += tile_size / 2;
	square = roadmap_square_location (&neighbour, 0);
	if (square != last_requested[4]) {
		roadmap_square_request (square, ROADMAP_TILE_STATUS_PRIORITY_NEIGHBOURS, 0); // south-east
		last_requested[4] = square;
	}
}
Beispiel #4
0
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;
}
Beispiel #5
0
int roadmap_square_find_neighbours (const RoadMapPosition *position, int scale_index, int squares[9]) {

	int					count = 0;
	RoadMapPosition	cross;
	int					square;
	int					step;
	RoadMapPosition	origin;

	if (scale_index < 0) {
		scale_index = RoadMapScaleCurrent;
	}

	step = roadmap_tile_get_size (scale_index);
	roadmap_tile_get_origin (RoadMapScaleCurrent, position, &origin);

	// check same square
	square = roadmap_square_search (&origin, scale_index);
	if (square != 	ROADMAP_SQUARE_GLOBAL) squares[count++] = square;

	// check square to the south
	cross.longitude = position->longitude;
	cross.latitude = origin.latitude;
	if (roadmap_math_point_is_visible (&cross)) {
		cross.longitude = origin.longitude;
		cross.latitude = origin.latitude - step;
		square = roadmap_square_search (&cross, scale_index);
		if (square != 	ROADMAP_SQUARE_GLOBAL) squares[count++] = square;
	}

	// check square to the north
	cross.longitude = position->longitude;
	cross.latitude = origin.latitude + step;
	if (roadmap_math_point_is_visible (&cross)) {
		cross.longitude = origin.longitude;
		square = roadmap_square_search (&cross, scale_index);
		if (square != 	ROADMAP_SQUARE_GLOBAL) squares[count++] = square;
	}

	// check square to the east
	cross.longitude = origin.longitude;
	cross.latitude = position->latitude;
	if (roadmap_math_point_is_visible (&cross)) {
		cross.longitude = origin.longitude - step;
		cross.latitude = origin.latitude;
		square = roadmap_square_search (&cross, scale_index);
		if (square != 	ROADMAP_SQUARE_GLOBAL) squares[count++] = square;
	}

	// check square to the west
	cross.longitude = origin.longitude + step;
	cross.latitude = position->latitude;
	if (roadmap_math_point_is_visible (&cross)) {
		cross.latitude = origin.latitude;
		square = roadmap_square_search (&cross, scale_index);
		if (square != 	ROADMAP_SQUARE_GLOBAL) squares[count++] = square;
	}

	// check square to the south-east
	cross.longitude = origin.longitude;
	cross.latitude = origin.latitude;
	if (roadmap_math_point_is_visible (&cross)) {
		cross.longitude = origin.longitude - step;
		cross.latitude = origin.latitude - step;
		square = roadmap_square_search (&cross, scale_index);
		if (square != 	ROADMAP_SQUARE_GLOBAL) squares[count++] = square;
	}

	// check square to the south-west
	cross.longitude = origin.longitude + step;
	cross.latitude = origin.latitude;
	if (roadmap_math_point_is_visible (&cross)) {
		cross.latitude = origin.latitude - step;
		square = roadmap_square_search (&cross, scale_index);
		if (square != 	ROADMAP_SQUARE_GLOBAL) squares[count++] = square;
	}

	// check square to the north-east
	cross.longitude = origin.longitude;
	cross.latitude = origin.latitude + step;
	if (roadmap_math_point_is_visible (&cross)) {
		cross.longitude = origin.longitude - step;
		square = roadmap_square_search (&cross, scale_index);
		if (square != 	ROADMAP_SQUARE_GLOBAL) squares[count++] = square;
	}

	// check square to the north-west
	cross.longitude = origin.longitude + step;
	cross.latitude = origin.latitude + step;
	if (roadmap_math_point_is_visible (&cross)) {
		square = roadmap_square_search (&cross, scale_index);
		if (square != 	ROADMAP_SQUARE_GLOBAL) squares[count++] = square;
	}

	return count;
}