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

[wip] Lint API code #4404

Merged
merged 2 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ANGULAR_VERSION := $(shell buildtools/get-version.sh angular)
ESLINT_CONFIG_FILES := $(shell find * -not -path 'node_modules/*' -type f -name '.eslintrc*')
WEBPACK_CONFIG_FILES := $(shell find . -not -path './node_modules/*' -name 'webpack.*.js')

API_JS_FILES = $(shell find api/src/ -type f -name '*.js')
NGEO_JS_FILES = $(shell find src/ -type f -name '*.js')
NGEO_PARTIALS_FILES := $(shell find src/ -name '*.html')
NGEO_ALL_SRC_FILES := $(shell find src/ -type f)
Expand Down Expand Up @@ -211,6 +212,7 @@ gh-pages: .build/python-venv.timestamp
buildtools/deploy.sh

.build/eslint.timestamp: .build/node_modules.timestamp $(ESLINT_CONFIG_FILES) \
$(API_JS_FILES) \
$(NGEO_JS_FILES) \
$(NGEO_TEST_JS_FILES) \
$(NGEO_EXAMPLES_JS_FILES) \
Expand Down
30 changes: 16 additions & 14 deletions api/src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import EPSG2056 from '@geoblocks/sources/EPSG2056.js';
class Map {

/**
* @param {Object} options
* @param {Object} options API options.
* @property {string} div
* @property {ol.Coordinate} center
* @property {number} [zoom=10]
Expand Down Expand Up @@ -135,7 +135,7 @@ class Map {

/**
* @private
* @return {HTMLElement}
* @return {HTMLElement} overlay container element.
*/
createOverlayDomTree_() {
const overlayContainer = document.createElement('div');
Expand All @@ -156,16 +156,16 @@ class Map {
}

/**
* @param {ol.Coordinate} center
* @param {number} zoom
* @param {ol.Coordinate} center Center.
* @param {number} zoom Zoom.
*/
recenter(center, zoom) {
this.view_.setCenter(center);
this.view_.setZoom(zoom);
}

/**
* @param {Object} options
* @param {Object} options Options.
* @property {ol.Coordinate} position
* @property {string} [icon]
* @property {ol.Size} [size]
Expand Down Expand Up @@ -219,16 +219,16 @@ class Map {

/**
* @param {string} type Layer type, only 'text' format is supported.
* @param {string} name
* @param {string} url
* @param {Object} [options]
* @param {string} name Name.
* @param {string} url URL.
* @param {Object} [options] Options
* @property {Array.<string>} [attr=['title', 'description']]
* @property {function()} [success]
* @property {function()} [error]
*/
addCustomLayer(type, name, url, options = {}) {
fetch(url)
.then((response) => response.text())
.then(response => response.text())
.then((text) => {
const attr = options.attr || ['title', 'description'];
const lines = text.split(/\r\n|\r|\n/);
Expand Down Expand Up @@ -266,7 +266,7 @@ class Map {
}

/**
* @param {string} id
* @param {string} id Identifier.
*/
selectObject(id) {
const feature = this.vectorSource_.getFeatureById(id);
Expand All @@ -286,8 +286,9 @@ class Map {


/**
* @param {Array.<string>} keys
* @param {Array.<*>} values
* @param {Array.<string>} keys Keys.
* @param {Array.<*>} values Values.
* @returns {Object<string, *>} Object.
*/
function zip(keys, values) {
const obj = {};
Expand All @@ -299,8 +300,9 @@ function zip(keys, values) {


/**
* @param {Object.<string, *>} obj
* @param {Array.<string>} keys
* @param {Object.<string, *>} obj Object.
* @param {Array.<string>} keys keys.
* @returns {Object<string, *>} Object.
*/
function filterByKeys(obj, keys) {
const filtered = {};
Expand Down
20 changes: 8 additions & 12 deletions api/src/Querent.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export function getFeaturesFromLayer(layer, ids) {
return;
}

const featureIds = ids.map((id) => {
return `${layer}.${id}`;
});
const featureIds = ids.map(id => `${layer}.${id}`);

const params = {
'FEATUREID': featureIds.join(','),
Expand All @@ -54,15 +52,13 @@ export function getFeaturesFromLayer(layer, ids) {
const url = olUriAppendParams(overlayDef.ogcServer.urlWfs, params);

fetch(url)
.then((response) => {
return response.text().then((responseText) => {
const wfsFormat = new olFormatWFS({
featureNS: overlayDef.ogcServer.namespace,
gmlFormat: new olFormatGML2()
});
features = wfsFormat.readFeatures(responseText);
.then(response => response.text().then((responseText) => {
const wfsFormat = new olFormatWFS({
featureNS: overlayDef.ogcServer.namespace,
gmlFormat: new olFormatGML2()
});
})
features = wfsFormat.readFeatures(responseText);
}))
.catch((response) => {
console.error(`WFS GetFeature request failed, response: ${response}`);
})
Expand All @@ -71,4 +67,4 @@ export function getFeaturesFromLayer(layer, ids) {
});
});
});
};
}
24 changes: 12 additions & 12 deletions api/src/Themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as constants from './constants.js';
/**
* @type {Promise}
*/
const themesPromise = fetch(constants.themesUrl).then((response) => response.json());
const themesPromise = fetch(constants.themesUrl).then(response => response.json());

/**
* @type {Promise|undefined}
Expand Down Expand Up @@ -40,7 +40,7 @@ export function getBackgroundLayers() {
}
return Promise.all(promises);
});
};
}

const overlayDefs = new Map();

Expand All @@ -53,14 +53,14 @@ export function getOverlayDefs() {
}
resolve(overlayDefs);
});
})
});
}
return overlayDefPromise;
};
}

export function writeOverlayDefs(config, ogcServers, opt_ogcServer) {
const ogcServer = opt_ogcServer ?
opt_ogcServer:
opt_ogcServer :
config.ogcServer ? ogcServers[config.ogcServer] : undefined;
if (config.children) {
for (const childConfig of config.children) {
Expand All @@ -75,7 +75,7 @@ export function writeOverlayDefs(config, ogcServers, opt_ogcServer) {
}
);
}
};
}

/**
* Returns a list of OpenLayers layer objects from the given layer names.
Expand All @@ -91,7 +91,7 @@ export function getOverlayLayers(layerNames) {
const overlayDef = overlayDefs.get(layerName);

if (!overlayDef) {
console.error(`Layer not found in themes: ${layerName}`)
console.error(`Layer not found in themes: ${layerName}`);
continue;
}

Expand All @@ -109,7 +109,7 @@ export function getOverlayLayers(layerNames) {
}
return Promise.all(promises);
});
};
}

/**
* @param {Object} config Layer config (i.e. gmf layer node)
Expand All @@ -128,7 +128,7 @@ export function createWMSLayer(config, ogcServer) {
})
})
);
};
}

/**
* @param {Object} config Layer config (i.e. gmf layer node)
Expand All @@ -148,15 +148,15 @@ export function createWMTSLayer(config) {
source: source
});
return layer;
})
};
});
}

const capabilities = new Map();

function getWMTSCapability(url) {
if (!(url in capabilities)) {
const request = fetch(url)
.then((response) => response.text())
.then(response => response.text())
.then((capability) => {
const parser = new WMTSCapabilities();
return parser.read(capability);
Expand Down
2 changes: 1 addition & 1 deletion api/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const resolutions = [250, 100, 50, 20, 10, 5, 2, 1, 0.5, 0.25, 0.1, 0.05]
/**
* @type {Array.<number>}
*/
export const extent = [420000, 30000, 660000, 350000];
export const extent = [420000, 30000, 660000, 350000];


/**
Expand Down