main.js
- Import DragAndDrop
- 초기 데이터가 없는 벡터 source 만들기
- map에서 이전 layer를 제거하고 빈 벡터 source로 새 layer를 만들어 추가
- 벡터 소스와 함께 작동하도록 map에 DragAndDrop 상호작용 추가
- GeoJOSN 파일을 map에 끌어다 놓고 렌더링된 파일 확인
import DragAndDrop from 'ol/interaction/DragAndDrop';
import GeoJSON from 'ol/format/GeoJSON';
import Map from 'ol/Map';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import View from 'ol/View';
const map = new Map({
target: 'map-container',
view: new View({
center: [0, 0],
zoom: 2,
}),
});
const source = new VectorSource();
const layer = new VectorLayer({
source: source,
});
map.addLayer(layer);
map.addInteraction(
new DragAndDrop({
source: source,
formatConstructors: [GeoJSON],
})
);