import Map from '../src/ol/Map.js'; import View from '../src/ol/View.js'; import Draw from '../src/ol/interaction/Draw.js'; import Modify from '../src/ol/interaction/Modify.js'; import Snap from '../src/ol/interaction/Snap.js'; import TileLayer from '../src/ol/layer/Tile.js'; import VectorLayer from '../src/ol/layer/Vector.js'; import OSM from '../src/ol/source/OSM.js'; import VectorSource from '../src/ol/source/Vector.js'; import _ol_style_Circle_ from '../src/ol/style/Circle.js'; import _ol_style_Fill_ from '../src/ol/style/Fill.js'; import _ol_style_Stroke_ from '../src/ol/style/Stroke.js'; import _ol_style_Style_ from '../src/ol/style/Style.js'; var raster = new TileLayer({ source: new OSM() }); var source = new VectorSource(); var vector = new VectorLayer({ source: source, style: new _ol_style_Style_({ fill: new _ol_style_Fill_({ color: 'rgba(255, 255, 255, 0.2)' }), stroke: new _ol_style_Stroke_({ color: '#ffcc33', width: 2 }), image: new _ol_style_Circle_({ radius: 7, fill: new _ol_style_Fill_({ color: '#ffcc33' }) }) }) }); var map = new Map({ layers: [raster, vector], target: 'map', view: new View({ center: [-11000000, 4600000], zoom: 4 }) }); var modify = new Modify({source: source}); map.addInteraction(modify); var draw, snap; // global so we can remove them later var typeSelect = document.getElementById('type'); function addInteractions() { draw = new Draw({ source: source, type: typeSelect.value }); map.addInteraction(draw); snap = new Snap({source: source}); map.addInteraction(snap); } /** * Handle change event. */ typeSelect.onchange = function() { map.removeInteraction(draw); map.removeInteraction(snap); addInteractions(); }; addInteractions();