# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: contributions/modules/mapstraction/mapstraction.drupal.js
--- contributions/modules/mapstraction/mapstraction.drupal.js Base (1.1.2.9.2.9)
+++ contributions/modules/mapstraction/mapstraction.drupal.js Locally Modified (Based On 1.1.2.9.2.9)
@@ -1,46 +1,83 @@
 // $Id: mapstraction.drupal.js,v 1.1.2.9.2.9 2010/05/18 18:36:10 loubabe Exp $
 Drupal.behaviors.mapstraction = function (context) {
   Drupal.mapstraction = [];
-  $(Drupal.settings.mapstraction).each(function() {
-    Drupal.mapstraction[this.mapId] = new mxn.Mapstraction(this.mapId, this.apiName);
 
-    // Set up hover behaviour.
-    if (this.behaviours) {
-      var hover = this.behaviours.hover;      
-    }
+  function addItemsAsMarkers(map, hover) {
+    return function(row) {
+      var markerPoint = new mxn.LatLonPoint(Number(row.latitude), Number(row.longitude));
+      var marker = new mxn.Marker(markerPoint);
 
-    // Set up markers and info bubbles.
-    for (var i in this.markers) {
-      var markerPoint = new mxn.LatLonPoint(Number(this.markers[i].latitude), Number(this.markers[i].longitude));
-      marker = new mxn.Marker(markerPoint);
-      
       // set info bubble if we have a title
-      if (this.markers[i].title) {
-        marker.setInfoBubble('<div class="mapstraction-info-window">'+ this.markers[i].title +'</div>');
+      if (row.title) {
+        marker.setInfoBubble('<div class="mapstraction-info-window">'+ row.title +'</div>');
       }
       
       // override default icon if provided
-      if (this.markers[i].icon) {
-        marker.setIcon(this.markers[i].icon.url, [this.markers[i].icon.width,this.markers[i].icon.height]);
+      if (row.icon) {
+        marker.setIcon(row.icon.url, [row.icon.width, row.icon.height]);
       }
 
       // set all attributes
-      if (this.markers[i].attributes){
-        for (var attr in this.markers[i].attributes) {
-          marker.setAttribute( attr, this.markers[i].attributes[attr] );
+      if (row.attributes){
+        $.each(row.attributes, marker.setAttribute);
         }        
-      }
 
       marker.setHover(hover);
-      Drupal.mapstraction[this.mapId].addMarker(marker);
+      map.addMarker(marker);
+      return marker;
+    };
     }
 
+  function detectPolylines(markers) {
+    for(var key in markers) {
+      return 'markers' in markers[key];
+    }
+    return false;
+  }
+
+  function addItemsAsPolylines(map) {
+    return function(row) {
+      var points = $.map(row.markers, function(point) {
+	return new mxn.LatLonPoint(Number(point.latitude), Number(point.longitude));
+      });
+
+      var poly = new mxn.Polyline(points);
+
+      //Shuffle colors
+      var color = '#';
+      while(color.length < 7) {
+	color = color.concat((Math.round(Math.random() * 15)).toString(16));
+      }
+
+      poly.color = color;
+      poly.width = 2;
+      poly.opacity = 1;
+      poly.closed = false;
+      map.addPolyline(poly);
+      return poly;
+    };
+  }
+
+  $(Drupal.settings.mapstraction).each(function() {
+    var map = Drupal.mapstraction[this.mapId] = new mxn.Mapstraction(this.mapId, this.apiName);
+
+    // Set up hover behaviour.
+    if (this.behaviours) {
+      var hover = this.behaviours.hover;      
+    }
+
+    // Set up markers and info bubbles.
+    $.map(this.markers,
+      detectPolylines(this.markers)
+        ? addItemsAsPolylines(map)
+        : addItemsAsMarkers(map, hover));
+
     // Set up controls.
-    Drupal.mapstraction[this.mapId].addControls(this.controls);
+    map.addControls(this.controls);
     
     // add terrain option if dealing with Google
     if (this.controls.map_type && G_PHYSICAL_MAP) {
-      Drupal.mapstraction[this.mapId].getMap().addMapType(G_PHYSICAL_MAP);
+      map.getMap().addMapType(G_PHYSICAL_MAP);
     }
 
     // default map type
@@ -49,21 +86,21 @@
       if(typeof(maptype) == 'string'){
         maptype = eval(maptype);
       }
-      Drupal.mapstraction[this.mapId].setMapType(maptype);
+      map.setMapType(maptype);
     }
 
     // declutter markers
     if (this.behaviours && this.behaviours.declutter) {
-      Drupal.mapstraction[this.mapId].declutterMarkers();
+      map.declutterMarkers();
     }
 
     // Set auto center and zoom.
     if (this.initialPoint.auto) {
-      Drupal.mapstraction[this.mapId].autoCenterAndZoom();
+      map.autoCenterAndZoom();
     }
     else {
       var startPoint = new mxn.LatLonPoint(Number(this.initialPoint.latitude), Number(this.initialPoint.longitude));
-      Drupal.mapstraction[this.mapId].setCenterAndZoom(startPoint, Number(this.initialPoint.zoom));
+      map.setCenterAndZoom(startPoint, Number(this.initialPoint.zoom));
     }
   });
 };
Index: contributions/modules/mapstraction/mapstraction.module
--- contributions/modules/mapstraction/mapstraction.module Base (1.1.2.7.2.8)
+++ contributions/modules/mapstraction/mapstraction.module Locally Modified (Based On 1.1.2.7.2.8)
@@ -92,7 +92,19 @@
         'uses options' => TRUE,
         'type' => 'normal',
       ),
+      'mapstraction_polyline' => array(
+        'title' => 'Mapstraction polyline',
+        'help' => 'Displays nodes and polylines as a Maptraction map.',
+        'handler' => 'mapstraction_polyline_style_map',
+        'theme' => 'mapstraction_map',
+        'theme file' => 'mapstraction.module',
+        'uses fields' => TRUE,
+        'uses grouping' => TRUE,
+        'uses options' => TRUE,
+        'type' => 'normal',
+        'parent' => 'mapstraction'
     ),
+    ),
   );
 }
 
@@ -205,10 +217,15 @@
     $api_script = call_user_func_array($api['render'], array($settings, $provider, $mapid));
   }
     
