WinForms Maps를 OpenStreetMap 타일에 연결하는 방법
추천0
페이지 정보
작성자 GrapeCity 작성일 2023-07-11 13:57 조회 347회 댓글 0건본문
관련링크
컨트롤이 포함되어 있습니다. 다양한 기본 제공을 포함하여, 사용자 정의 소스로부터 지리적 정보를 표시할 수 있습니다.
기본적으로 C1Map에서는 Microsoft Bing Maps에 액세스하는 항공, 도로 및 하이브리드 뷰 등 세 가지 기본 소스를 제공합니다.
이번 스터디에서는 간단한 두 단계로 OpenStreetMap의 타일 이미지를 사용하여 C1Map을 위한 사용자 정의 타일을 만드는 방법을 설명하고, 오프라인 사용자를 지원하기 위한 오프라인 맵(선택 사항)을 추가합니다.
사용자 정의 타일 소스 만들기
public interface ITileSource { int TileWidth { get; } int TileHeight { get; } void GetTile(int level, int x, int y, out string uri, out object image); }
OpenStreetMap을 온라인 맵 소스로 사용하고 있으므로, 다음 URI를 사용하여 지정된 확대/축소 수준과 x 및 y 위치에 대한 타일을 가져옵니다.
http://tile.openstreetmap.org/{zoom}/{x}/{y}.png
public class OpenStreetTileSource : ITileSource { private const string UrlTemplate = "http://tile.openstreetmap.org/{0}/{1}/{2}.png"; public void GetTile(int zoomLevel, int tilePositionX, int tilePositionY, out string url, out object image) { image = null; url = string.Format(UrlTemplate, zoomLevel, tilePositionX, tilePositionY); } public int TileWidth { get { return 256; } } public int TileHeight { get { return 256; } } }
Map1.TileLayer.TileSource = _customMapSource;
오프라인 맵 지원(선택 사항)
public class OfflineTilesSource : ITileSource { private readonly string tilesLocation; public OfflineTilesSource(string tilesLocation) { if (Directory.Exists(tilesLocation)) { this.tilesLocation = Path.Combine(tilesLocation); } else throw new DirectoryNotFoundException(); } public int TileWidth { get { return 256; } } public int TileHeight { get { return 256; } } public void GetTile(int level, int x, int y, out string uri, out object image) { uri = string.Empty; image = null; var imgPath = Path.Combine(tilesLocation, level.ToString(), x.ToString(), (y.ToString() + ".png")); if (File.Exists(imgPath)) { using (Bitmap bmp = new Bitmap(imgPath)) { image = new Bitmap(bmp); } } } }
타일 이미지 로컬로 저장하는 방법을 사용해야 합니다. 이번 스터디의 샘플 프로젝트에서는 숫자 값으로 레이블이 지정된 폴더에 타일 이미지를 저장했습니다. 폴더는 첫 번째가 확대/축소에 해당하고, 두 번째가 x 위치에 해당하고, 세 번째가 y 위치에 해당하도록 구성됩니다.
y 위치 폴더 내에서 타일 이미지를 찾을 수 있습니다.
이 정렬을 사용하면 GetTile 메서드에서 제공하는 값을 활용하여 필요한 이미지에 쉽게 액세스할 수 있습니다.
지금 바로 ComponentOne을 다운로드하여 직접 테스트해 보세요!
댓글목록
등록된 댓글이 없습니다.