r54565 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54564‎ | r54565 | r54566 >
Date:02:34, 7 August 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.3
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/GoogleMapFunctions.js (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php (added) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_BaseMap.php (modified) (history)
  • /trunk/extensions/Maps/Maps_MapFeature.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/Maps_ParserFunctions.php (added) (history)
  • /trunk/extensions/Maps/Maps_Settings.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Utils.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayersUtils.php (added) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php (modified) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMapsUtils.php (added) (history)
  • /trunk/extensions/Maps/YahooMaps/YahooMapFunctions.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php
@@ -1,6 +1,7 @@
22 <?php
 3+
34 /**
4 - * A class that holds static helper functions for Open Players
 5+ * Class for handling the Maps parser functions with OpenLayers
56 *
67 * @file Maps_OpenLayers.php
78 * @ingroup Maps
@@ -18,115 +19,15 @@
1920
2021 public $serviceName = self::SERVICE_NAME;
2122
22 - private static $loadedBing = false;
23 - private static $loadedYahoo = false;
24 - private static $loadedOL = false;
25 - private static $loadedOSM = false;
26 -
2723 /**
28 - * Load the dependencies of a layer if they are not loaded yet
 24+ * @see MapsBaseMap::setMapSettings()
2925 *
30 - * @param string $output The output to which the html to load the dependencies needs to be added
31 - * @param string $layer The layer to check (and load the dependencies for
32 - */
33 - public static function loadDependencyWhenNeeded(&$output, $layer) {
34 - global $wgJsMimeType;
35 - global $egGoogleMapsOnThisPage, $egMapsIncludePath;
36 -
37 - switch ($layer) {
38 - case 'google' : case 'google-normal' : case 'google-sattelite' : case 'google-hybrid' : case 'google-physical' :
39 - if (empty($egGoogleMapsOnThisPage)) {
40 - $egGoogleMapsOnThisPage = 0;
41 - MapsGoogleMaps::addGMapDependencies($output);
42 - }
43 - break;
44 - case 'bing' : case 'virtual-earth' :
45 - if (!self::$loadedBing) { $output .= "<script type='$wgJsMimeType' src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1'></script>\n"; self::$loadedBing = true; }
46 - break;
47 - case 'yahoo' : case 'yahoo-maps' :
48 - if (!self::$loadedYahoo) { $output .= "<style type='text/css'> #controls {width: 512px;}</style><script src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers'></script>\n"; self::$loadedYahoo = true; }
49 - break;
50 - case 'openlayers' : case 'open-layers' :
51 - if (!self::$loadedOL) { $output .= "<script type='$wgJsMimeType' src='http://clients.multimap.com/API/maps/1.1/metacarta_04'></script>\n"; self::$loadedOL = true; }
52 - break;
53 - case 'osm' : case 'openstreetmap' :
54 - if (!self::$loadedOSM) { $output .= "<script type='$wgJsMimeType' src='$egMapsIncludePath/OpenLayers/OSM/OpenStreetMap.js'></script>\n"; self::$loadedOSM = true; }
55 - break;
56 - }
57 - }
58 -
59 - /**
60 - * Retuns an array holding the default parameters and their values.
61 - *
62 - * @return array
63 - */
64 - public static function getDefaultParams() {
65 - return array
66 - (
67 - 'layers' => array(),
68 - 'baselayer' => ''
69 - );
70 - }
71 -
72 - /**
73 - * If this is the first open layers map on the page, load the API, styles and extra JS functions
74 - *
75 - * @param string $output
76 - */
77 - public static function addOLDependencies(&$output) {
78 - global $wgJsMimeType;
79 - global $egOpenLayersOnThisPage, $egMapsIncludePath;
80 -
81 - if (empty($egOpenLayersOnThisPage)) {
82 - $egOpenLayersOnThisPage = 0;
83 -
84 - $output .="<link rel='stylesheet' href='$egMapsIncludePath/OpenLayers/OpenLayers/theme/default/style.css' type='text/css' />
85 - <script type='$wgJsMimeType' src='$egMapsIncludePath/OpenLayers/OpenLayers/OpenLayers.js'></script>
86 - <script type='$wgJsMimeType' src='$egMapsIncludePath/OpenLayers/OpenLayerFunctions.js'></script>
87 - <script type='$wgJsMimeType'>setOLPopupType(200, 100);</script>\n";
88 - }
89 - }
90 -
91 - /**
92 - * Build up a csv string with the layers, to be outputted as a JS array
93 - *
94 - * @param string $output
95 - * @param array $layers
96 - * @return csv string
97 - */
98 - public static function createLayersStringAndLoadDependencies(&$output, array $layers) {
99 - global $egMapsOLLayers;
100 -
101 - if (count($layers) < 1) $layers = $egMapsOLLayers;
102 -
103 - $layerItems = '';
104 - foreach ($layers as $layer) {
105 - $layer = strtolower($layer);
106 - $layerItems .= "'$layer'" . ',';
107 - self::loadDependencyWhenNeeded($output, $layer);
108 - }
109 -
110 - return rtrim($layerItems, ',');
111 - }
112 -
113 - /**
114 - * Build up a csv string with the controls, to be outputted as a JS array
115 - *
116 - * @param array $controls
117 - * @return csv string
118 - */
119 - public static function createControlsString(array $controls) {
120 - global $egMapsOLControls;
121 - return MapsMapper::createJSItemsString($controls, $egMapsOLControls);
122 - }
123 -
124 - /**
125 - * @see MapsBaseMap::setFormInputSettings()
126 - *
12726 */
12827 protected function setMapSettings() {
12928 global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix;
13029
 30+ $this->defaultParams = MapsOpenLayersUtils::getDefaultParams();
 31+
13132 $this->elementNamePrefix = $egMapsOpenLayersPrefix;
13233 $this->defaultZoom = $egMapsOpenLayersZoom;
13334 }
@@ -138,7 +39,7 @@
13940 protected function doMapServiceLoad() {
14041 global $egOpenLayersOnThisPage;
14142
142 - self::addOLDependencies($this->output);
 43+ MapsOpenLayersUtils::addOLDependencies($this->output);
14344 $egOpenLayersOnThisPage++;
14445
14546 $this->elementNr = $egOpenLayersOnThisPage;
@@ -151,10 +52,10 @@
15253 public function addSpecificMapHTML() {
15354 global $wgJsMimeType;
15455
155 - $controlItems = self::createControlsString($this->controls);
 56+ $controlItems = MapsOpenLayersUtils::createControlsString($this->controls);
15657
15758 MapsMapper::enforceArrayValues($this->layers);
158 - $layerItems = self::createLayersStringAndLoadDependencies($this->output, $this->layers);
 59+ $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers);
15960
16061 MapsUtils::makePxValue($this->width);
16162 MapsUtils::makePxValue($this->height);
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersUtils.php
@@ -0,0 +1,122 @@
 2+<?php
 3+
 4+/**
 5+ * A class that holds static helper functions for OpenLayers
 6+ *
 7+ * @file Maps_OpenLayersUtils.php
 8+ * @ingroup Maps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+final class MapsOpenLayersUtils {
 18+
 19+ private static $loadedBing = false;
 20+ private static $loadedYahoo = false;
 21+ private static $loadedOL = false;
 22+ private static $loadedOSM = false;
 23+
 24+ /**
 25+ * Load the dependencies of a layer if they are not loaded yet
 26+ *
 27+ * @param string $output The output to which the html to load the dependencies needs to be added
 28+ * @param string $layer The layer to check (and load the dependencies for
 29+ */
 30+ public static function loadDependencyWhenNeeded(&$output, $layer) {
 31+ global $wgJsMimeType;
 32+ global $egGoogleMapsOnThisPage, $egMapsIncludePath;
 33+
 34+ switch ($layer) {
 35+ case 'google' : case 'google-normal' : case 'google-sattelite' : case 'google-hybrid' : case 'google-physical' :
 36+ if (empty($egGoogleMapsOnThisPage)) {
 37+ $egGoogleMapsOnThisPage = 0;
 38+ self::addGMapDependencies($output);
 39+ }
 40+ break;
 41+ case 'bing' : case 'virtual-earth' :
 42+ if (!self::$loadedBing) { $output .= "<script type='$wgJsMimeType' src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1'></script>\n"; self::$loadedBing = true; }
 43+ break;
 44+ case 'yahoo' : case 'yahoo-maps' :
 45+ if (!self::$loadedYahoo) { $output .= "<style type='text/css'> #controls {width: 512px;}</style><script src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers'></script>\n"; self::$loadedYahoo = true; }
 46+ break;
 47+ case 'openlayers' : case 'open-layers' :
 48+ if (!self::$loadedOL) { $output .= "<script type='$wgJsMimeType' src='http://clients.multimap.com/API/maps/1.1/metacarta_04'></script>\n"; self::$loadedOL = true; }
 49+ break;
 50+ case 'osm' : case 'openstreetmap' :
 51+ if (!self::$loadedOSM) { $output .= "<script type='$wgJsMimeType' src='$egMapsIncludePath/OpenLayers/OSM/OpenStreetMap.js'></script>\n"; self::$loadedOSM = true; }
 52+ break;
 53+ }
 54+ }
 55+
 56+ /**
 57+ * Retuns an array holding the default parameters and their values.
 58+ *
 59+ * @return array
 60+ */
 61+ public static function getDefaultParams() {
 62+ return array
 63+ (
 64+ 'layers' => array(),
 65+ 'baselayer' => ''
 66+ );
 67+ }
 68+
 69+ /**
 70+ * If this is the first open layers map on the page, load the API, styles and extra JS functions
 71+ *
 72+ * @param string $output
 73+ */
 74+ public static function addOLDependencies(&$output) {
 75+ global $wgJsMimeType;
 76+ global $egOpenLayersOnThisPage, $egMapsIncludePath;
 77+
 78+ if (empty($egOpenLayersOnThisPage)) {
 79+ $egOpenLayersOnThisPage = 0;
 80+
 81+ $output .="<link rel='stylesheet' href='$egMapsIncludePath/OpenLayers/OpenLayers/theme/default/style.css' type='text/css' />
 82+ <script type='$wgJsMimeType' src='$egMapsIncludePath/OpenLayers/OpenLayers/OpenLayers.js'></script>
 83+ <script type='$wgJsMimeType' src='$egMapsIncludePath/OpenLayers/OpenLayerFunctions.js'></script>
 84+ <script type='$wgJsMimeType'>setOLPopupType(200, 100);</script>\n";
 85+ }
 86+ }
 87+
 88+ /**
 89+ * Build up a csv string with the layers, to be outputted as a JS array
 90+ *
 91+ * @param string $output
 92+ * @param array $layers
 93+ * @return csv string
 94+ */
 95+ public static function createLayersStringAndLoadDependencies(&$output, array $layers) {
 96+ global $egMapsOLLayers;
 97+
 98+ if (count($layers) < 1) $layers = $egMapsOLLayers;
 99+
 100+ $layerItems = '';
 101+ foreach ($layers as $layer) {
 102+ $layer = strtolower($layer);
 103+ $layerItems .= "'$layer'" . ',';
 104+ self::loadDependencyWhenNeeded($output, $layer);
 105+ }
 106+
 107+ return rtrim($layerItems, ',');
 108+ }
 109+
 110+ /**
 111+ * Build up a csv string with the controls, to be outputted as a JS array
 112+ *
 113+ * @param array $controls
 114+ * @return csv string
 115+ */
 116+ public static function createControlsString(array $controls) {
 117+ global $egMapsOLControls;
 118+ return MapsMapper::createJSItemsString($controls, $egMapsOLControls);
 119+ }
 120+
 121+}
 122+
 123+?>
\ No newline at end of file
Index: trunk/extensions/Maps/Maps.php
@@ -34,6 +34,7 @@
3535 $wgAutoloadClasses['MapsMapFeature'] = $egMapsIP . '/Maps_MapFeature.php';
3636 $wgAutoloadClasses['MapsBaseMap'] = $egMapsIP . '/Maps_BaseMap.php';
3737 $wgAutoloadClasses['MapsMapper'] = $egMapsIP . '/Maps_Mapper.php';
 38+$wgAutoloadClasses['MapsParserFunctions'] = $egMapsIP . '/Maps_ParserFunctions.php';
3839 $wgAutoloadClasses['MapsUtils'] = $egMapsIP . '/Maps_Utils.php';
3940 $wgAutoloadClasses['MapsGeocoder'] = $egMapsIP . '/Maps_Geocoder.php';
4041 $wgAutoloadClasses['MapsBaseGeocoder'] = $egMapsIP . '/Maps_BaseGeocoder.php';
@@ -43,17 +44,25 @@
4445
4546 $egMapsServices['googlemaps'] = array(
4647 'pf' => array('class' => 'MapsGoogleMaps', 'file' => 'GoogleMaps/Maps_GoogleMaps.php', 'local' => true),
 48+ 'classes' => array(
 49+ array('class' => 'MapsGoogleMapsUtils', 'file' => 'GoogleMaps/Maps_GoogleMapsUtils.php', 'local' => true)
 50+ ),
4751 'aliases' => array('google', 'googlemap', 'gmap', 'gmaps'),
4852 'parameters' => array(
4953 'type' => array('map-type', 'map type'),
 54+ 'types' => array('map-types', 'map types'),
5055 'earth' => array(),
5156 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom'),
52 - 'class' => array()
 57+ 'class' => array(),
 58+ 'style' => array()
5359 )
5460 );
5561
5662 $egMapsServices['openlayers'] = array(
5763 'pf' => array('class' => 'MapsOpenLayers', 'file' => 'OpenLayers/Maps_OpenLayers.php', 'local' => true),
 64+ 'classes' => array(
 65+ array('class' => 'MapsOpenLayersUtils', 'file' => 'OpenLayers/Maps_OpenLayersUtils.php', 'local' => true)
 66+ ),
5867 'aliases' => array('layers', 'openlayer'),
5968 'parameters' => array(
6069 'layers' => array(),
@@ -63,9 +72,13 @@
6473
6574 $egMapsServices['yahoomaps'] = array(
6675 'pf' => array('class' => 'MapsYahooMaps', 'file' => 'YahooMaps/Maps_YahooMaps.php', 'local' => true),
 76+ 'classes' => array(
 77+ array('class' => 'MapsYahooMapsUtils', 'file' => 'YahooMaps/Maps_YahooMapsUtils.php', 'local' => true)
 78+ ),
6779 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps'),
6880 'parameters' => array(
6981 'type' => array('map-type'),
 82+ 'types' => array('map-types', 'map types'),
7083 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom')
7184 )
7285 );
@@ -104,6 +117,11 @@
105118 foreach ($egMapsServices as $serviceData) {
106119 $file = $serviceData['pf']['local'] ? $egMapsIP . '/' . $serviceData['pf']['file'] : $serviceData['pf']['file'];
107120 $wgAutoloadClasses[$serviceData['pf']['class']] = $file;
 121+
 122+ foreach($serviceData['classes'] as $class) {
 123+ $file = $class['local'] ? $egMapsIP . '/' . $class['file'] : $class['file'];
 124+ $wgAutoloadClasses[$class['class']] = $file;
 125+ }
108126 }
109127 }
110128
@@ -114,12 +132,12 @@
115133 global $wgParser;
116134
117135 // A hooks to enable the '#display_point' and '#display_points' parser functions
118 - $wgParser->setFunctionHook( 'display_point', array('MapsMapper', 'displayPointRender' ));
119 - $wgParser->setFunctionHook( 'display_points', array('MapsMapper', 'displayPointsRender' ));
 136+ $wgParser->setFunctionHook( 'display_point', array('MapsParserFunctions', 'displayPointRender' ));
 137+ $wgParser->setFunctionHook( 'display_points', array('MapsParserFunctions', 'displayPointsRender' ));
120138
121139 // A hooks to enable the '#display_adress' and '#display_adresses' parser functions
122 - $wgParser->setFunctionHook( 'display_address', array('MapsMapper', 'displayAddressRender' ));
123 - $wgParser->setFunctionHook( 'display_addresses', array('MapsMapper', 'displayAddressesRender' ));
 140+ $wgParser->setFunctionHook( 'display_address', array('MapsParserFunctions', 'displayAddressRender' ));
 141+ $wgParser->setFunctionHook( 'display_addresses', array('MapsParserFunctions', 'displayAddressesRender' ));
124142
125143 // A hook to enable the geocoder parser functions
126144 $wgParser->setFunctionHook( 'geocode', array('MapsGeocoder', 'renderGeocoder' ));
Index: trunk/extensions/Maps/Maps_Mapper.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * A class that holds handlers for the mapping parser functions
 5+ * A class that holds static helper functions for common functionality that is not map-spesific.
66 *
77 * @file Maps_Mapper.php
88 * @ingroup Maps
@@ -47,7 +47,7 @@
4848 */
4949 public static function setDefaultParValues(array $params, array $serviceDefaults, $strict = true) {
5050 global $egMapsMapLat, $egMapsMapLon, $egMapsMapWidth, $egMapsMapHeight, $egMapsDefaultService;
51 -
 51+
5252 $mapDefaults = array(
5353 'service' => $egMapsDefaultService,
5454 'coordinates' => "$egMapsMapLat, $egMapsMapLon",
@@ -70,45 +70,6 @@
7171 }
7272
7373 /**
74 - * Returns a valid version of the provided parameter array. Paramaters that are not allowed will
75 - * be ignored, and alias parameter names will be changed to main parameter names, using getMainParamName().
76 - *
77 - * @param array $params
78 - * @param array $serviceParameters
79 - * @return array
80 - */
81 - public static function getValidParams(array $params, array $serviceParameters) {
82 - $validParams = array();
83 -
84 - $allowedParms = array_merge(self::$mainParams, $serviceParameters);
85 -
86 - foreach($params as $paramName => $paramValue) {
87 - $paramName = self::getMainParamName($paramName, $allowedParms);
88 - if(array_key_exists($paramName, $allowedParms)) $validParams[$paramName] = $paramValue;
89 - }
90 -
91 - return $validParams;
92 - }
93 -
94 - /**
95 - * Checks if the patameter name is an alias for an actual parameter,
96 - * and changes it into the main paremeter name if this is the case.
97 - *
98 - * @param string $paramName
99 - * @param array $allowedParms
100 - * @return string
101 - */
102 - private static function getMainParamName($paramName, array $allowedParms) {
103 - if (!array_key_exists($paramName, $allowedParms)) {
104 - foreach ($allowedParms as $name => $aliases) {
105 - if (in_array($paramName, $aliases)) $paramName = $name;
106 - }
107 - }
108 -
109 - return $paramName;
110 - }
111 -
112 - /**
11374 * Returns the JS version (true/false as string) of the provided boolean parameter.
11475 *
11576 * @param boolean $bool
@@ -136,138 +97,60 @@
13798 *
13899 * @param array $items
139100 * @param array $defaultItems
 101+ * @param boolean $asStrings
140102 * @return string
141103 */
142 - public static function createJSItemsString(array $items, array $defaultItems) {
143 - if (count($items) < 1) $items = $defaultItems;
144 - return "'" . strtolower(implode("','", $items)) . "'";
145 - }
 104+ public static function createJSItemsString(array $items, array $defaultItems = null, $asStrings = true, $toLower = true) {
 105+ if (count($items) < 1 && isset($defaultItems)) $items = $defaultItems;
 106+ $itemString = $asStrings ? "'" . implode("','", $items) . "'" : implode(",", $items);
 107+ if ($toLower) $itemString = strtolower($itemString);
 108+ return $itemString;
 109+ }
146110
147111 /**
148 - * Sets the default map properties, gets the map HTML depending
149 - * on the provided service, and then returns it.
 112+ * Returns a valid version of the provided parameter array. Paramaters that are not allowed will
 113+ * be ignored, and alias parameter names will be changed to main parameter names, using getMainParamName().
150114 *
151 - * @param unknown_type $parser
 115+ * @param array $paramz
 116+ * @param array $serviceParameters
152117 * @return array
153118 */
154 - public static function displayPointRender(&$parser) {
155 - global $egMapsServices;
 119+ public static function getValidParams(array $paramz, array $serviceParameters) {
 120+ $validParams = array();
156121
157 - $params = func_get_args();
158 - array_shift( $params ); // We already know the $parser ...
 122+ $allowedParms = array_merge(self::$mainParams, $serviceParameters);
159123
160 - if (is_array($params[0])) $params = $params[0];
161 -
162 - $map = array();
163 -
164 - foreach($params as $param) {
165 - $split = split('=', $param);
166 - if (count($split) == 2) {
167 - $paramName = strtolower(trim($split[0]));
168 - $paramValue = trim($split[1]);
169 - $map[$paramName] = $paramValue;
170 - }
171 - if (count($split) == 1) { // Default parameter (without name)
172 - $map['coordinates'] = trim($split[0]);
173 - }
 124+ foreach($paramz as $paramName => $paramValue) {
 125+ //echo "$paramName ->into-> ";
 126+ $paramName = self::getMainParamName($paramName, $allowedParms);
 127+ //echo "$paramName ,withval, "; var_dump($paramValue); echo " <br />\n";
 128+ if(array_key_exists($paramName, $allowedParms)) $validParams[$paramName] = $paramValue;
174129 }
175130
176 - $map['coordinates'] = explode(';', $map['coordinates']);
177 -
178 - $map['service'] = self::getValidService($map['service']);
179 -
180 - $map = self::setDefaultParValues($map, $egMapsServices[$map['service']]['parameters'], true);
181 -
182 - $mapClass = new $egMapsServices[$map['service']]['pf']['class']();
183 -
184 - // Call the function according to the map service to get the HTML output
185 - $output = $mapClass->displayMap($parser, $map);
186 -
187 - // Return the result
188 - return array( $output, 'noparse' => true, 'isHTML' => true );
 131+ return $validParams;
189132 }
190 -
191 - /**
192 - * Sets the default map properties, gets the map HTML depending
193 - * on the provided service, and then returns it.
194 - *
195 - * @param unknown_type $parser
196 - */
197 - public static function displayPointsRender(&$parser) {
198 - $params = func_get_args();
199 - array_shift( $params ); // We already know the $parser ...
200 -
201 - return self::displayPointRender($parser, $params);
202 - }
203133
204134 /**
205 - * Turns the address parameter into coordinates, then lets
206 - * @see MapsMapper::displayPointRender() do the work and returns it.
 135+ * Checks if the patameter name is an alias for an actual parameter,
 136+ * and changes it into the main paremeter name if this is the case.
207137 *
208 - * @param unknown_type $parser
209 - * @return array
 138+ * @param string $paramName
 139+ * @param array $allowedParms
 140+ * @return string
210141 */
211 - public static function displayAddressRender(&$parser) {
212 - global $egMapsDefaultService;
213 -
214 - $params = func_get_args();
215 - array_shift( $params ); // We already know the $parser ...
216 -
217 - self::changeAddressToCoords($params);
218 -
219 - return self::displayPointRender($parser, $params);
220 - }
221 -
222 - /**
223 - * Turns the address parameter into coordinates, then lets
224 - * @see MapsMapper::displayPointRender() do the work and returns it.
225 - *
226 - * @param unknown_type $parser
227 - */
228 - public static function displayAddressesRender(&$parser) {
229 - return self::displayAddressRender(func_get_args());
230 - }
231 -
232 - /**
233 - * Changes the values of the address or addresses parameter into coordinates
234 - * in the provided array.
235 - *
236 - * @param array $params
237 - */
238 - private static function changeAddressToCoords(&$params) {
239 - global $egMapsDefaultService;
240 -
241 - for ($i = 0; $i < count($params); $i++) {
242 - $split = split('=', $params[$i]);
243 - if (strtolower(trim($split[0])) == 'service' && count($split) > 1) {
244 - $service = trim($split[1]);
 142+ private static function getMainParamName($paramName, array $allowedParms) {
 143+ //echo "$paramName -> ";
 144+ if (!array_key_exists($paramName, $allowedParms)) {
 145+ foreach ($allowedParms as $name => $aliases) {
 146+ if (in_array($paramName, $aliases)) {
 147+ $paramName = $name;
 148+ }
245149 }
246 - else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) {
247 - $geoservice = trim($split[1]);
248 - }
249150 }
250 -
251 - $service = isset($service) ? MapsMapper::getValidService($service) : $egMapsDefaultService;
252 - $geoservice = isset($geoservice) ? $geoservice : '';
 151+ //echo "$paramName<br />";
 152+ return $paramName;
 153+ }
253154
254 - for ($i = 0; $i < count($params); $i++) {
255 - $split = split('=', $params[$i]);
256 - if (((strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1) || count($split) == 1) {
257 - $address_srting = count($split) == 1 ? $split[0] : $split[1];
258 -
259 - $addresses = explode(';', $address_srting);
260 -
261 - $coordinates = array();
262 -
263 - foreach($addresses as $address) {
264 - $coordinates[] = MapsGeocoder::renderGeocoder(null, trim($address), $geoservice, $service);
265 - }
266 -
267 - $params[$i] = 'coordinates=' . implode(';', $coordinates);
268 - }
269 - }
270 - }
271 -
272155 /**
273156 * Returns a valid service. When an invalid service is provided, the default one will be returned.
274157 * Aliases are also chancged into the main service names @see MapsMapper::getMainServiceName().
Index: trunk/extensions/Maps/Maps_ParserFunctions.php
@@ -0,0 +1,145 @@
 2+<?php
 3+
 4+/**
 5+ * A class that holds handlers for the mapping parser functions.
 6+ * Spesific functions are located in @see MapsUtils
 7+ *
 8+ * @file Maps_ParserFunctions.php
 9+ * @ingroup Maps
 10+ *
 11+ * @author Jeroen De Dauw
 12+ */
 13+
 14+if( !defined( 'MEDIAWIKI' ) ) {
 15+ die( 'Not an entry point.' );
 16+}
 17+
 18+final class MapsParserFunctions {
 19+
 20+ /**
 21+ * Sets the default map properties, gets the map HTML depending
 22+ * on the provided service, and then returns it.
 23+ *
 24+ * @param unknown_type $parser
 25+ * @return array
 26+ */
 27+ public static function displayPointRender(&$parser) {
 28+ global $egMapsServices;
 29+
 30+ $params = func_get_args();
 31+ array_shift( $params ); // We already know the $parser ...
 32+
 33+ if (is_array($params[0])) $params = $params[0];
 34+
 35+ $map = array();
 36+
 37+ foreach($params as $param) {
 38+ $split = split('=', $param);
 39+ if (count($split) == 2) {
 40+ $paramName = strtolower(trim($split[0]));
 41+ $paramValue = trim($split[1]);
 42+ $map[$paramName] = $paramValue;
 43+ }
 44+ if (count($split) == 1) { // Default parameter (without name)
 45+ $map['coordinates'] = trim($split[0]);
 46+ }
 47+ }
 48+
 49+ $map['service'] = MapsMapper::getValidService($map['service']);
 50+
 51+ $mapClass = new $egMapsServices[$map['service']]['pf']['class']();
 52+
 53+ // Call the function according to the map service to get the HTML output
 54+ $output = $mapClass->displayMap($parser, $map);
 55+
 56+ // Return the result
 57+ return array( $output, 'noparse' => true, 'isHTML' => true );
 58+ }
 59+
 60+ /**
 61+ * Sets the default map properties, gets the map HTML depending
 62+ * on the provided service, and then returns it.
 63+ *
 64+ * @param unknown_type $parser
 65+ */
 66+ public static function displayPointsRender(&$parser) {
 67+ $params = func_get_args();
 68+ array_shift( $params ); // We already know the $parser ...
 69+
 70+ if (is_array($params[0])) $params = $params[0];
 71+
 72+ return self::displayPointRender($parser, $params);
 73+ }
 74+
 75+ /**
 76+ * Turns the address parameter into coordinates, then lets
 77+ * @see MapsMapper::displayPointRender() do the work and returns it.
 78+ *
 79+ * @param unknown_type $parser
 80+ * @return array
 81+ */
 82+ public static function displayAddressRender(&$parser) {
 83+ $params = func_get_args();
 84+ array_shift( $params ); // We already know the $parser ...
 85+
 86+ self::changeAddressToCoords($params);
 87+
 88+ return self::displayPointRender($parser, $params);
 89+ }
 90+
 91+ /**
 92+ * Turns the address parameter into coordinates, then lets
 93+ * @see MapsMapper::displayPointRender() do the work and returns it.
 94+ *
 95+ * @param unknown_type $parser
 96+ */
 97+ public static function displayAddressesRender(&$parser) {
 98+ $params = func_get_args();
 99+ array_shift( $params ); // We already know the $parser ...
 100+
 101+ self::changeAddressToCoords($params);
 102+
 103+ return self::displayPointsRender($parser, $params);
 104+ }
 105+
 106+ /**
 107+ * Changes the values of the address or addresses parameter into coordinates
 108+ * in the provided array.
 109+ *
 110+ * @param array $params
 111+ */
 112+ private static function changeAddressToCoords(&$params) {
 113+ global $egMapsDefaultService;
 114+
 115+ for ($i = 0; $i < count($params); $i++) {
 116+ $split = split('=', $params[$i]);
 117+ if (strtolower(trim($split[0])) == 'service' && count($split) > 1) {
 118+ $service = trim($split[1]);
 119+ }
 120+ else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) {
 121+ $geoservice = trim($split[1]);
 122+ }
 123+ }
 124+
 125+ $service = isset($service) ? MapsMapper::getValidService($service) : $egMapsDefaultService;
 126+ $geoservice = isset($geoservice) ? $geoservice : '';
 127+
 128+ for ($i = 0; $i < count($params); $i++) {
 129+ $split = split('=', $params[$i]);
 130+ if (((strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1) || count($split) == 1) {
 131+ $address_srting = count($split) == 1 ? $split[0] : $split[1];
 132+
 133+ $addresses = explode(';', $address_srting);
 134+
 135+ $coordinates = array();
 136+
 137+ foreach($addresses as $address) {
 138+ $coordinates[] = MapsGeocoder::renderGeocoder(null, trim($address), $geoservice, $service);
 139+ }
 140+
 141+ $params[$i] = 'coordinates=' . implode(';', $coordinates);
 142+ }
 143+ }
 144+ }
 145+
 146+}
\ No newline at end of file
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php
@@ -1,6 +1,7 @@
22 <?php
 3+
34 /**
4 -* Form input hook that adds an Google Maps map format to Semantic Forms
 5+ * Class for handling the Maps parser functions with Google Maps
56 *
67 * @file Maps_GoogleMaps.php
78 * @ingroup Maps
@@ -18,115 +19,15 @@
1920
2021 public $serviceName = self::SERVICE_NAME;
2122
22 - // http://code.google.com/apis/maps/documentation/introduction.html#MapTypes
23 - private static $mapTypes = array(
24 - 'normal' => 'G_NORMAL_MAP',
25 - 'satellite' => 'G_SATELLITE_MAP',
26 - 'hybrid' => 'G_HYBRID_MAP',
27 - 'physical' => 'G_PHYSICAL_MAP',
28 - 'earth' => 'G_SATELLITE_3D_MAP',
29 - );
30 -
31 - // http://code.google.com/apis/maps/documentation/controls.html#Controls_overview
32 - private static $controlClasses = array(
33 - 'large' => 'GLargeMapControl3D',
34 - 'small' => 'GSmallZoomControl3D',
35 - );
36 -
3723 /**
38 - * Returns the Google Map type (defined in MapsGoogleMaps::$mapTypes)
39 - * for the provided a general map type. When no match is found, the first
40 - * possible Google Map type will be returned as default.
41 - *
42 - * @param string $type
43 - * @param boolean $earthEnabled
44 - * @return string
45 - */
46 - public static function getGMapType($type, $earthEnabled = false) {
47 - global $egMapsGoogleMapsType;
48 -
49 - if (! array_key_exists($type, MapsGoogleMaps::$mapTypes)) {
50 - $type = $earthEnabled ? "earth" : $egMapsGoogleMapsType;;
51 - }
52 -
53 - return self::$mapTypes[ $type ];
54 - }
55 -
56 - /**
57 - * Returns the Google Map Control type (defined in MapsGoogleMaps::$controlClasses)
58 - * for the provided a general map control type. When no match is found, the provided
59 - * control name will be used.
60 - *
61 - * @param array $controls
62 - * @return string
63 - */
64 - public static function getGControlType(array $controls) {
65 - global $egMapsGMapControl;
66 - $control = count($controls) > 0 ? $controls[0] : $egMapsGMapControl;
67 - return array_key_exists($control, MapsGoogleMaps::$controlClasses) ? MapsGoogleMaps::$controlClasses[$control] : $control;
68 - }
69 -
70 - /**
71 - * Retuns an array holding the default parameters and their values.
72 - *
73 - * @return array
74 - */
75 - public static function getDefaultParams() {
76 - return array
77 - (
78 - 'type' => '',
79 - 'class' => 'pmap',
80 - 'autozoom' => '',
81 - 'earth' => ''
82 - );
83 - }
84 -
85 - /**
86 - * Add references to the Google Maps API and required JS file to the provided output
87 - *
88 - * @param unknown_type $output
89 - */
90 - public static function addGMapDependencies(&$output) {
91 - global $wgJsMimeType, $wgLang;
92 - global $egGoogleMapsKey, $egMapsIncludePath, $egGoogleMapsOnThisPage;
93 -
94 - if (empty($egGoogleMapsOnThisPage)) {
95 -
96 - $egGoogleMapsOnThisPage = 0;
97 - $output .= "<script src='http://maps.google.com/maps?file=api&v=2&key=$egGoogleMapsKey&hl={$wgLang->getCode()}' type='$wgJsMimeType'></script>
98 - <script type='$wgJsMimeType' src='$egMapsIncludePath/GoogleMaps/GoogleMapFunctions.js'></script>";
99 - }
100 - }
101 -
102 - /**
103 - * Retuns a boolean as string, true if $autozoom is on or yes.
104 - *
105 - * @param string $autozoom
106 - * @return string
107 - */
108 - public static function getAutozoomJSValue($autozoom) {
109 - return MapsMapper::getJSBoolValue(in_array($autozoom, array('on', 'yes')));
110 - }
111 -
112 - /**
113 - * Returns a boolean representing if the earth map type should be showed or not,
114 - * when provided the the wiki code value.
115 - *
116 - * @param string $earthValue
117 - * @return boolean Indicates wether the earth type should be enabled.
118 - */
119 - public static function getEarthValue($earthValue) {
120 - $trueValues = array('on', 'yes');
121 - return in_array($earthValue, $trueValues);
122 - }
123 -
124 - /**
12524 * @see MapsBaseMap::setFormInputSettings()
12625 *
12726 */
12827 protected function setMapSettings() {
12928 global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix;
13029
 30+ $this->defaultParams = MapsGoogleMapsUtils::getDefaultParams();
 31+
13132 $this->elementNamePrefix = $egMapsGoogleMapsPrefix;
13233 $this->defaultZoom = $egMapsGoogleMapsZoom;
13334 }
@@ -138,7 +39,7 @@
13940 protected function doMapServiceLoad() {
14041 global $egGoogleMapsOnThisPage;
14142
142 - self::addGMapDependencies($this->output);
 43+ MapsGoogleMapsUtils::addGMapDependencies($this->output);
14344 $egGoogleMapsOnThisPage++;
14445
14546 $this->elementNr = $egGoogleMapsOnThisPage;
@@ -150,14 +51,15 @@
15152 */
15253 public function addSpecificMapHTML() {
15354 global $wgJsMimeType;
 55+ global $egMapsGoogleMapsTypes;
15456
155 - $enableEarth = self::getEarthValue($this->earth);
 57+ $enableEarth = MapsGoogleMapsUtils::getEarthValue($this->earth);
15658 $this->earth = MapsMapper::getJSBoolValue($enableEarth);
15759
158 - $this->type = self::getGMapType($this->type, $enableEarth);
159 - $control = self::getGControlType($this->controls);
 60+ $this->type = MapsGoogleMapsUtils::getGMapType($this->type, $enableEarth);
 61+ $control = MapsGoogleMapsUtils::getGControlType($this->controls);
16062
161 - $this->autozoom = self::getAutozoomJSValue($this->autozoom);
 63+ $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom);
16264
16365 $markerItems = array();
16466
@@ -170,12 +72,25 @@
17173
17274 $markersString = implode(',', $markerItems);
17375
 76+ $this->types = explode(",", $this->types);
 77+
 78+ if (count($this->types) < 1) $this->types = $egMapsGoogleMapsTypes;
 79+
 80+ for($i = 0 ; $i < count($this->types); $i++) {
 81+ $this->types[$i] = MapsGoogleMapsUtils::getGMapType($this->types[$i], $enableEarth);
 82+ }
 83+
 84+ // This is to ensure backwards compatibility with 0.1 and 0.2.
 85+ if ($enableEarth && ! in_array('G_SATELLITE_3D_MAP', $this->types)) $this->types[] = 'G_SATELLITE_3D_MAP';
 86+
 87+ $typesString = MapsMapper::createJSItemsString($this->types, null, false, false);
 88+
17489 $this->output .=<<<END
17590
17691 <div id="$this->mapName" class="$this->class" style="$this->style" ></div>
17792 <script type="$wgJsMimeType"> /*<![CDATA[*/
17893 addLoadEvent(
179 - initializeGoogleMap('$this->mapName', $this->width, $this->height, $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, new $control(), $this->autozoom, $this->earth, [$markersString])
 94+ initializeGoogleMap('$this->mapName', $this->width, $this->height, $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], new $control(), $this->autozoom, $this->earth, [$markersString])
18095 );
18196 /*]]>*/ </script>
18297
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php
@@ -0,0 +1,151 @@
 2+<?php
 3+
 4+/**
 5+ * A class that holds static helper functions for Google Maps
 6+ *
 7+ * @file Maps_GooleMapsUtils.php
 8+ * @ingroup Maps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+final class MapsGoogleMapsUtils {
 18+
 19+ // http://code.google.com/apis/maps/documentation/reference.html#GMapType.G_NORMAL_MAP
 20+ // TODO: Add a true alliasing system? Might be overkill.
 21+ private static $mapTypes = array(
 22+ 'normal' => 'G_NORMAL_MAP',
 23+ 'G_NORMAL_MAP' => 'G_NORMAL_MAP',
 24+
 25+ 'satellite' => 'G_SATELLITE_MAP',
 26+ 'G_SATELLITE_MAP' => 'G_SATELLITE_MAP',
 27+
 28+ 'hybrid' => 'G_HYBRID_MAP',
 29+ 'G_HYBRID_MAP' => 'G_HYBRID_MAP',
 30+
 31+ 'physical' => 'G_PHYSICAL_MAP',
 32+ 'G_PHYSICAL_MAP' => 'G_PHYSICAL_MAP',
 33+
 34+ 'earth' => 'G_SATELLITE_3D_MAP',
 35+ 'G_SATELLITE_3D_MAP' => 'G_SATELLITE_3D_MAP',
 36+
 37+ 'sky' => 'G_SKY_VISIBLE_MAP',
 38+ 'G_SKY_VISIBLE_MAP' => 'G_SKY_VISIBLE_MAP',
 39+
 40+ 'moon' => 'G_MOON_VISIBLE_MAP',
 41+ 'G_MOON_VISIBLE_MAP' => 'G_MOON_VISIBLE_MAP',
 42+
 43+ 'moon-elevation' => 'G_MOON_ELEVATION_MAP',
 44+ 'G_MOON_ELEVATION_MAP' => 'G_MOON_ELEVATION_MAP',
 45+
 46+ 'mars' => 'G_MARS_VISIBLE_MAP',
 47+ 'G_MARS_VISIBLE_MAP' => 'G_MARS_VISIBLE_MAP',
 48+
 49+ 'mars-elevation' => 'G_MARS_ELEVATION_MAP',
 50+ 'G_MARS_ELEVATION_MAP' => 'G_MARS_ELEVATION_MAP',
 51+
 52+ 'mars-infrared' => 'G_MARS_INFRARED_MAP',
 53+ 'G_MARS_INFRARED_MAP' => 'G_MARS_INFRARED_MAP',
 54+ );
 55+
 56+ // http://code.google.com/apis/maps/documentation/controls.html#Controls_overview
 57+ private static $controlClasses = array(
 58+ 'large' => 'GLargeMapControl3D',
 59+ 'small' => 'GSmallZoomControl3D',
 60+ );
 61+
 62+ /**
 63+ * Returns the Google Map type (defined in MapsGoogleMaps::$mapTypes)
 64+ * for the provided a general map type. When no match is found, the
 65+ * default map type will be returned.
 66+ *
 67+ * @param string $type
 68+ * @param boolean $earthEnabled
 69+ * @return string
 70+ */
 71+ public static function getGMapType($type, $earthEnabled = false) {
 72+ global $egMapsGoogleMapsType;
 73+
 74+ if (! array_key_exists($type, self::$mapTypes)) {
 75+ $type = $earthEnabled ? "earth" : $egMapsGoogleMapsType;
 76+ }
 77+
 78+ return self::$mapTypes[ $type ];
 79+ }
 80+
 81+ /**
 82+ * Returns the Google Map Control type (defined in MapsGoogleMaps::$controlClasses)
 83+ * for the provided a general map control type. When no match is found, the provided
 84+ * control name will be used.
 85+ *
 86+ * @param array $controls
 87+ * @return string
 88+ */
 89+ public static function getGControlType(array $controls) {
 90+ global $egMapsGMapControl;
 91+ $control = count($controls) > 0 ? $controls[0] : $egMapsGMapControl;
 92+ return array_key_exists($control, self::$controlClasses) ? self::$controlClasses[$control] : $control;
 93+ }
 94+
 95+ /**
 96+ * Retuns an array holding the default parameters and their values.
 97+ *
 98+ * @return array
 99+ */
 100+ public static function getDefaultParams() {
 101+ return array
 102+ (
 103+ 'type' => '',
 104+ 'types' => array(),
 105+ 'class' => 'pmap',
 106+ 'autozoom' => '',
 107+ 'earth' => '',
 108+ 'style' => ''
 109+ );
 110+ }
 111+
 112+ /**
 113+ * Add references to the Google Maps API and required JS file to the provided output
 114+ *
 115+ * @param unknown_type $output
 116+ */
 117+ public static function addGMapDependencies(&$output) {
 118+ global $wgJsMimeType, $wgLang;
 119+ global $egGoogleMapsKey, $egMapsIncludePath, $egGoogleMapsOnThisPage;
 120+
 121+ if (empty($egGoogleMapsOnThisPage)) {
 122+
 123+ $egGoogleMapsOnThisPage = 0;
 124+ $output .= "<script src='http://maps.google.com/maps?file=api&v=2&key=$egGoogleMapsKey&hl={$wgLang->getCode()}' type='$wgJsMimeType'></script>
 125+ <script type='$wgJsMimeType' src='$egMapsIncludePath/GoogleMaps/GoogleMapFunctions.js'></script>";
 126+ }
 127+ }
 128+
 129+ /**
 130+ * Retuns a boolean as string, true if $autozoom is on or yes.
 131+ *
 132+ * @param string $autozoom
 133+ * @return string
 134+ */
 135+ public static function getAutozoomJSValue($autozoom) {
 136+ return MapsMapper::getJSBoolValue(in_array($autozoom, array('on', 'yes')));
 137+ }
 138+
 139+ /**
 140+ * Returns a boolean representing if the earth map type should be showed or not,
 141+ * when provided the the wiki code value.
 142+ *
 143+ * @param string $earthValue
 144+ * @return boolean Indicates wether the earth type should be enabled.
 145+ */
 146+ public static function getEarthValue($earthValue) {
 147+ $trueValues = array('on', 'yes');
 148+ return in_array($earthValue, $trueValues);
 149+ }
 150+
 151+
 152+}
\ No newline at end of file
Index: trunk/extensions/Maps/GoogleMaps/GoogleMapFunctions.js
@@ -11,8 +11,8 @@
1212
1313
1414 /**
15 - * Returns GMarker object on the provided location.
16 - * It will show a popup baloon with title and label when clicked, if either of these is set.
 15+ * Returns GMarker object on the provided location. It will show a popup baloon
 16+ * with title and label when clicked, if either of these is set.
1717 */
1818 function createGMarker(point, title, label, icon) {
1919 var marker;
@@ -42,31 +42,38 @@
4343 /**
4444 * Returns GMap2 object with the provided properties and markers.
4545 */
46 -function initializeGoogleMap(mapName, width, height, lat, lon, zoom, type, control, scrollWheelZoom, earthEnabled, markers) {
 46+function initializeGoogleMap(mapName, width, height, lat, lon, zoom, type, types, control, scrollWheelZoom, earthEnabled, markers) {
4747 var map;
4848
4949 var centre = (lat != null && lon != null) ? new GLatLng(lat, lon) : null;
5050
5151 if (GBrowserIsCompatible()) {
52 - map = createGoogleMap(document.getElementById(mapName), new GSize(width, height), centre, zoom, type, control, scrollWheelZoom, earthEnabled, markers);
 52+ map = createGoogleMap(document.getElementById(mapName), new GSize(width, height), centre, zoom, type, types, control, scrollWheelZoom, earthEnabled, markers);
5353 }
54 -
 54+
5555 return map;
5656 }
5757
5858 /**
5959 * Returns GMap2 object with the provided properties.
6060 */
61 -function createGoogleMap(mapElement, size, centre, zoom, type, control, scrollWheelZoom, earthEnabled, markers) {
62 - var map = new GMap2(mapElement, {size: size});
 61+function createGoogleMap(mapElement, size, centre, zoom, type, types, control, scrollWheelZoom, earthEnabled, markers) {
 62+ var typesContainType = false;
 63+
 64+ for (var i = 0; i < types.length; i++) {
 65+ if (types[i] == type) typesContainType = true;
 66+ }
6367
64 - if (earthEnabled) map.addMapType(G_SATELLITE_3D_MAP);
65 - map.addMapType(type);
 68+ if (! typesContainType) types.push(type);
6669
 70+ // TODO: Change labels of the moon/mars map types?
 71+
 72+ var map = new GMap2(mapElement, {size: size, mapTypes: types});
 73+
6774 map.setMapType(type);
6875
6976 var bounds = ((zoom == null || centre == null) && markers.length > 1) ? new GLatLngBounds() : null;
70 -
 77+
7178 for (i in markers) {
7279 var marker = markers[i];
7380 map.addOverlay(createGMarker(marker.point, marker.title, marker.label, marker.icon));
@@ -76,7 +83,7 @@
7784 if (bounds != null) {
7885 map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
7986 }
80 -
 87+
8188 if (centre != null) map.setCenter(centre);
8289 if (zoom != null) map.setZoom(zoom);
8390
@@ -85,6 +92,8 @@
8693 if (typeof(control) != 'undefined') map.addControl(control);
8794 if (scrollWheelZoom) map.enableScrollWheelZoom();
8895
 96+ map.enableContinuousZoom();
 97+
8998 return map;
9099 }
91100
Index: trunk/extensions/Maps/Maps_MapFeature.php
@@ -60,6 +60,8 @@
6161 $mapProperties = MapsMapper::getValidParams($mapProperties, $egMapsServices[$this->serviceName]['parameters']);
6262 $mapProperties = MapsMapper::setDefaultParValues($mapProperties, $this->defaultParams);
6363
 64+ $mapProperties['coordinates'] = explode(';', $mapProperties['coordinates']);
 65+
6466 // Go through the array with map parameters and create new variables
6567 // with the name of the key and value of the item if they don't exist on class level yet.
6668 foreach($mapProperties as $paramName => $paramValue) {
@@ -67,7 +69,7 @@
6870 $this->{$paramName} = $paramValue;
6971 }
7072 }
71 -
 73+
7274 MapsMapper::enforceArrayValues($this->controls);
7375 }
7476
Index: trunk/extensions/Maps/YahooMaps/YahooMapFunctions.js
@@ -31,31 +31,43 @@
3232 /**
3333 * Returns YMap object with the provided properties and markers.
3434 */
35 -function initializeYahooMap(mapName, lat, lon, zoom, type, controls, scrollWheelZoom, markers) {
 35+function initializeYahooMap(mapName, lat, lon, zoom, type, types, controls, scrollWheelZoom, markers) {
3636 var centre = (lon != null && lat != null) ? new YGeoPoint(lat, lon) : null;
37 - return createYahooMap(document.getElementById(mapName), centre, zoom, type, controls, scrollWheelZoom, markers);
 37+ return createYahooMap(document.getElementById(mapName), centre, zoom, type, types, controls, scrollWheelZoom, markers);
3838 }
3939
4040 /**
4141 * Returns YMap object with the provided properties.
4242 */
43 -function createYahooMap(mapElement, centre, zoom, type, controls, scrollWheelZoom, markers) {
44 - var map = new YMap(mapElement);
 43+function createYahooMap(mapElement, centre, zoom, type, types controls, scrollWheelZoom, markers) {
 44+ var typesContainType = false;
 45+
 46+ for (var i = 0; i < types.length; i++) {
 47+ if (types[i] == type) typesContainType = true;
 48+ }
4549
46 - map.addTypeControl();
 50+ if (! typesContainType) types.push(type);
 51+
 52+ var map = new YMap(mapElement, type);
4753
4854 for (i in controls){
4955 switch (controls[i]) {
 56+ case 'type' :
 57+ map.addTypeControl(types);
 58+ break;
5059 case 'pan' :
5160 map.addPanControl();
5261 break;
5362 case 'zoom' :
5463 map.addZoomLong();
55 - break;
 64+ break;
 65+ case 'short' :
 66+ map.addZoomShort();
 67+ break;
5668 }
5769 }
5870
59 - map.setMapType(type);
 71+ map.setMapType();
6072
6173 if (!scrollWheelZoom) map.disableKeyControls();
6274
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php
@@ -1,6 +1,7 @@
22 <?php
 3+
34 /**
4 - * A class that holds static helper functions for Yahoo! Maps
 5+ * Class for handling the Maps parser functions with Yahoo! Maps
56 *
67 * @file Maps_YahooMaps.php
78 * @ingroup Maps
@@ -18,84 +19,15 @@
1920
2021 public $serviceName = self::SERVICE_NAME;
2122
22 - // http://developer.yahoo.com/maps/ajax
23 - private static $mapTypes = array(
24 - 'normal' => 'YAHOO_MAP_REG',
25 - 'satellite' => 'YAHOO_MAP_SAT',
26 - 'hybrid' => 'YAHOO_MAP_HYB'
27 - );
28 -
2923 /**
30 - * Returns the Yahoo Map type (defined in MapsYahooMaps::$mapTypes)
31 - * for the provided a general map type. When no match is found, the first
32 - * Google Map type will be returned as default.
33 - *
34 - * @param string $type
35 - * @return string
36 - */
37 - public static function getYMapType($type) {
38 - global $egMapsYahooMapsType;
39 - if (! array_key_exists($type, MapsYahooMaps::$mapTypes)) $type = $egMapsYahooMapsType;
40 - return MapsYahooMaps::$mapTypes[ $type ];
41 - }
42 -
43 - /**
44 - * Build up a csv string with the controls, to be outputted as a JS array
45 - *
46 - * @param array $controls
47 - * @return csv string
48 - */
49 - public static function createControlsString(array $controls) {
50 - global $egMapsYMapControls;
51 - return MapsMapper::createJSItemsString($controls, $egMapsYMapControls);
52 - }
53 -
54 - /**
55 - * Retuns an array holding the default parameters and their values.
56 - *
57 - * @return array
58 - */
59 - public static function getDefaultParams() {
60 - return array
61 - (
62 - 'type' => '',
63 - 'autozoom' => '',
64 - );
65 - }
66 -
67 - /**
68 - * Add references to the Yahoo! Maps API and required JS file to the provided output
69 - *
70 - * @param string $output
71 - */
72 - public static function addYMapDependencies(&$output) {
73 - global $wgJsMimeType;
74 - global $egYahooMapsKey, $egMapsIncludePath, $egYahooMapsOnThisPage;
75 -
76 - if (empty($egYahooMapsOnThisPage)) {
77 - $egYahooMapsOnThisPage = 0;
78 - $output .= "<script type='$wgJsMimeType' src='http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=$egYahooMapsKey'></script>
79 - <script type='$wgJsMimeType' src='$egMapsIncludePath/YahooMaps/YahooMapFunctions.js'></script>";
80 - }
81 - }
82 -
83 - /**
84 - * Retuns a boolean as string, true if $autozoom is on or yes.
85 - *
86 - * @param string $autozoom
87 - * @return string
88 - */
89 - public static function getAutozoomJSValue($autozoom) {
90 - return MapsMapper::getJSBoolValue(in_array($autozoom, array('on', 'yes')));
91 - }
92 -
93 - /**
9424 * @see MapsBaseMap::setFormInputSettings()
9525 *
9626 */
9727 protected function setMapSettings() {
9828 global $egMapsYahooMapsZoom, $egMapsYahooMapsPrefix;
9929
 30+ $this->defaultParams = MapsYahooMapsUtils::getDefaultParams();
 31+
10032 $this->elementNamePrefix = $egMapsYahooMapsPrefix;
10133 $this->defaultZoom = $egMapsYahooMapsZoom;
10234 }
@@ -107,7 +39,7 @@
10840 protected function doMapServiceLoad() {
10941 global $egYahooMapsOnThisPage;
11042
111 - self::addYMapDependencies($this->output);
 43+ MapsYahooMapsUtils::addYMapDependencies($this->output);
11244 $egYahooMapsOnThisPage++;
11345
11446 $this->elementNr = $egYahooMapsOnThisPage;
@@ -120,13 +52,13 @@
12153 public function addSpecificMapHTML() {
12254 global $wgJsMimeType;
12355
124 - $this->type = self::getYMapType($this->type);
125 - $this->controls = self::createControlsString($this->controls);
 56+ $this->type = MapsYahooMapsUtils::getYMapType($this->type);
 57+ $this->controls = MapsYahooMapsUtils::createControlsString($this->controls);
12658
12759 MapsUtils::makePxValue($this->width);
12860 MapsUtils::makePxValue($this->height);
12961
130 - $this->autozoom = self::getAutozoomJSValue($this->autozoom);
 62+ $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom);
13163
13264 $markerItems = array();
13365
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsUtils.php
@@ -0,0 +1,95 @@
 2+<?php
 3+
 4+/**
 5+ * A class that holds static helper functions for Yahoo! Maps
 6+ *
 7+ * @file Maps_YahooMapsUtils.php
 8+ * @ingroup Maps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+final class MapsYahooMapsUtils {
 18+
 19+ // http://developer.yahoo.com/maps/ajax
 20+ private static $mapTypes = array(
 21+ 'normal' => 'YAHOO_MAP_REG',
 22+ 'YAHOO_MAP_REG' => 'YAHOO_MAP_REG',
 23+
 24+ 'satellite' => 'YAHOO_MAP_SAT',
 25+ 'YAHOO_MAP_SAT' => 'YAHOO_MAP_SAT',
 26+
 27+ 'hybrid' => 'YAHOO_MAP_HYB',
 28+ 'YAHOO_MAP_HYB' => 'YAHOO_MAP_HYB'
 29+ );
 30+
 31+ /**
 32+ * Returns the Yahoo Map type (defined in MapsYahooMaps::$mapTypes)
 33+ * for the provided a general map type. When no match is found, the first
 34+ * Google Map type will be returned as default.
 35+ *
 36+ * @param string $type
 37+ * @return string
 38+ */
 39+ public static function getYMapType($type) {
 40+ global $egMapsYahooMapsType;
 41+ if (! array_key_exists($type, self::$mapTypes)) $type = $egMapsYahooMapsType;
 42+ return self::$mapTypes[ $type ];
 43+ }
 44+
 45+ /**
 46+ * Build up a csv string with the controls, to be outputted as a JS array
 47+ *
 48+ * @param array $controls
 49+ * @return csv string
 50+ */
 51+ public static function createControlsString(array $controls) {
 52+ global $egMapsYMapControls;
 53+ return MapsMapper::createJSItemsString($controls, $egMapsYMapControls);
 54+ }
 55+
 56+ /**
 57+ * Retuns an array holding the default parameters and their values.
 58+ *
 59+ * @return array
 60+ */
 61+ public static function getDefaultParams() {
 62+ return array
 63+ (
 64+ 'type' => '',
 65+ 'autozoom' => '',
 66+ );
 67+ }
 68+
 69+ /**
 70+ * Add references to the Yahoo! Maps API and required JS file to the provided output
 71+ *
 72+ * @param string $output
 73+ */
 74+ public static function addYMapDependencies(&$output) {
 75+ global $wgJsMimeType;
 76+ global $egYahooMapsKey, $egMapsIncludePath, $egYahooMapsOnThisPage;
 77+
 78+ if (empty($egYahooMapsOnThisPage)) {
 79+ $egYahooMapsOnThisPage = 0;
 80+ $output .= "<script type='$wgJsMimeType' src='http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=$egYahooMapsKey'></script>
 81+ <script type='$wgJsMimeType' src='$egMapsIncludePath/YahooMaps/YahooMapFunctions.js'></script>";
 82+ }
 83+ }
 84+
 85+ /**
 86+ * Retuns a boolean as string, true if $autozoom is on or yes.
 87+ *
 88+ * @param string $autozoom
 89+ * @return string
 90+ */
 91+ public static function getAutozoomJSValue($autozoom) {
 92+ return MapsMapper::getJSBoolValue(in_array($autozoom, array('on', 'yes')));
 93+ }
 94+
 95+
 96+}
\ No newline at end of file
Index: trunk/extensions/Maps/Maps_Settings.php
@@ -81,6 +81,9 @@
8282 # String. The Google Maps map name prefix. It can not be identical to the one of another mapping service.
8383 $egMapsGoogleMapsPrefix = 'map_google';
8484
 85+# Array of String. The Google Maps default map types. This value will only be used when the user does not provide one.
 86+$egMapsGoogleMapsTypes = array('normal', 'satellite', 'hybrid', 'physical');
 87+
8588 # Integer. The default zoom of a map. This value will only be used when the user does not provide one.
8689 $egMapsGoogleMapsZoom = 14;
8790
@@ -106,6 +109,9 @@
107110 # String. The Yahoo maps map name prefix. It can not be identical to the one of another mapping service.
108111 $egMapsYahooMapsPrefix = 'map_yahoo';
109112
 113+# Array of String. The Google Maps default map types. This value will only be used when the user does not provide one.
 114+$egMapsYahooMapsTypes = array('normal', 'satellite', 'hybrid');
 115+
110116 # Integer. The default zoom of a map. This value will only be used when the user does not provide one.
111117 $egMapsYahooMapsZoom = 4;
112118
Index: trunk/extensions/Maps/Maps_Utils.php
@@ -1,7 +1,8 @@
22 <?php
33
44 /**
5 - * A class that holds static helper functions for Semantic Maps
 5+ * A class that holds static helper functions for common functionality that is map-spesific.
 6+ * Non spesific functions are located in @see MapsParserFunctions
67 *
78 * @file Maps_Utils.php
89 * @ingroup Maps
@@ -15,7 +16,7 @@
1617 die ( 'Not an entry point.' );
1718 }
1819
19 -class MapsUtils {
 20+class MapsUtils {
2021
2122 public static function getLatLon($coordinates) {
2223 $coordinates = preg_split ( "/,/", $coordinates );
Index: trunk/extensions/Maps/Maps_BaseMap.php
@@ -14,7 +14,10 @@
1515 }
1616
1717 abstract class MapsBaseMap extends MapsMapFeature {
18 -
 18+
 19+ // TODO: move this abstract function to a new MApsBaseMapUtils file?
 20+ //protected abstract static function getDefaultParams();
 21+
1922 protected $markerData = array();
2023
2124 /**
@@ -26,8 +29,6 @@
2730 * @return unknown
2831 */
2932 public final function displayMap(&$parser, $map) {
30 - $this->defaultParams = $this->getDefaultParams();
31 -
3233 $this->setMapSettings();
3334
3435 $this->doMapServiceLoad();
@@ -84,20 +85,25 @@
8586 private function setCentre() {
8687 if (empty($this->centre)) {
8788 if (count($this->markerData) == 1) {
 89+ // If centre is not set and there is exactelly one marker, use it's coordinates.
8890 $this->centre_lat = $this->markerData[0]['lat'];
8991 $this->centre_lon = $this->markerData[0]['lon'];
9092 }
9193 elseif (count($this->markerData) > 1) {
92 - // TODO
93 - die("// TODO: calculate centre and zoom (with SGM code?)");
 94+ // If centre is not set and there are multiple markers, set the values to null,
 95+ // to be auto determined by the JS of the mapping API.
 96+ $this->centre_lat = 'null';
 97+ $this->centre_lon = 'null';
9498 }
9599 else {
 100+ // If centre is not set and there are no markers, use the default latitude and longitutde.
96101 global $egMapsMapLat, $egMapsMapLon;
97102 $this->centre_lat = $egMapsMapLat;
98103 $this->centre_lon = $egMapsMapLon;
99104 }
100105 }
101106 else {
 107+ // If a centre value is set, use it.
102108 $centre = MapsUtils::getLatLon($this->centre);
103109 $this->centre_lat = $centre['lat'];
104110 $this->centre_lon = $centre['lon'];

Status & tagging log