qwc2
Version:
QGIS Web Client
173 lines (171 loc) • 8.22 kB
JavaScript
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); }
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 _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
/**
* Copyright 2020-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 ReducerIndex from '../reducers/index';
import windowsReducer from '../reducers/windows';
import ConfigUtils from '../utils/ConfigUtils';
import CoordinatesUtils from '../utils/CoordinatesUtils';
import LocaleUtils from '../utils/LocaleUtils';
import MapUtils from '../utils/MapUtils';
import { UrlParams } from '../utils/PermaLinkUtils';
ReducerIndex.register("windows", windowsReducer);
export var SHOW_IFRAME_DIALOG = 'SHOW_IFRAME_DIALOG';
export var SHOW_NOTIFICATION = 'SHOW_NOTIFICATION';
export var CLOSE_WINDOW = 'CLOSE_WINDOW';
export var CLOSE_ALL_WINDOWS = 'CLOSE_ALL_WINDOWS';
export var REGISTER_WINDOW = 'REGISTER_WINDOW';
export var UNREGISTER_WINDOW = 'UNREGISTER_WINDOW';
export var RAISE_WINDOW = 'RAISE_WINDOW';
export var SET_MENU_MARGIN = 'SET_MENU_MARGIN';
export var SET_SPLIT_SCREEN = 'SET_SPLIT_SCREEN';
export var SET_TOPBAR_HEIGHT = 'SET_TOPBAR_HEIGHT';
export var SET_BOTTOMBAR_HEIGHT = 'SET_BOTTOMBAR_HEIGHT';
export var NotificationType = {
INFO: 1,
WARN: 2,
ERROR: 3
};
export function showIframeDialog(name, url, options) {
return {
type: SHOW_IFRAME_DIALOG,
name: name,
url: url,
options: options
};
}
export function showNotification(name, text) {
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : NotificationType.INFO;
var sticky = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var actions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
return {
type: SHOW_NOTIFICATION,
name: name,
text: text,
notificationType: type,
sticky: sticky,
actions: actions
};
}
export function closeWindow(name) {
return {
type: CLOSE_WINDOW,
name: name
};
}
export function closeAllWindows() {
return {
type: CLOSE_ALL_WINDOWS
};
}
export function registerWindow(id) {
return {
type: REGISTER_WINDOW,
id: id
};
}
export function unregisterWindow(id) {
return {
type: UNREGISTER_WINDOW,
id: id
};
}
export function raiseWindow(id) {
return {
type: RAISE_WINDOW,
id: id
};
}
export function setSplitScreen(windowId, side, size, splitTopAndBottomBar) {
return {
type: SET_SPLIT_SCREEN,
windowId: windowId,
side: side,
size: size,
splitTopAndBottomBar: splitTopAndBottomBar
};
}
export function setMenuMargin(right, left) {
return {
type: SET_MENU_MARGIN,
right: right,
left: left
};
}
export function setTopbarHeight(height) {
return {
type: SET_TOPBAR_HEIGHT,
height: height
};
}
export function setBottombarHeight(height) {
return {
type: SET_BOTTOMBAR_HEIGHT,
height: height
};
}
export function openExternalUrl(url) {
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var iframeDialogOpts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
return function (dispatch, getState) {
// Replace all entries in URL
Object.entries(UrlParams.getParams()).forEach(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
url = url.replace('$' + key + '$', value);
});
// Additional entries
var state = getState();
var bounds = state.map.bbox.bounds;
var proj = state.map.projection;
var roundfactor = CoordinatesUtils.getUnits(proj) === 'degrees' ? 100000 : 1;
var xmin = Math.round(bounds[0] * roundfactor) / roundfactor;
var ymin = Math.round(bounds[1] * roundfactor) / roundfactor;
var xmax = Math.round(bounds[2] * roundfactor) / roundfactor;
var ymax = Math.round(bounds[3] * roundfactor) / roundfactor;
var x = Math.round(0.5 * (bounds[0] + bounds[2]) * roundfactor) / roundfactor;
var y = Math.round(0.5 * (bounds[1] + bounds[3]) * roundfactor) / roundfactor;
if (state.map.scales) {
var scale = Math.round(MapUtils.computeForZoom(state.map.scales, state.map.zoom));
url = url.replace('$s$', scale);
url = url.replace('$c$', x + "," + y);
}
url = url.replace('$e$', [xmin, ymin, xmax, ymax].join(","));
// Add separate x, y
url = url.replace('$x$', x);
url = url.replace('$y$', y);
url = url.replace('$crs$', proj);
url = url.replace('$user$', ConfigUtils.getConfigProp("username") || "");
url = url.replace('$lang$', LocaleUtils.lang());
if (target.startsWith(":iframedialog")) {
var targetParts = target.split(":");
var options = targetParts.slice(2).reduce(function (res, cur) {
var parts = cur.split("=");
if (parts.length === 2) {
var value = parseFloat(parts[1]);
res[parts[0]] = isNaN(value) ? parts[1] : value;
}
return res;
}, {});
dispatch(showIframeDialog(targetParts[2], url, _objectSpread(_objectSpread({}, iframeDialogOpts), options)));
} else {
window.open(url, target || "_blank");
}
};
}