Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 committed May 10, 2019
1 parent 4532528 commit 744ad3b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
23 changes: 13 additions & 10 deletions web/client/components/map/openlayers/__tests__/VectorStyle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ describe('Test VectorStyle', () => {
expect(olStyles.length).toBe(1);
// **************** icon ****************
expect(olStyles[0].getImage().getSrc()).toBe("url");
// this is weird, and a bug of ol see https://github.com/openlayers/openlayers/issues/6557, if you dont pass a size and units is fraction then anchor is null (but seems to be applied)
expect(olStyles[0].getImage().getAnchor()).toEqual(null);
// expect(olStyles[0].getImage().getSize()).toEqual(null);
expect(olStyles[0].getImage().getOrigin()).toEqual([0, 0]);
// this is weird, and a bug of ol see https://github.com/openlayers/openlayers/issues/6557
// if you dont pass a size and units is fraction then anchor is null (but seems to be applied)
const image = olStyles[0].getImage();
expect(image.getAnchor()).toEqual(null);
expect(image.getSize()).toEqual(null);
expect(image.getOrigin()).toEqual([0, 0]);
});
it('getMarkerStyle, with a Marker Style with url, no shadow, yes highlight', () => {
const markerStyle = {
Expand All @@ -193,11 +195,12 @@ describe('Test VectorStyle', () => {
expect(isArray(olStyles)).toBe(true);
expect(olStyles.length).toBe(2);
// **************** icon ****************
expect(olStyles[0].getImage().getSrc()).toBe("url");
const image = olStyles[0].getImage();
expect(image.getSrc()).toBe("url");
// this is weird, and a bug of ol see https://github.com/openlayers/openlayers/issues/6557, if you dont pass a size and units is fraction then anchor is null (but seems to be applied)
expect(olStyles[0].getImage().getAnchor()).toEqual(null);
// expect(olStyles[0].getImage().getSize()).toEqual(null);
expect(olStyles[0].getImage().getOrigin()).toEqual([0, 0]);
expect(image.getAnchor()).toEqual(null);
// expect(image.getSize()).toEqual(null);
expect(image.getOrigin()).toEqual([0, 0]);
});
it('getMarkerStyle, with a Marker Style with url and anchor in pixels, no shadow, no highlight', () => {
const markerStyle = {
Expand Down Expand Up @@ -250,7 +253,7 @@ describe('Test VectorStyle', () => {
expect(olStyles[1].getImage().getSrc()).toBe("iconUrl");
// this is weird, and a bug of ol see https://github.com/openlayers/openlayers/issues/6557, if you dont pass a size anchor is null, but seems to be applied?
expect(olStyles[1].getImage().getAnchor()).toEqual(null);
// expect(olStyles[0].getImage().getSize()).toEqual(null);
expect(olStyles[0].getImage().getSize()).toEqual(null);
expect(olStyles[1].getImage().getOrigin()).toEqual([0, 0]);
});
it('getMarkerStyle, with a Marker Style with url, yes shadow, yes highlight', () => {
Expand All @@ -270,7 +273,7 @@ describe('Test VectorStyle', () => {
expect(olStyles[1].getImage().getSrc()).toBe("iconUrl");
// this is weird, and a bug of ol see https://github.com/openlayers/openlayers/issues/6557, if you dont pass a size anchor is null, but seems to be applied?
expect(olStyles[1].getImage().getAnchor()).toEqual(null);
// expect(olStyles[0].getImage().getSize()).toEqual(null);
expect(olStyles[0].getImage().getSize()).toEqual(null);
expect(olStyles[1].getImage().getOrigin()).toEqual([0, 0]);
});
it('getMarkerStyle, with a Marker Style with url with anchor, yes shadow, yes highlight', () => {
Expand Down
17 changes: 9 additions & 8 deletions web/client/utils/openlayers/Icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ module.exports = {
}
},
standard: {
getIcon: ({style, anchorXUnits, anchorYUnits, iconAnchor }) => {
getIcon: ({style, iconAnchor }) => {
const anchor = style.iconAnchor || iconAnchor;
let markerStyle = [new ol.style.Style({
image: new ol.style.Icon(({
anchor: style.iconAnchor || iconAnchor || [0.5, 1],
anchorXUnits: (style.anchorXUnits || anchorXUnits || iconAnchor || iconAnchor === 0) ? 'pixels' : 'fraction',
anchorYUnits: (style.anchorYUnits || anchorYUnits || iconAnchor || iconAnchor === 0) ? 'pixels' : 'fraction',
size: style.size || [16, 16],
anchorOrigin: style.anchorOrigin || "bottom-right",
src: style.iconUrl
image: new ol.style.Icon(({
anchor: anchor || [0.5, 1],
anchorXUnits: style.anchorXUnits || ( anchor || anchor === 0) ? 'pixels' : 'fraction',
anchorYUnits: style.anchorYUnits || ( anchor || anchor === 0) ? 'pixels' : 'fraction',
size: style.size,
anchorOrigin: style.anchorOrigin || "top-left",
src: style.iconUrl || style.symbolUrlCustomized || style.symbolUrl
}))
})];
if (style.shadowUrl) {
Expand Down

0 comments on commit 744ad3b

Please sign in to comment.