]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/GoogleMaps.php
Merge OldTextFormattingRules into TextFormattingRules; rename underscore plugins
[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 getDescription()
62     {
63         return _("Display a marker with further infos (when clicking) on given coordinates.");
64     }
65
66     function getDefaultArguments()
67     {
68         return array(
69             'Longitude' => '',
70             'Latitude' => '',
71             'ZoomFactor' => 5,
72             'Marker' => true,
73             'InfoText' => '',
74             'MapType' => 'Hybrid', // Map|Satellite|Hybrid,
75             'SmallMapControl' => false, // large or small
76             'width' => '500px',
77             'height' => '400px',
78         );
79     }
80
81     function run($dbi, $argstr, &$request, $basepage)
82     {
83
84         $args = $this->getArgs($argstr, $request);
85         extract($args);
86
87         if ($Longitude === '') {
88             return $this->error(sprintf(_("A required argument ā€œ%sā€ is missing."), 'Longitude'));
89         }
90         if ($Latitude === '') {
91             return $this->error(sprintf(_("A required argument ā€œ%sā€ is missing."), 'Latitude'));
92         }
93
94         $maps = JavaScript('', array('src' => "http://maps.google.com/maps?file=api&v=1&key=" . GOOGLE_LICENSE_KEY));
95         $id = GenerateId("googlemap");
96         switch ($MapType) {
97             case "Satellite":
98                 $type = "_SATELLITE_TYPE";
99                 break;
100             case "Map":
101                 $type = "_MAP_TYPE";
102                 break;
103             case "Hybrid":
104                 $type = "_HYBRID_TYPE";
105                 break;
106             default:
107                 return $this->error(sprintf(_("Invalid argument %s"), $MapType));
108         }
109         $div = HTML::div(array('id' => $id, 'style' => 'width: ' . $width . '; height: ' . $height));
110
111         // TODO: Check for multiple markers or polygons
112         if (!$InfoText)
113             $Marker = false;
114         // Create a marker whose info window displays the given text
115         if ($Marker) {
116             if ($InfoText) {
117                 include_once 'lib/BlockParser.php';
118                 $page = $dbi->getPage($request->getArg('pagename'));
119                 $rev = $page->getCurrentRevision(false);
120                 $markertext = TransformText($InfoText, $basepage);
121             }
122             $markerjs = JavaScript("
123 function createMarker(point, text) {
124   var marker = new GMarker(point);
125   var html = text + \"<br><br><font size='-1'>[" .
126                 _("new&nbsp;window") .
127                 "]</font>\";
128   GEvent.addListener(marker, \"click\", function() {marker.openInfoWindowHtml(html);});
129   return marker;
130 }");
131         }
132
133         $run = JavaScript("
134 var map = new GMap(document.getElementById('" . $id . "'));\n" .
135                 ($SmallMapControl
136                     ? "map.addControl(new GSmallMapControl());\n"
137                     : "map.addControl(new GLargeMapControl());\n") . "
138 map.addControl(new GMapTypeControl());
139 map.centerAndZoom(new GPoint(" . $Longitude . ", " . $Latitude . "), " . $ZoomFactor . ");
140 map.setMapType(" . $type . ");" .
141                 ($Marker
142                     ? "
143 var point = new GPoint(" . $Longitude . "," . $Latitude . ");
144 var marker = createMarker(point, '" . $markertext->asXml() . "'); map.addOverlay(marker);"
145                     : "")
146         );
147         if ($Marker)
148             return HTML($markerjs, $maps, $div, $run);
149         else
150             return HTML($maps, $div, $run);
151     }
152 }
153
154 // Local Variables:
155 // mode: php
156 // tab-width: 8
157 // c-basic-offset: 4
158 // c-hanging-comment-ender-p: nil
159 // indent-tabs-mode: nil
160 // End: