tl;dr
Geofield should not save field data when all values are NULL. This will ensure a field will only render when there is data present. I am fairly sure "empty field" can be defined as "all values are NULL". Looking into the code myself and will pop back soon.
I have discovered that when a record is present in the field_data table for a field set to the "Geocode from another field" widget, even if all the "field_xxx" data columns have the value NULL, a map is still rendered when ideally no map should be rendered at all. Deleting said record solves this. Therefore, Geofield should treat all NULL values as an empty field.
My setup
Modules used:
AddressField 7.x-1.x-dev
Geocoder 7.x-1.0+8-dev
OpenLayers 7.x-2.0-beta1+46-dev
Fields:
- addressfield (AddressText)
- geofield wth "Geocode from another field" widget (AddressMap), using Google Geocoder, rejecting APPROXIMATE and GEOMETRIC_CENTER (this field does not compute any point data when only the Country value is passed from AddressText, which always happens with addressfield)
- geofield with "Openlayers Map" widget (CustomMap)
Display:
- AddressText as default (textual output)
- AddressMap as OpenLayers, set to use Full Geometry and an Openlayers View Layer (Google Map) with "Hide empty map for Views" set
- CustomMap as OpenLayers, set to use Full Geometry and an Openlayers View Layer (Google Map) with "Hide empty map for Views" set
Step 1:
Enter a full address into AddressText, and mark one/some point(s) on CustomMap.
Results:
Both AddressMap and CustomMap render maps, displaying their point data as markers.
Step 2:
Remove all text from all AddressText textfields, and delete all markers on CustomMap.
Results:
AddressMap renders an empty map according to the defaults. With OpenLayers, this can mean the initial center-point and extent set in the Center & Bounds options tab at admin/structure/openlayers/maps/map_name/edit.
CustomMap does not render a map, but does render a label if supplied.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | medienhafen.zip | 12.51 KB | Devr |
Comments
Comment #1
henryblyth commentedMy bad - this is an issue with the Geocoder widget. I have logged an issue there with a patch: #1592096: "Geocode from another field" widget does not delete field data when no results returned.
Comment #2
Devr commentedHm, the patch above didn't work for me.
I have a geofield, which geocodes from another field, a filefield with GPX data in my case. When I delete the GPX-file from the node, the field_data_field entry still remains in the table and will not be erased. The result is: the data from the deleted GPX is still rendered in the geofield...
Comment #3
henryblyth commentedHi @Devr,
Could you attach the GPX file so I may test with it please? I guess you have the latest stable releases of Geofield and Geocoder.
Thanks,
Henry
Comment #4
Devr commentedHi Henry,
thanks for your help.
I'm using geofield 7.x-2.x-dev (2012-Jun-23) and geocoder 7.x-1.1 (which includes the patch already).
I have included a GPX, but I had the same bug also with other files. The file was zipped, because of the upload restriction to extensions other than gpx.
Devr
Comment #5
ergophobe commentedThe better issue to link to is now #1992762: Programmatic Update of an entity empties a geofield due to regression introduced/exposed in issue #1777934
#1592096: "Geocode from another field" widget does not delete field data when no results returned. that is mentioned above in #1 is a duplicate of #1777934: Delete geo data when address becomes empty which introduced a bug which is fixed by #1992762: Programmatic Update of an entity empties a geofield due to regression introduced/exposed in issue #1777934