
OpenLayers๋?
์๋ฐ์คํฌ๋ฆฝํธ ์คํ ์์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ
์น ๋ธ๋ผ์ฐ์ ์์ ๋ํํ ์ง๋ ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ์ ๋์์ค
๋ค์ํ ์ง๋ฆฌ๊ณต๊ฐ ๋ฐ์ดํฐ ์์ค๋ฅผ ํตํฉํ์ฌ ์ฌ์ฉ์์๊ฒ ์ง๋ฆฌ ์ ๋ณด๋ฅผ ์๊ฐ์ ์ผ๋ก ์ ๊ณต
https://openlayers.org/en/latest/apidoc/
OpenLayers v10.1.0 API - Index
View The view manages the visual parameters of the map view, like resolution or rotation. View with center, projection, resolution and rotation
openlayers.org
๊ณต์ Document์ ์ฌ๋งํ๊ฒ ๋ค ์๊ณ , ์์ ์ฝ๋๊น์ง ๋ณผ ์ ์๊ธฐ ๋๋ฌธ์ ๊ผผ๊ผผํ๊ฒ ํ์ธํด๋ณด์.
OpenLayers๋ก GeoJSON ํ์ผ ์ฝ์ด์ ์ง๋ ์์ VectorLayer ์ฌ๋ฆฌ๊ธฐ
- map.html
OpenLayers๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์ script๋ฅผ ๋ก๋ํด์ผ ํ๋ค.
<!-- openlayers -->
<link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css">
<script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script>
body ๋ถ๋ถ์ map์ ๋์ธ div๋ฅผ ํ๋ ๋ง๋ค์ด์ค๋ค.

- geoMap.js
์คํฌ๋ฆฝํธ ์ฝ๋๋ฅผ ์์ฑํ๊ธฐ์ ์์, ๋ด๊ฐ ๋ฐ์ ๋ฐ์ดํฐ๋ SHP ํ์ผ์ด์๊ณ ์ด๋ QGIS๋ฅผ ํตํด์ GeoJSON ํ์์ผ๋ก ๋ฐ๊ฟ์ ์ ์ฅํ ์ ์๋ค.
์คํฌ๋ฆฝํธ์ ready ํจ์ ์์ ์๋์ ๊ฐ์ด map ๊ฐ์ฒด ์์ฑ
- target : html์์ ๋ง๋ ์ง๋๋ฅผ ๋์ธ div
- layers : ์ง๋์ ์ถ๊ฐํ ์ ์๋ ๋ค์ํ ๋ ์ด์ด๋ค, ๋๋ GeoJSON์ ์ฝ์ด์ ๋ ์ด์ด๋ฅผ ์ฌ๋ฆด ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ๋ฐฐ๊ฒฝ์ง๋๋ง ์ถ๊ฐํด์คฌ๋ค. OpenLayers์์ ๊ธฐ๋ณธ์ผ๋ก ์ ๊ณตํ๋ OSM ๋ฐฐ๊ฒฝ์ง๋๋ฅผ ์ฌ์ฉํ๋ค.
- view : ์ง๋๋ฅผ ๋ก๋ํ์ ๋ ์ฌ์ฉ์๊ฐ ๋ณด๊ฒ ๋๋ ์ง๋์์ ๊ตฌ๊ฐ์ ์๋ฏธํ๋ค.
- center : ์ค์ฌ์ด ๋๋ ์ขํ
- zoom : ์ง๋ ํ๋ ๋ ๋ฒจ