+  $library_path =
+    module_exists('libraries')
+      ? libraries_get_path('mapstraction') . '/source'
+      : drupal_get_path('module', 'mapstraction') . '/mapstraction/source';
+
   // load mxn core and provivder specific JS. Not using parameter approach due to drupal_add_js()
-  drupal_add_js(drupal_get_path('module', 'mapstraction') . '/mapstraction/source/mxn.js');
-  drupal_add_js(drupal_get_path('module', 'mapstraction') . '/mapstraction/source/mxn.core.js');
-  drupal_add_js(drupal_get_path('module', 'mapstraction') . '/mapstraction/source/mxn.'. $provider .'.core.js');
\ No newline at end of file
+  drupal_add_js($library_path . '/mxn.js');
+  drupal_add_js($library_path . '/mxn.core.js');
+  drupal_add_js($library_path . '/mxn.'. $provider .'.core.js');
\ No newline at end of file
   drupal_add_js(drupal_get_path('module', 'mapstraction') . '/mapstraction.drupal.js');
 
   $map = array(
Index: contributions/modules/mapstraction/mapstraction_polyline_style_map.inc
--- contributions/modules/mapstraction/mapstraction_polyline_style_map.inc No Base Revision
+++ contributions/modules/mapstraction/mapstraction_polyline_style_map.inc Locally New
@@ -0,0 +1,78 @@
+<?php
+/**
+ * @file
+ * Defines a style plugin that will display points and polylines on a map from a number of
+ * different providers.
+ */
+class mapstraction_polyline_style_map extends mapstraction_style_map {
+  function option_definition() {
+    $options = parent::option_definition();
+    $options += array(
+      'grouping' => '',
+    );
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+
+    // Taken from views_plugin_style.options_form
+    if ($this->uses_fields() && $this->definition['uses grouping']) {
+      $options = array('' => t('<None>'));
+      $options += $this->display->handler->get_field_labels();
+
+      // If there are no fields, we can't group on them.
+      if (count($options) > 1) {
+        $form['grouping'] = array(
+          '#type' => 'select',
+          '#title' => t('Grouping field'),
+          '#options' => $options,
+          '#default_value' => $this->options['grouping'],
+          '#description' => t('You may optionally specify a field by which to group the records. Leave blank to not group.'),
+        );
+      }
+    }
+  }
+
+  function render() {
+    if ($this->view->preview == TRUE && $this->view->live_preview) {
+      return '<div class="messages error">Preview is disabled for the Mapstraction style plugin.</div>';
+    }
+    else {
+      // Would like to use parent::render() here but there seems to be problem
+      // with the way the theme function is handled. Copying this from
+      // views_plugin_style.inc for now.
+      if ($this->uses_row_plugin() && empty($this->row_plugin)) {
+        vpr('views_plugin_style_default: Missing row plugin');
+        return;
+      }
+
+      // Group the rows according to the grouping field, if specified.
+      $sets = $this->render_grouping($this->view->result, $this->options['grouping']);
+
+      // Render each group separately and concatenate.  Plugins may override this
+      // method if they wish some other way of handling grouping.
+      $point_groups = array();
+      foreach ($sets as $title => $records) {
+        if ($this->uses_row_plugin()) {
+          $rows = array();
+          foreach ($records as $label => $row) {
+            $rows[] = $this->row_plugin->render($row);
+          }
+        }
+        else {
+          $rows = $records;
+        }
+        $point_groups[] = array(
+          'title' => $title,
+          'markers' => $this->map_points($records)
+        );
+      }
+
+      if (is_string($this->options['dimensions'])) {
+        list($this->options['width'], $this->options['height']) = explode('x', $this->options['dimensions']);
+      }
+      return mapstraction_render_map($this->view->name . '-' . $this->view->current_display, $this->view->style_plugin->options['api'], $this->options, $point_groups);
+    }
+  }
+}
\ No newline at end of file
Index: contributions/modules/mapstraction/mapstraction_style_map.inc
--- contributions/modules/mapstraction/mapstraction_style_map.inc Base (1.1.2.13.2.8)
+++ contributions/modules/mapstraction/mapstraction_style_map.inc Locally Modified (Based On 1.1.2.13.2.8)
@@ -14,22 +14,28 @@
    * @author Lev Tsypin
    */
   function option_definition() {
-    $options['api'] = array();
+    $options['api'] = array('default' => array());
     $options['width'] = array('default' => 'auto');
     $options['height'] = array('default' => '400px');
 
     $options['initial_point'] = array(
-      'auto' => TRUE,
-      'latitude' => '',
-      'longitude' => '',
-      'zoom' => 10,
+      'contains' => array(
+        'auto' => array('default' => TRUE),
+        'latitude' => array('default' => ''),
+        'longitude' => array('default' => ''),
+        'zoom' => array('default' => 10),
+      ),
     );
-    $options['controls'] = array();
-    $options['behaviours'] = array();
-    $options['zoon_control'] = array();
-    $options['default_maptype'] = array();
-    $options['fields'] = array();
     
+    $options['controls'] = array(
+      'contains' => array(
+        'zoom' => array('default' => 0),
+        'default_maptype' => array('default' => 1),
+      )
+    );
+    $options['behaviours'] = array('default' => array());
+    $options['fields'] = array('default' => array());
+    
     return $options;
   }
 
@@ -258,7 +264,7 @@
    * Return output that will render the view as a map
    */
   function render() {
-    if ($this->view->preview == TRUE) {
+    if ($this->view->preview == TRUE && $this->view->live_preview) {
       return '<div class="messages error">Preview is disabled for the Mapstraction style plugin.</div>';
     }
     else {
@@ -291,7 +297,7 @@
           list($this->options['width'], $this->options['height']) = explode('x', $this->options['dimensions']);
         }
 
-        $output .= mapstraction_render_map($this->view->name . '-' . $this->view->current_display, $this->view->style_plugin->options['api'], $this->options, $this->map_points());
+        $output .= mapstraction_render_map($this->view->name . '-' . $this->view->current_display, $this->view->style_plugin->options['api'], $this->options, $this->map_points($records));
       }
       return $output;
     }
@@ -300,22 +306,25 @@
   /**
    * Convert views results into array of points to render on the map
    */
-  function map_points() {
+  function map_points($rows = array()) {
     $points = array();
-    foreach ($this->rendered_fields as $field) {
+    foreach ($rows as $field) {
       $point = array();
       foreach ($this->options['fields'] as $key => $value) {
         // handle fields with more than one value
         if (is_array($value)){
           foreach($value as $item){
             if (!empty($item)) {
-              $values[$item] = $field[$item];              
+              $raw_field_name = $this->view->display_handler->get_handler('field', $item)->field_alias;
+              $values[$item] = $field->{$raw_field_name};
             }
           }
           $point[$key] = $values;          
-        } elseif ($key == 'icon'){
+        } elseif(!empty($value)) {
+          $value = $this->view->display_handler->get_handler('field', $value)->field_alias;
+          if ($key == 'icon'){
         // special case for icons as we want to get the image size  
-          $path = $field[$value];
+            $path = $field->{$value};
           if (!empty($path)){
             if (is_file($path)){
               list($width, $height) = getimagesize($path);
@@ -326,9 +335,10 @@
             $point['icon']['url'] = $url;
           }
         } else {
-          $point[$key] = $field[$value];
+            $point[$key] = $field->{$value};
         }
       } 
+      } 
\ No newline at end of file
       $points[] = $point;
     }
 
