Skip to content

Commit

Permalink
Merge f3c64b0 into 5ca7bd5
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVolland committed Sep 4, 2018
2 parents 5ca7bd5 + f3c64b0 commit e8445db
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
11 changes: 7 additions & 4 deletions src/MapUtil/MapUtil.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import OlMap from 'ol/map';
import OlProjection from 'ol/proj';
import OlSourceTileWMS from 'ol/source/tilewms';
import OlLayerTile from 'ol/layer/tile';
import OlSourceImageWMS from 'ol/source/imagewms';
import OlLayerGroup from 'ol/layer/group';
import OlLayerBase from 'ol/layer/base';

Expand Down Expand Up @@ -304,11 +304,14 @@ export class MapUtil {
Logger.error('Invalid input parameter for MapUtil.getLegendGraphicUrl.');
return;
}
const isTiledWMS = layer.getSource() instanceof OlSourceTileWMS;
const isImageWMS = layer.getSource() instanceof OlSourceImageWMS;

if (layer instanceof OlLayerTile
&& layer.getSource() instanceof OlSourceTileWMS) {
if (layer.getSource() && isTiledWMS || isImageWMS) {
const source = layer.getSource();
const url = source.getUrls() ? source.getUrls()[0] : '';
const url = isTiledWMS ?
source.getUrls() ? source.getUrls()[0] : ''
: source.getUrl();
const params = {
LAYER: source.getParams().LAYERS,
VERSION: '1.3.0',
Expand Down
63 changes: 46 additions & 17 deletions src/MapUtil/MapUtil.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import OlInteractionDragRotateAndZoom from 'ol/interaction/dragrotateandzoom';
import OlInteractionDraw from 'ol/interaction/draw';
import OlLayerTile from 'ol/layer/tile';
import OlLayerImage from 'ol/layer/image';
import OlSourceTileWMS from 'ol/source/tilewms';
import OlSourceImageWMS from 'ol/source/imagewms';
import OlSourceTileJson from 'ol/source/tilejson';
import OlFeature from 'ol/feature';
import OlGeomPoint from 'ol/geom/point';
Expand Down Expand Up @@ -465,6 +467,7 @@ describe('MapUtil', () => {

let layer1;
let layer2;
let layer3;

beforeEach(() => {
layer1 = new OlLayerTile({
Expand All @@ -475,7 +478,15 @@ describe('MapUtil', () => {
serverType: 'geoserver'
})
});
layer2 = new OlLayerTile({
layer2 = new OlLayerImage({
name: 'OSM-WMS',
source: new OlSourceImageWMS({
url: 'https://ows.terrestris.de/osm-gray/service',
params: {'LAYERS': 'OSM-WMS', 'TILED': true},
serverType: 'geoserver'
})
});
layer3 = new OlLayerTile({
name: 'Food insecurity',
source: new OlSourceTileJson({
url: 'https://api.tiles.mapbox.com/v3/mapbox.20110804-hoa-foodinsecurity-3month.json?secure',
Expand All @@ -497,28 +508,46 @@ describe('MapUtil', () => {

it('logs a warning if called with an unsupported layersource', () => {
const logSpy = jest.spyOn(Logger, 'warn');
const legendUrl = MapUtil.getLegendGraphicUrl(layer2);
const legendUrl = MapUtil.getLegendGraphicUrl(layer3);
expect(legendUrl).toBeUndefined();
expect(logSpy).toHaveBeenCalledWith('Source of "Food insecurity" is currently not supported by MapUtil.getLegendGraphicUrl.');
logSpy.mockReset();
logSpy.mockRestore();
});

it('returns a getLegendGraphicUrl from a given layer', () => {
const legendUrl = MapUtil.getLegendGraphicUrl(layer1);
const url = 'https://ows.terrestris.de/osm-gray/service?';
const layerParam = 'LAYER=OSM-WMS';
const versionParam = 'VERSION=1.3.0';
const serviceParam = 'SERVICE=WMS';
const requestParam = 'REQUEST=getLegendGraphic';
const formatParam = 'FORMAT=image%2Fpng';

expect(legendUrl).toContain(url);
expect(legendUrl).toContain(layerParam);
expect(legendUrl).toContain(versionParam);
expect(legendUrl).toContain(serviceParam);
expect(legendUrl).toContain(requestParam);
expect(legendUrl).toContain(formatParam);
describe('returns a getLegendGraphicUrl from a given layer', () => {
it('… for a tiled Layer', () => {
const legendUrl = MapUtil.getLegendGraphicUrl(layer1);
const url = 'https://ows.terrestris.de/osm-gray/service?';
const layerParam = 'LAYER=OSM-WMS';
const versionParam = 'VERSION=1.3.0';
const serviceParam = 'SERVICE=WMS';
const requestParam = 'REQUEST=getLegendGraphic';
const formatParam = 'FORMAT=image%2Fpng';

expect(legendUrl).toContain(url);
expect(legendUrl).toContain(layerParam);
expect(legendUrl).toContain(versionParam);
expect(legendUrl).toContain(serviceParam);
expect(legendUrl).toContain(requestParam);
expect(legendUrl).toContain(formatParam);
});
it('… for an image Layer', () => {
const legendUrl = MapUtil.getLegendGraphicUrl(layer2);
const url = 'https://ows.terrestris.de/osm-gray/service?';
const layerParam = 'LAYER=OSM-WMS';
const versionParam = 'VERSION=1.3.0';
const serviceParam = 'SERVICE=WMS';
const requestParam = 'REQUEST=getLegendGraphic';
const formatParam = 'FORMAT=image%2Fpng';

expect(legendUrl).toContain(url);
expect(legendUrl).toContain(layerParam);
expect(legendUrl).toContain(versionParam);
expect(legendUrl).toContain(serviceParam);
expect(legendUrl).toContain(requestParam);
expect(legendUrl).toContain(formatParam);
});
});

it('accepts extraParams for the request', () => {
Expand Down

0 comments on commit e8445db

Please sign in to comment.