-
Notifications
You must be signed in to change notification settings - Fork 416
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
Changes from 1 commit
bb36feb
791e957
0a109e3
ff98527
08712b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'); | ||
urls.forEach(url => SecurityUtils.addAuthenticationParameter(url, queryParameters)); | ||
let projectionExtent = projection.getExtent(); | ||
let matrixIds = new Array(22); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
})) | ||
}); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,25 @@ | |
"crs": "EPSG:4326" | ||
} | ||
}, | ||
{ | ||
"type": "wmts", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
There was a problem hiding this comment.
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