I noticed that if you save a node that has a leaflet widget geofield, but don't add any features to the widget, if then you go back and edit the node to try and add geo data there is an error from the map trying to load null values from the empty geofield that looks like this.
TypeError: this._northEast is undefined
in Firebug and it will kill all javascript on the page.
I found that adding this check in leaflet_widget.module on line 179 of function leaflet_widget_field_widget_form()
if($items[0]['geom']=="GEOMETRYCOLLECTION EMPTY")
$collection= array();
else
$collection = leaflet_widget_widget_prepare_items($items, $geom_type);
It doesn't try to load the null values that are in $items when no geo data is present.
Not sure if this is the correct patch worthy fix, probably need some others to try it first.
Hope it helps
Comment | File | Size | Author |
---|---|---|---|
#3 | empty_field_value_error-2399733-3.patch | 666 bytes | haggins |
Comments
Comment #1
MatthijsG CreditAttribution: MatthijsG commentedSame problem here. The console of Chrome Dev returns
Uncaught TypeError: Cannot read property 'lat' of undefined
When saving a existing node without geofield data, the error
Exception: Invalid GeoJSON: GeometryCollection with no component geometries in GeoJSON->objToGeometryCollection() (line 104 /[snap]/drupal7/sites/all/modules/geophp/geoPHP/lib/adapters/GeoJSON.class.php).
appears
No problem however, if there's a location present.
-- edit
tested your patch, it works! O many thanks!
This patch should be added to the .dev-version.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedSame here, the patch works !
Note: On version 7.2-beta1, the patch should replace line 160.
Comment #3
haggins CreditAttribution: haggins at Berger Schmidt commentedHere's a patch against current 7.x-2.x branch.
Comment #4
cbeier CreditAttribution: cbeier commentedThe patch from #3 fix the problem not completely for me. After applying the patch I get another php error:
The problematically call comes from the function leaflet_widget_process_geojson(). In my case the variable "$geojson" contains the value "[]" and is not empty. But the geoPHP::load() function checks only for a empty string and the json_decode() converts the "[]" to a empty array. And the geoPHP::load() does not accept an array here.
Comment #5
haggins CreditAttribution: haggins at Berger Schmidt commented@cbeier, are you using latest version of geophp? It's 7.x-1.7 currently.
Comment #6
haggins CreditAttribution: haggins at Berger Schmidt commentedPlease try additionaly this one: https://www.drupal.org/node/2456915#comment-11404565
Comment #7
Weka CreditAttribution: Weka commentedThanks haggis,
I just applied the patch in #3 against 7.x-2.0-beta1+7-dev and it fixes the issue for me.
Before applying the patch I was getting an PHP Error:
Exception: Invalid GeoJSON: GeometryCollection with no component geometries a GeoJSON->objToGeometryCollection() (line 104 in ...../sites/all/modules/geophp/geoPHP/lib/adapters/GeoJSON.class.php)
when trying to save a node without adding data to the Geofield field.
Now I just have to figure out how not to display a map in nodes when the user does not enter data into the field.