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

Create layers using custom options metadata #4092

Merged
merged 1 commit into from
Aug 6, 2018
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
6 changes: 4 additions & 2 deletions contribs/gmf/src/theme/Themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ exports.prototype.getBgLayers = function() {
gmfLayerWMTS.url,
gmfLayerWMTS.layer || '',
gmfLayerWMTS.matrixSet,
gmfLayer.dimensions
gmfLayer.dimensions,
gmfLayerWMTS.metadata.customOpenLayersOptions
).then(callback.bind(null, gmfLayer)).then(null, (response) => {
let message = `Unable to build layer "${gmfLayerWMTS.layer}" from WMTSCapabilities: ${gmfLayerWMTS.url}\n`;
message += `OpenLayers error is "${response['message']}`;
Expand All @@ -290,7 +291,8 @@ exports.prototype.getBgLayers = function() {
server.type,
undefined, // time
gmfLayer.dimensions,
server.credential ? 'use-credentials' : 'anonymous'
server.credential ? 'use-credentials' : 'anonymous',
gmfLayerWMS.metadata.customOpenLayersOptions
));
}
googAsserts.fail(`Unsupported type: ${gmfLayer.type}`);
Expand Down
14 changes: 8 additions & 6 deletions src/map/LayerHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ exports.REFRESH_PARAM = 'random';
* @param {string=} opt_time time parameter for layer queryable by time/periode
* @param {Object.<string, string>=} opt_params WMS parameters.
* @param {string=} opt_crossOrigin crossOrigin.
* @param {Object=} opt_customOptions Some initial options.
* @return {ol.layer.Image} WMS Layer.
* @export
*/
exports.prototype.createBasicWMSLayer = function(sourceURL,
sourceLayersName, sourceFormat, opt_serverType, opt_time, opt_params, opt_crossOrigin) {
sourceLayersName, sourceFormat, opt_serverType, opt_time, opt_params, opt_crossOrigin, opt_customOptions) {

const params = {
'FORMAT': sourceFormat,
Expand All @@ -92,12 +93,13 @@ exports.prototype.createBasicWMSLayer = function(sourceURL,
// OpenLayers expects 'qgis' insteads of 'qgisserver'
olServerType = opt_serverType.replace('qgisserver', 'qgis');
}
const source = new olSourceImageWMS({
const options = Object.assign({}, opt_customOptions, {
url: sourceURL,
params: params,
serverType: olServerType,
crossOrigin: opt_crossOrigin
});
const source = new olSourceImageWMS(options);
if (opt_params) {
source.updateParams(opt_params);
}
Expand Down Expand Up @@ -156,11 +158,12 @@ exports.prototype.createBasicWMSLayerFromDataSource = function(
* @param {string} layerName The name of the layer.
* @param {string=} opt_matrixSet Optional WMTS matrix set.
* @param {Object.<string, string>=} opt_dimensions WMTS dimensions.
* @param {Object=} opt_customOptions Some initial options.
* @return {angular.$q.Promise.<ol.layer.Tile>} A Promise with a layer (with source) on success,
* no layer else.
* @export
*/
exports.prototype.createWMTSLayerFromCapabilitites = function(capabilitiesURL, layerName, opt_matrixSet, opt_dimensions) {
exports.prototype.createWMTSLayerFromCapabilitites = function(capabilitiesURL, layerName, opt_matrixSet, opt_dimensions, opt_customOptions) {
const parser = new olFormatWMTSCapabilities();
const layer = new olLayerTile({
preload: this.tilesPreloadingLimit_
Expand All @@ -173,12 +176,11 @@ exports.prototype.createWMTSLayerFromCapabilitites = function(capabilitiesURL, l
result = parser.read(response.data);
}
if (result) {
const options = optionsFromCapabilities(result, {
const options = Object.assign({}, opt_customOptions, optionsFromCapabilities(result, {
matrixSet: opt_matrixSet,
crossOrigin: 'anonymous',
layer: layerName
});
googAsserts.assert(options);
}));
const source = new olSourceWMTS(/** @type {olx.source.WMTSOptions} */ (options));
if (opt_dimensions && !olObj.isEmpty(opt_dimensions)) {
source.updateDimensions(opt_dimensions);
Expand Down