폴리곤 영역이 전혀 나오지 않아서 문의드립니다

지도 위에 폴리곤 영역이 전혀 나오지 않아서 문의드립니다.

{
“type”: “FeatureCollection”,
“crs”: {
“type”: “name”,
“properties”: {
“name”: “urn:ogc:def:crs:OGC:1.3:CRS84”
}
},
“features”: [
{
“type”: “Feature”,
“properties”: {
“ALIAS”: null,
“REMARK”: “영덕천”,
“NTFDATE”: null,
“COL_ADM_SE”: “41110”,
“SGG_OID”: 2352,
“MNUM”: “64100004111020140266UJB1000006006”,
“EMD_CD”: “41463111”,
“EMD_ENG_NM”: “Yeongdeok-dong”,
“EMD_KOR_NM”: “영덕동”
},
“geometry”: {
“type”: “MultiPolygon”,
“coordinates”: [
[
[
[
37.27940625288863,
127.07048084716529
],
[
37.27931853662404,
127.0704047684397
],
[
37.27924221072307,
127.07026431567617
],
[
37.279187576384714,
127.07016379904354
],
[
37.279087668206664,
127.06998002656664
],
[
37.27885603723954,
127.06978158993067
],

하천.geojson은 카카오맵 좌표로 변환했고,
var areas = [];

function processJSONData() {
$.getJSON(“gpkg/하천.geojson”)
.done(function (geojson) {
var features = geojson.features;
features.forEach(function (feature) {
var properties = feature.properties; // Feature의 properties 가져오기
var geometry = feature.geometry;
var name = properties.EMD_KOR_NM || properties.REMARK || ‘’; // 이름 통일을 위한 프로퍼티 선택

          if (geometry.type === 'MultiPolygon') {
              geometry.coordinates.forEach(function (multiPolygon) {
                  multiPolygon.forEach(function (polygon) {
                      var paths = polygon.map(function (coordinates) {
                          return new kakao.maps.LatLng(coordinates[1], coordinates[0]);
                      });
                      areas.push({ name: name, paths: paths }); // 폴리곤 데이터를 areas 배열에 추가
                  });
              });
          } else if (geometry.type === 'Polygon') {
              var paths = geometry.coordinates.map(function (coordinates) {
                  return coordinates.map(function (coord) {
                      return new kakao.maps.LatLng(coord[1], coord[0]);
                  });
              });
              areas.push({ name: name, paths: paths }); // 폴리곤 데이터를 areas 배열에 추가
          }
      });

      // 폴리곤의 첫 번째 좌표를 가져와 지도의 중심으로 설정
      var firstPolygon = areas[0].paths[0][0];
      map.setCenter(firstPolygon);
      displayAreas(); // 지도에 폴리곤을 추가하는 함수 호출
  })
  .fail(function (jqxhr, textStatus, error) {
      var err = textStatus + ", " + error;
      console.error("Failed to load data: ", err);
  });

}

function displayAreas() {
if (!map) {
console.error(‘지도 객체가 존재하지 않습니다.’);
return;
}

areas.forEach(function (area) {
var polygon = new kakao.maps.Polygon({
paths: area.paths,
strokeWeight: 3,
strokeColor: ‘#39DE2A’,
strokeOpacity: 0.8,
strokeStyle: ‘longdash’,
fillColor: ‘#A2FF99’,
fillOpacity: 0.7
});

  polygon.setMap(map);

  // 폴리곤 이름 표시하기
  var content = area.name;
  var position = area.paths[0][0]; // 첫 번째 폴리곤의 좌표를 기준으로 이름 표시
  var customOverlay = new kakao.maps.CustomOverlay({
      map: map,
      position: position,
      content: content,
      xAnchor: 0.5,
      yAnchor: 0.5,
  });

});
}

var yonginCenter = document.getElementById(‘map-kakao’);
var mapOption = {
center: new kakao.maps.LatLng(37.27940625288863, 127.07048084716529),
level: 8
};

var map = new kakao.maps.Map(yonginCenter, mapOption);
var mapTypeControl = new kakao.maps.MapTypeControl();
map.addControl(mapTypeControl, kakao.maps.ControlPosition.TOPRIGHT);

var zoomControl = new kakao.maps.ZoomControl();
map.addControl(zoomControl, kakao.maps.ControlPosition.RIGHT);

processJSONData();

코드는 이렇게 작성했는데, 오류를 전혀 못잡겠어서요… 어떻게 하면 될지 선생님들 도와주세요ㅠㅠ

안녕하세요~

https://apis.map.kakao.com/web/documentation/#LatLng

위 클래스에 대한 문서를 확인해 보시기 바랍니다.
인자로 받는게 lattitude, longitude 순서입니다.

즉 y, x 순으로 입력을 받기 때문에, 올려주신 데이터에 따르면, 좌표의 정렬순서가
[lattitude, longiture] 순으로 정렬되어 있기에, LatLng 클래스에 0번 1번 순서로 넣어주셔야 합니다. 위도 → 경도 순서

이부분 확인해 보세요.

1개의 좋아요

0 1번으로 바꿨을 경우 이런식으로 나오는데, 이게 맞나요? 1, 0 으로 해야
37.27940625288863, 127.07048084716529 이런식으로 나오더라구요.

LatLng 객체에서 getLat(), getLng()을 했을때 값이 잘 나오면 되십니다.

현재 폴리곤 영역이 나오지 않은 상태일때는

데이터오류 또는 코드레벨에서 오류가 있을 수 있는데,
데이터를 검증하기엔 너무 많은 데이터를 한번에 밀어넣고 계십니다.

최대한 작은 데이터로 먼저 표출이 잘 되는지 확인바랍니다. 그래야 코드오류가 있는지 아닌지 알 수 있습니다.

올려주신 좌표는 대충 수원인근 지역같은데; 한번에 많은 데이터말고 작은 데이터를 이용해보시고,

올려주신 코드외에 다른 부분에서 오류가 있을 수도있습니다. 콘솔에 에러표시는 안나지만, 간혹; 지도 객체가 2개가 떠서 덮어써져서 안보이는 것같은 현상도 발생한 케이스가 있습니다.

작은 단위로 하나씩 디버깅 해보시는걸 추천드립니다.