]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/GoogleMaps.php
fix syntax error
[SourceForge/phpwiki.git] / lib / plugin / GoogleMaps.php
1 <?php // -*-php-*-
2 rcs_id('$Id: GoogleMaps.php,v 1.3 2005-09-18 16:11:40 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  *   drawing polygons
57  *   Automatic route following
58  */
59 class WikiPlugin_GoogleMaps
60 extends WikiPlugin
61 {
62     function getName() {
63         return _("GoogleMaps");
64     }
65
66     function getDescription() {
67       return _("Displays a marker with further infos (when clicking) on given coordinates");
68     }
69
70     function getVersion() {
71         return preg_replace("/[Revision: $]/", '',
72                             "\$Revision: 1.3 $");
73     }
74
75     function getDefaultArguments() {
76         return array( 
77                      'Longitude' =>     '',
78                      'Latitude'  =>     '',
79                      'ZoomFactor'=>     5,
80                      'Marker'    =>     true,
81                      'InfoText'  =>     '',
82                      'MapType'   =>     'Hybrid', // Map|Satellite|Hybrid,
83                      'SmallMapControl' => false,  // large or small
84                      'width'     =>     '500px',
85                      'height'    =>     '400px',
86                     );
87     }
88
89     function run($dbi, $argstr, &$request, $basepage) {
90         global $WikiTheme;
91
92         $args = $this->getArgs($argstr, $request);
93         extract($args);
94
95         if ($Longitude === '') {
96             return $this->error(fmt("%s parameter missing", "'Longitude'"));
97         }
98         if ($Latitude === '') {
99             return $this->error(fmt("%s parameter missing", "'Latitude'"));
100         }
101
102         $maps = JavaScript('',array('src'=>"http://maps.google.com/maps?file=api&v=1&key=" . GOOGLE_LICENSE_KEY));
103         $id = GenerateId("googlemap");
104         switch ($MapType) {
105         case "Satellite": $type = "_SATELLITE_TYPE"; break;
106         case "Map":       $type = "_MAP_TYPE"; break;
107         case "Hybrid":    $type = "_HYBRID_TYPE"; break;
108         default: return $this->error(sprintf(_("invalid argument %s"), $MapType));
109         }
110         $div = HTML::div(array('id'=>$id,'style'=>'width: '.$width.'; height: '.$height));
111
112         // TODO: Check for multiple markers or polygons
113         if (!$InfoText) 
114             $Marker = false;
115         // Create a marker whose info window displays the given text
116         if ($Marker) {
117             if ($InfoText) {
118                 include_once("lib/BlockParser.php");
119                 $page = $dbi->getPage($request->getArg('pagename'));
120                 $rev  = $page->getCurrentRevision(false);
121                 $markup = $rev->get('markup');
122                 $markertext = TransformText($InfoText, $markup, $basepage);
123             }
124             $markerjs = JavaScript("
125 function createMarker(point, text) {
126   var marker = new GMarker(point);
127   var html = text + \"<br><br><font size='-1'>[" . 
128                                                _("new&nbsp;window") .
129                                                "]</font>\";
130   GEvent.addListener(marker, \"click\", function() {marker.openInfoWindowHtml(html);});
131   return marker;
132 }");
133         }
134
135         $run = JavaScript("
136 var map = new GMap(document.getElementById('".$id."'));\n" .
137 ($SmallMapControl 
138  ? "map.addControl(new GSmallMapControl());\n"
139  : "map.addControl(new GLargeMapControl());\n") . "
140 map.addControl(new GMapTypeControl());
141 map.centerAndZoom(new GPoint(".$Longitude.", ".$Latitude."), ".$ZoomFactor.");
142 map.setMapType(".$type.");" . 
143 ($Marker 
144  ? "
145 var point = new GPoint(".$Longitude.",".$Latitude.");
146 var marker = createMarker(point, '".$markertext->asXml()."'); map.addOverlay(marker);"
147  : "")
148 );
149         if ($Marker)
150             return HTML($markerjs,$maps,$div,$run);
151         else
152             return HTML($maps,$div,$run);
153     }
154 };
155
156 // $Log: not supported by cvs2svn $
157 // Revision 1.2  2005/09/11 13:29:56  rurban
158 // remove InfoLink, wiki parse Infotext instead
159 //
160 // Revision 1.1  2005/09/07 16:53:46  rurban
161 // initial version, idea from http://www.giswiki.de/index.php/Google_Maps_Extensions
162 //
163 //
164
165 // (c-file-style: "gnu")
166 // Local Variables:
167 // mode: php
168 // tab-width: 8
169 // c-basic-offset: 4
170 // c-hanging-comment-ender-p: nil
171 // indent-tabs-mode: nil
172 // End:
173 ?>