tchen-vuelayers
Version:
Web map Vue components with the power of OpenLayers
170 lines (154 loc) • 3.54 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 _Object$defineProperties from '@babel/runtime-corejs2/core-js/object/define-properties';
import _Promise from '@babel/runtime-corejs2/core-js/promise';
import { isFunction } from '../util/minilo';
import mergeDescriptors from '../util/multi-merge-descriptors';
import cmp from './ol-virt-cmp';
import useMapCmp from './use-map-cmp';
var props = {
attributions: [String, Array],
logo: String,
projection: String,
wrapX: {
type: Boolean,
default: true
}
};
var methods = {
/**
* @return {Source|Promise<Source>}
* @protected
*/
createOlObject: function createOlObject() {
return this.createSource();
},
/**
* @return {Source|Promise<Source>}
* @protected
* @abstract
*/
createSource: function createSource() {
throw new Error('Not implemented method');
},
/**
* @return {Promise}
* @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 {Object}
* @protected
*/
getServices: function getServices() {
var vm = this;
return mergeDescriptors(cmp.methods.getServices.call(this), {
get source() {
return vm.$source;
}
});
},
/**
* @return {void}
* @protected
*/
mount: function mount() {
this.$sourceContainer && this.$sourceContainer.setSource(this);
this.subscribeAll();
},
/**
* @return {void}
* @protected
*/
unmount: function unmount() {
this.unsubscribeAll();
this.$sourceContainer && this.$sourceContainer.setSource(undefined);
},
/**
* @return {Promise<void>}
*/
refresh: function refresh() {
var _this = this;
if (this.$source && !isFunction(this.$source.clear)) {
return cmp.methods.refresh.call(this);
}
return new _Promise(function (resolve) {
var done = function done() {
++_this.rev;
resolve();
};
if (_this.$source) {
_this.$source.once('change', done);
_this.$source.clear();
} else {
done();
}
});
}
};
var watch = {
attributions: function attributions(value) {
this.$source && this.$source.setAttributions(value);
}
};
var source = {
mixins: [cmp, useMapCmp],
props: props,
methods: methods,
watch: watch,
stubVNode: {
empty: function empty() {
return this.$options.name;
}
},
created: function created() {
var _this2 = this;
_Object$defineProperties(this, {
/**
* @type {Source|undefined}
*/
$source: {
enumerable: true,
get: function get() {
return _this2.$olObject;
}
},
$map: {
enumerable: true,
get: function get() {
return _this2.$services && _this2.$services.map;
}
},
$view: {
enumerable: true,
get: function get() {
return _this2.$services && _this2.$services.view;
}
},
$sourceContainer: {
enumerable: true,
get: function get() {
return _this2.$services && _this2.$services.sourceContainer;
}
}
});
}
};
export default source;