UNPKG

tchen-vuelayers

Version:

Web map Vue components with the power of OpenLayers

197 lines (170 loc) 4.48 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 Icon from 'ol/style/Icon'; import imageStyle from '../mixin/image-style'; import { isEqual, pick } from '../util/minilo'; import _Object$assign from '@babel/runtime-corejs2/core-js/object/assign'; var props = { src: { type: String, required: true }, size: { type: Array, validator: function validator(value) { return value.length === 2; } }, anchor: { type: Array, default: function _default() { return [0.5, 0.5]; }, validator: function validator(value) { return value.length === 2; } }, anchorOrigin: { type: String, default: 'top-left' // bottom-left, bottom-right, top-left or top-right }, anchorXUnits: { type: String, default: 'fraction' // pixels, fraction }, anchorYUnits: { type: String, default: 'fraction' // pixels, fraction }, color: [Array, String], crossOrigin: String, offset: { type: Array, default: function _default() { return [0, 0]; }, validator: function validator(value) { return value.length === 2; } }, offsetOrigin: { type: String, default: 'top-left' // bottom-left, bottom-right, top-left or top-right }, opacity: { type: Number, default: 1 }, scale: { type: Number, default: 1 }, rotateWithView: { type: Boolean, default: false }, rotation: { type: Number, default: 0 } }; var methods = { /** * @return {Icon} * @protected */ createStyle: function createStyle() { return new Icon({ anchor: this.anchor, anchorOrigin: this.anchorOrigin, anchorXUnits: this.anchorXUnits, anchorYUnits: this.anchorYUnits, color: this.color, crossOrigin: this.crossOrigin, offset: this.offset, offsetOrigin: this.offsetOrigin, opacity: this.opacity, scale: this.scale, rotateWithView: this.rotateWithView, rotation: this.rotation, size: this.size, src: this.src }); } }; // todo other watchers var watch = { src: function src(value) { if (this.$style && !isEqual(value, this.$style.getSrc())) { this.scheduleRefresh(); } }, size: function size(value) { if (this.$style && !isEqual(value, this.$style.getSize())) { this.scheduleRefresh(); } }, anchor: function anchor(value) { if (this.$style && !isEqual(value, this.$style.getAnchor())) { this.scheduleRefresh(); } }, scale: function scale(value) { if (this.$style && !isEqual(value, this.$style.getScale())) { this.scheduleRefresh(); } } }; var script = { name: 'vl-style-icon', mixins: [imageStyle], props: props, methods: methods, watch: watch }; /* script */ var __vue_script__ = script; /* template */ /* style */ var __vue_inject_styles__ = undefined; /* scoped */ var __vue_scope_id__ = undefined; /* module identifier */ var __vue_module_identifier__ = undefined; /* functional template */ var __vue_is_functional_template__ = undefined; /* component normalizer */ function __vue_normalize__(template, style, script$$1, scope, functional, moduleIdentifier, createInjector, createInjectorSSR) { var component = (typeof script$$1 === 'function' ? script$$1.options : script$$1) || {}; // For security concerns, we use only base name in production mode. component.__file = "style.vue"; if (!component.render) { component.render = template.render; component.staticRenderFns = template.staticRenderFns; component._compiled = true; if (functional) component.functional = true; } component._scopeId = scope; return component; } /* style inject */ /* style inject SSR */ var Style = __vue_normalize__({}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined); function plugin(Vue) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (plugin.installed) { return; } plugin.installed = true; options = pick(options, 'dataProjection'); _Object$assign(Style, options); Vue.component(Style.name, Style); } export default plugin; export { Style, plugin as install };