qwc2-lts
Version:
QGIS Web Client
10 lines • 6.96 kB
JavaScript
var _excluded=["type"];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 _objectWithoutProperties(e,t){if(null==e)return{};var o,r,i=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(r=0;r<n.length;r++)o=n[r],-1===t.indexOf(o)&&{}.propertyIsEnumerable.call(e,o)&&(i[o]=e[o])}return i}function _objectWithoutPropertiesLoose(r,e){if(null==r)return{};var t={};for(var n in r)if({}.hasOwnProperty.call(r,n)){if(-1!==e.indexOf(n))continue;t[n]=r[n]}return t}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)}/**
* 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 isEmpty from"lodash.isempty";import{CHANGE_MAP_VIEW,CONFIGURE_MAP,CHANGE_ZOOM_LVL,ZOOM_TO_EXTENT,ZOOM_TO_POINT,PAN_TO,CHANGE_ROTATION,CLICK_ON_MAP,TOGGLE_MAPTIPS,SET_DISPLAY_CRS,SET_TOPBAR_HEIGHT,SET_BOTTOMBAR_HEIGHT,SET_SNAPPING_CONFIG}from"../actions/map";import ConfigUtils from"../utils/ConfigUtils";import CoordinatesUtils from"../utils/CoordinatesUtils";import MapUtils from"../utils/MapUtils";import{UrlParams}from"../utils/PermaLinkUtils";var defaultState={bbox:{bounds:[0,0,0,0],rotation:0},center:[0,0],dpi:MapUtils.DEFAULT_SCREEN_DPI,projection:"EPSG:3857",displayCrs:"EPSG:3857",zoom:0,scales:[0],resolutions:[0],topbarHeight:0,bottombarHeight:0,click:null,snapping:{enabled:false,active:false}};export default function map(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;// Always reset mapStateSource, CHANGE_MAP_VIEW will set it if necessary
if(state.mapStateSource){state=_objectSpread(_objectSpread({},state),{},{mapStateSource:null})}switch(action.type){case CHANGE_MAP_VIEW:{// eslint-disable-next-line
var type=action.type,params=_objectWithoutProperties(action,_excluded);var newState=_objectSpread(_objectSpread({},state),params);var newParams={};var positionFormat=ConfigUtils.getConfigProp("urlPositionFormat");var positionCrs=ConfigUtils.getConfigProp("urlPositionCrs")||newState.projection;var prec=CoordinatesUtils.getPrecision(positionCrs);if(positionFormat==="centerAndZoom"){var center=CoordinatesUtils.reproject(newState.center,newState.projection,positionCrs);var scale=Math.round(MapUtils.computeForZoom(newState.scales,newState.zoom));Object.assign(newParams,{c:center.map(function(x){return x.toFixed(prec)}).join(","),s:scale})}else{var bounds=CoordinatesUtils.reprojectBbox(newState.bbox.bounds,newState.projection,positionCrs);Object.assign(newParams,{e:bounds.map(function(x){return x.toFixed(prec)}).join(",")})}if(positionCrs!==newState.projection){Object.assign(newParams,{crs:positionCrs})}if(!isEmpty(newParams)){UrlParams.updateParams(newParams)}return newState}case CONFIGURE_MAP:{var resolutions=MapUtils.getResolutionsForScales(action.scales,action.crs,state.dpi);var _bounds;var _center;var zoom;if(action.view.center){_center=CoordinatesUtils.reproject(action.view.center,action.view.crs||action.crs,action.crs);zoom=action.view.zoom;_bounds=MapUtils.getExtentForCenterAndZoom(_center,zoom,resolutions,state.size)}else{_bounds=CoordinatesUtils.reprojectBbox(action.view.bounds,action.view.crs||state.projection,action.crs);_center=[0.5*(_bounds[0]+_bounds[2]),0.5*(_bounds[1]+_bounds[3])];zoom=MapUtils.getZoomForExtent(_bounds,resolutions,state.size,0,action.scales.length-1)}return _objectSpread(_objectSpread({},state),{},{bbox:_objectSpread(_objectSpread({},state.bbox),{},{bounds:_bounds}),center:_center,zoom:zoom,projection:action.crs,displayCrs:action.crs,scales:action.scales,resolutions:resolutions})}case CHANGE_ZOOM_LVL:{return _objectSpread(_objectSpread({},state),{},{zoom:action.zoom})}case ZOOM_TO_EXTENT:{var _bounds2=CoordinatesUtils.reprojectBbox(action.extent,action.crs||state.projection,state.projection);var padding=(state.topbarHeight+10)/state.size.height;var width=_bounds2[2]-_bounds2[0];var height=_bounds2[3]-_bounds2[1];_bounds2[0]-=padding*width;_bounds2[2]+=padding*width;_bounds2[1]-=padding*height;_bounds2[3]+=padding*height;return _objectSpread(_objectSpread({},state),{},{center:[0.5*(_bounds2[0]+_bounds2[2]),0.5*(_bounds2[1]+_bounds2[3])],zoom:MapUtils.getZoomForExtent(_bounds2,state.resolutions,state.size,0,state.scales.length-1)+action.zoomOffset,bbox:_objectSpread(_objectSpread({},state.bbox),{},{bounds:_bounds2})})}case ZOOM_TO_POINT:{return _objectSpread(_objectSpread({},state),{},{center:CoordinatesUtils.reproject(action.pos,action.crs||state.projection,state.projection),zoom:action.zoom})}case PAN_TO:{return _objectSpread(_objectSpread({},state),{},{center:CoordinatesUtils.reproject(action.pos,action.crs||state.projection,state.projection)})}case CHANGE_ROTATION:{return _objectSpread(_objectSpread({},state),{},{bbox:_objectSpread(_objectSpread({},state.bbox),{},{rotation:action.rotation})})}case CLICK_ON_MAP:{return _objectSpread(_objectSpread({},state),{},{click:action.click})}case TOGGLE_MAPTIPS:{return _objectSpread(_objectSpread({},state),{},{maptips:action.active})}case SET_TOPBAR_HEIGHT:{return _objectSpread(_objectSpread({},state),{},{topbarHeight:action.height})}case SET_BOTTOMBAR_HEIGHT:{return _objectSpread(_objectSpread({},state),{},{bottombarHeight:action.height})}case SET_SNAPPING_CONFIG:{return _objectSpread(_objectSpread({},state),{},{snapping:{enabled:action.enabled,active:action.active}})}case SET_DISPLAY_CRS:{return _objectSpread(_objectSpread({},state),{},{displayCrs:action.displayCrs})}default:return state}}