diff --git a/geofield.widgets.openlayers.inc b/geofield.widgets.openlayers.inc index 6aa045f..9aaf836 100644 --- a/geofield.widgets.openlayers.inc +++ b/geofield.widgets.openlayers.inc @@ -167,18 +167,25 @@ function openlayers_field_widget_form(&$form, &$form_state, $field, $instance, $ $geoms[] = geoPHP::load($item['geom']); } else { - $geoms[] = geoPHP::load($item); + if (empty($item['lat']) && empty($item['lon'])) { + $item = array('wkt' => "POINT (0 0)"); + } + else { + $item = array('wkt' => "POINT ({$item['lat']} {$item['lon']} 0)"); + } + + $geoms[] = geoPHP::load($item, 'wkt'); } } $combined_geom = geoPHP::geometryReduce($geoms); - + if ($combined_geom) { // We want to force the combined_geom into a geometryCollection $geom_type = $combined_geom->geometryType(); if ($geom_type == 'MultiPolygon' || $geom_type == 'MultiLineString' || $geom_type == 'MultiPoint') { $combined_geom = new GeometryCollection($combined_geom->getComponents()); } - + $combined_wkt = $combined_geom->out('wkt'); // A value of 'GEOMETRYCOLLECTION EMPTY' breaks OpenLayers JS later on down the line. if ($combined_wkt == 'GEOMETRYCOLLECTION EMPTY') { @@ -188,7 +195,7 @@ function openlayers_field_widget_form(&$form, &$form_state, $field, $instance, $ else { $combined_wkt = ''; } - + $items = array(array('wkt' => $combined_wkt)); $element['geom'] = array(