์ฒ์์๋ javaScript์์ ์ ๊ณตํ๋ fetch API๋ฅผ ์ด์ฉํด์ GeoJSON ํ์ผ์ ์ฝ์ด์ค๋ ค๊ณ ํ์ผ๋ CORS ์๋ฌ ๋ฌธ์ ๋ก ์ ์ ๋ณด๋ฅํ๊ณ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์ฐพ์๋ค.
VectorSource์์ GeoJSON().readFeatures()๋ฅผ ์ฌ์ฉํ์ฌ GeoJSON ๊ฐ์ฒด๋ฅผ ์ฝ์ด์๋ค.
GeoJSON ๊ฐ์ฒด๋ฅผ ์ฝ๊ธฐ ์ํด ํด๋น json ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ฒด๋ก ์ ์ธํด์ ์ ์ฅํด์ฃผ์๋ค.
- Feature : ์ขํ ๋ฐ์ดํฐ๋ฅผ ๋ด์ ๊ฐ์ฒด
- Source : Feature์ ์งํฉ๊ฐ์ฒด
GeoJSON ํ์ผ์ ์ฝ์ด์ ์ง๋๋ฅผ ์ฌ๋ฆด ๋ ๊ฐ์ฅ ์ฃผ์ํด์ผํ ์ ์ ์ขํ๊ณ์ด๋ค.
์ขํ๊ณ๋ฅผ ํต์ผํด์ค์ผ ์ง๋๊ฐ ์ ์์ ์ผ๋ก ํ์ถ๋๋ค.
GIS ๋ด๋น์ํํ ๋ฐ์ SHP ํ์ผ์ ์ขํ๊ณ๊ฐ 5186์ด์๊ณ , ๋ด๊ฐ js์์ ๊ตฌํํ๋ ค๊ณ ํ ์ขํ๊ณ๋ 3857์ด์๋ค...
์ง๋๋ฅผ ์ฒ์ ๊ตฌํํด๋ณด๋๋ฐ๋ค๊ฐ ์ด๋ฐ ์ขํ๊ณ์ ๋ํ ์ ๋ณด๊ฐ ์ ํ ์์๊ธฐ ๋๋ฌธ์ ์ด ๋ถ๋ถ์์ ์กฐ๊ธ ํค๋งธ๋ค.
์ขํ๊ณ์ ๋ํ ์ ๋ณด๋ฅผ ์ ํ์ธํ๊ณ ๋ง์ถฐ์ ๊ฐ๋ฐ์ ํด์ผํ๋ค.
QGIS์์ GeoJSON์ผ๋ก ๋ณํํ ๋ ์ต์ ์ผ๋ก ์ขํ๊ณ ์ ํํ๋ ๋ถ๋ถ์ด ์๊ธฐ์ ์ด๋ฅผ ํตํด ์ํ๋ ์ขํ๊ณ๋ก ๋ณํํด์ฃผ์๋ค.
- featureProjection : Vector ์์ค ์ฒ๋ฆฌํ ๋ ์ฌ์ฉํ๋ ์ต์ . GeoJSON์ Projection๊ณผ ๋ง์ถฐ์ค๋ค.
feature๋ฅผ ์ฝ์ด์ Geometry ํ์ ์ ๋ฐ๋ผ style์ ์ง์ ํ ํ VectorLayer๋ฅผ returnํ๋๋ก ํ๋ค.
style ๊ฐ์ฒด ์์ฑ์ ๋ํ ๊ฒ๋ค์ OpenLayers ๊ณต์ Document์ ์์ธํ ์ค๋ช ์ด ๋ผ ์๋ค.
GeoJSON ํ์ผ์ ์ฌ๋ฌ๊ฐ ์ฝ์ด์ ๊ฐ๊ฐ ์คํ์ผ์ ์ง์ ํ์ฌ ๋ ์ด์ด๋ฅผ ์ฌ๋ฆฌ๊ณ ์ถ์๊ธฐ ๋๋ฌธ์ ์ฝ๋์ ์ค๋ณต์ ์ค์ด๊ณ ์ ์๋์๊ฐ์ด ๊ณตํตํจ์๋ฅผ ๋ง๋ค์๋ค.

์์์ ๋ง๋ ๊ณตํตํจ์์ parameter๋ฅผ ๊ฐ์ด ๋ณด๋ด์ VectorLayer๋ฅผ ๋ง๋ ๋ค.
vectorLayer_node = createVectorLayer(nodeObject, styleFunction);
vectorLayer_link = createVectorLayer(linkObject, styleFunction);
map ๊ฐ์ฒด์ addLayer()๋ฅผ ์ด์ฉํด Layer๋ฅผ ์ถ๊ฐํ๋ฉด ๋๋ค.
// ๋งต์ Layer ์ถ๊ฐ
map.addLayer(vectorLayer_node);
map.addLayer(vectorLayer_link);
๊ฒฐ๊ณผ
node, link 2๊ฐ์ GeoJSON ํ์ผ์ ์ฝ์ด์ ์ง๋ ์์ ์ฌ๋ฆฐ ๊ฒฐ๊ณผ์ด๋ค.

* ์์ ํฌ์คํ ์ ๊ฐ์ธ์ ์ธ ๊ณต๋ถ, ์ ๋ฆฌ๋ฅผ ์ํ ๊ฒ์ ๋๋ค.
* ๋ฐ๋ผ์ ์ ํํ์ง ์์ ๋ถ๋ถ์ด ์์์๋ ์์.
* ๋ด์ฉ์ ์๋ชป๋ ๋ถ๋ถ, ์ค๋ฅ ์ง์ , ๋ ๋์ ๋ฐฉ๋ฒ์ ๊ฐ์ฌํ ๋ฐ๊ฒ ์ต๋๋ค.
'Frontend > OpenLayers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [GIS] SHPํ์ผ์ ๊ตฌ์กฐ (0) | 2023.03.29 |
|---|---|
| [OpenLayers] ์ง๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ OpenLayers์ ๊ธฐ๋ณธ ๊ฐ๋ (0) | 2023.03.23 |