]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/GoogleMaps.php
initial version, idea from http://www.giswiki.de/index.php/Google_Maps_Extensions
[SourceForge/phpwiki.git] / lib / plugin / GoogleMaps.php
1 <?php // -*-php-*-
2 rcs_id('$Id: GoogleMaps.php,v 1.1 2005-09-07 16:53:46 rurban Exp $');
3 /**
4  Copyright 2005 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * Uses Google Maps as a Map Server
25  *
26  * This plugin displays a marker with further infos (when clicking) on given coordinates.
27
28  * Hint: You need to sign up for a Google Maps API key!
29  *         http://www.google.com/apis/maps/signup.html
30  *       Then enter the key in config/config.ini under GOOGLE_LICENSE_KEY= 
31  *
32  * Usage:
33  *  <?plugin GoogleMaps
34  *           Latitude=53.053
35  *           Longitude=7.803
36  *           ZoomFactor=10
37  *           Marker=true
38  *           InfoText=
39  *           InfoLink=
40  *           MapType=Map|Satellite|Hybrid
41  *           width=500px
42  *           height=400px
43  *  ?>
44  *
45  * @author Reini Urban
46  *
47  * @see plugin/GooglePlugin
48  *      http://www.giswiki.de/index.php/Google_Maps_Extensions
49  *      http://www.google.com/apis/maps/, http://maps.google.com/
50  *      http://libgmail.sourceforge.net/googlemaps.html 
51  *
52  * NOT YET SUPPORTED:
53  *   Search for keywords (search=)
54  *   mult. markers would need a new syntax
55  *   directions (from - to)
56  */
57 class WikiPlugin_GoogleMaps
58 extends WikiPlugin
59 {
60     function getName() {
61         return _("GoogleMaps");
62     }
63
64     function getDescription() {
65       return _("Displays a marker with further infos (when clicking) on given coordinates");
66     }
67
68     function getVersion() {
69         return preg_replace("/[Revision: $]/", '',
70                             "\$Revision: 1.1 $");
71     }
72
73     function getDefaultArguments() {
74         return array( 
75                      'Longitude' =>     '',
76                      'Latitude'  =>     '',
77                      'ZoomFactor'=>     5,
78                      'Marker'    =>     true,
79                      'InfoText'  =>     '',
80                      'InfoLink'  =>     '',
81                      'MapType'   =>     'Hybrid',    // Map|Satellite|Hybrid,
82                      'SmallMapControl' => false,  // large or small
83                      'width'     =>     '500px',
84                      'height'    =>     '400px',
85                     );
86     }
87
88     function run($dbi, $argstr, &$request, $basepage) {
89         global $WikiTheme;
90
91         $args = $this->getArgs($argstr, $request);
92         extract($args);
93
94         if ($Longitude === '') {
95             return $this->error(fmt("%s parameter missing", "'Longitude'"));
96         }
97         if ($Latitude === '') {
98             return $this->error(fmt("%s parameter missing", "'Latitude'"));
99         }
100         if ($InfoLink and ! IsSafeURL($InfoLink)) {
101             return $this->error(sprintf(_("Bad url in %s: remove all of <, >, \""), "InfoLink"));
102         }
103
104         if (!$InfoText) 
105             $Marker = false;
106         if ($Marker) {
107             if (!$InfoLink and $InfoText)
108                 $InfoLink = $InfoText;
109             $markerlink = HTML::a(array('href'=>$InfoLink,'target'=>"_blank"),
110                                   $InfoText);
111             // Creates a marker whose info window displays the given number
112             $markerjs = JavaScript("
113 function createMarker(point, text) {
114   var marker = new GMarker(point);
115   var html = text + \"<br><br><font size='-1'>[" . 
116                                                _("new&nbsp;window") .
117                                                "]</font>\";
118   GEvent.addListener(marker, \"click\", function() {marker.openInfoWindowHtml(html);});
119   return marker;
120 }");
121         }
122         $maps = JavaScript('',array('src'=>"http://maps.google.com/maps?file=api&v=1&key=" . GOOGLE_LICENSE_KEY));
123         $id = GenerateId("googlemap");
124         switch ($MapType) {
125         case "Satellite": $type = "_SATELLITE_TYPE"; break;
126         case "Map":       $type = "_MAP_TYPE"; break;
127         case "Hybrid":    $type = "_HYBRID_TYPE"; break;
128         default: return $this->error(sprintf(_("invalid argument %s"), $MapType));
129         }
130         $div = HTML::div(array('id'=>$id,'style'=>'width: '.$width.'; height: '.$height));
131         $run = JavaScript("
132 var map = new GMap(document.getElementById('".$id."'));\n" .
133 ($SmallMapControl 
134  ? "map.addControl(new GSmallMapControl());\n"
135  : "map.addControl(new GLargeMapControl());\n") . "
136 map.addControl(new GMapTypeControl());
137 map.centerAndZoom(new GPoint(".$Longitude.", ".$Latitude."), ".$ZoomFactor.");
138 map.setMapType(".$type.");
139 var point = new GPoint(".$Longitude.",".$Latitude.");\n" . 
140 ($Marker 
141  ? "var marker = createMarker(point, '".$markerlink->asXml()."'); map.addOverlay(marker);\n"
142  : "")
143 );
144         if ($Marker)
145             return HTML($markerjs,$maps,$div,$run);
146         else
147             return HTML($maps,$div,$run);
148     }
149 };
150
151 // $Log: not supported by cvs2svn $
152 //
153
154 // (c-file-style: "gnu")
155 // Local Variables:
156 // mode: php
157 // tab-width: 8
158 // c-basic-offset: 4
159 // c-hanging-comment-ender-p: nil
160 // indent-tabs-mode: nil
161 // End:
162 ?>