Modifying features

jieun·2022년 9월 20일
0

openlayers

목록 보기
3/8

main.js

  1. import Modify
  2. 벡터 source에 연결된 새 상호작용을 만들고 map에 추가
  • map에 데이터를 추가한 후 꼭짓점을 드래그하여 feature 수정
  • alt+click으로 꼭짓점 삭제 가능
import Modify from 'ol/interaction/Modify';
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],
  })
);

map.addInteraction(
  new Modify({
    source: source,
  })
);
profile
개발새발 블로그

0개의 댓글