tchen-vuelayers
Version:
Web map Vue components with the power of OpenLayers
111 lines (97 loc) • 2.57 kB
JavaScript
/**
* 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 Interaction from 'ol/interaction/Interaction';
import Vue from 'vue';
import { instanceOf } from '../util/assert';
var methods = {
/**
* @return {IndexedCollectionAdapter}
* @protected
*/
getInteractionsTarget: function getInteractionsTarget() {
throw new Error('Not implemented method');
},
/**
* @param {Interaction|Vue} interaction
* @return {void}
*/
addInteraction: function addInteraction(interaction) {
interaction = interaction instanceof Vue ? interaction.$interaction : interaction;
instanceOf(interaction, Interaction);
if (this.getInteractionsTarget().has(interaction) === false) {
this.getInteractionsTarget().add(interaction);
this.sortInteractions();
}
},
/**
* @param {Interaction|Vue} interaction
* @return {void}
*/
removeInteraction: function removeInteraction(interaction) {
interaction = interaction instanceof Vue ? interaction.$interaction : interaction;
if (!interaction) return;
if (this.getInteractionsTarget().has(interaction)) {
this.getInteractionsTarget().remove(interaction);
this.sortInteractions();
}
},
/**
* @return {Interaction[]}
*/
getInteractions: function getInteractions() {
return this.getInteractionsTarget().elements;
},
/**
* @param {string|number} id
* @return {Interaction|undefined}
*/
getInteractionById: function getInteractionById(id) {
return this.getInteractionsTarget().findByKey(id);
},
/**
* @return {void}
*/
sortInteractions: function sortInteractions(sorter) {
sorter || (sorter = this.getDefaultInteractionsSorter());
this.getInteractionsTarget().sort(sorter);
},
/**
* @return {function}
* @protected
*/
getDefaultInteractionsSorter: function getDefaultInteractionsSorter() {
return function () {
return 0;
};
},
/**
* @return {void}
*/
clearInteractions: function clearInteractions() {
this.getInteractionsTarget().clear();
},
/**
* @returns {Object}
* @protected
*/
getServices: function getServices() {
var vm = this;
return {
get interactionsContainer() {
return vm;
}
};
}
};
var interactionsContainer = {
methods: methods
};
export default interactionsContainer;