Snapping

jieun·2022년 9월 20일
0

openlayers

목록 보기
5/8
  1. import Snap
  2. 벡터 source와 함께 map에 추가
  • features를 그리거나 수정하는 동안 토폴리지를 보존할 수 있음

main.js

import Snap from 'ol/interaction/Snap';
import Draw from 'ol/interaction/Draw';
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,
  })
);

map.addInteraction(
  new Draw({
    type: 'Polygon',
    source: source,
  })
);

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

0개의 댓글