From e1c45851e85b4c6d53e5c962000c709737dcb0bd Mon Sep 17 00:00:00 2001
From: Mikkel Hoegh <mikkel@hoegh.org>
Date: Thu, 8 Aug 2013 04:49:46 +0000
Subject: [PATCH] Make Google Maps API v3 actually work.

---
 includes/layer_types/google.inc                    |   15 +++------------
 includes/layer_types/js/google.js                  |   15 +++++++++------
 .../openlayers_ui/includes/openlayers_ui.admin.inc |    6 +++---
 openlayers.module                                  |    2 +-
 4 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/includes/layer_types/google.inc b/includes/layer_types/google.inc
index 9ffd251..553261b 100644
--- a/includes/layer_types/google.inc
+++ b/includes/layer_types/google.inc
@@ -70,16 +70,6 @@ class openlayers_layer_type_google extends openlayers_layer_type {
    */
   function settings_form() {
     return array(
-      'openlayers_google_version' => array(
-        '#type' => 'select',
-        '#title' => t('Google Maps API version'),
-        '#description' => t('If you use Google Maps v3, an API key is not necessary.'),
-        '#options' => array(
-          '2' => t('v2'),
-          '3.2' => t('v3.2'),
-        ),
-        '#default_value' => variable_get('openlayers_google_version', '2'),
-      ),
       'openlayers_layers_google_api' => array(
         '#type' => 'textfield',
         '#title' => t('Google API Key'),
@@ -115,7 +105,7 @@ class openlayers_layer_type_google extends openlayers_layer_type {
         '/includes/layer_types/js/google.js');
 
       // Create URL for google include
-      $url = '//maps.google.com/maps?file=api&sensor=false&v='. variable_get('openlayers_google_version', '2');
+      $url = '//maps.googleapis.com/maps/api/js?sensor=false&v=3.2';
 
       $lang = variable_get('openlayers_layers_google_language', '');
       $url .= !empty($lang) ? '&hl=' . $lang : '';
@@ -123,9 +113,10 @@ class openlayers_layer_type_google extends openlayers_layer_type {
       $key = variable_get('openlayers_layers_google_api', variable_get('googlemap_api_key', ''));
       $url .= !empty($key) ? '&key=' . $key : '';
 
-      drupal_set_html_head('<script src="' . $url . '" type="text/javascript"></script>');
+      drupal_set_html_head('<script src="' . $url . '"></script>');
       $google_maps_included = TRUE;
     }
+
     return $this->options;
   }
 }
diff --git a/includes/layer_types/js/google.js b/includes/layer_types/js/google.js
index ca11f9b..f916ce8 100644
--- a/includes/layer_types/js/google.js
+++ b/includes/layer_types/js/google.js
@@ -13,12 +13,15 @@ Drupal.openlayers.layer.google = function(title, map, options) {
   var styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID);
 
   var google_type_map = {
-    'normal': G_NORMAL_MAP,
-    'satellite': G_SATELLITE_MAP,
-    'hybrid': G_HYBRID_MAP,
-    'physical': G_PHYSICAL_MAP,
-    'mapmaker-normal': G_MAPMAKER_NORMAL_MAP,
-    'mapmaker-hybrid': G_MAPMAKER_HYBRID_MAP
+    'normal': google.maps.MapTypeId.ROADMAP,
+    'satellite': google.maps.MapTypeId.SATELLITE,
+    'hybrid': google.maps.MapTypeId.HYBRID,
+    'physical': google.maps.MapTypeId.TERRAIN,
+    // Mapmaker is not a map type in Google's API v3.
+    // To enable mapmaker, we need to run 
+    // map.setOptions({mapMaker: true }); later.
+    'mapmaker-normal': google.maps.MapTypeId.ROADMAP,
+    'mapmaker-hybrid': google.maps.MapTypeId.HYBRID
   };
 
   options.sphericalMercator = true;
diff --git a/modules/openlayers_ui/includes/openlayers_ui.admin.inc b/modules/openlayers_ui/includes/openlayers_ui.admin.inc
index 453f472..396eeb9 100644
--- a/modules/openlayers_ui/includes/openlayers_ui.admin.inc
+++ b/modules/openlayers_ui/includes/openlayers_ui.admin.inc
@@ -16,7 +16,7 @@ function openlayers_ui_admin_settings() {
   $source_description = '<p>'
     . t('By default the your site will point to a hosted version of
     the OpenLayers library, at <code>@ol_api_url.</code>',
-    array('@ol_api_url' => 'http://openlayers.org/api/2.9/OpenLayers.js'))
+    array('@ol_api_url' => 'http://openlayers.org/api/2.10/OpenLayers.js'))
     . t('Alternately, you can <a href="!ol_url">download OpenLayers</a>,
     add it to your Drupal installation, and use a relative path like
     <code>@suggested_path</code> . You can also use a double backslash
@@ -24,7 +24,7 @@ function openlayers_ui_admin_settings() {
     then respects the use of both HTTPS and HTTP protocols.',
       array(
         '!ol_url' => 'http://openlayers.org/',
-        '@suggested_path' => drupal_get_path('module', 'openlayers') . '/OpenLayers-2.7/OpenLayers.js',
+        '@suggested_path' => drupal_get_path('module', 'openlayers') . '/OpenLayers-2.10/OpenLayers.js',
       )
     )
     . '</li></ul>';
@@ -34,7 +34,7 @@ function openlayers_ui_admin_settings() {
     '#type' => 'textfield',
     '#title' => t('OpenLayers Source'),
     '#description' => $source_description,
-    '#default_value' => variable_get('openlayers_source', 'http://openlayers.org/api/2.9/OpenLayers.js'),
+    '#default_value' => variable_get('openlayers_source', 'http://openlayers.org/api/2.10/OpenLayers.js'),
   );
 
   $form['openlayers_default_preset'] = array(
diff --git a/openlayers.module b/openlayers.module
index 32f3465..26db79a 100644
--- a/openlayers.module
+++ b/openlayers.module
@@ -61,7 +61,7 @@ function openlayers_include() {
     $once = TRUE;
 
     $path = check_plain(variable_get('openlayers_source', 
-      'http://openlayers.org/api/2.9/OpenLayers.js'));
+      'http://openlayers.org/api/2.10/OpenLayers.js'));
 
     // Correctly handle URLs beginning with a double backslash, see RFC 1808 Section 4
     if (substr($path, 0, 2) == '//') {
-- 
1.7.9.5

