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

Fix #1304 Implemented WMTS on OpenLayers #1341

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
64 changes: 64 additions & 0 deletions web/client/components/map/openlayers/plugins/WMTSLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Copyright 2015, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

var Layers = require('../../../../utils/openlayers/Layers');
var ol = require('openlayers');
var objectAssign = require('object-assign');
const CoordinatesUtils = require('../../../../utils/CoordinatesUtils');
const {isArray} = require('lodash');
const SecurityUtils = require('../../../../utils/SecurityUtils');
const mapUtils = require('../../../../utils/MapUtils');

function wmtsToOpenlayersOptions(options) {
// NOTE: can we use opacity to manage visibility?
return objectAssign({}, options.baseParams, {
LAYERS: options.name,
STYLES: options.style || "",
FORMAT: options.format || 'image/png',
TRANSPARENT: options.transparent !== undefined ? options.transparent : true,
SRS: CoordinatesUtils.normalizeSRS(options.srs || 'EPSG:3857', options.allowedSRS),
CRS: CoordinatesUtils.normalizeSRS(options.srs || 'EPSG:3857', options.allowedSRS),
TILED: options.tiled || false,
VERSION: options.version || "1.3.0"
}, options.params || {});
}

function getWMSURLs( urls ) {
return urls.map((url) => url.split("\?")[0]);
}

Layers.registerType('wmts', {
create: (options) => {
const urls = getWMSURLs(isArray(options.url) ? options.url : [options.url]);
const queryParameters = wmtsToOpenlayersOptions(options) || {};
var projection = ol.proj.get('EPSG:900913');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the srs in options, not a fixed 900913

urls.forEach(url => SecurityUtils.addAuthenticationParameter(url, queryParameters));
let projectionExtent = projection.getExtent();
let matrixIds = new Array(22);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tile matrix zoom levels are not 22 everywhere. Even when auto-generation is used, the list of resolutions and matrixIds can be variable. In general we should follow the information from WMTS.
Keep in mind these 2 examples:

As you see the identifier and the list are not the same.

for (let z = 0; z < 22; ++z) {
// generate matrixIds arrays for this WMTS
matrixIds[z] = options.tileMatrixPrefix + z;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a list of matrixIds as a configuration option. In the future it have to be populated checking the catalog. If the list is not present in configuration, this autogeneration method can be the solution.

}
return new ol.layer.Tile({
opacity: options.opacity !== undefined ? options.opacity : 1,
source: new ol.source.WMTS(objectAssign({
urls: urls,
layer: options.name,
matrixSet: options.tileMatrixSet,
format: 'image/png',
tileGrid: new ol.tilegrid.WMTS({
origin: ol.extent.getTopLeft(projectionExtent),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider using originX and originY options as we do for leaflet

resolutions: mapUtils.getResolutions(),
matrixIds: matrixIds
}),
style: '',
wrapX: true
}))
});
}
});
3 changes: 2 additions & 1 deletion web/client/components/map/openlayers/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ module.exports = {
OverlayLayer: require('./OverlayLayer'),
TileProviderLayer: require('./TileProviderLayer'),
VectorLayer: require('./VectorLayer'),
WMSLayer: require('./WMSLayer')
WMSLayer: require('./WMSLayer'),
WMTSLayer: require('./WMTSLayer')
};
19 changes: 19 additions & 0 deletions web/client/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@
"crs": "EPSG:4326"
}
},
{
"type": "wmts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this layer from default configuration

"url":"http://demo.geo-solutions.it/geoserver/gwc/service/wmts?",
"visibility": true,
"opacity": 1,
"title": "WMTS sample",
"name": "sf:archsites_hidden",
"group": "Meteo",
"tileSize":"",
"matrixIds": "EPSG:900913:",
"tileMatrixPrefix": "EPSG:900913:",
"tileMatrixSet": "EPSG:900913",
"minx":20037508.3428,
"maxx":-20037508.3428,
"bbox": {
"bounds": {"minx": -25.6640625, "miny": 26.194876675795218, "maxx": 48.1640625, "maxy": 56.80087831233043},
"crs": "EPSG:4326"
}
},
{
"type": "tileprovider",
"title": "OpenTopoMap",
Expand Down