UNPKG

ole

Version:

OpenLayers Editor

62 lines (61 loc) 2.61 kB
import { Draw } from 'ol/interaction'; import Control from './control'; import drawPointSVG from '../../img/draw_point.svg'; import drawPolygonSVG from '../../img/draw_polygon.svg'; import drawLineSVG from '../../img/draw_line.svg'; /** * Control for drawing features. * @extends {Control} * @alias ole.DrawControl */ class DrawControl extends Control { /** * @param {Object} [options] Tool options. * @param {string} [options.type] Geometry type ('Point', 'LineString', 'Polygon', * 'MultiPoint', 'MultiLineString', 'MultiPolygon' or 'Circle'). * Default is 'Point'. * @param {Object} [options.drawInteractionOptions] Options for the Draw interaction (ol/interaction/Draw). * @param {ol.style.Style.StyleLike} [options.style] Style used for the draw interaction. */ constructor(options) { let image = null; switch (options === null || options === void 0 ? void 0 : options.type) { case 'Polygon': image = drawPolygonSVG; break; case 'LineString': image = drawLineSVG; break; default: image = drawPointSVG; } super(Object.assign({ title: `Draw ${(options === null || options === void 0 ? void 0 : options.type) || 'Point'}`, className: 'ole-control-draw', image }, (options || {}))); /** * @type {ol.interaction.Draw} */ this.drawInteraction = new Draw(Object.assign({ type: (options === null || options === void 0 ? void 0 : options.type) || 'Point', features: options === null || options === void 0 ? void 0 : options.features, source: options === null || options === void 0 ? void 0 : options.source, style: options === null || options === void 0 ? void 0 : options.style, stopClick: true }, ((options === null || options === void 0 ? void 0 : options.drawInteractionOptions) || {}))); this.drawInteraction.on('drawstart', (evt) => { this.editor.setDrawFeature(evt.feature); }); this.drawInteraction.on('drawend', () => { this.editor.setDrawFeature(); }); } /** * @inheritdoc */ activate() { var _a; (_a = this.map) === null || _a === void 0 ? void 0 : _a.addInteraction(this.drawInteraction); super.activate(); } /** * @inheritdoc */ deactivate(silent) { var _a; (_a = this.map) === null || _a === void 0 ? void 0 : _a.removeInteraction(this.drawInteraction); super.deactivate(silent); } } export default DrawControl;