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

Add Customizable layer origin for ol3 wms Fix #1184 #1186

Merged
merged 2 commits into from
Oct 27, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions web/client/components/map/openlayers/__tests__/Layer-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ describe('Openlayers layer', () => {
<OpenlayersLayer type="wms"
options={options} map={map}/>, document.getElementById("container"));


expect(layer).toExist();
// count layers
expect(map.getLayers().getLength()).toBe(1);
Expand All @@ -184,13 +183,34 @@ describe('Openlayers layer', () => {
<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().urls.length).toBe(2);
});

it('creates a wms layer with custom origin', () => {
var options = {
"type": "wms",
"visibility": true,
"name": "nurc:Arc_Sample",
"group": "Meteo",
"format": "image/png",
"origin": [0, 0],
"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).getSource().getTileGrid().getOrigin()).toEqual([0, 0]);
});

it('creates a wms layer with proxy for openlayers map', () => {
var options = {
"type": "wms",
Expand Down
16 changes: 10 additions & 6 deletions web/client/components/map/openlayers/plugins/WMSLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const CoordinatesUtils = require('../../../../utils/CoordinatesUtils');
const ProxyUtils = require('../../../../utils/ProxyUtils');
const {isArray} = require('lodash');
const SecurityUtils = require('../../../../utils/SecurityUtils');

const mapUtils = require('../../../../utils/MapUtils');

function wmsToOpenlayersOptions(options) {
// NOTE: can we use opacity to manage visibility?
Expand Down Expand Up @@ -44,7 +44,7 @@ function proxyTileLoadFunction(imageTile, src) {
}

Layers.registerType('wms', {
create: (options) => {
create: (options, map) => {
const urls = getWMSURLs(isArray(options.url) ? options.url : [options.url]);
const queryParameters = wmsToOpenlayersOptions(options) || {};
urls.forEach(url => SecurityUtils.addAuthenticationParameter(url, queryParameters));
Expand All @@ -59,17 +59,21 @@ Layers.registerType('wms', {
})
});
}
const mapSrs = map && map.getView() && map.getView().getProjection() && map.getView().getProjection().getCode() || 'EPSG:3857';
const extent = ol.proj.get(CoordinatesUtils.normalizeSRS(options.srs || mapSrs, options.allowedSRS)).getExtent();
return new ol.layer.Tile({
opacity: options.opacity !== undefined ? options.opacity : 1,
visible: options.visibility !== false,
zIndex: options.zIndex,
source: new ol.source.TileWMS(objectAssign({
urls: urls,
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
tileGrid: new ol.tilegrid.TileGrid({
extent: extent,
resolutions: mapUtils.getResolutions(),
tileSize: options.tileSize ? options.tileSize : 256,
origin: options.origin ? options.origin : [extent[0], extent[1]]
})
}, (options.forceProxy) ? {tileLoadFunction: proxyTileLoadFunction} : {}))
});
},
Expand Down