When there is no data to render in a Data Overlay we get these messages:

Error message

  • Notice: Undefined offset: 0 in openlayers_views_style_data->render() (line 38 of /home/ao2/public_html/test_site/profiles/d7/modules/contrib/openlayers/modules/openlayers_views/views/openlayers_views_style_data.inc).
  • Notice: Undefined index: in openlayers_views_style_data->render() (line 38 of /home/ao2/public_html/test_site/profiles/d7/modules/contrib/openlayers/modules/openlayers_views/views/openlayers_views_style_data.inc).
  • Warning: Invalid argument supplied for foreach() in openlayers_views_style_data->render() (line 38 of /home/ao2/public_html/test_site/profiles/d7/modules/contrib/openlayers/modules/openlayers_views/views/openlayers_views_style_data.inc).

Which can be made silent with a change like that:

diff --git a/modules/openlayers_views/views/openlayers_views_style_data.inc b/modules/openlayers_views/views/openlayers_views_style_data.inc
index 04850d5..ec0495b 100644
--- a/modules/openlayers_views/views/openlayers_views_style_data.inc
+++ b/modules/openlayers_views/views/openlayers_views_style_data.inc
@@ -33,9 +33,11 @@ class openlayers_views_style_data extends views_plugin_style {
       // If we are in preview mode, dump out some useful information about this data layer
       $output = "You can use the following parameters in your styles as dynamic values";
       $output .= "\n------------\n";
-      $keys = array_keys($data);
-      foreach ($data[$keys[0]]['attributes'] as $key => $value) {
-        $output .= '${'.$key."}\n";
+      if (!empty($data)) {
+        $keys = array_keys($data);
+        foreach ($data[$keys[0]]['attributes'] as $key => $value) {
+          $output .= '${'.$key."}\n";
+        }
       }
       $output .= "\n------------\n";

Comments

Countzero’s picture

Thanks for the tip. Seems good to me and make the error disappear.

Related to the same logic, an Openlayers Map display fails with the following error :

Call to a member function render() on a non-object

... when no data is pulled. This one seems tougher to solve.

kurtzhong’s picture

Nice fix, thanks.

zzolo’s picture

Status: Active » Fixed

Thansk @ao2! Committed. @Countzero, if you can provide an error message or more information, please open a new issue for that error.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.