Skip to content

Commit

Permalink
Fix #10448 Map plugin should not initizialize invalid maps (#10449)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Oct 21, 2024
1 parent afafc5c commit daf9bcb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
16 changes: 12 additions & 4 deletions web/client/plugins/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,8 @@ class MapPlugin extends React.Component {
onMapTypeLoaded: () => {},
pluginsCreator
};
state = {
canRender: true
};

state = {};

UNSAFE_componentWillMount() {
// moved the font load of FontAwesome only to styleParseUtils (#9653)
Expand Down Expand Up @@ -378,7 +377,7 @@ class MapPlugin extends React.Component {
};

render() {
if (this.props.map && this.state.canRender && this.state.plugins) {
if (this.isValidMapConfiguration(this.props.map) && this.state.plugins) {
const {mapOptions = {}} = this.props.map;

return (
Expand Down Expand Up @@ -440,6 +439,15 @@ class MapPlugin extends React.Component {
}
});
};
isValidMapConfiguration = (map) => {
// when the center is included inside the map config
// we know that the configuration has been loaded
// we should prevent to mount the map component
// in case we have a configuration like this one: { eventListeners: {}, mousePointer: '' }
// if we allow invalid configuration default props will be used instead
// initializing the map in the wrong position
return !!map?.center;
}
}

export default createPlugin('Map', {
Expand Down
27 changes: 27 additions & 0 deletions web/client/plugins/__tests__/Map-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,31 @@ describe('Map Plugin', () => {
})
.catch(done);
});
it('should not mount the map if the configuration is not valid', (done) => {
const { Plugin } = getPluginForTest(MapPlugin, { map: { eventListeners: {} } });
ReactDOM.render(<Plugin
onLoadingMapPlugins={(loading) => {
if (!loading) {
expect(document.querySelector('.mapLoadingMessage')).toBeTruthy();
done();
}
}}
pluginsCreator={() => Promise.resolve({
Map: ({ children }) => <div className="map">{children}</div>,
Layer: ({ options }) => <div id={options.id} className="layers">{options.type}</div>,
Feature: () => null,
tools: {
overview: () => null,
scalebar: () => null,
draw: () => null,
highlight: () => null,
selection: () => null,
popup: () => null,
box: () => null
},
mapType: 'openlayers'
})}
on
/>, document.getElementById("container"));
});
});

0 comments on commit daf9bcb

Please sign in to comment.