Google Maps API를 사용하여 맞춤지도 유형을 만들었습니다.

맵 틸러를 사용하여 다양한 확대 / 축소 레이어와 0을 만들었습니다. 레이어 (실제로 축소됨)는 256 x 256 타일입니다. 그러나 이미지는 134 x 112 만 포함합니다.

Google지도의 기본 지구 좌표가 아닌 전체지도를 기준으로지도 좌표를 만들 수 있기를 원합니다. 예를 들어, 왼쪽 상단은 (0,0)이고 오른쪽 하단은 (50,50)이어야합니다.

여기에서 Heitor Chang의 도움을 받았습니다. https://stackoverflow.com/questions/11192281/can-i-reset-latlng-coordinates-for-a-custom-map-type

문제는 여기에 있습니다.

dayzProjection.prototype.fromLatLngToPoint = function(latlng) { // pixel size of tile at zoom 0 var max = 134; // define bottom-right corner as (50, 50) var x = max * latlng.lng() / 50; var y = max * latlng.lat() / 50; return new google.maps.Point(x, y); }; dayzProjection.prototype.fromPointToLatLng = function(pixel) { // inverse conversion var lng = pixel.x / max * 50; var lat = pixel.y / max * 50; return new google.maps.LatLng(lat, lng); }; 

누구든지이 좌표를 변환하는 데 도움을 줄 수 있습니까?

이 정보가 도움이 될 수 있습니다. https://developers.google.com/maps/documentation/javascript/maptypes#Projections

답변

실제로 왼쪽 상단 모서리를 0,0에 배치하고 오른쪽 하단을 50,50에 배치 할 수 있습니다. 당신이 이것을 원한다면. 물론 위도는 -90 / + 90, 경도는 -180 / + 180과 같이 한도 내에서 오른쪽 하단 모서리를 10,10 또는 기타 위치에 배치 할 수 있습니다.

비율은 다음과 같아야합니다.

/* ****************************************** Custom Projection - CARTESIAN ****************************************** */ function CartesianProjection() { // map size at zoom 0 is equal to tile size this.tileSize = 256; }; CartesianProjection.prototype.fromLatLngToPoint = function(latLng) { var x = (latLng.lng() / 50) * this.tileSize; var y = (latLng.lat() / 50) * this.tileSize; return new google.maps.Point(x, y); }; CartesianProjection.prototype.fromPointToLatLng = function(point, noWrap) { var lng = (point.x / this.tileSize) * 50; var lat = (point.y / this.tileSize) * 50; return new google.maps.LatLng(lat, lng, noWrap); }; 

그런 다음지도 옵션에서지도의 중심을 LatLng (25,25)에 배치해야합니다.

답글 남기기

이메일 주소를 발행하지 않을 것입니다. 필수 항목은 *(으)로 표시합니다