@@ -41,17 +41,23 @@ function (
4141 // Help dialog displayed when clicking the question mark icon
4242 _helpDialog : null ,
4343
44+ _logPrefix : "[GoogleMapsEditor]" ,
45+
4446 templateString : template ,
4547
4648 _setValueAttr : function ( /*anything*/ newValue , /*Boolean?*/ priorityChange ) {
4749 this . inherited ( arguments ) ;
4850
49- this . textbox . value = newValue ;
51+ this . textbox . value = newValue || "" ;
5052
5153 if ( this . _marker == null ) // Initial load
5254 {
5355 this . _refreshMarkerLocation ( ) ;
5456 }
57+
58+ if ( this . _isComplexType ( ) ) {
59+ this . onChange ( newValue ) ; // Otherwise onChange won't trigger correctly for complex property types
60+ }
5561 } ,
5662
5763 /**
@@ -138,7 +144,7 @@ function (
138144 }
139145
140146 // Clear the property value
141- this . set ( "value" , null ) ;
147+ this . _setCoordinatesValue ( null ) ;
142148 } ,
143149
144150 /**
@@ -190,7 +196,7 @@ function (
190196 return ;
191197 }
192198
193- const messageWithPrefix = `[GoogleMapsEditor] ${ message } ` ;
199+ const messageWithPrefix = `${ this . _logPrefix } ${ message } ` ;
194200
195201 if ( data ) {
196202 console . log ( messageWithPrefix , data ) ;
@@ -331,30 +337,39 @@ function (
331337 return ;
332338 }
333339
334- const longitude = location . lng ( ) ,
335- latitude = location . lat ( ) ;
340+ let value = null ;
336341
337- if ( longitude === undefined || latitude === undefined ) {
338- return ;
342+ if ( ! location ) {
343+ if ( this . _isComplexType ( ) ) {
344+ // Set "empty" value (still an object for local block properties)
345+ value = {
346+ "latitude" : null ,
347+ "longitude" : null
348+ } ;
349+ }
339350 }
351+ else { // Has a location
352+ const longitude = location . lng ( ) ,
353+ latitude = location . lat ( ) ;
340354
341- // Get the new value in the correct format
342- let value ;
343- if ( this . _isComplexType ( ) ) {
344- value = {
345- "latitude" : parseFloat ( latitude ) ,
346- "longitude" : parseFloat ( longitude )
347- } ;
348- } else {
349- value = latitude + "," + longitude ;
355+ if ( longitude === undefined || latitude === undefined ) {
356+ console . error ( `${ this . _logPrefix } Unexpectedly missing longitude and/or latitude coordinate` ) ;
357+ return ;
358+ }
359+
360+ // Get the new value in the correct format
361+ if ( this . _isComplexType ( ) ) {
362+ value = {
363+ "latitude" : parseFloat ( latitude ) ,
364+ "longitude" : parseFloat ( longitude )
365+ } ;
366+ } else {
367+ value = latitude + "," + longitude ;
368+ }
350369 }
351370
352371 // Set the widget (i.e. property) value and trigger change event to notify the CMS (and possibly others) that the value has changed
353372 this . set ( "value" , value ) ;
354-
355- if ( this . _isComplexType ( ) ) {
356- this . onChange ( value ) ; // Otherwise onChange won't trigger correctly for complex property types
357- }
358373 } ,
359374
360375 /**
0 commit comments