From 20f1623af6636f913534321cf47e0216a6f74100 Mon Sep 17 00:00:00 2001 From: Mathias Walker Date: Thu, 24 Nov 2016 17:10:34 +0100 Subject: [PATCH] Fix OpenlayersMap not detecting all changes of the map resolutions --- web/client/components/map/openlayers/Map.jsx | 8 ++- .../map/openlayers/__tests__/Map-test.jsx | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/web/client/components/map/openlayers/Map.jsx b/web/client/components/map/openlayers/Map.jsx index 1cc68b4500..7b4e3ca8d8 100644 --- a/web/client/components/map/openlayers/Map.jsx +++ b/web/client/components/map/openlayers/Map.jsx @@ -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({}, { diff --git a/web/client/components/map/openlayers/__tests__/Map-test.jsx b/web/client/components/map/openlayers/__tests__/Map-test.jsx index 4e68beb4e7..1d6df59059 100644 --- a/web/client/components/map/openlayers/__tests__/Map-test.jsx +++ b/web/client/components/map/openlayers/__tests__/Map-test.jsx @@ -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'); @@ -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( + + , 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(