@@ -47,7 +47,7 @@ export class DtMapModal extends DtBase {
4747 connectedCallback ( ) {
4848 super . connectedCallback ( ) ;
4949
50- this . canEdit = ! this . metadata ;
50+ this . canEdit = ! ( this . metadata ?. lat ) ;
5151
5252 if ( ! window . mapboxgl ) {
5353 const script = document . createElement ( 'script' ) ;
@@ -85,24 +85,27 @@ export class DtMapModal extends DtBase {
8585 // Add pin if there is one
8686 this . addPinFromMetadata ( ) ;
8787
88- // If map is editable add/move marker on click
89- this . map . on ( 'click ' , ( e ) => {
88+ // Keep pin in the center of the map
89+ this . map . on ( 'move ' , ( ) => {
9090 if ( ! this . canEdit ) {
9191 return ;
9292 }
93+
94+ const currentCenter = this . map . getCenter ( ) ;
95+
9396 if ( this . marker ) {
94- this . marker . setLngLat ( e . lngLat )
97+ this . marker . setLngLat ( currentCenter ) ;
9598 } else {
9699 this . marker = new mapboxgl . Marker ( )
97- . setLngLat ( e . lngLat )
100+ . setLngLat ( currentCenter )
98101 . addTo ( this . map ) ;
99102 }
100103 } ) ;
101104 }
102105 }
103106
104107 addPinFromMetadata ( ) {
105- if ( this . metadata ) {
108+ if ( this . metadata ?. lat ) {
106109 const { lng, lat, level } = this . metadata ;
107110 let zoom = 15
108111 if ( level === 'admin0' ) {
@@ -137,7 +140,7 @@ export class DtMapModal extends DtBase {
137140 }
138141
139142 onClose ( e ) {
140- if ( e ?. detail ?. action === 'button' && this . marker ) {
143+ if ( e ?. detail ?. action === 'button' && this . marker && this . canEdit ) {
141144 this . dispatchEvent ( new CustomEvent ( 'submit' , {
142145 detail : {
143146 location : this . marker . getLngLat ( ) ,
@@ -152,6 +155,7 @@ export class DtMapModal extends DtBase {
152155 .title =${ this . metadata ?. label }
153156 ?isopen =${ this . isOpen }
154157 hideButton
158+ closeButton
155159 @close=${ this . onClose }
156160 tabindex="-1"
157161 >
0 commit comments