UNPKG

tchen-vuelayers

Version:

Web map Vue components with the power of OpenLayers

202 lines (186 loc) 4.72 kB
/** * VueLayers * Web map Vue components with the power of OpenLayers * * @package vuelayers * @author Vladimir Vershinin <ghettovoice@gmail.com> * @version 0.11.1 * @license MIT * @copyright (c) 2017-2019, Vladimir Vershinin <ghettovoice@gmail.com> */ import _Object$defineProperties from '@babel/runtime-corejs2/core-js/object/define-properties'; import _regeneratorRuntime from '@babel/runtime-corejs2/regenerator'; import _asyncToGenerator from '@babel/runtime-corejs2/helpers/esm/asyncToGenerator'; import uuid from 'uuid/v4'; import mergeDescriptors from '../util/multi-merge-descriptors'; import cmp from './ol-virt-cmp'; import useMapCmp from './use-map-cmp'; var props = { id: { type: [String, Number], default: function _default() { return uuid(); } }, active: { type: Boolean, default: true }, /** * Priority of interactions in the event handling stream. * The higher the value, the sooner it will handle map event. * @type {number} */ priority: { type: Number, default: 0 } }; var methods = { /** * @return {Promise<Interaction>} * @protected */ createOlObject: function () { var _createOlObject = _asyncToGenerator( /*#__PURE__*/ _regeneratorRuntime.mark(function _callee() { var interaction; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return this.createInteraction(); case 2: interaction = _context.sent; interaction.setActive(this.active); interaction.setProperties({ id: this.id, priority: this.priority }); return _context.abrupt("return", interaction); case 6: case "end": return _context.stop(); } } }, _callee, this); })); return function createOlObject() { return _createOlObject.apply(this, arguments); }; }(), /** * @return {Interaction|Promise<Interaction>} * @protected * @abstract */ createInteraction: function createInteraction() { throw new Error('Not implemented method'); }, /** * @returns {Object} * @protected */ getServices: function getServices() { var vm = this; return mergeDescriptors(cmp.methods.getServices.call(this), { get interaction() { return vm.$interaction; } }); }, /** * @return {Promise} Resolves when initialization completes * @protected */ init: function init() { return cmp.methods.init.call(this); }, /** * @return {void|Promise<void>} * @protected */ deinit: function deinit() { return cmp.methods.deinit.call(this); }, /** * @return {void} * @protected */ mount: function mount() { this.$interactionsContainer && this.$interactionsContainer.addInteraction(this); this.subscribeAll(); }, /** * @return {void} * @protected */ unmount: function unmount() { this.unsubscribeAll(); this.$interactionsContainer && this.$interactionsContainer.removeInteraction(this); }, /** * @return {Promise} */ refresh: function refresh() { return cmp.methods.refresh.call(this); } }; var watch = { active: function active(value) { if (this.$interaction && value !== this.$interaction.getActive()) { this.$interaction.setActive(value); } }, priority: function priority(value) { if (!this.$interactionsContainer) return; this.$interaction.set('priority', value); this.$interactionsContainer.sortInteractions(); } }; var interaction = { mixins: [cmp, useMapCmp], props: props, methods: methods, watch: watch, stubVNode: { empty: function empty() { return this.$options.name; } }, created: function created() { var _this = this; _Object$defineProperties(this, { /** * @type {Interaction|undefined} */ $interaction: { enumerable: true, get: function get() { return _this.$olObject; } }, $map: { enumerable: true, get: function get() { return _this.$services && _this.$services.map; } }, $view: { enumerable: true, get: function get() { return _this.$services && _this.$services.view; } }, $interactionsContainer: { enumerable: true, get: function get() { return _this.$services && _this.$services.interactionsContainer; } } }); } }; export default interaction;