@@ -8,6 +8,7 @@ import {ProjectionLike} from 'ol/proj';
88
99import { RContext } from './context' ;
1010import { RlayersBase } from './REvent' ;
11+ import debug from './debug' ;
1112
1213/** Center and zoom level */
1314export type RView = {
@@ -78,6 +79,12 @@ export interface RMapProps extends PropsWithChildren<unknown> {
7879 onRenderComplete ?: ( this : RMap , e : RenderEvent ) => boolean | void ;
7980 /** Called on every change */
8081 onChange ?: ( this : RMap , e : BaseEvent ) => void ;
82+ /** Called when the map starts loading */
83+ onLoadStart ?: ( this : RMap , e : MapEvent ) => void ;
84+ /** Called when the map has completely loaded */
85+ onLoadEnd ?: ( this : RMap , e : MapEvent ) => void ;
86+ /** Generic error handled */
87+ onError ?: ( this : RMap , e : BaseEvent ) => void ;
8188 /** A set of properties that can be accessed later by .get()/.getProperties() */
8289 properties ?: Record < string , unknown > ;
8390 /** Extent of the map, cannot be dynamically modified
@@ -151,7 +158,10 @@ export default class RMap extends RlayersBase<RMapProps, Record<string, never>>
151158
152159 componentDidMount ( ) : void {
153160 super . componentDidMount ( ) ;
154- this . ol . setTarget ( this . target . current ) ;
161+ if ( this . ol . getTarget ( ) !== this . target . current ) {
162+ debug ( 'Setting target' , this , this . target . current ) ;
163+ this . ol . setTarget ( this . target . current ) ;
164+ }
155165 }
156166
157167 private updateView = ( e : MapEvent ) : void => {
@@ -169,9 +179,13 @@ export default class RMap extends RlayersBase<RMapProps, Record<string, never>>
169179 const view = this . ol . getView ( ) ;
170180 for ( const p of [ 'minZoom' , 'maxZoom' , 'constrainResolution' ] ) {
171181 const m = p . charAt ( 0 ) . toUpperCase ( ) + p . substring ( 1 ) ;
172- if ( ! prevProps || this . props [ p ] !== prevProps [ p ] ) view [ 'set' + m ] ( this . props [ p ] ) ;
182+ if ( this . props ?. [ p ] !== prevProps ?. [ p ] ) {
183+ debug ( 'Setting' , this , m , this . props [ p ] ) ;
184+ view [ 'set' + m ] ( this . props [ p ] ) ;
185+ }
173186 }
174187 if ( this . props . view ) {
188+ debug ( 'Setting view' , this , this . props . view ) ;
175189 view . setCenter ( this . props . view [ 0 ] . center ) ;
176190
177191 if ( this . props . view [ 0 ] . resolution === undefined ) view . setZoom ( this . props . view [ 0 ] . zoom ) ;
0 commit comments