Skip to content

Commit

Permalink
Fixes geosolutions-it#2741: set openlayers single tile wms layers def…
Browse files Browse the repository at this point in the history
…ault ratio to 1
  • Loading branch information
mbarto committed Mar 14, 2018
1 parent 6d3cab6 commit 66e28f8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
62 changes: 62 additions & 0 deletions web/client/components/map/openlayers/__tests__/Layer-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,68 @@ describe('Openlayers layer', () => {
expect(map.getLayers().item(0).getSource().urls.length).toBe(1);
});

it('creates a single tile wms layer for openlayers map', () => {
var options = {
"type": "wms",
"visibility": true,
"name": "nurc:Arc_Sample",
"group": "Meteo",
"format": "image/png",
"singleTile": true,
"url": "http://sample.server/geoserver/wms"
};
// create layers
var layer = ReactDOM.render(
<OpenlayersLayer type="wms"
options={options} map={map} />, document.getElementById("container"));

expect(layer).toExist();
// count layers
expect(map.getLayers().getLength()).toBe(1);
expect(map.getLayers().item(0).getSource().getUrl()).toExist();
});

it('creates a single tile wms layer for openlayers map ratio', (done) => {
var options = {
"type": "wms",
"visibility": true,
"name": "nurc:Arc_Sample",
"group": "Meteo",
"format": "image/png",
"singleTile": true,
"url": "http://sample.server/geoserver/wms"
};
// create layers
var layer = ReactDOM.render(
<OpenlayersLayer type="wms"
options={options} map={map} />, document.getElementById("container"));

expect(layer).toExist();
// count layers
expect(map.getLayers().getLength()).toBe(1);
expect(map.getLayers().item(0).getSource().getUrl()).toExist();
let width = 0;
const loadFun = (image, src) => {
if (width === 0) {
width = parseInt(src.match(/WIDTH=([0-9]+)/i)[1], 10);
layer = ReactDOM.render(
<OpenlayersLayer type="wms"
options={assign({}, options, {
ratio: 2
})} map={map} />, document.getElementById("container"));
map.getLayers().item(0).getSource().setImageLoadFunction(loadFun);
map.getLayers().item(0).getSource().refresh();
} else {
const oldWidth = width;
width = parseInt(src.match(/WIDTH=([0-9]+)/i)[1], 10);
expect(oldWidth !== width).toBe(true);
done();
}
};
map.getLayers().item(0).getSource().setImageLoadFunction(loadFun);
map.getLayers().item(0).getSource().refresh();
});

it('creates a wmts layer for openlayers map', () => {
var options = {
"type": "wmts",
Expand Down
7 changes: 4 additions & 3 deletions web/client/components/map/openlayers/plugins/WMSLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Layers.registerType('wms', {
source: new ol.source.ImageWMS({
url: urls[0],
params: queryParameters,
ratio: options.ratio
ratio: options.ratio || 1
})
});
}
Expand Down Expand Up @@ -124,7 +124,7 @@ Layers.registerType('wms', {
if (changed) {
layer.getSource().updateParams(objectAssign(newParams, newOptions.params));
}
if (oldOptions.singleTile !== newOptions.singleTile || oldOptions.securityToken !== newOptions.securityToken) {
if (oldOptions.singleTile !== newOptions.singleTile || oldOptions.securityToken !== newOptions.securityToken || oldOptions.ratio !== newOptions.ratio) {
const urls = getWMSURLs(isArray(newOptions.url) ? newOptions.url : [newOptions.url]);
const queryParameters = wmsToOpenlayersOptions(newOptions) || {};
urls.forEach(url => SecurityUtils.addAuthenticationParameter(url, queryParameters, newOptions.securityToken));
Expand All @@ -137,7 +137,8 @@ Layers.registerType('wms', {
zIndex: newOptions.zIndex,
source: new ol.source.ImageWMS({
url: urls[0],
params: queryParameters
params: queryParameters,
ratio: newOptions.ratio || 1
})
});
} else {
Expand Down

0 comments on commit 66e28f8

Please sign in to comment.