Closed zhjygit closed 1 month ago
Hi, Actually only one position is displayed on TFT, current position of the GPS.
Remember, this project can't include external info (GPS, etc etc) from another devices , and this feature isn't planned to do in future.
if i have two gps data, one is local gps, like 110.2800, 25.2300;another is outside data from another gps device,like 110.1000, 25.0000. i want to show these two location on the tft display. Here is my try on the map.h file: /**
/**
*/ MapTile CurrentMapTile;//假设为本地设备 MapTile RoundMapTile; //MapTile CurrentMapTileB;//假设为外面设备 //MapTile RoundMapTileB;
/**
*/ ScreenCoord NavArrow_position; ScreenCoord NavArrow_positionA;
static const char *map_scale[] = {"5000 Km","2500 Km","1500 Km","700 Km","350 Km", "150 Km","100 Km","40 Km","20 Km","10 Km","5 Km", "2,5 Km","1,5 Km","700 m","350 m","150 m","80 m", "40 m","20 m","10 m"};
/**
define DEFAULT_LON 110.2800
define DEFAULT_LAT 25.2300
static double getLat() { if (GPS.location.isValid()) return GPS.location.lat(); else {
ifdef DEFAULT_LAT
else
endif
} }
/**
ifdef DEFAULT_LON
return DEFAULT_LON;
else
return 0.0;
endif
} }
double gpsA[2];//定义外部设备A,存放经度和纬度 //gpsA[0]=getLon();//使用和本地设备同样的经度; //gpsA[1]=getLat();
/**
/**
*/ static void delete_map_scr_sprites() { sprArrow.deleteSprite(); map_rot.deleteSprite(); zoom_spr.deleteSprite(); }
/**
/ static void create_map_scr_sprites() { // Map Sprite map_rot.createSprite(320, 374); map_rot.pushSprite(0, 27); // Arrow Sprite sprArrow.createSprite(16, 16); sprArrow.setColorDepth(16); sprArrow.pushImage(0, 0, 16, 16, (uint16_t )navigation);
sprArrowA.createSprite(16, 16); sprArrowA.setColorDepth(16); sprArrowA.pushImage(0, 0, 16, 16, (uint16_t )nav_1); // Zoom Sprite zoom_spr.createSprite(48, 28); zoom_spr.setColorDepth(16); zoom_spr.pushImage(0, 0, 24, 24, (uint16_t )zoom_ico); }
/**
@param event / static void update_map(lv_event_t event) { //CurrentMapTile = get_map_tile(getLon(), getLat(), zoom, 0, 0); CurrentMapTile = get_map_tile(110.2800, 25.2300, zoom, 0, 0); if (strcmp(CurrentMapTile.file, OldMapTile.file) != 0 || CurrentMapTile.zoom != OldMapTile.zoom || CurrentMapTile.tilex != OldMapTile.tilex || CurrentMapTile.tiley != OldMapTile.tiley) {//这个判断的意思是,当前瓦片和上一个瓦片不同 is_map_draw = false; map_found = false; // map_spr.deleteSprite(); // map_spr.createSprite(768, 768); }
if (!is_map_draw) {//如果瓦片不同,则更新瓦片,将新瓦片赋值给老瓦片保存起来即可; OldMapTile.zoom = CurrentMapTile.zoom; OldMapTile.tilex = CurrentMapTile.tilex; OldMapTile.tiley = CurrentMapTile.tiley; OldMapTile.file = CurrentMapTile.file;
log_v("TILE: %s", CurrentMapTile.file); log_v("ZOOM: %d", zoom);
// Center Tile map_found = map_spr.drawPngFile(SD, CurrentMapTile.file, 256, 256);
uint8_t centerX = 0; uint8_t centerY = 0; int8_t startX = centerX - 1; int8_t startY = centerY - 1; bool tileFound = false;
if (map_found) { for (int y = startY; y <= startY + 2; y++) { for (int x = startX; x <= startX + 2; x++) { if (x == centerX && y == centerY) { // Skip Center Tile continue; } //RoundMapTile = get_map_tile(getLon(), getLat(), zoom, x, y); RoundMapTile = get_map_tile(110.2800, 25.2300, zoom, x, y); tileFound = map_spr.drawPngFile(SD, RoundMapTile.file, (x - startX) tileSize, (y - startY) tileSize); if (!tileFound) map_spr.fillRect((x - startX) tileSize, (y - startY) tileSize, tileSize, tileSize, LVGL_BKG); } } }
is_map_draw = true; }
if (map_found) { //NavArrow_position = coord_to_scr_pos(getLon(), getLat(), zoom); NavArrow_position = coord_to_scr_pos(110.2800, 25.2300, zoom); NavArrow_positionA = coord_to_scr_pos(110.1000, 25.0000, zoom); map_spr.setPivot(tileSize + NavArrow_position.posx, tileSize + NavArrow_position.posy);
if (abs(NavArrow_positionA.posx - NavArrow_position.posx) < 16 && abs(NavArrow_positionA.posy - NavArrow_position.posy) < 16) { // 如果重叠,根据需要调整第二个导航图标的位置 NavArrow_positionA.posx += 20; // 假设调整20个像素 NavArrow_positionA.posy += 20; // 假设调整20个像素 }
map_sprA.setPivot(tileSize + NavArrow_positionA.posx, tileSize + NavArrow_positionA.posy); map_rot.pushSprite(0, 27);//用于将地图推送到tft
ifdef ENABLE_COMPASS
else
endif
} }
as above shown, i give the static maps,and these two gps data can be shown on one map tile theoretically。 however, two icons related to two gps location datas are displayed on the same location on the tft finally. how can i change the code to display two gps datas on the same map tile?