Skip to content

Commit

Permalink
fixed #2990 custom styles plus tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 committed Jun 11, 2018
1 parent 4bcc399 commit fa2a358
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 3 additions & 3 deletions web/client/components/map/openlayers/VectorStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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)];
};

Expand Down
30 changes: 30 additions & 0 deletions web/client/components/map/openlayers/__tests__/VectorStyle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ describe('Test VectorStyle', () => {

it('test styleFunction with MultiPolygon', () => {


const multiPolygon = new ol.Feature({
geometry: new ol.geom.MultiPolygon([
[
Expand Down Expand Up @@ -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");
});

});

0 comments on commit fa2a358

Please sign in to comment.