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

[backport 2.4] Translate layers names in API layer switcher #5123

Merged
merged 2 commits into from
Sep 18, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ serve-gmf: .build/node_modules.timestamp $(ANGULAR_LOCALES_FILES)
serve-gmf-apps: .build/node_modules.timestamp $(ANGULAR_LOCALES_FILES)
npm run serve-gmf-apps

.PHONY: serve-api
serve-api:
npm run serve-api

.PHONY: examples-hosted
examples-hosted: \
examples-hosted-ngeo \
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ then visit them using
https://localhost:3000/contribs/gmf/apps/<app_name>.html, for example:
https://localhost:3000/contribs/gmf/apps/desktop.html


### Run the Simple API Help

To run the Simple API Help:

```
make serve-api
```

Then visit https://localhost:3000/apihelp.html

### Go further

* [Developer guide](docs/developer-guide.md) – This guide is for ngeo developers.
Expand Down
2 changes: 2 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Map from './src/Map.js';
config.themesUrl = 'https://geomapfish-demo-2-4.camptocamp.com/themes?' +
'version=2&background=background&interface=api';

config.localeUrl = 'https://geomapfish-demo-2-4.camptocamp.com/locale.json';

const lib = {
Map
};
Expand Down
36 changes: 32 additions & 4 deletions api/src/Themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ function getThemesPromise() {
return themesPromise;
}

/**
* @type {Promise<Object<string, string>>} Promise
* @hidden
*/
let localePromise;

/**
* @hidden
* @return {Promise<Object<string, string>>} Promise
*/
function getLocalePromise() {
if (!constants.localeUrl) {
// Fallback to an empty dict
return Promise.resolve({});
}
if (!localePromise) {
localePromise = fetch(constants.localeUrl).then(response => response.json()).then(data =>
// Return the first property as data should looks like { 'fr': { ... } }
data[Object.keys(data)[0]]
);
}
return localePromise;
}

/**
* @type {Promise<Map<string, overlayDefinition>>|undefined}
* @hidden
Expand Down Expand Up @@ -196,9 +220,11 @@ export function createWMSLayer(config, ogcServer) {
minResolution: config.minResolutionHint,
maxResolution: config.maxResolutionHint
});
layer.set('title', config.name);
layer.set('config.name', config.name);
return Promise.resolve(layer);
return getLocalePromise().then(translations => {
layer.set('title', translations[config.name] || config.name);
return layer;
});
}

/**
Expand All @@ -207,7 +233,9 @@ export function createWMSLayer(config, ogcServer) {
* @hidden
*/
export function createWMTSLayer(config) {
return getWMTSCapability(config.url).then((capability) => {
return Promise.all([getLocalePromise(), getWMTSCapability(config.url)]).then(result => {
const translations = result[0];
const capability = result[1];
const options = optionsFromCapabilities(capability, {
crossOrigin: 'anonymous',
layer: config.layer,
Expand All @@ -219,7 +247,7 @@ export function createWMTSLayer(config) {
preload: Infinity,
source: source
});
layer.set('title', config.name);
layer.set('title', translations[config.name] || config.name);
layer.set('config.name', config.name);
return layer;
});
Expand Down
2 changes: 2 additions & 0 deletions api/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import EPSG21781 from '@geoblocks/proj/src/EPSG_21781.js';

export default {
themesUrl: undefined,
localeUrl: undefined,

projection: EPSG21781,
resolutions: [250, 100, 50, 20, 10, 5, 2, 1, 0.5, 0.25, 0.1, 0.05],
extent: undefined,
Expand Down