Skip to content

Commit

Permalink
Fixes #1005: customizable tilesize for WMS layers in OL3 and Leaflet
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto committed Oct 10, 2016
1 parent cb2d38a commit 1b63007
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
25 changes: 25 additions & 0 deletions web/client/components/map/leaflet/__tests__/Layer-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,31 @@ describe('Leaflet layer', () => {
expect(urls.length).toBe(1);
});

it('creates a wms layer for leaflet map with custom tileSize', () => {
var options = {
"type": "wms",
"visibility": true,
"name": "nurc:Arc_Sample",
"group": "Meteo",
"format": "image/png",
"tileSize": 512,
"url": "http://demo.geo-solutions.it/geoserver/wms"
};
// create layers
var layer = ReactDOM.render(
<LeafLetLayer type="wms"
options={options} map={map}/>, document.getElementById("container"));
var lcount = 0;

expect(layer).toExist();
// count layers
map.eachLayer(function() {lcount++; });
expect(lcount).toBe(1);
let width;
map.eachLayer((l) => width = l.wmsParams.width);
expect(width).toBe(512);
});

it('creates a wms layer with multiple urls for leaflet map', () => {
var options = {
"type": "wms",
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/map/leaflet/plugins/WMSLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ function wmsToLeafletOptions(options) {
opacity: opacity,
version: options.version || "1.3.0",
SRS: CoordinatesUtils.normalizeSRS(options.srs || 'EPSG:3857', options.allowedSRS),
CRS: CoordinatesUtils.normalizeSRS(options.srs || 'EPSG:3857', options.allowedSRS)
CRS: CoordinatesUtils.normalizeSRS(options.srs || 'EPSG:3857', options.allowedSRS),
tileSize: options.tileSize || 256
}, options.params || {});
}

Expand Down
22 changes: 22 additions & 0 deletions web/client/components/map/openlayers/__tests__/Layer-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,28 @@ describe('Openlayers layer', () => {
expect(map.getLayers().item(0).getSource().urls.length).toBe(1);
});

it('creates a wms layer for openlayers map with custom tileSize', () => {
var options = {
"type": "wms",
"visibility": true,
"name": "nurc:Arc_Sample",
"group": "Meteo",
"format": "image/png",
"tileSize": 512,
"url": "http://demo.geo-solutions.it/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).getProperties().source.getTileGrid().getTileSize()).toBe(512);
});

it('creates a wms layer with multiple urls for openlayers map', () => {
var options = {
"type": "wms",
Expand Down
6 changes: 5 additions & 1 deletion web/client/components/map/openlayers/plugins/WMSLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ Layers.registerType('wms', {
zIndex: options.zIndex,
source: new ol.source.TileWMS(objectAssign({
urls: urls,
params: queryParameters
params: queryParameters,
tileGrid: options.tileSize ? ol.tilegrid.createXYZ({
extent: ol.proj.get(CoordinatesUtils.normalizeSRS(options.srs || 'EPSG:3857', options.allowedSRS)).getExtent(),
tileSize: options.tileSize
}) : undefined
}, (options.forceProxy) ? {tileLoadFunction: proxyTileLoadFunction} : {}))
});
},
Expand Down

0 comments on commit 1b63007

Please sign in to comment.