From d77b424c21fb9dbbb2fc61a2ce01d1ea3c66487c Mon Sep 17 00:00:00 2001
From: Pol Dell'Aiera <Pol@47194.no-reply.drupal.org>
Date: Mon, 20 Aug 2012 17:39:06 +0200
Subject: [PATCH] Issue #1741220: Rewrite get_group_wkt().

---
 .../views/openlayers_views_style_data.inc          |   66 +------------------
 1 files changed, 4 insertions(+), 62 deletions(-)

diff --git a/modules/openlayers_views/views/openlayers_views_style_data.inc b/modules/openlayers_views/views/openlayers_views_style_data.inc
index 2f3397b..695367b 100644
--- a/modules/openlayers_views/views/openlayers_views_style_data.inc
+++ b/modules/openlayers_views/views/openlayers_views_style_data.inc
@@ -196,7 +196,7 @@ class openlayers_views_style_data extends views_plugin_style {
         '#row' => '<' . t('entire row') . '>',
       ), $fields);
     }
-    
+
     // Description field
     $form['data_source']['description_field'] = array(
       '#type' => 'select',
@@ -385,7 +385,6 @@ class openlayers_views_style_data extends views_plugin_style {
    * openlayers_views_style_data specific
    */
   function coalesce_groups($features, $handlers, $ds) {
-
     // Combine wkt into geometry collections if they are an array
     foreach ($features as &$feature) {
       if (is_array($feature['wkt'])) {
@@ -441,66 +440,9 @@ class openlayers_views_style_data extends views_plugin_style {
    * openlayers_views_style_data specific
    */
   function get_group_wkt($wkt_array) {
-    //@@TODO: DO this in geoPHP - four lines of code...
-    $output = 'GEOMETRYCOLLECTION(';
-    $i = 0;
-    foreach ($wkt_array as $wkt) {
-      $wkt = strtoupper($wkt);
-      if ($i != 0) {
-        $output .= ',';
-      }
-      switch (substr($wkt,0,5)) {
-        case 'POINT':
-        case 'LINES':
-        case 'POLYG':
-          $output .= $wkt;
-          break;
-        case 'MULTI':
-          $subwkt = str_replace(array('MULTIPOINT','MULTIPOLYGON','MULTILINESTRING'),'',$wkt);
-          $subwkt = str_replace(', ',',',$subwkt);
-          $subwkt = trim($subwkt);
-          switch (substr($wkt,0,10)) {
-            case 'MULTIPOINT':
-              $subwkt = str_replace(array('(',')'),'',$subwkt);
-              $parts = explode(',',$subwkt);
-              $j = 0;
-              foreach ($parts as $part) {
-                if ($j != 0) $output .= ',';
-                $output .= 'POINT('.$part.')';
-                $j++;
-              }
-              break;
-            case 'MULTILINES':
-              $subwkt = str_replace(array('((','))'),'',$subwkt);
-              $parts = explode('),(',$subwkt);
-              $j = 0;
-              foreach ($parts as $part) {
-                if ($j != 0) $output .= ',';
-                $output .= 'LINESTRING('.$part.')';
-                $j++;
-              }
-              break;
-            case 'MULTIPOLYG':
-              //@@TODO: This does not support polygons with holes
-              $subwkt = str_replace(array('(((',')))'),'',$subwkt);
-              $parts = explode(')),((',$subwkt);
-              $j = 0;
-              foreach ($parts as $part) {
-                if ($j != 0) $output .= ',';
-                $output .= 'POLYGON(('.$part.'))';
-                $j++;
-              }
-              break;
-          }
-          break;
-        case 'GEOME':
-          $output .= trim(substr($wkt,18,-1));
-          break;
-      }
-      $i++;
-    }
-    $output .= ')';
-    return $output;
+    geophp_load();
+    $geophp = geoPHP::load($wkt_array, 'wkt');
+    return $geophp->out('wkt');
   }
 
   /**
-- 
1.7.3.4

