]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/GoogleMaps.php
Update getDescription
[SourceForge/phpwiki.git] / lib / plugin / GoogleMaps.php
1 <?php
2
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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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  * Hint: You need to sign up for a Google Maps API key!
28  *         http://www.google.com/apis/maps/signup.html
29  *       Then enter the key in config/config.ini under GOOGLE_LICENSE_KEY=
30  *
31  * Usage:
32  *  <<GoogleMaps
33  *           Latitude=53.053
34  *             Longitude=7.803
35  *           ZoomFactor=10
36  *           Marker=true
37  *           InfoText=
38  *           InfoLink=
39  *           MapType=Map|Satellite|Hybrid
40  *           width=500px
41  *           height=400px
42  *  >>
43  *
44  * @author Reini Urban
45  *
46  * @see plugin/GooglePlugin
47  *      http://www.giswiki.de/index.php/Google_Maps_Extensions
48  *      http://www.google.com/apis/maps/, http://maps.google.com/
49  *      http://libgmail.sourceforge.net/googlemaps.html
50  *
51  * NOT YET SUPPORTED:
52  *   Search for keywords (search=)
53  *   mult. markers would need a new syntax
54  *   directions (from - to)
55  *   drawing polygons
56  *   Automatic route following
57  */
58 class WikiPlugin_GoogleMaps
59     extends WikiPlugin
60 {
61     function getName()
62     {
63         return _("GoogleMaps");
64     }
65
66     function getDescription()
67     {
68         return _("Displays a marker with further infos (when clicking) on given coordinates.");
69     }
70
71     function getDefaultArguments()
72     {
73         return array(
74             'Longitude' => '',
75             'Latitude' => '',
76             'ZoomFactor' => 5,
77             'Marker' => true,
78             'InfoText' => '',
79             'MapType' => 'Hybrid', // Map|Satellite|Hybrid,
80             'SmallMapControl' => false, // large or small
81             'width' => '500px',
82             'height' => '400px',
83         );
84     }
85
86     function run($dbi, $argstr, &$request, $basepage)
87     {
88
89         $args = $this->getArgs($argstr, $request);
90         extract($args);
91
92         if ($Longitude === '') {
93             return $this->error(sprintf(_("A required argument ā€œ%sā€ is missing."), 'Longitude'));
94         }
95         if ($Latitude === '') {
96             return $this->error(sprintf(_("A required argument ā€œ%sā€ is missing."), 'Latitude'));
97         }
98
99         $maps = JavaScript('', array('src' => "http://maps.google.com/maps?file=api&v=1&key=" . GOOGLE_LICENSE_KEY));
100         $id = GenerateId("googlemap");
101         switch ($MapType) {
102             case "Satellite":
103                 $type = "_SATELLITE_TYPE";
104                 break;
105             case "Map":
106                 $type = "_MAP_TYPE";
107                 break;
108             case "Hybrid":
109                 $type = "_HYBRID_TYPE";
110                 break;
111             default:
112                 return $this->error(sprintf(_("Invalid argument %s"), $MapType));
113         }
114         $div = HTML::div(array('id' => $id, 'style' => 'width: ' . $width . '; height: ' . $height));
115
116         // TODO: Check for multiple markers or polygons
117         if (!$InfoText)
118             $Marker = false;
119         // Create a marker whose info window displays the given text
120         if ($Marker) {
121             if ($InfoText) {
122                 include_once 'lib/BlockParser.php';
123                 $page = $dbi->getPage($request->getArg('pagename'));
124                 $rev = $page->getCurrentRevision(false);
125                 $markup = $rev->get('markup');
126                 $markertext = TransformText($InfoText, $markup, $basepage);
127             }
128             $markerjs = JavaScript("
129 function createMarker(point, text) {
130   var marker = new GMarker(point);
131   var html = text + \"<br><br><font size='-1'>[" .
132                 _("new&nbsp;window") .
133                 "]</font>\";
134   GEvent.addListener(marker, \"click\", function() {marker.openInfoWindowHtml(html);});
135   return marker;
136 }");
137         }
138
139         $run = JavaScript("
140 var map = new GMap(document.getElementById('" . $id . "'));\n" .
141                 ($SmallMapControl
142                     ? "map.addControl(new GSmallMapControl());\n"
143                     : "map.addControl(new GLargeMapControl());\n") . "
144 map.addControl(new GMapTypeControl());
145 map.centerAndZoom(new GPoint(" . $Longitude . ", " . $Latitude . "), " . $ZoomFactor . ");
146 map.setMapType(" . $type . ");" .
147                 ($Marker
148                     ? "
149 var point = new GPoint(" . $Longitude . "," . $Latitude . ");
150 var marker = createMarker(point, '" . $markertext->asXml() . "'); map.addOverlay(marker);"
151                     : "")
152         );
153         if ($Marker)
154             return HTML($markerjs, $maps, $div, $run);
155         else
156             return HTML($maps, $div, $run);
157     }
158 }
159
160 // Local Variables:
161 // mode: php
162 // tab-width: 8
163 // c-basic-offset: 4
164 // c-hanging-comment-ender-p: nil
165 // indent-tabs-mode: nil
166 // End: