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

fixed #2990 custom styles and added tests #2998

Merged
merged 1 commit into from
Jun 11, 2018
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
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");
});

});