Skip to content

Commit

Permalink
Make constants.extent optional in the API
Browse files Browse the repository at this point in the history
  • Loading branch information
fredj committed May 3, 2019
1 parent 7335403 commit e55b4d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
23 changes: 13 additions & 10 deletions api/src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} [layers]
*/

/**
* @private
Expand All @@ -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}
Expand All @@ -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));
}

Expand Down
26 changes: 17 additions & 9 deletions api/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@ import EPSG21781 from '@geoblocks/proj/src/EPSG_21781.js';
* @property {?string} themesUrl
* @property {string} projection
* @property {Array<number>} 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',
});
};

0 comments on commit e55b4d0

Please sign in to comment.