Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php |
— | — | @@ -100,7 +100,7 @@ |
101 | 101 | */ |
102 | 102 | public static function createControlsString($controls) { |
103 | 103 | global $egMapsOLControls; |
104 | | - return MapsMapper::createControlsString($controls, $egMapsOLControls); |
| 104 | + return MapsMapper::createJSItemsString($controls, $egMapsOLControls); |
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
— | — | @@ -112,6 +112,14 @@ |
113 | 113 | |
114 | 114 | $this->elementNamePrefix = $egMapsOpenLayersPrefix; |
115 | 115 | $this->defaultZoom = $egMapsOpenLayersZoom; |
| 116 | + |
| 117 | + $this->serviceName = 'openlayers'; |
| 118 | + |
| 119 | + $this->defaultParams = array |
| 120 | + ( |
| 121 | + 'layers' => array(), |
| 122 | + 'baselayer' => '' |
| 123 | + ); |
116 | 124 | } |
117 | 125 | |
118 | 126 | /** |
— | — | @@ -135,15 +143,27 @@ |
136 | 144 | global $wgJsMimeType; |
137 | 145 | |
138 | 146 | $controlItems = self::createControlsString($this->controls); |
| 147 | + |
| 148 | + MapsMapper::enforceArrayValues($this->layers); |
139 | 149 | $layerItems = self::createLayersStringAndLoadDependencies($this->output, $this->layers); |
140 | 150 | |
141 | 151 | MapsUtils::makePxValue($this->width); |
142 | 152 | MapsUtils::makePxValue($this->height); |
143 | 153 | |
| 154 | + $markerItems = array(); |
| 155 | + |
| 156 | + foreach ($this->markerData as $markerData) { |
| 157 | + $lat = $markerData['lat']; |
| 158 | + $lon = $markerData['lon']; |
| 159 | + $markerItems[] = "getOLMarkerData($lon, $lat, '$this->title', '$this->label')"; |
| 160 | + } |
| 161 | + |
| 162 | + $markersString = implode(',', $markerItems); |
| 163 | + |
144 | 164 | $this->output .= "<div id='$this->mapName' style='width: $this->width; height: $this->height; background-color: #cccccc;'></div> |
145 | 165 | <script type='$wgJsMimeType'> /*<![CDATA[*/ |
146 | 166 | addLoadEvent( |
147 | | - initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[getOLMarkerData($this->marker_lon, $this->marker_lat, '$this->title', '$this->label')]) |
| 167 | + initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[$markersString]) |
148 | 168 | ); |
149 | 169 | /*]]>*/ </script>"; |
150 | 170 | } |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -46,15 +46,31 @@ |
47 | 47 | |
48 | 48 | $egMapsServices['googlemaps'] = array( |
49 | 49 | 'pf' => array('class' => 'MapsGoogleMaps', 'file' => 'GoogleMaps/Maps_GoogleMaps.php', 'local' => true), |
50 | | - 'aliases' => array('google', 'googlemap', 'gmap', 'gmaps') |
| 50 | + 'aliases' => array('google', 'googlemap', 'gmap', 'gmaps'), |
| 51 | + 'parameters' => array( |
| 52 | + 'type' => array('map-type', 'map type'), |
| 53 | + 'earth' => array(), |
| 54 | + 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom'), |
| 55 | + 'class' => array() |
| 56 | + ) |
51 | 57 | ); |
| 58 | + |
52 | 59 | $egMapsServices['openlayers'] = array( |
53 | 60 | 'pf' => array('class' => 'MapsOpenLayers', 'file' => 'OpenLayers/Maps_OpenLayers.php', 'local' => true), |
54 | | - 'aliases' => array('layers', 'openlayer') |
| 61 | + 'aliases' => array('layers', 'openlayer'), |
| 62 | + 'parameters' => array( |
| 63 | + 'layers' => array(), |
| 64 | + 'baselayer' => array() |
| 65 | + ) |
55 | 66 | ); |
| 67 | + |
56 | 68 | $egMapsServices['yahoomaps'] = array( |
57 | 69 | 'pf' => array('class' => 'MapsYahooMaps', 'file' => 'YahooMaps/Maps_YahooMaps.php', 'local' => true), |
58 | | - 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps') |
| 70 | + 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps'), |
| 71 | + 'parameters' => array( |
| 72 | + 'type' => array('map-type'), |
| 73 | + 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom') |
| 74 | + ) |
59 | 75 | ); |
60 | 76 | |
61 | 77 | /** |
— | — | @@ -100,11 +116,13 @@ |
101 | 117 | function efMapsAddParserHooks() { |
102 | 118 | global $wgParser; |
103 | 119 | |
104 | | - // A hook to enable the '#display_point' parser function |
| 120 | + // A hooks to enable the '#display_point' and '#display_points' parser functions |
105 | 121 | $wgParser->setFunctionHook( 'display_point', array('MapsMapper', 'displayPointRender' )); |
| 122 | + $wgParser->setFunctionHook( 'display_points', array('MapsMapper', 'displayPointsRender' )); |
106 | 123 | |
107 | | - // A hook to enable the '#display_adress' parser function |
| 124 | + // A hooks to enable the '#display_adress' and '#display_adresses' parser functions |
108 | 125 | $wgParser->setFunctionHook( 'display_address', array('MapsMapper', 'displayAddressRender' )); |
| 126 | + $wgParser->setFunctionHook( 'display_addresses', array('MapsMapper', 'displayAddressesRender' )); |
109 | 127 | |
110 | 128 | // A hook to enable the geocoder parser functions |
111 | 129 | $wgParser->setFunctionHook( 'geocode', array('MapsGeocoder', 'renderGeocoder' )); |
— | — | @@ -113,21 +131,13 @@ |
114 | 132 | } |
115 | 133 | |
116 | 134 | /** |
117 | | - * This function ensures backward compatibility with Semantic Google Maps and other extensions |
118 | | - * using $wgGoogleMapsKey instead of $egGoogleMapsKey. |
119 | | - */ |
120 | | -function efMapsValidateGoogleMapsKey() { |
121 | | - global $egGoogleMapsKey, $wgGoogleMapsKey; |
122 | | - |
123 | | - if (strlen($egGoogleMapsKey) < 1 && isset($wgGoogleMapsKey)) $egGoogleMapsKey = $wgGoogleMapsKey; |
124 | | -} |
125 | | - |
126 | | -/** |
127 | 135 | * Adds the magic words for the parser functions |
128 | 136 | */ |
129 | 137 | function efMapsFunctionMagic( &$magicWords, $langCode ) { |
130 | 138 | $magicWords['display_point'] = array( 0, 'display_point' ); |
| 139 | + $magicWords['display_points'] = array( 0, 'display_points' ); |
131 | 140 | $magicWords['display_address'] = array( 0, 'display_address' ); |
| 141 | + $magicWords['display_addresses'] = array( 0, 'display_addresses' ); |
132 | 142 | |
133 | 143 | $magicWords['geocode'] = array( 0, 'geocode' ); |
134 | 144 | $magicWords['geocodelat'] = array ( 0, 'geocodelat' ); |
— | — | @@ -137,6 +147,16 @@ |
138 | 148 | } |
139 | 149 | |
140 | 150 | /** |
| 151 | + * This function ensures backward compatibility with Semantic Google Maps and other extensions |
| 152 | + * using $wgGoogleMapsKey instead of $egGoogleMapsKey. |
| 153 | + */ |
| 154 | +function efMapsValidateGoogleMapsKey() { |
| 155 | + global $egGoogleMapsKey, $wgGoogleMapsKey; |
| 156 | + |
| 157 | + if (strlen($egGoogleMapsKey) < 1 && isset($wgGoogleMapsKey)) $egGoogleMapsKey = $wgGoogleMapsKey; |
| 158 | +} |
| 159 | + |
| 160 | +/** |
141 | 161 | * Adds a link to Admin Links page |
142 | 162 | */ |
143 | 163 | function efMapsAddToAdminLinks(&$admin_links_tree) { |
Index: trunk/extensions/Maps/Maps_Mapper.php |
— | — | @@ -14,61 +14,123 @@ |
15 | 15 | } |
16 | 16 | |
17 | 17 | final class MapsMapper { |
18 | | - |
| 18 | + |
19 | 19 | /** |
| 20 | + * Array holding the allowed main parameters and their alias. |
| 21 | + * The array keys hold the main name, and the values are arrays holding the aliases. |
| 22 | + * |
| 23 | + * @var array |
| 24 | + */ |
| 25 | + private static $mainParams = array |
| 26 | + ( |
| 27 | + 'service' => array(), |
| 28 | + 'coordinates' => array('coords', 'location'), |
| 29 | + 'zoom' => array(), |
| 30 | + 'centre' => array('center'), |
| 31 | + 'width' => array(), |
| 32 | + 'height' => array(), |
| 33 | + 'controls' => array(), |
| 34 | + 'label' => array(), |
| 35 | + 'title' => array() |
| 36 | + ); |
| 37 | + |
| 38 | + /** |
20 | 39 | * Sets the default map properties and returns the new array. |
| 40 | + * This function also ensures all the properties are present, even when being empty, |
| 41 | + * which is important for the weakly typed classes using them. |
21 | 42 | * |
22 | 43 | * @param array $params Array containing the current set of pareters. |
| 44 | + * @param array $serviceDefaults Array with the default parameters and their values for the used mapping service. |
23 | 45 | * @param boolean $strict If set to false, values which a key that does not |
24 | 46 | * exist in the $map array will be retained. |
25 | 47 | * @return unknown |
26 | 48 | */ |
27 | | - public static function setDefaultParValues(array $params, $strict) { |
28 | | - global $egMapsMapCoordinates, $egMapsMapWidth, $egMapsMapHeight, $egMapsEnableAutozoom, $egMapsEnableEarth; |
| 49 | + public static function setDefaultParValues(array $params, array $serviceDefaults, $strict = true) { |
| 50 | + global $egMapsMapLat, $egMapsMapLon, $egMapsMapWidth, $egMapsMapHeight, $egMapsDefaultZoom, $egMapsDefaultService; |
29 | 51 | |
30 | | - $map = array( |
31 | | - 'service' => '', |
32 | | - 'coordinates' => $egMapsMapCoordinates, |
33 | | - 'zoom' => '', |
34 | | - 'centre' => '', |
35 | | - 'type' => '', |
36 | | - 'width' => "$egMapsMapWidth", |
37 | | - 'height' => "$egMapsMapHeight", |
38 | | - 'controls' => array(), |
39 | | - 'autozoom' => $egMapsEnableAutozoom ? 'on' : 'off', |
40 | | - 'earth' => $egMapsEnableEarth ? 'on' : 'off', |
41 | | - 'class' => 'pmap', |
42 | | - 'layers' => array(), |
43 | | - 'baselayer' => '', |
44 | | - 'title' => '', |
45 | | - 'label' => '', |
46 | | - 'style' => '' |
47 | | - ); |
| 52 | + $mapDefaults = array( |
| 53 | + 'service' => $egMapsDefaultService, |
| 54 | + 'coordinates' => "$egMapsMapLat, $egMapsMapLon", |
| 55 | + 'zoom' => $egMapsDefaultZoom, |
| 56 | + 'centre' => '', |
| 57 | + 'width' => $egMapsMapWidth, |
| 58 | + 'height' => $egMapsMapHeight, |
| 59 | + 'controls' => array(), |
| 60 | + 'title' => '', |
| 61 | + 'label' => '' |
| 62 | + ); |
| 63 | + |
| 64 | + $map = array_merge($mapDefaults, $serviceDefaults); |
48 | 65 | |
49 | 66 | foreach($params as $paramName => $paramValue) { |
50 | 67 | if(array_key_exists($paramName, $map) || !$strict) $map[$paramName] = $paramValue; |
51 | 68 | } |
52 | 69 | |
53 | | - // Alias for centre |
54 | | - if(array_key_exists('center', $params)) $map['centre'] = $params['center']; |
| 70 | + return $map; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 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 unknown_type $params |
| 78 | + * @param unknown_type $serviceParameters |
| 79 | + * @return unknown |
| 80 | + */ |
| 81 | + public static function getValidParams($params, $serviceParameters) { |
| 82 | + $validParams = array(); |
55 | 83 | |
56 | | - self::enforceArrayValues($map['controls']); |
57 | | - self::enforceArrayValues($map['layers']); |
| 84 | + $allowedParms = array_merge(self::$mainParams, $serviceParameters); |
58 | 85 | |
59 | | - return $map; |
| 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; |
60 | 92 | } |
61 | 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 | + /** |
| 113 | + * Turns the provided values into an array by splitting it on comma's if |
| 114 | + * it's not an array yet. |
| 115 | + * |
| 116 | + * @param unknown_type $values |
| 117 | + * @param unknown_type $delimeter |
| 118 | + */ |
62 | 119 | public static function enforceArrayValues(&$values, $delimeter = ',') { |
63 | 120 | if (!is_array($values)) $values = split($delimeter, $values); // If not an array yet, split the values |
64 | 121 | for ($i = 0; $i < count($values); $i++) $values[$i] = trim($values[$i]); // Trim all values |
65 | 122 | } |
66 | 123 | |
67 | | - public static function createControlsString(array $controls, array $defaultControls) { |
68 | | - if (count($controls) < 1) $controls = $defaultControls; |
69 | | - $controlItems = ''; |
70 | | - foreach ($controls as $control) $controlItems .= "'$control'" . ','; |
71 | | - |
72 | | - return strtolower(rtrim($controlItems, ',')); |
| 124 | + /** |
| 125 | + * Checks if the items array has members, and sets it to the default when this is not the case. |
| 126 | + * Then returns an imploded/joined, comma seperated, version of the array as string. |
| 127 | + * |
| 128 | + * @param array $items |
| 129 | + * @param array $defaultItems |
| 130 | + * @return unknown |
| 131 | + */ |
| 132 | + public static function createJSItemsString(array $items, array $defaultItems) { |
| 133 | + if (count($items) < 1) $items = $defaultItems; |
| 134 | + return "'" . strtolower(implode("','", $items)) . "'"; |
73 | 135 | } |
74 | 136 | |
75 | 137 | /** |
— | — | @@ -79,6 +141,8 @@ |
80 | 142 | * @return unknown |
81 | 143 | */ |
82 | 144 | public static function displayPointRender(&$parser) { |
| 145 | + global $egMapsServices; |
| 146 | + |
83 | 147 | $params = func_get_args(); |
84 | 148 | array_shift( $params ); // We already know the $parser ... |
85 | 149 | |
— | — | @@ -98,24 +162,13 @@ |
99 | 163 | } |
100 | 164 | } |
101 | 165 | |
102 | | - $map = self::setDefaultParValues($map, true); |
103 | | - |
| 166 | + $map['coordinates'] = explode(';', $map['coordinates']); |
| 167 | + |
104 | 168 | $map['service'] = self::getValidService($map['service']); |
105 | | - |
106 | 169 | |
107 | | - switch($map['service']) { |
108 | | - case 'openlayers' : |
109 | | - $mapClass = new MapsOpenLayers(); |
110 | | - break; |
111 | | - case 'yahoomaps' : |
112 | | - $mapClass = new MapsYahooMaps(); |
113 | | - break; |
114 | | - default: |
115 | | - $mapClass = new MapsGoogleMaps(); |
116 | | - break; |
117 | | - } |
| 170 | + $map = self::setDefaultParValues($map, $egMapsServices[$map['service']]['parameters'], true); |
118 | 171 | |
119 | | - $mapClass = new $egMapsServices[$map['service']]['qp']['class'](); |
| 172 | + $mapClass = new $egMapsServices[$map['service']]['pf']['class'](); |
120 | 173 | |
121 | 174 | // Call the function according to the map service to get the HTML output |
122 | 175 | $output = $mapClass->displayMap($parser, $map); |
— | — | @@ -125,6 +178,16 @@ |
126 | 179 | } |
127 | 180 | |
128 | 181 | /** |
| 182 | + * Sets the default map properties, gets the map HTML depending |
| 183 | + * on the provided service, and then returns it. |
| 184 | + * |
| 185 | + * @param unknown_type $parser |
| 186 | + */ |
| 187 | + public static function displayPointsRender(&$parser) { |
| 188 | + return self::displayPointRender(func_get_args()); |
| 189 | + } |
| 190 | + |
| 191 | + /** |
129 | 192 | * Turns the address parameter into coordinates, then lets |
130 | 193 | * @see MapsMapper::displayPointRender() do the work and returns it. |
131 | 194 | * |
— | — | @@ -132,42 +195,64 @@ |
133 | 196 | * @return unknown |
134 | 197 | */ |
135 | 198 | public static function displayAddressRender(&$parser) { |
136 | | - // TODO: refactor to reduce redundancy and improve performance |
137 | 199 | global $egMapsDefaultService; |
138 | 200 | |
139 | 201 | $params = func_get_args(); |
140 | 202 | array_shift( $params ); // We already know the $parser ... |
141 | 203 | |
| 204 | + self::changeAddressToCoords($params); |
| 205 | + |
| 206 | + return self::displayPointRender($parser, $params); |
| 207 | + } |
| 208 | + |
| 209 | + /** |
| 210 | + * Turns the address parameter into coordinates, then lets |
| 211 | + * @see MapsMapper::displayPointRender() do the work and returns it. |
| 212 | + * |
| 213 | + * @param unknown_type $parser |
| 214 | + */ |
| 215 | + public static function displayAddressesRender(&$parser) { |
| 216 | + return self::displayAddressRender(func_get_args()); |
| 217 | + } |
| 218 | + |
| 219 | + /** |
| 220 | + * Changes the values of the address or addresses parameter into coordinates |
| 221 | + * in the provided array. |
| 222 | + * |
| 223 | + * @param array $params |
| 224 | + */ |
| 225 | + private static function changeAddressToCoords(&$params) { |
| 226 | + global $egMapsDefaultService; |
| 227 | + |
142 | 228 | for ($i = 0; $i < count($params); $i++) { |
143 | 229 | $split = split('=', $params[$i]); |
144 | 230 | if (strtolower(trim($split[0])) == 'service' && count($split) > 1) { |
145 | 231 | $service = trim($split[1]); |
146 | 232 | } |
| 233 | + else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) { |
| 234 | + $geoservice = trim($split[1]); |
| 235 | + } |
147 | 236 | } |
148 | 237 | |
149 | | - |
150 | 238 | $service = isset($service) ? MapsMapper::getValidService($service) : $egMapsDefaultService; |
| 239 | + $geoservice = isset($geoservice) ? $geoservice : ''; |
151 | 240 | |
152 | | - $geoservice = ''; |
153 | | - |
154 | 241 | for ($i = 0; $i < count($params); $i++) { |
155 | 242 | $split = split('=', $params[$i]); |
156 | | - if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) { |
157 | | - $geoservice = trim($split[1]); |
| 243 | + if (((strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1) || count($split) == 1) { |
| 244 | + $address_srting = count($split) == 1 ? $split[0] : $split[1]; |
| 245 | + |
| 246 | + $addresses = explode(';', $address_srting); |
| 247 | + |
| 248 | + $coordinates = array(); |
| 249 | + |
| 250 | + foreach($addresses as $address) { |
| 251 | + $coordinates[] = MapsGeocoder::renderGeocoder(null, trim($address), $geoservice, $service); |
| 252 | + } |
| 253 | + |
| 254 | + $params[$i] = 'coordinates=' . implode(';', $coordinates); |
158 | 255 | } |
159 | | - } |
160 | | - |
161 | | - for ($i = 0; $i < count($params); $i++) { |
162 | | - $split = split('=', $params[$i]); |
163 | | - if (strtolower(trim($split[0])) == 'address' && count($split) > 1) { |
164 | | - $params[$i] = 'coordinates=' . MapsGeocoder::renderGeocoder($parser, trim($split[1]), $geoservice, $service); |
165 | | - } |
166 | | - if (count($split) == 1) { // Default parameter (without name) |
167 | | - $params[$i] = 'coordinates=' . MapsGeocoder::renderGeocoder($parser, trim($split[0]), $geoservice, $service); |
168 | | - } |
169 | | - } |
170 | | - |
171 | | - return self::displayPointRender($parser, $params); |
| 256 | + } |
172 | 257 | } |
173 | 258 | |
174 | 259 | /** |
— | — | @@ -187,7 +272,7 @@ |
188 | 273 | } |
189 | 274 | |
190 | 275 | /** |
191 | | - * Checks if the service name is an allias for an actual service, |
| 276 | + * Checks if the service name is an alias for an actual service, |
192 | 277 | * and changes it into the main service name if this is the case. |
193 | 278 | * |
194 | 279 | * @param unknown_type $service |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php |
— | — | @@ -16,11 +16,11 @@ |
17 | 17 | |
18 | 18 | // http://code.google.com/apis/maps/documentation/introduction.html#MapTypes |
19 | 19 | private static $mapTypes = array( |
20 | | - 'earth' => 'G_SATELLITE_3D_MAP', |
21 | 20 | 'normal' => 'G_NORMAL_MAP', |
22 | 21 | 'satellite' => 'G_SATELLITE_MAP', |
23 | 22 | 'hybrid' => 'G_HYBRID_MAP', |
24 | 23 | 'physical' => 'G_PHYSICAL_MAP', |
| 24 | + 'earth' => 'G_SATELLITE_3D_MAP', |
25 | 25 | ); |
26 | 26 | |
27 | 27 | // http://code.google.com/apis/maps/documentation/controls.html#Controls_overview |
— | — | @@ -35,10 +35,13 @@ |
36 | 36 | * possible Google Map type will be returned as default. |
37 | 37 | */ |
38 | 38 | public static function getGMapType($type, $earthEnabled = false) { |
39 | | - $keyz = array_keys(MapsGoogleMaps::$mapTypes); |
40 | | - $defaultKey = $earthEnabled ? 0 : 1; |
41 | | - $keyName = array_key_exists($type, MapsGoogleMaps::$mapTypes) ? $type : $keyz[ "$defaultKey" ]; |
42 | | - return self::$mapTypes[ $keyName ]; |
| 39 | + global $egMapsGoogleMapsType; |
| 40 | + |
| 41 | + if (! array_key_exists($type, MapsGoogleMaps::$mapTypes)) { |
| 42 | + $type = $earthEnabled ? "earth" : $egMapsGoogleMapsType;; |
| 43 | + } |
| 44 | + |
| 45 | + return self::$mapTypes[ $type ]; |
43 | 46 | } |
44 | 47 | |
45 | 48 | /** |
— | — | @@ -100,6 +103,16 @@ |
101 | 104 | |
102 | 105 | $this->elementNamePrefix = $egMapsGoogleMapsPrefix; |
103 | 106 | $this->defaultZoom = $egMapsGoogleMapsZoom; |
| 107 | + |
| 108 | + $this->serviceName = 'googlemaps'; |
| 109 | + |
| 110 | + $this->defaultParams = array |
| 111 | + ( |
| 112 | + 'type' => '', |
| 113 | + 'class' => 'pmap', |
| 114 | + 'autozoom' => '', |
| 115 | + 'earth' => '' |
| 116 | + ); |
104 | 117 | } |
105 | 118 | |
106 | 119 | /** |
— | — | @@ -127,13 +140,25 @@ |
128 | 141 | |
129 | 142 | $this->type = self::getGMapType($this->type, $enableEarth); |
130 | 143 | $control = self::getGControlType($this->controls); |
131 | | - |
| 144 | + |
| 145 | + $this->autozoom = ($this->autozoom == 'no' || $this->autozoom == 'off') ? 'false' : 'true'; |
| 146 | + |
| 147 | + $markerItems = array(); |
| 148 | + |
| 149 | + foreach ($this->markerData as $markerData) { |
| 150 | + $lat = $markerData['lat']; |
| 151 | + $lon = $markerData['lon']; |
| 152 | + $markerItems[] = "getGMarkerData($lat, $lon, '$this->title', '$this->label')"; |
| 153 | + } |
| 154 | + |
| 155 | + $markersString = implode(',', $markerItems); |
| 156 | + |
132 | 157 | $this->output .=<<<END |
133 | 158 | |
134 | 159 | <div id="$this->mapName" class="$this->class" style="$this->style" ></div> |
135 | 160 | <script type="$wgJsMimeType"> /*<![CDATA[*/ |
136 | 161 | addLoadEvent( |
137 | | - initializeGoogleMap('$this->mapName', $this->width, $this->height, $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, new $control(), $this->autozoom, $this->earth, [getGMarkerData($this->marker_lat, $this->marker_lon, '$this->title', '$this->label', '')]) |
| 162 | + initializeGoogleMap('$this->mapName', $this->width, $this->height, $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, new $control(), $this->autozoom, $this->earth, [$markersString]) |
138 | 163 | ); |
139 | 164 | /*]]>*/ </script> |
140 | 165 | |
Index: trunk/extensions/Maps/Maps_Geocoder.php |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | private static $mEnableCache = true; |
26 | 26 | private static $mGeocoderCache = array(); |
27 | 27 | |
28 | | - public static function renderGeocoder(&$parser, $address, $service = '', $mappingService = '') { |
| 28 | + public static function renderGeocoder($parser, $address, $service = '', $mappingService = '') { |
29 | 29 | $geovalues = MapsGeocoder::geocode($address, $service, $mappingService); |
30 | 30 | return $geovalues ? $geovalues['lat'].', '.$geovalues['lon'] : ''; |
31 | 31 | } |
Index: trunk/extensions/Maps/Maps_MapFeature.php |
— | — | @@ -33,7 +33,12 @@ |
34 | 34 | */
|
35 | 35 | protected abstract function addSpecificMapHTML();
|
36 | 36 |
|
| 37 | + protected $defaultParams = array();
|
| 38 | +
|
| 39 | + protected $serviceName;
|
| 40 | +
|
37 | 41 | protected $defaultZoom;
|
| 42 | +
|
38 | 43 | protected $elementNr;
|
39 | 44 | protected $elementNamePrefix;
|
40 | 45 |
|
— | — | @@ -50,15 +55,20 @@ |
51 | 56 | * @param unknown_type $map
|
52 | 57 | */
|
53 | 58 | protected function manageMapProperties($mapProperties, $className) {
|
54 | | - $mapProperties = MapsMapper::setDefaultParValues($mapProperties, true);
|
| 59 | + global $egMapsServices;
|
55 | 60 |
|
| 61 | + $mapProperties = MapsMapper::getValidParams($mapProperties, $egMapsServices[$this->serviceName]['parameters']);
|
| 62 | + $mapProperties = MapsMapper::setDefaultParValues($mapProperties, $this->defaultParams);
|
| 63 | +
|
56 | 64 | // Go through the array with map parameters and create new variables
|
57 | 65 | // with the name of the key and value of the item if they don't exist on class level yet.
|
58 | 66 | foreach($mapProperties as $paramName => $paramValue) {
|
59 | 67 | if (!property_exists($className, $paramName)) {
|
60 | 68 | $this->{$paramName} = $paramValue;
|
61 | 69 | }
|
62 | | - }
|
| 70 | + }
|
| 71 | +
|
| 72 | + MapsMapper::enforceArrayValues($this->controls);
|
63 | 73 | }
|
64 | 74 |
|
65 | 75 | /**
|
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php |
— | — | @@ -27,9 +27,8 @@ |
28 | 28 | * Google Map type will be returned as default. |
29 | 29 | */ |
30 | 30 | public static function getYMapType($type) { |
31 | | - $keyz = array_keys(MapsYahooMaps::$mapTypes); |
32 | | - $keyName = array_key_exists($type, MapsYahooMaps::$mapTypes) ? $type : $keyz[0]; |
33 | | - return MapsYahooMaps::$mapTypes[ $keyName ]; |
| 31 | + if (! array_key_exists($type, MapsYahooMaps::$mapTypes)) $type = $egMapsYahooMapsType; |
| 32 | + return MapsYahooMaps::$mapTypes[ $type ]; |
34 | 33 | } |
35 | 34 | |
36 | 35 | /** |
— | — | @@ -40,7 +39,7 @@ |
41 | 40 | */ |
42 | 41 | public static function createControlsString($controls) { |
43 | 42 | global $egMapsYMapControls; |
44 | | - return MapsMapper::createControlsString($controls, $egMapsYMapControls); |
| 43 | + return MapsMapper::createJSItemsString($controls, $egMapsYMapControls); |
45 | 44 | } |
46 | 45 | |
47 | 46 | /** |
— | — | @@ -68,6 +67,14 @@ |
69 | 68 | |
70 | 69 | $this->elementNamePrefix = $egMapsYahooMapsPrefix; |
71 | 70 | $this->defaultZoom = $egMapsYahooMapsZoom; |
| 71 | + |
| 72 | + $this->serviceName = 'yahoomaps'; |
| 73 | + |
| 74 | + $this->defaultParams = array |
| 75 | + ( |
| 76 | + 'type' => '', |
| 77 | + 'autozoom' => '', |
| 78 | + ); |
72 | 79 | } |
73 | 80 | |
74 | 81 | /** |
— | — | @@ -96,12 +103,24 @@ |
97 | 104 | MapsUtils::makePxValue($this->width); |
98 | 105 | MapsUtils::makePxValue($this->height); |
99 | 106 | |
| 107 | + $this->autozoom = ($this->autozoom == 'no' || $this->autozoom == 'off') ? 'false' : 'true'; |
| 108 | + |
| 109 | + $markerItems = array(); |
| 110 | + |
| 111 | + foreach ($this->markerData as $markerData) { |
| 112 | + $lat = $markerData['lat']; |
| 113 | + $lon = $markerData['lon']; |
| 114 | + $markerItems[] = "getYMarkerData($lat, $lon, '$this->title', '$this->label', '')"; |
| 115 | + } |
| 116 | + |
| 117 | + $markersString = implode(',', $markerItems); |
| 118 | + |
100 | 119 | $this->output .= <<<END |
101 | 120 | <div id="$this->mapName" style="width: $this->width; height: $this->height;"></div> |
102 | 121 | |
103 | 122 | <script type="$wgJsMimeType">/*<![CDATA[*/ |
104 | 123 | addLoadEvent( |
105 | | - initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$this->controls], $this->autozoom, [getYMarkerData($this->marker_lat, $this->marker_lon, '$this->title', '$this->label', '')]) |
| 124 | + initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$this->controls], $this->autozoom, [$markersString]) |
106 | 125 | ); |
107 | 126 | /*]]>*/</script> |
108 | 127 | END; |
Index: trunk/extensions/Maps/Maps_Settings.php |
— | — | @@ -30,6 +30,8 @@ |
31 | 31 | |
32 | 32 | |
33 | 33 | |
| 34 | + |
| 35 | + |
34 | 36 | # Map services configuration |
35 | 37 | |
36 | 38 | # Array of String. Array containing all the mapping services that will be made available to the user. |
— | — | @@ -42,6 +44,8 @@ |
43 | 45 | |
44 | 46 | |
45 | 47 | |
| 48 | + |
| 49 | + |
46 | 50 | # Geocoding services configuration |
47 | 51 | |
48 | 52 | # Array of String. Array containing all the geocoding services that will be made available to the user. |
— | — | @@ -54,6 +58,8 @@ |
55 | 59 | |
56 | 60 | |
57 | 61 | |
| 62 | + |
| 63 | + |
58 | 64 | # General map properties configuration |
59 | 65 | |
60 | 66 | # Integer. The default width and height of a map. These values will only be used when the user does not provide them. |
— | — | @@ -61,20 +67,29 @@ |
62 | 68 | $egMapsMapHeight = 350; |
63 | 69 | |
64 | 70 | # String. The default coordinates of the marker. This value will only be used when the user does not provide one. |
65 | | -$egMapsMapCoordinates = '1,1'; |
| 71 | +$egMapsMapLat = '1'; |
| 72 | +$egMapsMapLon = '1'; |
66 | 73 | |
| 74 | +# Integer. The default zoom of a map. This value will only be used when the user does not provide one. |
| 75 | +$egMapsDefaultZoom = 10; # Will be used when the default for a service is not provided |
67 | 76 | |
68 | 77 | |
| 78 | + |
| 79 | + |
| 80 | + |
69 | 81 | # Specific map properties configuration |
70 | 82 | |
| 83 | +# Google maps |
| 84 | + |
| 85 | +# String. The Google Maps map name prefix. It can not be identical to the one of another mapping service. |
| 86 | +$egMapsGoogleMapsPrefix = 'map_google'; |
| 87 | + |
71 | 88 | # Integer. The default zoom of a map. This value will only be used when the user does not provide one. |
72 | | -$egMapsGoogleMapsZoom = 14; # Google Maps |
73 | | -$egMapsYahooMapsZoom = 4; # Yahoo! Maps |
74 | | -$egMapsOpenLayersZoom = 10; # OpenLayers |
| 89 | +$egMapsGoogleMapsZoom = 14; |
75 | 90 | |
76 | 91 | # Boolean. The default value for enabling or disabling the autozoom of a map. |
77 | | -# This is for Google Maps and Yahoo! Maps only. This value will only be used when the user does not provide one. |
78 | | -$egMapsEnableAutozoom = true; |
| 92 | +# This value will only be used when the user does not provide one. |
| 93 | +$egMapsGoogleAutozoom = true; |
79 | 94 | |
80 | 95 | # Boolean. The default value for enabling or disabling the earth map type for Google Maps. |
81 | 96 | # This value will only be used when the user does not provide one. |
— | — | @@ -84,10 +99,40 @@ |
85 | 100 | # Available short values: large, small. Other values: http://code.google.com/apis/maps/documentation/controls.html#Controls_overview |
86 | 101 | $egMapsGMapControl = 'large'; |
87 | 102 | |
| 103 | +# String. The default map type. This value will only be used when the user does not provide one. |
| 104 | +$egMapsGoogleMapsType = 'normal'; |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +# Yahoo maps |
| 109 | + |
| 110 | +# String. The Yahoo maps map name prefix. It can not be identical to the one of another mapping service. |
| 111 | +$egMapsYahooMapsPrefix = 'map_yahoo'; |
| 112 | + |
| 113 | +# Integer. The default zoom of a map. This value will only be used when the user does not provide one. |
| 114 | +$egMapsYahooMapsZoom = 4; |
| 115 | + |
| 116 | +# Boolean. The default value for enabling or disabling the autozoom of a map. |
| 117 | +# This value will only be used when the user does not provide one. |
| 118 | +$egMapsYahooAutozoom = true; |
| 119 | + |
88 | 120 | # Array of String. The default controls for Yahoo! Maps. This value will only be used when the user does not provide one. |
89 | 121 | # Available values: pan, zoom |
90 | 122 | $egMapsYMapControls = array('pan', 'zoom'); |
91 | 123 | |
| 124 | +# String. The default map type. This value will only be used when the user does not provide one. |
| 125 | +$egMapsYahooMapsType = 'normal'; |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +# OpenLayers |
| 130 | + |
| 131 | +# String. The OpenLayers map name prefix. It can not be identical to the one of another mapping service. |
| 132 | +$egMapsOpenLayersPrefix = 'open_layer'; |
| 133 | + |
| 134 | +# Integer. The default zoom of a map. This value will only be used when the user does not provide one. |
| 135 | +$egMapsOpenLayersZoom = 10; |
| 136 | + |
92 | 137 | # Array of String. The default controls for Open Layers. This value will only be used when the user does not provide one. |
93 | 138 | # Available values: layerswitcher, mouseposition, panzoom, panzoombar, scaleline, navigation, keyboarddefaults, overviewmap, permalink |
94 | 139 | # Note: panzoom and panzoombar can NOT be used together |
— | — | @@ -97,9 +142,8 @@ |
98 | 143 | # Available values: google, bing, yahoo, openlayers, nasa |
99 | 144 | $egMapsOLLayers = array('openlayers'); |
100 | 145 | |
101 | | -# String(s). The map name prefixes for each service. They can not be identical. |
102 | | -$egMapsGoogleMapsPrefix = 'map_google'; |
103 | | -$egMapsYahooMapsPrefix = 'map_yahoo'; |
104 | | -$egMapsOpenLayersPrefix = 'open_layer'; |
105 | 146 | |
106 | 147 | |
| 148 | + |
| 149 | + |
| 150 | + |
Index: trunk/extensions/Maps/Maps_Utils.php |
— | — | @@ -11,74 +11,75 @@ |
12 | 12 | * @author Jeroen De Dauw |
13 | 13 | */ |
14 | 14 | |
15 | | -if( !defined( 'MEDIAWIKI' ) ) { |
16 | | - die( 'Not an entry point.' ); |
| 15 | +if (! defined ( 'MEDIAWIKI' )) { |
| 16 | + die ( 'Not an entry point.' ); |
17 | 17 | } |
18 | 18 | |
19 | 19 | class MapsUtils { |
20 | | - |
21 | | - public static function getLatLon($param2) { |
22 | | - $coordinates = preg_split("/,/", $param2); |
23 | | - if (count($coordinates) == 2) { |
24 | | - $lat = MapsUtils::convertCoord($coordinates[0]); |
25 | | - $lon = MapsUtils::convertCoord($coordinates[1]); |
26 | | - return array($lat, $lon); |
| 20 | + |
| 21 | + public static function getLatLon($coordinates) { |
| 22 | + $coordinates = preg_split ( "/,/", $coordinates ); |
| 23 | + if (count ( $coordinates ) == 2) { |
| 24 | + $lat = MapsUtils::convertCoord ( $coordinates [0] ); |
| 25 | + $lon = MapsUtils::convertCoord ( $coordinates [1] ); |
| 26 | + return array ('lat' => $lat, 'lon' => $lon); |
| 27 | + } else { |
| 28 | + return array ('lat' => null, 'lon' => null); |
27 | 29 | } |
28 | | - return array(null, null); |
29 | 30 | } |
30 | | - |
31 | | - private static function degree2Decimal($deg_coord="") { |
32 | | - $dpos=strpos($deg_coord,'°'); |
33 | | - $mpos=strpos($deg_coord,'.'); |
34 | | - $spos=strpos($deg_coord,'"'); |
35 | | - $mlen=(($mpos-$dpos)-1); |
36 | | - $slen=(($spos-$mpos)-1); |
37 | | - $direction=substr(strrev($deg_coord),0,1); |
38 | | - $degrees=substr($deg_coord,0,$dpos); |
39 | | - $minutes=substr($deg_coord,$dpos+1,$mlen); |
40 | | - $seconds=substr($deg_coord,$mpos+1,$slen); |
41 | | - $seconds=($seconds/60); |
42 | | - $minutes=($minutes+$seconds); |
43 | | - $minutes=($minutes/60); |
44 | | - $decimal=($degrees+$minutes); |
| 31 | + |
| 32 | + private static function degree2Decimal($deg_coord = "") { |
| 33 | + $dpos = strpos ( $deg_coord, '°' ); |
| 34 | + $mpos = strpos ( $deg_coord, '.' ); |
| 35 | + $spos = strpos ( $deg_coord, '"' ); |
| 36 | + $mlen = (($mpos - $dpos) - 1); |
| 37 | + $slen = (($spos - $mpos) - 1); |
| 38 | + $direction = substr ( strrev ( $deg_coord ), 0, 1 ); |
| 39 | + $degrees = substr ( $deg_coord, 0, $dpos ); |
| 40 | + $minutes = substr ( $deg_coord, $dpos + 1, $mlen ); |
| 41 | + $seconds = substr ( $deg_coord, $mpos + 1, $slen ); |
| 42 | + $seconds = ($seconds / 60); |
| 43 | + $minutes = ($minutes + $seconds); |
| 44 | + $minutes = ($minutes / 60); |
| 45 | + $decimal = ($degrees + $minutes); |
45 | 46 | //South latitudes and West longitudes need to return a negative result |
46 | | - if (($direction=="S") or ($direction=="W")) { |
47 | | - $decimal *= -1; |
| 47 | + if (($direction == "S") or ($direction == "W")) { |
| 48 | + $decimal *= - 1; |
48 | 49 | } |
49 | 50 | return $decimal; |
50 | 51 | } |
51 | | - |
| 52 | + |
52 | 53 | private static function decDegree2Decimal($deg_coord = "") { |
53 | | - $direction = substr(strrev($deg_coord), 0, 1); |
54 | | - $decimal = floatval($deg_coord); |
| 54 | + $direction = substr ( strrev ( $deg_coord ), 0, 1 ); |
| 55 | + $decimal = floatval ( $deg_coord ); |
55 | 56 | if (($direction == "S") or ($direction == "W")) { |
56 | | - $decimal *= -1; |
| 57 | + $decimal *= - 1; |
57 | 58 | } |
58 | 59 | return $decimal; |
59 | 60 | } |
60 | | - |
| 61 | + |
61 | 62 | private static function convertCoord($deg_coord = "") { |
62 | | - if (preg_match('/°/', $deg_coord)) { |
63 | | - if (preg_match('/"/', $deg_coord)) { |
64 | | - return MapsUtils::degree2Decimal($deg_coord); |
| 63 | + if (preg_match ( '/°/', $deg_coord )) { |
| 64 | + if (preg_match ( '/"/', $deg_coord )) { |
| 65 | + return MapsUtils::degree2Decimal ( $deg_coord ); |
65 | 66 | } else { |
66 | | - return MapsUtils::decDegree2Decimal($deg_coord); |
| 67 | + return MapsUtils::decDegree2Decimal ( $deg_coord ); |
67 | 68 | } |
68 | 69 | } |
69 | 70 | return $deg_coord; |
70 | 71 | } |
71 | | - |
| 72 | + |
72 | 73 | public static function latDecimal2Degree($decimal) { |
73 | 74 | if ($decimal < 0) { |
74 | | - return abs($decimal) . "° S"; |
| 75 | + return abs ( $decimal ) . "° S"; |
75 | 76 | } else { |
76 | 77 | return $decimal . "° N"; |
77 | 78 | } |
78 | 79 | } |
79 | | - |
| 80 | + |
80 | 81 | public static function lonDecimal2Degree($decimal) { |
81 | 82 | if ($decimal < 0) { |
82 | | - return abs($decimal) . "° W"; |
| 83 | + return abs ( $decimal ) . "° W"; |
83 | 84 | } else { |
84 | 85 | return $decimal . "° E"; |
85 | 86 | } |
— | — | @@ -90,7 +91,8 @@ |
91 | 92 | * @param unknown_type $value |
92 | 93 | */ |
93 | 94 | public static function makePxValue(&$value) { |
94 | | - if (substr($value, strlen($value) - 2) != 'px') $value .= 'px'; |
| 95 | + if (substr ( $value, strlen ( $value ) - 2 ) != 'px') |
| 96 | + $value .= 'px'; |
95 | 97 | } |
96 | 98 | |
97 | 99 | } |
Index: trunk/extensions/Maps/Maps_BaseMap.php |
— | — | @@ -15,6 +15,8 @@ |
16 | 16 | |
17 | 17 | abstract class MapsBaseMap extends MapsMapFeature { |
18 | 18 | |
| 19 | + protected $markerData = array(); |
| 20 | + |
19 | 21 | /** |
20 | 22 | * Handles the request from the parser hook by doing the work that's common for all |
21 | 23 | * mapping services, calling the specific methods and finally returning the resulting output. |
— | — | @@ -31,8 +33,6 @@ |
32 | 34 | |
33 | 35 | $this->manageMapProperties($map, 'MapsBaseMap'); |
34 | 36 | |
35 | | - $this->autozoom = ($this->autozoom == 'no' || $this->autozoom == 'off') ? 'false' : 'true'; |
36 | | - |
37 | 37 | $this->setZoom(); |
38 | 38 | |
39 | 39 | $this->setCoordinates(); |
— | — | @@ -43,8 +43,6 @@ |
44 | 44 | return $this->output; |
45 | 45 | } |
46 | 46 | |
47 | | - |
48 | | - |
49 | 47 | /** |
50 | 48 | * Sets the zoom level to the provided value, or when not set, to the default. |
51 | 49 | * |
— | — | @@ -57,10 +55,12 @@ |
58 | 56 | * Sets the $marler_lon and $marler_lat fields. |
59 | 57 | * |
60 | 58 | */ |
61 | | - private function setCoordinates() { |
62 | | - $this->coordinates = str_replace('″', '"', $this->coordinates); |
63 | | - $this->coordinates = str_replace('′', "'", $this->coordinates); |
64 | | - list($this->marker_lat, $this->marker_lon) = MapsUtils::getLatLon($this->coordinates); |
| 59 | + private function setCoordinates() { |
| 60 | + foreach($this->coordinates as $coordinates) { |
| 61 | + $coordinates = str_replace('″', '"', $coordinates); |
| 62 | + $coordinates = str_replace('′', "'", $coordinates); |
| 63 | + $this->markerData[] = MapsUtils::getLatLon($coordinates); |
| 64 | + } |
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
— | — | @@ -70,11 +70,24 @@ |
71 | 71 | */ |
72 | 72 | private function setCentre() { |
73 | 73 | if (empty($this->centre)) { |
74 | | - $this->centre_lat = $this->marker_lat; |
75 | | - $this->centre_lon = $this->marker_lon; |
| 74 | + if (count($this->markerData) == 1) { |
| 75 | + $this->centre_lat = $this->markerData[0]['lat']; |
| 76 | + $this->centre_lon = $this->markerData[0]['lon']; |
| 77 | + } |
| 78 | + elseif (count($this->markerData) > 1) { |
| 79 | + // TODO |
| 80 | + die("// TODO: calculate centre and zoom (with SGM code?)"); |
| 81 | + } |
| 82 | + else { |
| 83 | + global $egMapsMapLat, $egMapsMapLon; |
| 84 | + $this->centre_lat = $egMapsMapLat; |
| 85 | + $this->centre_lon = $egMapsMapLon; |
| 86 | + } |
76 | 87 | } |
77 | 88 | else { |
78 | | - list($this->centre_lat, $this->centre_lon) = MapsUtils::getLatLon($this->centre); |
| 89 | + $centre = MapsUtils::getLatLon($this->centre); |
| 90 | + $this->centre_lat = $centre['lat']; |
| 91 | + $this->centre_lon = $centre['lon']; |
79 | 92 | } |
80 | 93 | } |
81 | 94 | |