ํฐ์คํ ๋ฆฌ ๋ทฐ
โ Programming/โ GIS
[ Openlayers ] geojson ๋ฐ์ดํฐ ์ขํ๋ณํ ํด์ ๋ ์ด์ด ํ์ถํ๊ธฐ ( ol6 ๊ธฐ์ค )
Kithub 2023. 3. 21. 13:52๋ฐ์ํ
์คํ๋ ์ด์ด์ค๋ก ๊ฐ๋ฐ์ ๋ฐฐ๊ฒฝ์ง๋์ ๋ง์ง ์๋ ์ขํ๊ณ์ ๋ฐ์ดํฐ๋ฅผ ํ์ถํด์ผํ ๊ฒฝ์ฐ ๊ฐ 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,
}),
});
๋ฐ์ํ
'โ Programming > โ GIS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋๊ธ