UNPKG

qwc2

Version:
90 lines (89 loc) 5.06 kB
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } /** * Copyright 2015 GeoSolutions Sas * Copyright 2016-2024 Sourcepole AG * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ import axios from 'axios'; import isMobile from 'ismobilejs'; import url from 'url'; var config = { assetsPath: "assets", translationsPath: "translations", defaultFeatureStyle: { strokeColor: [0, 0, 255, 1], strokeWidth: 2, strokeDash: [4], fillColor: [0, 0, 255, 0.33], circleRadius: 10, textFill: 'black', textStroke: 'white' } }; var sessionConfig = {}; export default { getDefaults: function getDefaults() { return config; }, loadConfiguration: function loadConfiguration() { var configParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var configFile = 'config.json'; var urlQuery = url.parse(window.location.href, true).query; if (urlQuery.localConfig) { configFile = urlQuery.localConfig + '.json'; } return axios.get(configFile, { params: configParams }).then(function (response) { if (_typeof(response.data) === 'object') { config = _objectSpread(_objectSpread({}, config), response.data); } else { /* eslint-disable-next-line */ console.warn("Broken configuration file " + configFile + "!"); } // Set isMobile config.isMobile = isMobile(window.navigator).any; return config; }); }, isMobile: function isMobile() { return config.isMobile; }, getConfigProp: function getConfigProp(prop, theme) { var _theme$config$section, _theme$config, _theme$config2, _ref, _ref2, _config$section; var defval = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; var section = config.isMobile ? "mobile" : "desktop"; var themeProp = (_theme$config$section = theme === null || theme === void 0 || (_theme$config = theme.config) === null || _theme$config === void 0 || (_theme$config = _theme$config[section]) === null || _theme$config === void 0 ? void 0 : _theme$config[prop]) !== null && _theme$config$section !== void 0 ? _theme$config$section : theme === null || theme === void 0 || (_theme$config2 = theme.config) === null || _theme$config2 === void 0 ? void 0 : _theme$config2[prop]; return (_ref = (_ref2 = themeProp !== null && themeProp !== void 0 ? themeProp : (_config$section = config[section]) === null || _config$section === void 0 ? void 0 : _config$section[prop]) !== null && _ref2 !== void 0 ? _ref2 : config[prop]) !== null && _ref !== void 0 ? _ref : defval; }, getAssetsPath: function getAssetsPath() { return config.assetsPath.replace(/\/$/g, ""); }, getTranslationsPath: function getTranslationsPath() { return config.translationsPath.replace(/\/$/g, ""); }, havePlugin: function havePlugin(name) { return config.plugins[config.isMobile ? "mobile" : "desktop"].find(function (entry) { return entry.name === name; }); }, getPluginConfig: function getPluginConfig(name) { return config.plugins[config.isMobile ? "mobile" : "desktop"].find(function (entry) { return entry.name === name; }) || {}; }, setSessionConfig: function setSessionConfig(name, value) { sessionConfig[name] = value; }, getSessionConfig: function getSessionConfig(name) { return sessionConfig[name]; } };