mirror of
https://github.com/0015/map_tiles.git
synced 2026-01-17 09:06:59 +01:00
Update example code
This commit is contained in:
26
.gitignore
vendored
Normal file
26
.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# macOS
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Build artifacts
|
||||
build/
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Editor files
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# Python
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
.Python
|
||||
*.egg-info/
|
||||
dist/
|
||||
10
README.md
10
README.md
@@ -2,6 +2,16 @@
|
||||
|
||||
A comprehensive map tiles component for ESP-IDF projects using LVGL 9.x. This component provides functionality to load and display map tiles with GPS coordinate conversion, designed for embedded applications requiring offline map display capabilities.
|
||||
|
||||
## Recent Updates
|
||||
|
||||
**v1.3.0 (December 20, 2025)**
|
||||
- **Fixed critical marker positioning bugs in example code:**
|
||||
- Bug Fix #1: Corrected `map_display_add_marker()` to calculate position from actual GPS coordinates instead of using stored offset
|
||||
- Bug Fix #2: Added scroll position compensation for scrollable map containers
|
||||
- Markers now appear at correct GPS locations regardless of map center position, zoom level, or scroll position
|
||||
- Enhanced debug logging with detailed marker calculation information
|
||||
- Added bounds checking for marker positions with warnings
|
||||
|
||||
## Features
|
||||
|
||||
- **LVGL 9.x Compatible**: Fully compatible with LVGL 9.x image handling
|
||||
|
||||
@@ -197,9 +197,40 @@ void map_display_add_marker(double lat, double lon)
|
||||
return;
|
||||
}
|
||||
|
||||
// Get marker offset within the current tile grid
|
||||
int offset_x, offset_y;
|
||||
map_tiles_get_marker_offset(map_handle, &offset_x, &offset_y);
|
||||
// Convert GPS to tile coordinates
|
||||
double tile_x, tile_y;
|
||||
map_tiles_gps_to_tile_xy(map_handle, lat, lon, &tile_x, &tile_y);
|
||||
|
||||
// Get current grid position (top-left tile)
|
||||
int base_tile_x, base_tile_y;
|
||||
map_tiles_get_position(map_handle, &base_tile_x, &base_tile_y);
|
||||
|
||||
// Calculate absolute pixel position of marker
|
||||
int abs_px = (int)(tile_x * MAP_TILES_TILE_SIZE);
|
||||
int abs_py = (int)(tile_y * MAP_TILES_TILE_SIZE);
|
||||
|
||||
// Calculate top-left pixel position of current tile grid
|
||||
int top_left_px_x = base_tile_x * MAP_TILES_TILE_SIZE;
|
||||
int top_left_px_y = base_tile_y * MAP_TILES_TILE_SIZE;
|
||||
|
||||
// Get scroll position if map is scrollable
|
||||
lv_coord_t scroll_x = lv_obj_get_scroll_x(map_container);
|
||||
lv_coord_t scroll_y = lv_obj_get_scroll_y(map_container);
|
||||
|
||||
// Calculate marker position relative to current view
|
||||
int marker_x = abs_px - top_left_px_x - scroll_x - 5; // -5 to center the 10px marker
|
||||
int marker_y = abs_py - top_left_px_y - scroll_y - 5;
|
||||
|
||||
ESP_LOGI(TAG, "Marker calculation: tile_xy=(%.3f,%.3f) base=(%d,%d) abs_px=(%d,%d) scroll=(%d,%d) pixel=(%d,%d)",
|
||||
tile_x, tile_y, base_tile_x, base_tile_y, abs_px, abs_py, scroll_x, scroll_y, marker_x, marker_y);
|
||||
|
||||
// Check if marker is within visible bounds
|
||||
int container_width = grid_cols * MAP_TILES_TILE_SIZE;
|
||||
int container_height = grid_rows * MAP_TILES_TILE_SIZE;
|
||||
if (marker_x < -10 || marker_x > container_width || marker_y < -10 || marker_y > container_height) {
|
||||
ESP_LOGW(TAG, "Marker at (%d, %d) is outside visible bounds (0,0) to (%d,%d)",
|
||||
marker_x, marker_y, container_width, container_height);
|
||||
}
|
||||
|
||||
// Create or update marker object
|
||||
static lv_obj_t* marker = NULL;
|
||||
@@ -212,15 +243,10 @@ void map_display_add_marker(double lat, double lon)
|
||||
lv_obj_set_style_border_color(marker, lv_color_hex(0xFFFFFF), 0);
|
||||
}
|
||||
|
||||
// Position marker based on GPS offset
|
||||
int center_tile_col = grid_cols / 2;
|
||||
int center_tile_row = grid_rows / 2;
|
||||
int marker_x = center_tile_col * MAP_TILES_TILE_SIZE + offset_x - 5;
|
||||
int marker_y = center_tile_row * MAP_TILES_TILE_SIZE + offset_y - 5;
|
||||
|
||||
lv_obj_set_pos(marker, marker_x, marker_y);
|
||||
|
||||
ESP_LOGI(TAG, "GPS marker positioned at (%d, %d)", marker_x, marker_y);
|
||||
ESP_LOGI(TAG, "GPS marker at (%.6f, %.6f) positioned at pixel (%d, %d)",
|
||||
lat, lon, marker_x, marker_y);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace: "0015"
|
||||
name: "map_tiles"
|
||||
version: "1.2.0"
|
||||
version: "1.3.0"
|
||||
maintainers:
|
||||
- Eric Nam <thatprojectstudio@gmail.com>
|
||||
description: "Map tiles component for LVGL 9.x - Load and display map tiles with GPS coordinate conversion"
|
||||
|
||||
Reference in New Issue
Block a user