UNPKG

tchen-vuelayers

Version:

Web map Vue components with the power of OpenLayers

278 lines (242 loc) 6.71 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 Geolocation from 'ol/Geolocation'; import { merge } from 'rxjs/_esm5/internal/observable/merge'; import { olCmp, useMapCmp, projTransforms } from '../mixin'; import { observableFromOlChangeEvent } from '../rx-ext'; import { hasGeolocation } from '../util/assert'; import _Object$assign from '@babel/runtime-corejs2/core-js/object/assign'; import { pick } from '../util/minilo'; var props = { tracking: { type: Boolean, default: true }, trackingOptions: Object, /** * @type {string} */ projection: String // todo add autoCenter, bindToPosition }; var computed = { accuracy: function accuracy() { if (this.rev && this.$geolocation) { return this.$geolocation.getAccuracy(); } }, altitude: function altitude() { if (this.rev && this.$geolocation) { return this.$geolocation.getAltitude(); } }, altitudeAccuracy: function altitudeAccuracy() { if (this.rev && this.$geolocation) { return this.$geolocation.getAltitudeAccuracy(); } }, heading: function heading() { if (this.rev && this.$geolocation) { return this.$geolocation.getHeading(); } }, speed: function speed() { if (this.rev && this.$geolocation) { return this.$geolocation.getSpeed(); } }, position: function position() { if (this.rev && this.$geolocation) { return this.$geolocation.getPosition(); } }, positionViewProj: function positionViewProj() { if (this.position && this.resolvedDataProjection) { return this.pointToViewProj(this.position); } } }; var methods = { /** * @return {Geolocation} * @private */ createOlObject: function createOlObject() { return new Geolocation({ tracking: this.tracking, trackingOptions: this.trackingOptions, projection: this.resolvedDataProjection }); }, /** * @return {void} * @private */ mount: function mount() { this.subscribeAll(); }, /** * @return {void} * @private */ unmount: function unmount() { hasGeolocation(this); this.unsubscribeAll(); this.$geolocation.setTracking(false); }, /** * @return {void} * @protected */ subscribeAll: function subscribeAll() { subscribeToGeolocation.call(this); } }; var watch = { /** * @param {boolean} value */ tracking: function tracking(value) { if (this.$geolocation && value !== this.$geolocation.getTracking()) { this.$geolocation.setTracking(value); } }, tracingOptions: function tracingOptions(value) { this.$geolocation && this.$geolocation.setTrackingOptions(value); }, resolvedDataProjection: function resolvedDataProjection(value) { if (this.$geolocation) { this.$geolocation.setProjection(value); } } }; var script = { name: 'vl-geoloc', mixins: [olCmp, useMapCmp, projTransforms], props: props, computed: computed, methods: methods, watch: watch, stubVNode: { empty: function empty() { return this.$options.name; } }, created: function created() { var _this = this; _Object$defineProperties(this, { /** * @type {Geolocation|undefined} */ $geolocation: { enumerable: true, get: function get() { return _this.$olObject; } }, $map: { enumerable: true, get: function get() { return _this.$services && _this.$services.map; } }, /** * Reference to `ol.View` instance. * @type {View|undefined} */ $view: { enumerable: true, get: function get() { return _this.$services && _this.$services.view; } } }); } }; /** * @return {void} * @private */ function subscribeToGeolocation() { var _this2 = this; hasGeolocation(this); var ft = 100; var changes = merge(observableFromOlChangeEvent(this.$geolocation, ['accuracy', 'altitude', 'altitudeaccuracy', 'heading', 'speed'], true, ft), observableFromOlChangeEvent(this.$geolocation, 'position', true, ft, function () { return _this2.position; })); this.subscribeTo(changes, function (_ref) { var prop = _ref.prop, value = _ref.value; ++_this2.rev; _this2.$emit("update:".concat(prop), value); }); } /* script */ var __vue_script__ = script; /* template */ var __vue_render__ = function __vue_render__() { var _vm = this; var _h = _vm.$createElement; var _c = _vm._self._c || _h; return _c('i', { class: [_vm.$options.name], staticStyle: { "display": "none !important" } }, [_vm._t("default", null, { accuracy: _vm.accuracy, altitude: _vm.altitude, altitudeAccuracy: _vm.altitudeAccuracy, heading: _vm.heading, position: _vm.position, speed: _vm.speed })], 2); }; var __vue_staticRenderFns__ = []; /* 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__ = false; /* 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 = "geoloc.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 Geoloc = __vue_normalize__({ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ }, __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(Geoloc, options); Vue.component(Geoloc.name, Geoloc); } export default plugin; export { Geoloc, plugin as install };