From e55b4d0d8f9adfd9dc9d5c7b3ba87d033d065397 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 3 May 2019 09:00:22 +0200 Subject: [PATCH] Make constants.extent optional in the API --- api/src/Map.js | 23 +++++++++++++---------- api/src/constants.js | 26 +++++++++++++++++--------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/api/src/Map.js b/api/src/Map.js index d5754d0e4ab7..c4089a6c8175 100644 --- a/api/src/Map.js +++ b/api/src/Map.js @@ -42,6 +42,17 @@ import * as themes from './Themes.js'; * @property {string} [icon] */ +/** + * @typedef {Object} MapOptions + * @property {string} div + * @property {import("ol/coordinate.js").Coordinate} center + * @property {number} [zoom=10] + * @property {boolean} [showCoords=true] + * @property {boolean} [addMiniMap=false] + * @property {boolean} [miniMapExpanded=true] + * @property {boolean} [addLayerSwitcher=false] + * @property {Array} [layers] + */ /** * @private @@ -50,17 +61,9 @@ import * as themes from './Themes.js'; class Map { /** - * @param {Object} options API options. - * @property {string} div - * @property {import("ol/coordinate.js").Coordinate} center - * @property {number} [zoom=10] - * @property {boolean} [showCoords=true] - * TODO: more options + * @param {MapOptions} options API options. */ constructor(options) { - if (!constants.extent) { - throw new Error('Missing extent'); - } /** * @private * @type {View} @@ -74,7 +77,7 @@ class Map { if (options.center !== undefined) { this.view_.setCenter(options.center); - } else if (constants.extent !== undefined) { + } else if (constants.extent) { this.view_.setCenter(getCenter(constants.extent)); } diff --git a/api/src/constants.js b/api/src/constants.js index 04ccac60a33c..0b285f1dd71d 100644 --- a/api/src/constants.js +++ b/api/src/constants.js @@ -6,18 +6,26 @@ import EPSG21781 from '@geoblocks/proj/src/EPSG_21781.js'; * @property {?string} themesUrl * @property {string} projection * @property {Array} resolutions - * @property {?[number, number, number, number]} extent + * @property {[number, number, number, number]} [extent] * @property {string} backgroundLayer */ -export default /** @type {APIConfig} */({ - themesUrl: null, +export default { + // The URL to the themes service. + themesUrl: 'https://www.example.com', + + // The projection of the map projection: EPSG21781, + + // The resolutions list. resolutions: [250, 100, 50, 20, 10, 5, 2, 1, 0.5, 0.25, 0.1, 0.05], - extent: null, - /** - * The name of the layer to use as background. May be a single value - * (WMTS) or a comma-separated list of layer names (WMS). - */ + + // The extent restriction, must be in the same projection as `config.projection`. + // the format is `[minx, miny, maxx, maxy]`for example: `[420000, 30000, 660000, 350000]` + // the default is ǹo restriction. + // extent: undefined, + + // The name of the GeoMapFish layer to use as background. May be a single value + // (WMTS) or a comma-separated list of layer names (WMS). backgroundLayer: 'orthophoto', -}); +};