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

CommentFileSizeAuthor
#3 empty_field_value_error-2399733-3.patch666 byteshaggins
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MatthijsG’s picture

Same 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.

Anonymous’s picture

Same here, the patch works !

Note: On version 7.2-beta1, the patch should replace line 160.

haggins’s picture

Status: Active » Needs review
FileSize
666 bytes

Here's a patch against current 7.x-2.x branch.

cbeier’s picture

Status: Needs review » Needs work

The patch from #3 fix the problem not completely for me. After applying the patch I get another php error:

Exception: Invalid JSON in GeoJSON->read() (Zeile 23 von /.../sites/all/modules/contrib/geophp/geoPHP/lib/adapters/GeoJSON.class.php).

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.

haggins’s picture

@cbeier, are you using latest version of geophp? It's 7.x-1.7 currently.

haggins’s picture

Status: Needs work » Needs review
Weka’s picture

Thanks 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.