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

Fix OpenlayersMap not detecting all changes of the map resolutions #1333

Merged
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
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