UNPKG

qwc2-lts

Version:
11 lines 10.7 kB
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 _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var _n=0,F=function F(){};return{s:F,n:function n(){return _n>=r.length?{done:!0}:{done:!1,value:r[_n++]}},e:function e(r){throw r},f:F}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,u=!1;return{s:function s(){t=t.call(r)},n:function n(){var r=t.next();return a=r.done,r},e:function e(r){u=!0,o=r},f:function f(){try{a||null==t["return"]||t["return"]()}finally{if(u)throw o}}}}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}/** * 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 url from"url";import{LayerRole}from"../actions/layers";import ConfigUtils from"../utils/ConfigUtils";import LayerUtils from"../utils/LayerUtils";var UrlQuery={};var historyUpdateTimeout=null;var pendingParams={};export var UrlParams={updateParams:function updateParams(dict){var forceLocationUrl=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(ConfigUtils.getConfigProp("omitUrlParameterUpdates")===true){UrlQuery=Object.assign(UrlQuery,dict);var propNames=Object.getOwnPropertyNames(UrlQuery);var _iterator=_createForOfIteratorHelper(propNames),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var propName=_step.value;if(UrlQuery[propName]===undefined){delete UrlQuery[propName]}}}catch(err){_iterator.e(err)}finally{_iterator.f()}if(!forceLocationUrl){return}}// Delay URL updates to avoid "Too many calls to Location or History APIs within a short timeframe." if(historyUpdateTimeout!==null){clearTimeout(historyUpdateTimeout)}pendingParams=_objectSpread(_objectSpread({},pendingParams),dict);historyUpdateTimeout=setTimeout(function(){var urlObj=url.parse(window.location.href,true);urlObj.query=Object.assign(urlObj.query,pendingParams);var propNames=Object.getOwnPropertyNames(urlObj.query);var _iterator2=_createForOfIteratorHelper(propNames),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _propName=_step2.value;if(urlObj.query[_propName]===undefined){delete urlObj.query[_propName]}}}catch(err){_iterator2.e(err)}finally{_iterator2.f()}delete urlObj.search;history.replaceState({id:urlObj.host},"",url.format(urlObj));historyUpdateTimeout=null;pendingParams={}},250)},getParam:function getParam(key){var urlObj=url.parse(window.location.href,true);if(ConfigUtils.getConfigProp("omitUrlParameterUpdates")===true){var _urlObj$query$key;return(_urlObj$query$key=urlObj.query[key])!==null&&_urlObj$query$key!==void 0?_urlObj$query$key:UrlQuery[key]}else{return urlObj.query[key]}},getParams:function getParams(){var query=url.parse(window.location.href,true).query;if(ConfigUtils.getConfigProp("omitUrlParameterUpdates")===true){return _objectSpread(_objectSpread({},UrlQuery),query)}else{return query}},clear:function clear(){this.updateParams({k:undefined,t:undefined,l:undefined,bl:undefined,bk:undefined,c:undefined,s:undefined,e:undefined,crs:undefined,st:undefined,sp:undefined,f:undefined},true)},getFullUrl:function getFullUrl(){if(ConfigUtils.getConfigProp("omitUrlParameterUpdates")===true){var urlObj=url.parse(window.location.href,true);urlObj.query=UrlQuery;delete urlObj.search;return url.format(urlObj)}else{return window.location.href}}};export function generatePermaLink(state,callback){var user=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var fullUrl=UrlParams.getFullUrl();if(!ConfigUtils.getConfigProp("permalinkServiceUrl")){callback(fullUrl);return}var permalinkState={};if(ConfigUtils.getConfigProp("storeAllLayersInPermalink")){permalinkState.layers=state.layers.flat.filter(function(layer){return layer.role!==LayerRole.BACKGROUND})}else{// Only store redlining layers var exploded=LayerUtils.explodeLayers(state.layers.flat.filter(function(layer){return layer.role!==LayerRole.BACKGROUND}));var redliningLayers=exploded.map(function(entry,idx){return _objectSpread(_objectSpread({},entry),{},{pos:idx})}).filter(function(entry){return entry.layer.role===LayerRole.USERLAYER&&entry.layer.type==="vector"}).map(function(entry){return _objectSpread(_objectSpread({},entry.layer),{},{pos:entry.pos})});permalinkState.layers=redliningLayers}permalinkState.permalinkParams=state.localConfig.permalinkParams;permalinkState.url=fullUrl;var route=user?"userpermalink":"createpermalink";axios.post(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/,"")+"/"+route,permalinkState).then(function(response){return callback(response.data.permalink||fullUrl,response.data.expires||null)})["catch"](function(){return callback(fullUrl)})}export function resolvePermaLink(initialParams,callback){var key=UrlParams.getParam("k");var bkey=UrlParams.getParam("bk");if(key){axios.get(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/,"")+"/resolvepermalink?key="+key).then(function(response){var data=response.data;callback(_objectSpread(_objectSpread(_objectSpread({},initialParams),data.query||{}),data.state.permalinkParams||{}),data.state||{},!!data.query)})["catch"](function(){callback(initialParams,{},false)})}else if(bkey){axios.get(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/,"")+"/bookmarks/"+bkey).then(function(response){var data=response.data;callback(_objectSpread(_objectSpread(_objectSpread({},initialParams),data.query||{}),data.state.permalinkParams||{}),data.state||{},!!data.query)})["catch"](function(){callback(initialParams,{},false)})}else{callback(initialParams,{},true)}}export function resolveBookmark(bookmarkKey,callback){axios.get(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/,"")+"/bookmarks/"+bookmarkKey).then(function(response){var data=response.data;callback(_objectSpread({},data.query||{}),data.state||{},!!data.query)})["catch"](function(){callback(bookmarkKey,{},false)})}export function getUserBookmarks(user,callback){if(user){axios.get(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/,"")+"/bookmarks/").then(function(response){callback(response.data||[])})["catch"](function(){callback([])})}}export function removeBookmark(bkey,callback){if(bkey){axios["delete"](ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/,"")+"/bookmarks/"+bkey).then(function(){callback(true)})["catch"](function(){return callback(false)})}}export function createBookmark(state,description,callback){if(!ConfigUtils.getConfigProp("permalinkServiceUrl")){callback(false);return}// Only store redlining layers var exploded=LayerUtils.explodeLayers(state.layers.flat.filter(function(layer){return layer.role!==LayerRole.BACKGROUND}));var bookmarkState={};if(ConfigUtils.getConfigProp("storeAllLayersInPermalink")){bookmarkState.layers=state.layers.flat.filter(function(layer){return layer.role!==LayerRole.BACKGROUND})}else{var redliningLayers=exploded.map(function(entry,idx){return _objectSpread(_objectSpread({},entry),{},{pos:idx})}).filter(function(entry){return entry.layer.role===LayerRole.USERLAYER&&entry.layer.type==="vector"}).map(function(entry){return _objectSpread(_objectSpread({},entry.layer),{},{pos:entry.pos})});bookmarkState.layers=redliningLayers}bookmarkState.permalinkParams=state.localConfig.permalinkParams;bookmarkState.url=UrlParams.getFullUrl();axios.post(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/,"")+"/bookmarks/"+"?description="+description,bookmarkState).then(function(){return callback(true)})["catch"](function(){return callback(false)})}export function updateBookmark(state,bkey,description,callback){if(!ConfigUtils.getConfigProp("permalinkServiceUrl")){callback(false);return}// Only store redlining layers var exploded=LayerUtils.explodeLayers(state.layers.flat.filter(function(layer){return layer.role!==LayerRole.BACKGROUND}));var bookmarkState={};if(ConfigUtils.getConfigProp("storeAllLayersInPermalink")){bookmarkState.layers=state.layers.flat.filter(function(layer){return layer.role!==LayerRole.BACKGROUND})}else{var redliningLayers=exploded.map(function(entry,idx){return _objectSpread(_objectSpread({},entry),{},{pos:idx})}).filter(function(entry){return entry.layer.role===LayerRole.USERLAYER&&entry.layer.type==="vector"}).map(function(entry){return _objectSpread(_objectSpread({},entry.layer),{},{pos:entry.pos})});bookmarkState.layers=redliningLayers}bookmarkState.permalinkParams=state.localConfig.permalinkParams;bookmarkState.url=UrlParams.getFullUrl();axios.put(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/,"")+"/bookmarks/"+bkey+"?description="+description,bookmarkState).then(function(){return callback(true)})["catch"](function(){return callback(false)})}