@@ -74,23 +74,13 @@ export class MapViewer extends HTMLElement {
7474 }
7575 }
7676 get projection ( ) {
77- return this . hasAttribute ( 'projection' )
77+ return this . hasAttribute ( 'projection' ) && M [ this . getAttribute ( 'projection' ) ]
7878 ? this . getAttribute ( 'projection' )
79- : '' ;
79+ : 'OSMTILE ' ;
8080 }
8181 set projection ( val ) {
8282 if ( val && M [ val ] ) {
8383 this . setAttribute ( 'projection' , val ) ;
84- if ( this . _map && this . _map . options . projection !== val ) {
85- this . _map . options . crs = M [ val ] ;
86- this . _map . options . projection = val ;
87- for ( let layer of this . querySelectorAll ( 'layer-' ) ) {
88- layer . removeAttribute ( 'disabled' ) ;
89- let reAttach = this . removeChild ( layer ) ;
90- this . appendChild ( reAttach ) ;
91- }
92- if ( this . _debug ) for ( let i = 0 ; i < 2 ; i ++ ) this . toggleDebug ( ) ;
93- } else this . dispatchEvent ( new CustomEvent ( 'createmap' ) ) ;
9484 } else throw new Error ( 'Undefined Projection' ) ;
9585 }
9686 get zoom ( ) {
@@ -176,7 +166,6 @@ export class MapViewer extends HTMLElement {
176166 // is because the mapml-viewer element has / can have a size of 0 up until after
177167 // something that happens between this point and the event handler executing
178168 // perhaps a browser rendering cycle??
179- this . addEventListener ( 'createmap' , this . _createMap ) ;
180169
181170 let custom = ! [ 'CBMTILE' , 'APSTILE' , 'OSMTILE' , 'WGS84' ] . includes (
182171 this . projection
@@ -185,9 +174,8 @@ export class MapViewer extends HTMLElement {
185174 // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent
186175 // In particular:
187176 // "All applicable event handlers are called and return before dispatchEvent() returns."
188- if ( ! custom ) {
189- this . dispatchEvent ( new CustomEvent ( 'createmap' ) ) ;
190- }
177+ this . _createMap ( ) ;
178+
191179 // https://github.com/Maps4HTML/Web-Map-Custom-Element/issues/274
192180 this . setAttribute ( 'role' , 'application' ) ;
193181 this . _toggleStatic ( ) ;
@@ -362,6 +350,22 @@ export class MapViewer extends HTMLElement {
362350 case 'static' :
363351 this . _toggleStatic ( ) ;
364352 break ;
353+ case 'projection' :
354+ if ( newValue && M [ newValue ] ) {
355+ if ( this . _map && this . _map . options . projection !== newValue ) {
356+ this . _map . options . crs = M [ newValue ] ;
357+ this . _map . options . projection = newValue ;
358+ for ( let layer of this . querySelectorAll ( 'layer-' ) ) {
359+ layer . removeAttribute ( 'disabled' ) ;
360+ let reAttach = this . removeChild ( layer ) ;
361+ this . appendChild ( reAttach ) ;
362+ }
363+ if ( this . _debug ) for ( let i = 0 ; i < 2 ; i ++ ) this . toggleDebug ( ) ;
364+ this . zoomTo ( this . lat , this . lon , this . zoom ) ;
365+ //this.dispatchEvent(new CustomEvent('projectionchange'));
366+ }
367+ }
368+ break ;
365369 }
366370 }
367371
@@ -815,7 +819,7 @@ export class MapViewer extends HTMLElement {
815819 this . _updateMapCenter ( ) ;
816820 this . _addToHistory ( ) ;
817821 this . dispatchEvent (
818- new CustomEvent ( 'moveend' , { detail : { target : this } } )
822+ new CustomEvent ( 'map- moveend' , { detail : { target : this } } )
819823 ) ;
820824 } ,
821825 this
0 commit comments