DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:google_maps

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
plugin:google_maps [2012-08-11 23:52] – corrected the link 81.182.154.254plugin:google_maps [2019-04-22 09:45] (current) – [Bugs and ToDo] hua
Line 7: Line 7:
 type       : syntax type       : syntax
 lastupdate : 2010-10-18 lastupdate : 2010-10-18
-compatible : 2009-12-25c, 2008-05-05, 2006-11-06+compatible : 2009-12-25c, 2008-05-05, 2006-11-06, 2016-06-26a
 depends    :  depends    : 
 conflicts  conflicts 
Line 13: Line 13:
 tags       : media, maps, google, embed tags       : media, maps, google, embed
  
-downloadurl: http://centurion.dynalias.com/w/_media/plugin/google-2010-10-15.tar.bz2+downloadurl: https://www.centurion.link/w/_media/plugin/google-2016-09-20.tar.bz2
 ---- ----
 +
  
 ===== Download and Installation ===== ===== Download and Installation =====
  
-Download and install the plugin using the [[plugin:plugin|Plugin Manager]] using the [[http://centurion.dynalias.com/w/_media/plugin/google-2010-10-15.tar.bz2|following URL]]. Refer to [[:Plugins]] on how to install plugins manually.+Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually.
  
-The up-to-date version of the plugin and this description is [[http://centurion.dynalias.com/w/plugin/google_maps|here]].+[[https://www.centurion.link/w/plugin/google_maps|Up-to-date version of the plugin and this description]].
  
  
Line 57: Line 58:
  
 ^  Parameter name ^  Possible valid values ^ ^  Parameter name ^  Possible valid values ^
-| **google_api_key** | Valid Google API key for the current site. See [[#configuration|below]] for more details about how to generate it. |+| **google_api_key** | Valid Google API key for the current site. See [[#configuration]] for more details about how to generate it. |
 | **small_width** | //(default is **425**)// size in px -- the width of small frame, if **size=small** was specified | | **small_width** | //(default is **425**)// size in px -- the width of small frame, if **size=small** was specified |
 | **small_height** | //(default is **350**)// size in px -- the height of small frame, if **size=small** was specified | | **small_height** | //(default is **350**)// size in px -- the height of small frame, if **size=small** was specified |
 | **large_width** | //(default is **550**)// size in px -- the width of large frame, if **size=large** was specified | | **large_width** | //(default is **550**)// size in px -- the width of large frame, if **size=large** was specified |
 | **large_height** | //(default is **450**)// size in px -- the height of large frame, if **size=large** was specified | | **large_height** | //(default is **450**)// size in px -- the height of large frame, if **size=large** was specified |
 +
  
 ===== Demonstration ===== ===== Demonstration =====
  
-See [[http://centurion.dynalias.com/w/playground|here]].+[[https://www.centurion.link/w/wiki/playground|Try the plugin]].
  
  
Line 71: Line 73:
  
 Important is to register your site at Google to receive an access to Google services. Registration is free: Important is to register your site at Google to receive an access to Google services. Registration is free:
-  * Register your website [[http://code.google.com/apis/maps/signup.html|here]] and receive you unique Google API key.+  * [[http://code.google.com/apis/maps/signup.html|Register your website]] and receive you unique Google API key.
   * Modify the configuration file and put a newly generated key to **google_api_key**.   * Modify the configuration file and put a newly generated key to **google_api_key**.
  
Line 88: Line 90:
  
 ===== Source ===== ===== Source =====
- 
  
 ==== syntax/maps.php ==== ==== syntax/maps.php ====
Line 124: Line 125:
       'author'  => 'Dmitry Katsubo',       'author'  => 'Dmitry Katsubo',
       'email'    => 'dma_k@mail.ru',       'email'    => 'dma_k@mail.ru',
-      'date'    => '2010-10-15',+      'date'    => '2016-09-20',
       'name'    => 'Google Maps Plugin',       'name'    => 'Google Maps Plugin',
       'desc'    => 'Adds a Google Maps frame        'desc'    => 'Adds a Google Maps frame 
          syntax: {{googlemaps>address1;address2;address3[zoom=16,size=small,control=hierarchical,overviewmap=true,width=800,height=600,type=embedded]|alternative text}}',          syntax: {{googlemaps>address1;address2;address3[zoom=16,size=small,control=hierarchical,overviewmap=true,width=800,height=600,type=embedded]|alternative text}}',
-      'url'    => 'http://centurion.dynalias.com/w/plugin/google_maps',+      'url'    => 'http://centurion.dynalias.com/wiki/plugin/google_maps',
     );     );
   }   }
Line 168: Line 169:
   }   }
  
-  function handle($match, $state, $pos, &$handler)+  function handle($match, $state, $pos, Doku_Handler $handler)
   {   {
     switch ($state)     switch ($state)
Line 201: Line 202:
   }   }
  
-  function render($mode, &$renderer, $data)+  function render($mode, Doku_Renderer $renderer, $data)
   {   {
     if ($mode == 'xhtml')     if ($mode == 'xhtml')
Line 230: Line 231:
           {           {
             // Dynamic injection of this script via JS causes FF to hang, so we have to include it for each map:             // Dynamic injection of this script via JS causes FF to hang, so we have to include it for each map:
-            $renderer->doc .= "\n<script type='text/javascript' src='http://maps.google.com/maps?file=api&v=2.x&key=" . $this->getConf('google_api_key') . "'></script>";+            $renderer->doc .= "\n<script type='text/javascript' src='//maps.google.com/maps?file=api&v=2.x&key=" . $this->getConf('google_api_key') . "'></script>";
  
             // Default values:             // Default values:
Line 276: Line 277:
  
           // Query is already escaped, params are taken from options:           // Query is already escaped, params are taken from options:
-          $url = "http://maps.google.com/maps?q=$locations[0]$params";+          $url = "//maps.google.com/maps?q=$locations[0]$params";
  
           // External link:           // External link:
Line 318: Line 319:
  */  */
  
-var max_geo_results = 1; +(function() { 
-var geocoder;+// Globals: 
 +var GMAPS_MAX_RETRY_COUNT = 5; 
 +var GMAPS_RETRY_DELAY = 100; 
 +var GMAPS_MAX_GEO_RESULTS = 1; 
 +var GMAPS_GEOCODER = null;
  
 /* /*
Line 340: Line 345:
  * This recursive function sends an ansynchronous query to Google GeoCoder and marks results on the map.  * This recursive function sends an ansynchronous query to Google GeoCoder and marks results on the map.
  */  */
-function queryGoogleGeo(map, bounds, locations, index, zoom)+function queryGoogleGeo(map, bounds, locations, index, zoom, retry)
 { {
-  if (geocoder == null)+  if (GMAPS_GEOCODER == null)
   {   {
     // Can be initialized only at this point, as Google libraries should have been included:     // Can be initialized only at this point, as Google libraries should have been included:
-    geocoder = new GClientGeocoder();+    GMAPS_GEOCODER = new GClientGeocoder();
   }   }
  
-  geocoder.getLocations(locations[index],+  GMAPS_GEOCODER.getLocations(locations[index],
     function generateMarkersFromGoogleGeoResult(response)     function generateMarkersFromGoogleGeoResult(response)
     {     {
       // Was not able to locate any data:       // Was not able to locate any data:
-      if (response == null || response.Status.code != 200)+      if (response == null)
       {       {
-        //alert("Sorry, we were unable to locate " + locations[index] + " address");+        alert("No response from GeoCoder for location " + locations[index] + ". Giving up.")
 +        return;
       }       }
-      else+      else if (response.Status.code == 602)
       {       {
-        var places = response.Placemark; +        if (retry++ >= GMAPS_MAX_RETRY_COUNT)
- +
-        for (var i = 0; i < places.length && i < max_geo_results; i++)+
         {         {
-          var place = places[i]; +          alert("The maximum amount of retries (" + GMAPS_MAX_RETRY_COUNT + ") has been reached for location " + locations[index+ "Giving up."); 
-          var point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);+          return; 
 +        }
  
-          bounds.extend(point);+        setTimeout(queryGoogleGeo, GMAPS_RETRY_DELAY, map, bounds, locations, index, zoom, retry); 
 +        return; 
 +      } 
 +      else if (response.Status.code != 200) 
 +      { 
 +        alert("Invalid response code (" + response.Status.code + "from GeoCoder for location " + locations[index] + ". Giving up."); 
 +        return; 
 +      }
  
-          map.addOverlay(createMarker(point, '<div class="gmaps_marker"><strong>' + place.address + '</strong><br/>' +      var places = response.Placemark; 
-            + place.AddressDetails.Country.CountryNameCode + 
-          )); +      for (var i = 0; i < places.length && i < GMAPS_MAX_GEO_RESULTS; i++) 
-        }+      { 
 +        var place = places[i]; 
 +        var point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); 
 + 
 +        bounds.extend(point); 
 + 
 +        map.addOverlay(createMarker(point, '<div class="gmaps_marker"><strong>' + place.address + '</strong><br/>' 
 +          + place.AddressDetails.Country.CountryNameCode 
 +        ));
       }       }
  
Line 394: Line 414:
       {       {
         // Query recuresively other locations:         // Query recuresively other locations:
-        queryGoogleGeo(map, bounds, locations, index + 1, zoom);+        queryGoogleGeo(map, bounds, locations, index + 1, zoom, retry);
       }       }
     });     });
Line 404: Line 424:
 function loadMaps() function loadMaps()
 { {
-  var headNode = document.getElementsByTagName("head").item(0); +  jQuery('div.gmaps_frame').each(function() { 
-  var divNodes document.body.getElementsByTagName('div');+    var attrs this.attributes;
  
-  for (var 0i < divNodes.length; i++) +    // Create a map: 
-  { +    var map new GMap2(this)
-    if (divNodes[i].className.match(/\bgmaps_frame\b/)) +    map.setCenter(new GLatLng(34, 0), 1); // default point
-    { +
-      var attrs = divNodes[i].attributes;+
  
-      // Create a map: +    // left-top navigator and zoomer 
-      var map new GMap2(divNodes[i]); +    if (attrs.size.value == 'small') 
-      map.setCenter(new GLatLng(34, 0), 1); // default point+      map.addControl(new GSmallMapControl()); 
 +    else if (attrs.size.value == 'large') 
 +      map.addControl(new GLargeMapControl());
  
-      // left-top navigator and zoomer +    // right-top map type switch buttons 
-      if (attrs.size.value == 'small') +    if (attrs.control.value == 'hierarchical') 
-        map.addControl(new GSmallMapControl()); +      map.addControl(new GHierarchicalMapTypeControl()); 
-      else +    else if (attrs.control.value == 'all') 
-      if (attrs.size.value == 'large') +      map.addControl(new GMapTypeControl());
-        map.addControl(new GLargeMapControl());+
  
-      // right-top map type switch buttons +    // mini-map in the bottom-right corner 
-      if (attrs.control.value == 'hierarchical') +    if (attrs.overviewmap.value == 'true') 
-        map.addControl(new GHierarchicalMapTypeControl()); +    { 
-      else if (attrs.control.value == 'all'+      var overviewMap = new GOverviewMapControl(); 
-        map.addControl(new GMapTypeControl());+      map.addControl(overviewMap); 
 +      overviewMap.hide(); 
 +    }
  
-      // mini-map in the bottom-right corner +    map.enableScrollWheelZoom();
-      if (attrs.overviewmap.value == 'true'+
-      { +
-        var overviewMap = new GOverviewMapControl(); +
-        map.addControl(overviewMap); +
-        overviewMap.hide(); +
-      }+
  
-      map.enableScrollWheelZoom();+    var locations = new Array();
  
-      var locations new Array(); +    var 0; 
- +    while (true
-      var n = 0; +    { 
-      while (true)+      if (attrs['location'n== null)
       {       {
-        if (attrs['location' + n] == null) +        break;
-        { +
-          break+
-        } +
- +
-        locations[n] = attrs['location' + n].value; +
-        n++;+
       }       }
  
-      queryGoogleGeo(map, new GLatLngBounds(), locations, 0, attrs.zoom == null ? null : attrs.zoom.value);+      locations[n] = attrs['location' + n].value
 +      n++;
     }     }
-  }+ 
 +    queryGoogleGeo(map, new GLatLngBounds(), locations, 0, attrs.zoom == null ? null : attrs.zoom.value, 0); 
 +  });
 } }
  
 // A special Wiki-wide function, defined in lib/scripts/events.js: // A special Wiki-wide function, defined in lib/scripts/events.js:
-addInitEvent(loadMaps); +jQuery(loadMaps); 
-</code>+})();</code>
  
  
Line 481: Line 493:
 </code> </code>
  
-The latest source code snapshot can be taken from SVN''svn co https://centurion.dynalias.com/svn/public/trunk/web/dokuwiki/lib/plugins/google/''+The latest source code can be taken from [[https://github.com/dmak/dokuwiki/tree/master/lib/plugins/google|Github]]. 
 + 
 + 
 +===== Release History ===== 
 + 
 +  * 2008-03-17 (r05) --- Initial version. 
 +  * [[https://www.centurion.link/w/_media/plugin/google_maps-2008-04-12.tar.bz2|2008-04-12]] 
 +  * [[https://www.centurion.link/w/_media/plugin/google_maps-2008-10-03.tar.bz2|2008-10-03 (r47)]] --- Plugin was refactored to allow formatting in comment. Also aligned in compliance with common practices how to process the flow. 
 +  * [[https://www.centurion.link/w/_media/plugin/google-2010-10-15.tar.bz2|2010-10-15 (r205)]] --- Three google-related plugins are merged into one bundle. Multiple addresses support was added. 
 +  * [[https://www.centurion.link/w/_media/plugin/google-2016-09-20.tar.bz2|2016-09-20]] --- HTTPS fix. API adapted for "Elenor of Tsort" DokuWiki release. 
 + 
 + 
 +===== Bugs and ToDo =====
  
 +Tested with IE 6.0 SP1, FF 3.5.x. No bugs at the moment.
  
-===== ToDo =====+There is nothing right now in my ToDo list. Please, add comment to this page.
  
-There is nothing right now in my ToDo list. Please, send your suggestions to [[dma_k@mail.ru|Dmitry Katsubo]].+Question:\\ 
 +1. Google API key should be placed in \doku\lib\plugins\google_maps\conf\default.php ?\\ 
 +It doesn't work for me somehow
  
plugin/google_maps.1344721949.txt.gz · Last modified: 2012-08-11 23:52 by 81.182.154.254

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki