UNPKG

tchen-vuelayers

Version:

Web map Vue components with the power of OpenLayers

66 lines (57 loc) 2.16 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 _toConsumableArray from '@babel/runtime-corejs2/helpers/esm/toConsumableArray'; import _Array$isArray from '@babel/runtime-corejs2/core-js/array/is-array'; import { merge } from 'rxjs/_esm5/internal/observable/merge'; import { distinctUntilChanged } from 'rxjs/_esm5/internal/operators/distinctUntilChanged'; import { map } from 'rxjs/_esm5/internal/operators/map'; import { throttleTime } from 'rxjs/_esm5/internal/operators/throttleTime'; import { isEqual, isFunction } from '../util/minilo'; import fromOlEvent from './from-ol-event'; /** * Creates Observable from OpenLayers change:* event * @param {ol.Object} target * @param {string|string[]} [prop] * @param {boolean|function(a, b):boolean|undefined} [distinct] Distinct values by isEqual fn or by custom comparator * @param {number|undefined} [throttle] Throttle values by passed amount of ms. * @param {function(target: ol.Object, prop: string):*|undefined} [selector] Custom selector * @return {Observable<{prop: string, value: *}>} */ function fromOlChangeEvent(target, prop, distinct, throttle, selector) { if (_Array$isArray(prop)) { return merge.apply(void 0, _toConsumableArray(prop.map(function (p) { return fromOlChangeEvent(target, p); }))); } selector = selector || function (target, prop) { return target.get(prop); }; var event = "change:".concat(prop); var observable = fromOlEvent(target, event, function () { return selector(target, prop); }); var operations = []; if (throttle != null) { operations.push(throttleTime(throttle)); } if (distinct) { isFunction(distinct) || (distinct = isEqual); operations.push(distinctUntilChanged(distinct)); } operations.push(map(function (value) { return { prop: prop, value: value }; })); return observable.pipe.apply(observable, operations); } export default fromOlChangeEvent;