Skip to content

Commit

Permalink
Fix OpenlayersMap not detecting all changes of the map resolutions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro authored and mbarto committed Dec 7, 2016
1 parent 37d6142 commit bdeb615
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
8 changes: 3 additions & 5 deletions web/client/components/map/openlayers/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,9 @@ var OpenlayersMap = React.createClass({
);
},
haveResolutionsChanged(newProps) {
if (this.props.mapOptions && this.props.mapOptions.view && this.props.mapOptions.view.resolutions &&
newProps.mapOptions && newProps.mapOptions.view && newProps.mapOptions.view.resolutions) {
return !isEqual(newProps.mapOptions.view.resolutions, this.props.mapOptions.view.resolutions);
}
return false;
const resolutions = this.props.mapOptions && this.props.mapOptions.view ? this.props.mapOptions.view.resolutions : undefined;
const newResolutions = newProps.mapOptions && newProps.mapOptions.view ? newProps.mapOptions.view.resolutions : undefined;
return !isEqual(resolutions, newResolutions);
},
createView(center, zoom, projection, options) {
const viewOptions = assign({}, {
Expand Down
49 changes: 49 additions & 0 deletions web/client/components/map/openlayers/__tests__/Map-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var ReactDOM = require('react-dom');
var OpenlayersMap = require('../Map.jsx');
var OpenlayersLayer = require('../Layer.jsx');
var expect = require('expect');
var assign = require('object-assign');
var ol = require('openlayers');
var mapUtils = require('../../../../utils/MapUtils');

Expand Down Expand Up @@ -175,6 +176,54 @@ describe('OpenlayersMap', () => {
expect(center[0].toFixed(1)).toBe('10.0');
});

it('check result of "haveResolutionsChanged()" when receiving new props', () => {
const map = ReactDOM.render(
<OpenlayersMap
center={{y: 43.9, x: 10.3}}
zoom={11.6}
measurement={{}}
/>
, document.getElementById("map"));

let origProps = assign({}, map.props);
function testProps(newProps) {
// update original props with newProps
return assign({}, origProps, newProps);
}

map.setProps(testProps({mapOptions: undefined}));
expect( map.haveResolutionsChanged(testProps({mapOptions: undefined})) ).toBe(false);
expect( map.haveResolutionsChanged(testProps({mapOptions: {}})) ).toBe(false);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {}}})) ).toBe(false);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: []}}})) ).toBe(true);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: [10, 5, 2, 1]}}})) ).toBe(true);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: [100, 50, 25]}}})) ).toBe(true);

map.setProps(testProps({mapOptions: {}}));
expect( map.haveResolutionsChanged(testProps({mapOptions: undefined})) ).toBe(false);
expect( map.haveResolutionsChanged(testProps({mapOptions: {}})) ).toBe(false);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {}}})) ).toBe(false);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: []}}})) ).toBe(true);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: [10, 5, 2, 1]}}})) ).toBe(true);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: [100, 50, 25]}}})) ).toBe(true);

map.setProps(testProps({mapOptions: {view: {}}}));
expect( map.haveResolutionsChanged(testProps({mapOptions: undefined})) ).toBe(false);
expect( map.haveResolutionsChanged(testProps({mapOptions: {}})) ).toBe(false);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {}}})) ).toBe(false);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: []}}})) ).toBe(true);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: [10, 5, 2, 1]}}})) ).toBe(true);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: [100, 50, 25]}}})) ).toBe(true);

map.setProps(testProps({mapOptions: {view: {resolutions: [10, 5, 2, 1]}}}));
expect( map.haveResolutionsChanged(testProps({mapOptions: undefined})) ).toBe(true);
expect( map.haveResolutionsChanged(testProps({mapOptions: {}})) ).toBe(true);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {}}})) ).toBe(true);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: []}}})) ).toBe(true);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: [10, 5, 2, 1]}}})) ).toBe(false);
expect( map.haveResolutionsChanged(testProps({mapOptions: {view: {resolutions: [100, 50, 25]}}})) ).toBe(true);
});

it('check if the map has "auto" cursor as default', () => {
const map = ReactDOM.render(
<OpenlayersMap
Expand Down

0 comments on commit bdeb615

Please sign in to comment.