Skip to content
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
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"));
});
});