//重置瓦片网格 void ResetTilePos() { int mm = 0; row_L = r_L; row_R = r_R; col_T = c_T; col_B = c_B; container.anchoredPosition = Vector2.zero; for (int i = row_L; i <= row_R; i++) { for (int j = col_B; j <= col_T; j++) { container.GetChild(mm).name = i + "_" + j; RectTransform rt = container.GetChild(mm).GetComponent <RectTransform>(); rt.anchoredPosition = new Vector2(i * size, j * size); rt.GetComponent <RawImage>().texture = null; mm++; } } Tile tile = BDMapTool.GetTile(lon, lat, level); centerX = tile.X; centerY = tile.Y; }
void SetTileYPos(int x, int y, int i, MoveState_T state) { int xV = 0; int yV = 0; float hight = 0; int rem = 0; int div = 0; float xPos = 0; float yPos = 0; yV = y + i; if (yV >= levelOffect[level].indexB && yV <= levelOffect[level].indexT) { RawImage img = null; for (int j = row_L; j <= row_R; j++) { xV = x + j; rem = xV % mul; div = Mathf.Abs(xV / mul); if (xV < levelOffect[level].indexL) { if (rem < levelOffect[level].indexL) { xPos = (2 * size - levelOffect[level].widthL - levelOffect[level].widthR) * (div + 1); xV = rem + mul; } else { xPos = (2 * size - levelOffect[level].widthL - levelOffect[level].widthR) * div; xV = rem; } } else if (xV > levelOffect[level].indexR) { if (rem > levelOffect[level].indexR) { xPos = (levelOffect[level].widthL + levelOffect[level].widthR - 2 * size) * (div + 1); xV = rem - mul; } else { xPos = (levelOffect[level].widthL + levelOffect[level].widthR - 2 * size) * div; xV = rem; } } else { xPos = 0; yPos = 0; } hight = size * j; if (state == MoveState_T.buttom) { img = container.Find(j + "_" + col_T).GetComponent <RawImage>(); img.rectTransform.anchoredPosition = new Vector2(hight, -size) + new Vector2(xPos, yPos) + lastVect_B; } else if (state == MoveState_T.top) { img = container.Find(j + "_" + col_B).GetComponent <RawImage>(); img.rectTransform.anchoredPosition = new Vector2(hight, size) + new Vector2(xPos, yPos) + lastVect_T; } img.name = j + "_" + i; img.texture = null; if (!texture_rawDic.ContainsKey(img.transform.GetChild(0).name)) { texture_rawDic.Add(img.transform.GetChild(0).name, j + "_" + i); } else { rawDic.Remove(texture_rawDic[img.transform.GetChild(0).name]); } rawDic.Add(j + "_" + i, new RawImageV(img, "http://online1.map.bdimg.com/onlinelabel/?qt=tile" + $"&x={xV}&y={yV}&z={level}")); } if (state == MoveState_T.buttom) { lastVect_B = new Vector2(0, img.rectTransform.anchoredPosition.y); col_B--; col_T--; lastVect_T = new Vector2(0, container.Find(row_L + "_" + col_T).GetComponent <RectTransform>().anchoredPosition.y); centerY--; } else if (state == MoveState_T.top) { lastVect_T = new Vector2(0, img.rectTransform.anchoredPosition.y); col_T++; col_B++; lastVect_B = new Vector2(0, container.Find(row_L + "_" + col_B).GetComponent <RectTransform>().anchoredPosition.y); centerY++; } } else { Debug.Log("超出矩形限制范围"); } latLngPoint = BDMapTool.Tile2LngLat(centerX, centerY, level); lon = (float)latLngPoint.Lng; lat = (float)latLngPoint.Lat; }
void SetTileXPos(int x, int y, int i, MoveState_L state) { int xV = 0; int yV = 0; int rem = 0; int div = 0; float xPos = 0; float yPos = 0; float hight = 0; xV = x + i; rem = xV % mul; div = xV / mul; float rectX = 0; if (state == MoveState_L.left) { if (xV == levelOffect[level].indexR + mul * div) { xPos = (size / 2 - levelOffect[level].widthL) + (size / 2 - levelOffect[level].widthR) + size; } else if (xV == levelOffect[level].indexL + mul * div - 1) { rectX = size - levelOffect[level].widthR; xPos = (size / 2 - levelOffect[level].widthL) + (size / 2 - levelOffect[level].widthR) + size; } else if (xV == levelOffect[level].indexL + mul * div) { rectX = size - levelOffect[level].widthL; } centerX--; } else if (state == MoveState_L.right) { if (xV == levelOffect[level].indexL + mul * div) { xPos = -((size / 2 - levelOffect[level].widthL) + (size / 2 - levelOffect[level].widthR) + size); } else if (xV == levelOffect[level].indexR + mul * div + 1) { xPos = -((size / 2 - levelOffect[level].widthL) + (size / 2 - levelOffect[level].widthR) + size); rectX = size - levelOffect[level].widthL; } else if (xV == levelOffect[level].indexR + mul * div) { rectX = size - levelOffect[level].widthR; } centerX++; } if (xV < levelOffect[level].indexL) { if (rem < levelOffect[level].indexL) { xV = rem + mul; } else { xV = rem; } } else if (xV > levelOffect[level].indexR) { if (rem > levelOffect[level].indexR) { xV = rem - mul; } else { xV = rem; } } RawImage img = null; for (int j = col_B; j <= col_T; j++) { yV = y + j; hight = size * j; if (state == MoveState_L.left) { img = container.Find(row_R + "_" + j).GetComponent <RawImage>(); img.rectTransform.anchoredPosition = new Vector2(-size, hight) + new Vector2(xPos, yPos) + lastVect_L; } else if (state == MoveState_L.right) { img = container.Find(row_L + "_" + j).GetComponent <RawImage>(); img.rectTransform.anchoredPosition = new Vector2(size, hight) + new Vector2(xPos, yPos) + lastVect_R; } img.name = i + "_" + j; img.texture = null; if (!texture_rawDic.ContainsKey(img.transform.GetChild(0).name)) { texture_rawDic.Add(img.transform.GetChild(0).name, i + "_" + j); } else { rawDic.Remove(texture_rawDic[img.transform.GetChild(0).name]); } rawDic.Add(i + "_" + j, new RawImageV(img, "http://online1.map.bdimg.com/onlinelabel/?qt=tile" + $"&x={xV}&y={yV}&z={level}")); } if (state == MoveState_L.left) { lastVect_L = new Vector2(img.rectTransform.anchoredPosition.x, 0); row_L--; row_R--; lastVect_R = new Vector2(container.Find(row_R + "_" + col_B).GetComponent <RectTransform>().anchoredPosition.x, 0); if (lastVect_L.x + pposX + rectX - size / 2 - rect.x > 0) { SetTileXPos(x, y, row_L - 1, state); } } else if (state == MoveState_L.right) { lastVect_R = new Vector2(img.rectTransform.anchoredPosition.x, 0); row_R++; row_L++; lastVect_L = new Vector2(container.Find(row_L + "_" + col_B).GetComponent <RectTransform>().anchoredPosition.x, 0); if (lastVect_R.x + pposX - rectX + size / 2 < rect.width) { SetTileXPos(x, y, row_R + 1, state); } } latLngPoint = BDMapTool.Tile2LngLat(centerX, centerY, level); lon = (float)latLngPoint.Lng; lat = (float)latLngPoint.Lat; }
void InitMap() { int xV = 0; int yV = 0; int size = 0; mul = levelOffect[level].indexR - levelOffect[level].indexL + 1; int rem = 0; int div = 0; float xPos = 0; float yPos = 0; ResetTilePos(); Tile tile = BDMapTool.GetTile(latLngPoint.Lng, latLngPoint.Lat, level); x = tile.X; y = tile.Y; for (int i = row_L; i <= row_R; i++) { xV = x + i; rem = xV % mul; div = xV / mul; size = 256; if (xV < levelOffect[level].indexL) { if (rem < levelOffect[level].indexL) { xV = rem + mul; if (div == 0) { div = -1; } else if (div < 0) { div = div - 1; } } else { xV = rem; } xPos = -((size / 2 - levelOffect[level].widthL) + (size / 2 - levelOffect[level].widthR) + size) * div; } else if (xV > levelOffect[level].indexR) { if (rem > levelOffect[level].indexR) { xV = rem - mul; if (div == 0) { div = 1; } else if (div > 0) { div = div + 1; } } else { xV = rem; } xPos = -((size / 2 - levelOffect[level].widthL) + (size / 2 - levelOffect[level].widthR) + size) * div; } else { xPos = 0; yPos = 0; } for (int j = col_B; j <= col_T; j++) { yV = y + j; StartCoroutine(GetHttpTexture(container.Find(i + "_" + j).GetComponent <RawImage>(), "http://online1.map.bdimg.com/onlinelabel/?qt=tile" + $"&x={xV}&y={yV}&z={level}")); container.Find(i + "_" + j).GetComponent <RectTransform>().anchoredPosition = container.Find(i + "_" + j).GetComponent <RectTransform>().anchoredPosition + new Vector2(xPos, yPos); } } lastVect_L = new Vector2(container.Find(row_L + "_" + col_T).GetComponent <RectTransform>().anchoredPosition.x, 0); lastVect_R = new Vector2(container.Find(row_R + "_" + col_T).GetComponent <RectTransform>().anchoredPosition.x, 0); lastVect_B = new Vector2(0, container.Find(row_L + "_" + col_B).GetComponent <RectTransform>().anchoredPosition.y); lastVect_T = new Vector2(0, container.Find(row_L + "_" + col_T).GetComponent <RectTransform>().anchoredPosition.y); unit.text = zoomLevel[level]; UpdateTileOffectOfScale(); }