Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make constants.extent optional in the API #4870

Merged
merged 1 commit into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
});
};