ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

์˜คํ”ˆ๋ ˆ์ด์–ด์Šค๋กœ ๊ฐœ๋ฐœ์‹œ ๋ฐฐ๊ฒฝ์ง€๋„์™€ ๋งž์ง€ ์•Š๋Š” ์ขŒํ‘œ๊ณ„์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ‘œ์ถœํ•ด์•ผํ•  ๊ฒฝ์šฐ ๊ฐ feature์˜ coordinates๋ฅผ ๋ณ€ํ™˜ํ•ด์ค˜์•ผํ•œ๋‹ค. ๊ทธ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์†Œ์Šค๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

 

๋ฐฐ๊ฒฝ์ง€๋„ - EPSG:3857

๋ฐ์ดํ„ฐ - EPSG:5179

  // EPSG:5179 ์ขŒํ‘œ๊ณ„ ๋“ฑ๋ก
  proj4.defs("EPSG:5179", "+proj=tmerc +lat_0=38 +lon_0=127.5 +k=0.9996 +x_0=1000000 +y_0=2000000 +ellps=GRS80 +units=m +no_defs");
  ol.proj.proj4.register(proj4);

  var vectorSource = new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    loader: function (extent) {
      const url = "./geojson/code_sgg_polygon.geojson"; // geojson ํŒŒ์ผ ๋กœ๋“œ
      fetch(url)
        .then((response) => response.json())
        .then((data) => {
          const features = vectorSource.getFormat().readFeatures(data);
          
          // feature ์ขŒํ‘œ๊ณ„ ๋ณ€ํ™˜
          features.forEach((feature) => feature.getGeometry().transform('EPSG:5179', 'EPSG:3857'));
          
          // features ์—…๋ฐ์ดํŠธ
          vectorSource.addFeatures(features)
        });
    },
  });

  var vectorLayer = new ol.layer.Vector({
    source: vectorSource,
    style: new ol.style.Style({
      fill: new ol.style.Fill({
        color: "rgba(255,255,0,0.3)",
      }),
      stroke: new ol.style.Stroke({
        color: "rgba(0,255,255,0.8)",
        width: 2,
      }),
    }),
  });

  var map = new ol.Map({
    target: "map",
    layers: [
      new ol.layer.Tile({
        source: new ol.source.XYZ({
          url: "http://xdworld.vworld.kr:8080/2d/Base/202002/{z}/{x}/{y}.png",
        }),
      }),
      vectorLayer,
    ],
    view: new ol.View({
      center: [14135490.777017945, 4518386.883679577],
      projection:"EPSG:3857", // ๋ฐฐ๊ฒฝ์ง€๋„ ์ขŒํ‘œ๊ณ„ ์„ค์ •
      zoom: 11,
      minZoom: 7,
      maxZoom: 19,
    }),
  });

 

๋Œ“๊ธ€
๋ฐ˜์‘ํ˜•