From 6e9f01166173c095b00eadb39f0d6fe24f2bc7da Mon Sep 17 00:00:00 2001
From: Reuben Turk <reubenturk@gmail.com>
Date: Thu, 4 Nov 2010 11:50:31 +0000
Subject: [PATCH] #315236 by Bartezz, Fabianx, NigelCunningham, jcmarco et al.
 - gmap views that use ajax break when exposed filters are used.

---
 gmap.module           | 33 +++++++++++++++++++++++++++++++
 js/gmap_views_ajax.js | 45 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)
 create mode 100644 js/gmap_views_ajax.js

diff --git a/gmap.module b/gmap.module
index 61dbe69..169d03f 100644
--- a/gmap.module
+++ b/gmap.module
@@ -1263,3 +1263,36 @@ function gmap_views_plugins() {
     ),
   );
 }
+
+/**
+ * Implementation of hook_views_pre_render().
+ */
+function gmap_views_pre_render(&$view) {
+  static $gmap_processed;
+  // Add js only for gmap style views with ajax and not already processed.
+  if (($view->plugin_name != 'gmap' && !$view->use_ajax) || $gmap_processed) {
+    return;
+  }
+  // Mark the view as already processed.
+  $gmap_processed = TRUE;
+  // Add js with new views callback.
+  drupal_add_js(drupal_get_path('module', 'gmap') . '/js/gmap_views_ajax.js', 'module');
+}
+
+/**
+ * Implementation of hook_ajax_data_alter().
+ */
+function gmap_ajax_data_alter(&$object, $views, $view) {
+  // Add js callback only with gmap style plugins and with ajax.
+  if ($view->plugin_name != 'gmap' || !$view->use_ajax) {
+    return;
+  }
+
+  // Save settings.
+  $js = drupal_add_js(NULL, NULL, 'header');
+  $object->settings = $js['setting'];
+
+  // Register custom callback.
+  $object->__callbacks = array_merge($object->__callbacks, array('Drupal.gmapAjax.ajaxFixMaps'));
+}
+
diff --git a/js/gmap_views_ajax.js b/js/gmap_views_ajax.js
new file mode 100644
index 0000000..1353dc0
--- /dev/null
+++ b/js/gmap_views_ajax.js
@@ -0,0 +1,45 @@
+// $Id$
+
+/**
+ * @file
+ * When using views with ajax enabled, the use of ajaxified
+ * exposed filters breaks the gmap javascript.
+ * This file is part of the solution to this problem.
+ */
+
+$(document).ready(function() {
+  Drupal.gmapAjax = Drupal.gmapAjax || {};
+
+  /**
+   * An ajax responder that accepts a packet of JSON data and acts appropriately.
+   *
+   * The following fields control behavior.
+   * - 'display': Display the associated data in the view area.
+   */
+  Drupal.gmapAjax.ajaxFixMaps = function(target, response) {
+    var $view = $(target);
+
+    if (response.settings) {
+      var i = 0;
+      var gmap = {};
+
+      for (i = 0; i < response.settings.length; i++) {
+        if (typeof(response.settings[i]['gmap']) == 'object') {
+          gmap = response.settings[i]['gmap'];
+        }
+      }
+
+      $view.find('.gmap-map').each(function() {
+        var id = '#' + $(this).attr("id");
+        var t = id.split('-');
+        var mapid = t[1];
+        Drupal.gmap.unloadMap(mapid);
+        if (gmap && gmap[mapid]) {
+          Drupal.settings.gmap[mapid] = gmap[mapid];
+        }
+        $(id).empty().each(Drupal.gmap.setup);
+      });
+    }
+  };
+});
+
-- 
GitLab