From fa2a3585bba7b71ad97264b23ce1d4e42b984f15 Mon Sep 17 00:00:00 2001 From: Matteo Velludini Date: Mon, 11 Jun 2018 18:02:07 +0200 Subject: [PATCH] fixed #2990 custom styles plus tests --- .../components/map/openlayers/VectorStyle.js | 6 ++-- .../openlayers/__tests__/VectorStyle-test.js | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/web/client/components/map/openlayers/VectorStyle.js b/web/client/components/map/openlayers/VectorStyle.js index ac58c96f4a..ffe20157fd 100644 --- a/web/client/components/map/openlayers/VectorStyle.js +++ b/web/client/components/map/openlayers/VectorStyle.js @@ -27,7 +27,7 @@ const image = new ol.style.Circle({ * @param {boolean} options.applyToPolygon tells if this style can be applied to a polygon * @return {ol.style.Style} style of the point */ -const firstPointOfPolylineStyle = ({radius = 5, fillColor = 'green', applyToPolygon = false}) => new ol.style.Style({ +const firstPointOfPolylineStyle = ({radius = 5, fillColor = 'green', applyToPolygon = false} = {}) => new ol.style.Style({ image: new ol.style.Circle({ radius, fill: new ol.style.Fill({ @@ -53,7 +53,7 @@ const firstPointOfPolylineStyle = ({radius = 5, fillColor = 'green', applyToPoly * @param {boolean} options.applyToPolygon tells if this style can be applied to a polygon * @return {ol.style.Style} style of the point */ -const lastPointOfPolylineStyle = ({radius = 5, fillColor = 'red', applyToPolygon = false}) => new ol.style.Style({ +const lastPointOfPolylineStyle = ({radius = 5, fillColor = 'red', applyToPolygon = false} = {}) => new ol.style.Style({ image: new ol.style.Circle({ radius, fill: new ol.style.Fill({ @@ -74,7 +74,7 @@ const lastPointOfPolylineStyle = ({radius = 5, fillColor = 'red', applyToPolygon /** creates styles to highlight/customize start and end point of a polylin */ -const startEndPolylineStyle = (startPointOptions, endPointOptions) => { +const startEndPolylineStyle = (startPointOptions = {}, endPointOptions = {}) => { return [firstPointOfPolylineStyle(startPointOptions), lastPointOfPolylineStyle(endPointOptions)]; }; diff --git a/web/client/components/map/openlayers/__tests__/VectorStyle-test.js b/web/client/components/map/openlayers/__tests__/VectorStyle-test.js index a26cb16d2e..ce9fd6f426 100644 --- a/web/client/components/map/openlayers/__tests__/VectorStyle-test.js +++ b/web/client/components/map/openlayers/__tests__/VectorStyle-test.js @@ -219,6 +219,7 @@ describe('Test VectorStyle', () => { it('test styleFunction with MultiPolygon', () => { + const multiPolygon = new ol.Feature({ geometry: new ol.geom.MultiPolygon([ [ @@ -286,4 +287,33 @@ describe('Test VectorStyle', () => { }); + it('test firstPointOfPolylineStyle defaults', () => { + let olStyle = VectorStyle.firstPointOfPolylineStyle(); + expect(olStyle.getImage().getRadius()).toBe(5); + expect(olStyle.getImage().getFill().getColor()).toBe("green"); + }); + it('test lastPointOfPolylineStyle defaults', () => { + let olStyle = VectorStyle.lastPointOfPolylineStyle(); + expect(olStyle.getImage().getRadius()).toBe(5); + expect(olStyle.getImage().getFill().getColor()).toBe("red"); + }); + + it('test firstPointOfPolylineStyle {radius: 4}', () => { + let olStyle = VectorStyle.firstPointOfPolylineStyle({radius: 4}); + expect(olStyle.getImage().getRadius()).toBe(4); + expect(olStyle.getImage().getFill().getColor()).toBe("green"); + }); + it('test lastPointOfPolylineStyle {radius: 4}', () => { + let olStyle = VectorStyle.lastPointOfPolylineStyle({radius: 4}); + expect(olStyle.getImage().getRadius()).toBe(4); + expect(olStyle.getImage().getFill().getColor()).toBe("red"); + }); + it('test startEndPolylineStyle defaults', () => { + let styles = VectorStyle.startEndPolylineStyle(); + expect(styles[0].getImage().getRadius()).toBe(5); + expect(styles[0].getImage().getFill().getColor()).toBe("green"); + expect(styles[1].getImage().getRadius()).toBe(5); + expect(styles[1].getImage().getFill().getColor()).toBe("red"); + }); + });