File tree Expand file tree Collapse file tree 2 files changed +39
-4
lines changed
Expand file tree Collapse file tree 2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -251,9 +251,8 @@ class MapPlugin extends React.Component {
251251 onMapTypeLoaded : ( ) => { } ,
252252 pluginsCreator
253253 } ;
254- state = {
255- canRender : true
256- } ;
254+
255+ state = { } ;
257256
258257 UNSAFE_componentWillMount ( ) {
259258 // moved the font load of FontAwesome only to styleParseUtils (#9653)
@@ -378,7 +377,7 @@ class MapPlugin extends React.Component {
378377 } ;
379378
380379 render ( ) {
381- if ( this . props . map && this . state . canRender && this . state . plugins ) {
380+ if ( this . isValidMapConfiguration ( this . props . map ) && this . state . plugins ) {
382381 const { mapOptions = { } } = this . props . map ;
383382
384383 return (
@@ -440,6 +439,15 @@ class MapPlugin extends React.Component {
440439 }
441440 } ) ;
442441 } ;
442+ isValidMapConfiguration = ( map ) => {
443+ // when the center is included inside the map config
444+ // we know that the configuration has been loaded
445+ // we should prevent to mount the map component
446+ // in case we have a configuration like this one: { eventListeners: {}, mousePointer: '' }
447+ // if we allow invalid configuration default props will be used instead
448+ // initializing the map in the wrong position
449+ return ! ! map ?. center ;
450+ }
443451}
444452
445453export default createPlugin ( 'Map' , {
Original file line number Diff line number Diff line change @@ -113,4 +113,31 @@ describe('Map Plugin', () => {
113113 } )
114114 . catch ( done ) ;
115115 } ) ;
116+ it ( 'should not mount the map if the configuration is not valid' , ( done ) => {
117+ const { Plugin } = getPluginForTest ( MapPlugin , { map : { eventListeners : { } } } ) ;
118+ ReactDOM . render ( < Plugin
119+ onLoadingMapPlugins = { ( loading ) => {
120+ if ( ! loading ) {
121+ expect ( document . querySelector ( '.mapLoadingMessage' ) ) . toBeTruthy ( ) ;
122+ done ( ) ;
123+ }
124+ } }
125+ pluginsCreator = { ( ) => Promise . resolve ( {
126+ Map : ( { children } ) => < div className = "map" > { children } </ div > ,
127+ Layer : ( { options } ) => < div id = { options . id } className = "layers" > { options . type } </ div > ,
128+ Feature : ( ) => null ,
129+ tools : {
130+ overview : ( ) => null ,
131+ scalebar : ( ) => null ,
132+ draw : ( ) => null ,
133+ highlight : ( ) => null ,
134+ selection : ( ) => null ,
135+ popup : ( ) => null ,
136+ box : ( ) => null
137+ } ,
138+ mapType : 'openlayers'
139+ } ) }
140+ on
141+ /> , document . getElementById ( "container" ) ) ;
142+ } ) ;
116143} ) ;
You can’t perform that action at this time.
0 commit comments