Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Class for handling the display_point(s) parser functions with OpenLayers |
| 5 | + * File holding the MapsOpenLayersDispPoint class. |
6 | 6 | * |
7 | 7 | * @file Maps_OpenLayersDispPoint.php |
8 | 8 | * @ingroup MapsOpenLayers |
— | — | @@ -13,6 +13,12 @@ |
14 | 14 | die( 'Not an entry point.' ); |
15 | 15 | } |
16 | 16 | |
| 17 | + |
| 18 | +/** |
| 19 | + * Class for handling the display_point(s) parser functions with OpenLayers. |
| 20 | + * |
| 21 | + * @author Jeroen De Dauw |
| 22 | + */ |
17 | 23 | class MapsOpenLayersDispPoint extends MapsBasePointMap { |
18 | 24 | |
19 | 25 | public $serviceName = MapsOpenLayersUtils::SERVICE_NAME; |
— | — | @@ -28,6 +34,8 @@ |
29 | 35 | |
30 | 36 | $this->elementNamePrefix = $egMapsOpenLayersPrefix; |
31 | 37 | $this->defaultZoom = $egMapsOpenLayersZoom; |
| 38 | + |
| 39 | + $this->markerStringFormat = 'getOLMarkerData(lat, lon, "title", "label", "icon")'; |
32 | 40 | } |
33 | 41 | |
34 | 42 | /** |
— | — | @@ -53,31 +61,12 @@ |
54 | 62 | $controlItems = MapsOpenLayersUtils::createControlsString($this->controls); |
55 | 63 | |
56 | 64 | MapsMapper::enforceArrayValues($this->layers); |
57 | | - $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers); |
| 65 | + $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers); |
58 | 66 | |
59 | | - $markerItems = array(); |
60 | | - |
61 | | - // TODO: Refactor up |
62 | | - foreach ($this->markerData as $markerData) { |
63 | | - $lat = $markerData['lat']; |
64 | | - $lon = $markerData['lon']; |
65 | | - |
66 | | - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title; |
67 | | - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label; |
68 | | - |
69 | | - $title = str_replace("'", "\'", $title); |
70 | | - $label = str_replace("'", "\'", $label); |
71 | | - |
72 | | - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : ''; |
73 | | - $markerItems[] = "getOLMarkerData($lon, $lat, '$title', '$label', '$icon')"; |
74 | | - } |
75 | | - |
76 | | - $markersString = implode(',', $markerItems); |
77 | | - |
78 | 67 | $this->output .= "<div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div> |
79 | 68 | <script type='$wgJsMimeType'> /*<![CDATA[*/ |
80 | 69 | addOnloadHook( |
81 | | - initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[$markersString], $this->height) |
| 70 | + initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[$this->markerString], $this->height) |
82 | 71 | ); |
83 | 72 | /*]]>*/ </script>"; |
84 | 73 | } |
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php |
— | — | @@ -1,94 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * File holding the MapsParserGeocoder class. |
6 | | - * |
7 | | - * @file Maps_ParserGeocoder.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 | | -/** |
18 | | - * Class that holds static helpers for the mapping parser functions. The helpers aid in |
19 | | - * determining the availability of the geocoding parser functions and calling them. |
20 | | - * |
21 | | - * @author Jeroen De Dauw |
22 | | - * |
23 | | - */ |
24 | | -final class MapsParserGeocoder { |
25 | | - |
26 | | - /** |
27 | | - * Changes the values of the address or addresses parameter into coordinates |
28 | | - * in the provided array. Returns an array containing the addresses that |
29 | | - * could not be geocoded. |
30 | | - * |
31 | | - * @param array $params |
32 | | - */ |
33 | | - public static function changeAddressesToCoords(&$params) { |
34 | | - global $egMapsDefaultService; |
35 | | - |
36 | | - $fails = array(); |
37 | | - |
38 | | - // Get the service and geoservice from the parameters, since they are needed to geocode addresses. |
39 | | - for ($i = 0; $i < count($params); $i++) { |
40 | | - $split = explode('=', $params[$i]); |
41 | | - if (MapsMapper::inParamAliases(strtolower(trim($split[0])), 'service') && count($split) > 1) { |
42 | | - $service = trim($split[1]); |
43 | | - } |
44 | | - else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) { |
45 | | - $geoservice = trim($split[1]); |
46 | | - } |
47 | | - } |
48 | | - |
49 | | - // Make sure the service and geoservice are valid. |
50 | | - $service = isset($service) ? MapsMapper::getValidService($service, 'pf') : $egMapsDefaultService; |
51 | | - if (! isset($geoservice)) $geoservice = ''; |
52 | | - |
53 | | - // Go over all parameters. |
54 | | - for ($i = 0; $i < count($params); $i++) { |
55 | | - $split = explode('=', $params[$i]); |
56 | | - $isAddress = (strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1; |
57 | | - $isDefault = count($split) == 1; |
58 | | - |
59 | | - // If a parameter is either the default (no name), or an addresses list, extract all locations. |
60 | | - if ($isAddress || $isDefault) { |
61 | | - |
62 | | - $address_srting = $split[count($split) == 1 ? 0 : 1]; |
63 | | - $addresses = explode(';', $address_srting); |
64 | | - |
65 | | - $coordinates = array(); |
66 | | - |
67 | | - // Go over every location and attempt to geocode it. |
68 | | - foreach($addresses as $address) { |
69 | | - $args = explode('~', $address); |
70 | | - $args[0] = trim($args[0]); |
71 | | - |
72 | | - if (strlen($args[0]) > 0) { |
73 | | - $coords = MapsGeocodeUtils::attemptToGeocode($args[0], $geoservice, $service, $isDefault); |
74 | | - |
75 | | - if ($coords) { |
76 | | - $args[0] = $coords; |
77 | | - $coordinates[] = implode('~', $args); |
78 | | - } |
79 | | - else { |
80 | | - $fails[] = $args[0]; |
81 | | - } |
82 | | - } |
83 | | - } |
84 | | - |
85 | | - // Add the geocoded result back to the parameter list. |
86 | | - $params[$i] = implode(';', $coordinates); |
87 | | - |
88 | | - } |
89 | | - |
90 | | - } |
91 | | - |
92 | | - return $fails; |
93 | | - } |
94 | | - |
95 | | -} |
\ No newline at end of file |
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * |
| 5 | + * File holding the registration and handling functions for the display_point parser function. |
6 | 6 | * |
7 | 7 | * @file Maps_DisplayPoint.php |
8 | 8 | * @ingroup Maps |
— | — | @@ -20,111 +20,42 @@ |
21 | 21 | $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint'; |
22 | 22 | |
23 | 23 | /** |
24 | | - * Adds the magic words for the parser functions |
| 24 | + * Adds the magic words for the parser functions. |
25 | 25 | */ |
26 | 26 | function efMapsDisplayPointMagic( &$magicWords, $langCode ) { |
27 | 27 | // The display_address(es) aliases are for backward compatibility only, and will be removed eventually. |
28 | 28 | $magicWords['display_point'] = array( 0, 'display_point', 'display_points', 'display_address', 'display_addresses' ); |
29 | 29 | |
30 | | - return true; // Unless we return true, other parser functions won't get loaded |
| 30 | + return true; // Unless we return true, other parser functions won't get loaded. |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Adds the parser function hooks |
35 | 35 | */ |
36 | 36 | function efMapsRegisterDisplayPoint(&$wgParser) { |
37 | | - // Hooks to enable the '#display_point' and '#display_points' parser functions |
| 37 | + // Hooks to enable the '#display_point' and '#display_points' parser functions. |
38 | 38 | $wgParser->setFunctionHook( 'display_point', array('MapsDisplayPoint', 'displayPointRender') ); |
39 | 39 | |
40 | 40 | return true; |
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
| 44 | + * Class containing the rendering functions for the display_point parser function. |
44 | 45 | * |
45 | | - * |
46 | 46 | * @author Jeroen De Dauw |
47 | 47 | * |
48 | 48 | */ |
49 | 49 | final class MapsDisplayPoint { |
50 | 50 | |
51 | 51 | /** |
52 | | - * Sets the default map properties, gets the map HTML depending |
53 | | - * on the provided service, and then returns it. |
| 52 | + * Returns the output for a display_point call. |
54 | 53 | * |
55 | 54 | * @param unknown_type $parser |
56 | 55 | * @return array |
57 | 56 | */ |
58 | 57 | public static function displayPointRender(&$parser) { |
59 | | - $params = func_get_args(); |
60 | | - array_shift( $params ); // We already know the $parser ... |
61 | | - |
62 | | - $fails = MapsParserGeocoder::changeAddressesToCoords($params); |
63 | | - |
64 | | - return self::getMapHtml($parser, $params, 'display_point', $fails); |
| 58 | + $args = func_get_args(); |
| 59 | + return MapsParserFunctions::getMapHtml($parser, $args, 'display_point'); |
65 | 60 | } |
66 | 61 | |
67 | | - // TODO: refactor up |
68 | | - public static function getMapHtml(&$parser, array $params, $parserFunction, array $geoFails = array()) { |
69 | | - global $wgLang; |
70 | | - |
71 | | - $map = array(); |
72 | | - $coordFails = array(); |
73 | | - |
74 | | - // Go through all parameters, split their names and values, and put them in the $map array. |
75 | | - foreach($params as $param) { |
76 | | - $split = explode('=', $param); |
77 | | - if (count($split) > 1) { |
78 | | - $paramName = strtolower(trim($split[0])); |
79 | | - $paramValue = trim($split[1]); |
80 | | - if (strlen($paramName) > 0 && strlen($paramValue) > 0) { |
81 | | - $map[$paramName] = $paramValue; |
82 | | - if (MapsMapper::inParamAliases($paramName, 'coordinates')) $coordFails = MapsParserFunctions::filterInvalidCoords($map[$paramName]); |
83 | | - } |
84 | | - } |
85 | | - else if (count($split) == 1) { // Default parameter (without name) |
86 | | - $split[0] = trim($split[0]); |
87 | | - if (strlen($split[0]) > 0) $map['coordinates'] = $split[0]; |
88 | | - } |
89 | | - } |
90 | | - |
91 | | - $coords = MapsMapper::getParamValue('coordinates', $map); |
92 | | - |
93 | | - if ($coords) { |
94 | | - if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = ''; |
95 | | - $map['service'] = MapsMapper::getValidService($map['service'], 'pf'); |
96 | | - |
97 | | - $mapClass = self::getParserClassInstance($map['service'], $parserFunction); |
98 | | - |
99 | | - // Call the function according to the map service to get the HTML output |
100 | | - $output = $mapClass->displayMap($parser, $map); |
101 | | - |
102 | | - if (count($coordFails) > 0) { |
103 | | - $output .= '<i>' . wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; |
104 | | - } |
105 | | - |
106 | | - if (count($geoFails) > 0) { |
107 | | - $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; |
108 | | - } |
109 | | - } |
110 | | - elseif (trim($coords) == "" && (count($geoFails) > 0 || count($coordFails) > 0)) { |
111 | | - if (count($coordFails) > 0) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; |
112 | | - if (count($geoFails) > 0) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; |
113 | | - $output .= '<i>' . wfMsg('maps_map_cannot_be_displayed') .'</i>'; |
114 | | - } |
115 | | - else { |
116 | | - $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>'; |
117 | | - } |
118 | | - |
119 | | - // Return the result |
120 | | - return array( $output, 'noparse' => true, 'isHTML' => true ); |
121 | | - } |
122 | | - |
123 | | - // TODO: refactor up |
124 | | - private static function getParserClassInstance($service, $parserFunction) { |
125 | | - global $egMapsServices; |
126 | | - // TODO: add check to see if the service actually supports this parser function, and return false for error handling if not. |
127 | | - //die($egMapsServices[$service]['pf'][$parserFunction]['class']); |
128 | | - return new $egMapsServices[$service]['pf'][$parserFunction]['class'](); |
129 | | - } |
130 | | - |
131 | 62 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php |
— | — | @@ -1,13 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Abstract class MapsBasePointMap provides the scafolding for classes handling display_point(s) |
6 | | - * and display_address(es) calls for a spesific mapping service. It inherits from MapsMapFeature and therefore |
7 | | - * forces inheriting classes to implement sereveral methods. |
8 | | - * |
| 5 | + * File holding class MapsBasePointMap. |
| 6 | + * |
9 | 7 | * @file Maps_BasePointMap.php |
10 | 8 | * @ingroup Maps |
11 | | - * |
| 9 | + * |
12 | 10 | * @author Jeroen De Dauw |
13 | 11 | */ |
14 | 12 | |
— | — | @@ -15,9 +13,18 @@ |
16 | 14 | die( 'Not an entry point.' ); |
17 | 15 | } |
18 | 16 | |
| 17 | +/** |
| 18 | + * Abstract class MapsBasePointMap provides the scafolding for classes handling display_point(s) |
| 19 | + * and display_address(es) calls for a spesific mapping service. It inherits from MapsMapFeature and therefore |
| 20 | + * forces inheriting classes to implement sereveral methods. |
| 21 | + * |
| 22 | + * @author Jeroen De Dauw |
| 23 | + */ |
19 | 24 | abstract class MapsBasePointMap extends MapsMapFeature { |
20 | 25 | |
21 | | - protected $markerData = array(); |
| 26 | + private $markerData = array(); |
| 27 | + protected $markerStringFormat = ''; |
| 28 | + protected $markerString; |
22 | 29 | |
23 | 30 | /** |
24 | 31 | * Handles the request from the parser hook by doing the work that's common for all |
— | — | @@ -31,13 +38,15 @@ |
32 | 39 | public final function displayMap(&$parser, array $params) { |
33 | 40 | $this->setMapSettings(); |
34 | 41 | |
35 | | - $coords = $this->manageMapProperties($params, __CLASS__); |
| 42 | + /* $coords = */ $this->manageMapProperties($params, __CLASS__); |
36 | 43 | |
37 | 44 | $this->doMapServiceLoad(); |
38 | 45 | |
39 | 46 | $this->setMapName(); |
40 | 47 | |
41 | | - $this->setCoordinates($parser); |
| 48 | + $this->setCoordinates($parser); |
| 49 | + |
| 50 | + $this->createMarkerString(); |
42 | 51 | |
43 | 52 | $this->setZoom(); |
44 | 53 | |
— | — | @@ -110,6 +119,35 @@ |
111 | 120 | } |
112 | 121 | |
113 | 122 | /** |
| 123 | + * Creates a JS string with the marker data. |
| 124 | + * |
| 125 | + * @return unknown_type |
| 126 | + */ |
| 127 | + private function createMarkerString() { |
| 128 | + $markerItems = array(); |
| 129 | + |
| 130 | + foreach ($this->markerData as $markerData) { |
| 131 | + $lat = $markerData['lat']; |
| 132 | + $lon = $markerData['lon']; |
| 133 | + |
| 134 | + $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title; |
| 135 | + $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label; |
| 136 | + |
| 137 | + $title = str_replace("'", "\'", $title); |
| 138 | + $label = str_replace("'", "\'", $label); |
| 139 | + |
| 140 | + $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : ''; |
| 141 | + |
| 142 | + $markerItems[] = str_replace( array('lon', 'lat', 'title', 'label', 'icon'), |
| 143 | + array($lon, $lat, $title, $label, $label), |
| 144 | + $this->markerStringFormat |
| 145 | + ); |
| 146 | + } |
| 147 | + |
| 148 | + $this->markerString = implode(',', $markerItems); |
| 149 | + } |
| 150 | + |
| 151 | + /** |
114 | 152 | * Sets the $centre_lat and $centre_lon fields. |
115 | 153 | * Note: this needs to be done AFTRE the maker coordinates are set. |
116 | 154 | */ |
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * |
| 5 | + * File holding the registration and handling functions for the display_map parser function. |
6 | 6 | * |
7 | 7 | * @file Maps_DisplayMap.php |
8 | 8 | * @ingroup Maps |
— | — | @@ -20,109 +20,41 @@ |
21 | 21 | $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap'; |
22 | 22 | |
23 | 23 | /** |
24 | | - * Adds the magic words for the parser functions |
| 24 | + * Adds the magic words for the parser functions. |
25 | 25 | */ |
26 | 26 | function efMapsDisplayMapMagic( &$magicWords, $langCode ) { |
27 | 27 | $magicWords['display_map'] = array( 0, 'display_map'); |
28 | 28 | |
29 | | - return true; // Unless we return true, other parser functions won't get loaded |
| 29 | + return true; // Unless we return true, other parser functions won't get loaded. |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Adds the parser function hooks |
34 | 34 | */ |
35 | 35 | function efMapsRegisterDisplayMap(&$wgParser) { |
36 | | - // A hook to enable the '#display_map' parser function |
| 36 | + // A hook to enable the '#display_map' parser function. |
37 | 37 | $wgParser->setFunctionHook( 'display_map', array('MapsDisplayMap', 'displayMapRender') ); |
38 | 38 | |
39 | 39 | return true; |
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
| 43 | + * Class containing the rendering functions for the display_map parser function. |
43 | 44 | * |
44 | | - * |
45 | 45 | * @author Jeroen De Dauw |
46 | 46 | * |
47 | 47 | */ |
48 | 48 | final class MapsDisplayMap { |
49 | 49 | |
50 | 50 | /** |
51 | | - * If an address value is provided, turn it into coordinates, |
52 | | - * then calls getMapHtml() and returns it's result. |
| 51 | + * Returns the output for a display_map call. |
53 | 52 | * |
54 | 53 | * @param unknown_type $parser |
55 | 54 | * @return array |
56 | 55 | */ |
57 | | - public static function displayMapRender(&$parser) { |
58 | | - $params = func_get_args(); |
59 | | - array_shift( $params ); // We already know the $parser ... |
60 | | - |
61 | | - $fails = MapsParserGeocoder::changeAddressesToCoords($params); |
62 | | - |
63 | | - return self::getMapHtml($parser, $params, 'display_map', $fails); |
| 56 | + public static function displayMapRender(&$parser) { |
| 57 | + $args = func_get_args(); |
| 58 | + return MapsParserFunctions::getMapHtml($parser, $args, 'display_map'); |
64 | 59 | } |
65 | | - |
66 | | - // TODO: refactor up |
67 | | - public static function getMapHtml(&$parser, array $params, $parserFunction, array $geoFails = array()) { |
68 | | - global $wgLang; |
69 | | - |
70 | | - $map = array(); |
71 | | - $coordFails = array(); |
72 | | - |
73 | | - // Go through all parameters, split their names and values, and put them in the $map array. |
74 | | - foreach($params as $param) { |
75 | | - $split = split('=', $param); |
76 | | - if (count($split) > 1) { |
77 | | - $paramName = strtolower(trim($split[0])); |
78 | | - $paramValue = trim($split[1]); |
79 | | - if (strlen($paramName) > 0 && strlen($paramValue) > 0) { |
80 | | - $map[$paramName] = $paramValue; |
81 | | - if (MapsMapper::inParamAliases($paramName, 'coordinates')) $coordFails = MapsParserFunctions::filterInvalidCoords($map[$paramName]); |
82 | | - } |
83 | | - } |
84 | | - else if (count($split) == 1) { // Default parameter (without name) |
85 | | - $split[0] = trim($split[0]); |
86 | | - if (strlen($split[0]) > 0) $map['coordinates'] = $split[0]; |
87 | | - } |
88 | | - } |
89 | | - |
90 | | - $coords = MapsMapper::getParamValue('coordinates', $map); |
91 | | - |
92 | | - if ($coords) { |
93 | | - if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = ''; |
94 | | - $map['service'] = MapsMapper::getValidService($map['service'], 'pf'); |
95 | | - |
96 | | - $mapClass = self::getParserClassInstance($map['service'], $parserFunction); |
97 | | - |
98 | | - // Call the function according to the map service to get the HTML output |
99 | | - $output = $mapClass->displayMap($parser, $map); |
100 | | - |
101 | | - if (count($coordFails) > 0) { |
102 | | - $output .= '<i>' . wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; |
103 | | - } |
104 | | - |
105 | | - if (count($geoFails) > 0) { |
106 | | - $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText($geoFails ), count( $geoFails ) ) . '</i>'; |
107 | | - } |
108 | | - } |
109 | | - elseif (trim($coords) == "" && (count($geoFails) > 0 || count($coordFails) > 0)) { |
110 | | - if (count($coordFails) > 0) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; |
111 | | - if (count($geoFails) > 0) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; |
112 | | - $output .= '<i>' . wfMsg('maps_map_cannot_be_displayed') .'</i>'; |
113 | | - } |
114 | | - else { |
115 | | - $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>'; |
116 | | - } |
117 | | - |
118 | | - // Return the result |
119 | | - return array( $output, 'noparse' => true, 'isHTML' => true ); |
120 | | - } |
121 | 60 | |
122 | | - private static function getParserClassInstance($service, $parserFunction) { |
123 | | - global $egMapsServices; |
124 | | - // TODO: add check to see if the service actually supports this parser function, and return false for error handling if not. |
125 | | - //die($egMapsServices[$service]['pf'][$parserFunction]['class']); |
126 | | - return new $egMapsServices[$service]['pf'][$parserFunction]['class'](); |
127 | | - } |
128 | | - |
129 | 61 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php |
— | — | @@ -15,23 +15,18 @@ |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * A class that holds handlers for the mapping parser functions. |
19 | | - * Spesific functions are located in @see MapsUtils |
20 | 19 | * |
21 | 20 | * @author Jeroen De Dauw |
22 | | - * |
23 | 21 | */ |
24 | 22 | final class MapsParserFunctions { |
25 | 23 | |
26 | 24 | /** |
27 | 25 | * Initialize the parser functions feature. This function handles the parser function hook, |
28 | 26 | * and will load the required classes. |
29 | | - * |
30 | 27 | */ |
31 | 28 | public static function initialize() { |
32 | | - global $egMapsIP, $IP, $wgAutoloadClasses, $egMapsAvailableFeatures, $egMapsServices; |
| 29 | + global $egMapsIP, $IP, $wgAutoloadClasses, $egMapsServices; |
33 | 30 | |
34 | | - $wgAutoloadClasses['MapsParserGeocoder'] = $egMapsIP. '/ParserFunctions/Maps_ParserGeocoder.php'; |
35 | | - |
36 | 31 | foreach($egMapsServices as $serviceName => $serviceData) { |
37 | 32 | // Check if the service has parser function support |
38 | 33 | $hasPFs = array_key_exists('pf', $serviceData); |
— | — | @@ -48,13 +43,83 @@ |
49 | 44 | } |
50 | 45 | |
51 | 46 | /** |
| 47 | + * Returns the output for the call to the specified parser function. |
| 48 | + * |
| 49 | + * @param $parser |
| 50 | + * @param array $params |
| 51 | + * @param string $parserFunction |
| 52 | + * |
| 53 | + * @return array |
| 54 | + */ |
| 55 | + public static function getMapHtml(&$parser, array $params, $parserFunction) { |
| 56 | + global $wgLang; |
| 57 | + |
| 58 | + array_shift( $params ); // We already know the $parser. |
| 59 | + |
| 60 | + $map = array(); |
| 61 | + $coordFails = array(); |
| 62 | + |
| 63 | + $geoFails = self::changeAddressesToCoords($params); |
| 64 | + |
| 65 | + // Go through all parameters, split their names and values, and put them in the $map array. |
| 66 | + foreach($params as $param) { |
| 67 | + $split = explode('=', $param); |
| 68 | + if (count($split) > 1) { |
| 69 | + $paramName = strtolower(trim($split[0])); |
| 70 | + $paramValue = trim($split[1]); |
| 71 | + if (strlen($paramName) > 0 && strlen($paramValue) > 0) { |
| 72 | + $map[$paramName] = $paramValue; |
| 73 | + if (MapsMapper::inParamAliases($paramName, 'coordinates')) $coordFails = self::filterInvalidCoords($map[$paramName]); |
| 74 | + } |
| 75 | + } |
| 76 | + else if (count($split) == 1) { // Default parameter (without name) |
| 77 | + $split[0] = trim($split[0]); |
| 78 | + if (strlen($split[0]) > 0) $map['coordinates'] = $split[0]; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + $coords = MapsMapper::getParamValue('coordinates', $map); |
| 83 | + |
| 84 | + if ($coords) { |
| 85 | + if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = ''; |
| 86 | + $map['service'] = MapsMapper::getValidService($map['service'], 'pf'); |
| 87 | + |
| 88 | + $mapClass = self::getParserClassInstance($map['service'], $parserFunction); |
| 89 | + |
| 90 | + // Call the function according to the map service to get the HTML output |
| 91 | + $output = $mapClass->displayMap($parser, $map); |
| 92 | + |
| 93 | + if (count($coordFails) > 0) { |
| 94 | + $output .= '<i>' . wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; |
| 95 | + } |
| 96 | + |
| 97 | + if (count($geoFails) > 0) { |
| 98 | + $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; |
| 99 | + } |
| 100 | + } |
| 101 | + elseif (trim($coords) == "" && (count($geoFails) > 0 || count($coordFails) > 0)) { |
| 102 | + if (count($coordFails) > 0) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; |
| 103 | + if (count($geoFails) > 0) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; |
| 104 | + $output .= '<i>' . wfMsg('maps_map_cannot_be_displayed') .'</i>'; |
| 105 | + } |
| 106 | + else { |
| 107 | + $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>'; |
| 108 | + } |
| 109 | + |
| 110 | + // Return the result |
| 111 | + return array( $output, 'noparse' => true, 'isHTML' => true ); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
52 | 115 | * Filters all non coordinate valus from a coordinate string, |
53 | 116 | * and returns an array containing all filtered out values. |
54 | 117 | * |
55 | 118 | * @param string $coordList |
| 119 | + * @param string $delimeter |
| 120 | + * |
56 | 121 | * @return array |
57 | 122 | */ |
58 | | - public static function filterInvalidCoords(&$coordList, $delimeter = ';') { |
| 123 | + private static function filterInvalidCoords(&$coordList, $delimeter = ';') { |
59 | 124 | $coordFails = array(); |
60 | 125 | $validCoordinates = array(); |
61 | 126 | $coordinates = explode($delimeter, $coordList); |
— | — | @@ -72,6 +137,89 @@ |
73 | 138 | return $coordFails; |
74 | 139 | } |
75 | 140 | |
| 141 | + /** |
| 142 | + * Changes the values of the address or addresses parameter into coordinates |
| 143 | + * in the provided array. Returns an array containing the addresses that |
| 144 | + * could not be geocoded. |
| 145 | + * |
| 146 | + * @param array $params |
| 147 | + * |
| 148 | + * @return array |
| 149 | + */ |
| 150 | + private static function changeAddressesToCoords(&$params) { |
| 151 | + global $egMapsDefaultService; |
76 | 152 | |
| 153 | + $fails = array(); |
| 154 | + |
| 155 | + // Get the service and geoservice from the parameters, since they are needed to geocode addresses. |
| 156 | + for ($i = 0; $i < count($params); $i++) { |
| 157 | + $split = explode('=', $params[$i]); |
| 158 | + if (MapsMapper::inParamAliases(strtolower(trim($split[0])), 'service') && count($split) > 1) { |
| 159 | + $service = trim($split[1]); |
| 160 | + } |
| 161 | + else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) { |
| 162 | + $geoservice = trim($split[1]); |
| 163 | + } |
| 164 | + } |
77 | 165 | |
| 166 | + // Make sure the service and geoservice are valid. |
| 167 | + $service = isset($service) ? MapsMapper::getValidService($service, 'pf') : $egMapsDefaultService; |
| 168 | + if (! isset($geoservice)) $geoservice = ''; |
| 169 | + |
| 170 | + // Go over all parameters. |
| 171 | + for ($i = 0; $i < count($params); $i++) { |
| 172 | + $split = explode('=', $params[$i]); |
| 173 | + $isAddress = (strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1; |
| 174 | + $isDefault = count($split) == 1; |
| 175 | + |
| 176 | + // If a parameter is either the default (no name), or an addresses list, extract all locations. |
| 177 | + if ($isAddress || $isDefault) { |
| 178 | + |
| 179 | + $address_srting = $split[count($split) == 1 ? 0 : 1]; |
| 180 | + $addresses = explode(';', $address_srting); |
| 181 | + |
| 182 | + $coordinates = array(); |
| 183 | + |
| 184 | + // Go over every location and attempt to geocode it. |
| 185 | + foreach($addresses as $address) { |
| 186 | + $args = explode('~', $address); |
| 187 | + $args[0] = trim($args[0]); |
| 188 | + |
| 189 | + if (strlen($args[0]) > 0) { |
| 190 | + $coords = MapsGeocodeUtils::attemptToGeocode($args[0], $geoservice, $service, $isDefault); |
| 191 | + |
| 192 | + if ($coords) { |
| 193 | + $args[0] = $coords; |
| 194 | + $coordinates[] = implode('~', $args); |
| 195 | + } |
| 196 | + else { |
| 197 | + $fails[] = $args[0]; |
| 198 | + } |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + // Add the geocoded result back to the parameter list. |
| 203 | + $params[$i] = implode(';', $coordinates); |
| 204 | + |
| 205 | + } |
| 206 | + |
| 207 | + } |
| 208 | + |
| 209 | + return $fails; |
| 210 | + } |
| 211 | + |
| 212 | + /** |
| 213 | + * Returns an instance of the class supporting the spesified mapping service for |
| 214 | + * the also spesified parser function. |
| 215 | + * |
| 216 | + * @param string $service |
| 217 | + * @param string $parserFunction |
| 218 | + * |
| 219 | + * @return class |
| 220 | + */ |
| 221 | + private static function getParserClassInstance($service, $parserFunction) { |
| 222 | + global $egMapsServices; |
| 223 | + return new $egMapsServices[$service]['pf'][$parserFunction]['class'](); |
| 224 | + } |
| 225 | + |
78 | 226 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | die( 'Not an entry point.' ); |
25 | 25 | } |
26 | 26 | |
27 | | -define('Maps_VERSION', '0.4.2 rc2'); |
| 27 | +define('Maps_VERSION', '0.5 a1'); |
28 | 28 | |
29 | 29 | $egMapsScriptPath = $wgScriptPath . '/extensions/Maps'; |
30 | 30 | $egMapsIP = $IP . '/extensions/Maps'; |
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispPoint.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Class for handling the display_point(s) parser functions with OSM. |
| 5 | + * File holding the MapsOSMDispPoint class. |
6 | 6 | * |
7 | 7 | * @file Maps_OSMDispPoint.php |
8 | 8 | * @ingroup MapsOpenStreetMap |
— | — | @@ -13,6 +13,11 @@ |
14 | 14 | die( 'Not an entry point.' ); |
15 | 15 | } |
16 | 16 | |
| 17 | +/** |
| 18 | + * Class for handling the display_point(s) parser functions with OSM. |
| 19 | + * |
| 20 | + * @author Jeroen De Dauw |
| 21 | + */ |
17 | 22 | class MapsOSMDispPoint extends MapsBasePointMap { |
18 | 23 | |
19 | 24 | public $serviceName = MapsOSMUtils::SERVICE_NAME; |
— | — | @@ -28,6 +33,8 @@ |
29 | 34 | |
30 | 35 | $this->elementNamePrefix = $egMapsOSMPrefix; |
31 | 36 | $this->defaultZoom = $egMapsOSMZoom; |
| 37 | + |
| 38 | + $this->markerStringFormat = 'getOSMMarkerData(lat, lon, "title", "label", "icon")'; |
32 | 39 | } |
33 | 40 | |
34 | 41 | /** |
— | — | @@ -48,27 +55,8 @@ |
49 | 56 | * |
50 | 57 | */ |
51 | 58 | public function addSpecificMapHTML() { |
52 | | - global $wgJsMimeType; |
| 59 | + global $wgJsMimeType; |
53 | 60 | |
54 | | - $markerItems = array(); |
55 | | - |
56 | | - // TODO: Refactor up |
57 | | - foreach ($this->markerData as $markerData) { |
58 | | - $lat = $markerData['lat']; |
59 | | - $lon = $markerData['lon']; |
60 | | - |
61 | | - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title; |
62 | | - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label; |
63 | | - |
64 | | - $title = str_replace("'", "\'", $title); |
65 | | - $label = str_replace("'", "\'", $label); |
66 | | - |
67 | | - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : ''; |
68 | | - $markerItems[] = "getOSMMarkerData($lon, $lat, '$title', '$label', '$icon')"; |
69 | | - } |
70 | | - |
71 | | - $markersString = implode(',', $markerItems); |
72 | | - |
73 | 61 | $controlItems = MapsOSMUtils::createControlsString($this->controls); |
74 | 62 | |
75 | 63 | $this->output .= <<<EOT |
— | — | @@ -81,7 +69,7 @@ |
82 | 70 | zoom: $this->zoom, |
83 | 71 | width: $this->width, |
84 | 72 | height: $this->height, |
85 | | - markers: [$markersString], |
| 73 | + markers: [$this->markerString], |
86 | 74 | controls: [$controlItems] |
87 | 75 | |
88 | 76 | });</script> |
Index: trunk/extensions/Maps/Maps_Mapper.php |
— | — | @@ -42,6 +42,7 @@ |
43 | 43 | * @param string $name The name you want to check for. |
44 | 44 | * @param string $mainParamName The main parameter name. |
45 | 45 | * @param boolean $compareMainName Boolean indicating wether the main name should also be compared. |
| 46 | + * |
46 | 47 | * @return boolean |
47 | 48 | */ |
48 | 49 | public static function inParamAliases($name, $mainParamName, $compareMainName = true) { |
— | — | @@ -61,6 +62,7 @@ |
62 | 63 | * @param string $paramName |
63 | 64 | * @param array $stack |
64 | 65 | * @param boolean $checkForAliases |
| 66 | + * |
65 | 67 | * @return boolean |
66 | 68 | */ |
67 | 69 | public static function paramIsPresent($paramName, array $stack, $checkForAliases = true) { |
— | — | @@ -84,6 +86,7 @@ |
85 | 87 | * @param string $paramName |
86 | 88 | * @param array $stack |
87 | 89 | * @param boolean $checkForAliases |
| 90 | + * |
88 | 91 | * @return the parameter value or false |
89 | 92 | */ |
90 | 93 | public static function getParamValue($paramName, array $stack, $checkForAliases = true) { |
— | — | @@ -109,6 +112,7 @@ |
110 | 113 | * @param array $serviceDefaults Array with the default parameters and their values for the used mapping service. |
111 | 114 | * @param boolean $strict If set to false, values which a key that does not |
112 | 115 | * exist in the $map array will be retained. |
| 116 | + * |
113 | 117 | * @return array |
114 | 118 | */ |
115 | 119 | public static function setDefaultParValues(array $params, array $serviceDefaults, $strict = true) { |
— | — | @@ -154,7 +158,7 @@ |
155 | 159 | * @param string $delimeter |
156 | 160 | */ |
157 | 161 | public static function enforceArrayValues(&$values, $delimeter = ',') { |
158 | | - if (!is_array($values)) $values = split($delimeter, $values); // If not an array yet, split the values |
| 162 | + if (!is_array($values)) $values = explode($delimeter, $values); // If not an array yet, split the values |
159 | 163 | for ($i = 0; $i < count($values); $i++) $values[$i] = trim($values[$i]); // Trim all values |
160 | 164 | } |
161 | 165 | |
— | — | @@ -165,6 +169,8 @@ |
166 | 170 | * @param array $items |
167 | 171 | * @param array $defaultItems |
168 | 172 | * @param boolean $asStrings |
| 173 | + * @param boolean $toLower |
| 174 | + * |
169 | 175 | * @return string |
170 | 176 | */ |
171 | 177 | public static function createJSItemsString(array $items, array $defaultItems = null, $asStrings = true, $toLower = true) { |
— | — | @@ -180,6 +186,8 @@ |
181 | 187 | * |
182 | 188 | * @param array $paramz |
183 | 189 | * @param array $serviceParameters |
| 190 | + * @param boolean $strict |
| 191 | + * |
184 | 192 | * @return array |
185 | 193 | */ |
186 | 194 | public static function getValidParams(array $paramz, array $serviceParameters, $strict = true) { |
— | — | @@ -201,6 +209,7 @@ |
202 | 210 | * |
203 | 211 | * @param string $paramName |
204 | 212 | * @param array $allowedParms |
| 213 | + * |
205 | 214 | * @return string |
206 | 215 | */ |
207 | 216 | private static function getMainParamName($paramName, array $allowedParms) { |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php |
— | — | @@ -124,7 +124,7 @@ |
125 | 125 | * @param string $output |
126 | 126 | */ |
127 | 127 | public static function addGMapDependencies(&$output) { |
128 | | - global $wgJsMimeType, $wgLang, $wgOut; |
| 128 | + global $wgJsMimeType, $wgLang; |
129 | 129 | global $egGoogleMapsKey, $egMapsScriptPath, $egGoogleMapsOnThisPage, $egMapsStyleVersion; |
130 | 130 | |
131 | 131 | if (empty($egGoogleMapsOnThisPage)) { |
— | — | @@ -150,26 +150,6 @@ |
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
154 | | - * Returns a boolean representing if the earth map type should be showed or not, |
155 | | - * when provided the the wiki code value. |
156 | | - * |
157 | | - * @param string $earthValue |
158 | | - * @param boolean $adaptDefault When not set to false, the default map type will be changed to earth when earth is enabled |
159 | | - * @return boolean Indicates wether the earth type should be enabled. |
160 | | - */ |
161 | | - public static function getEarthValue($earthValue, $adaptDefault = true) { |
162 | | - $trueValues = array('on', 'yes'); |
163 | | - $enabled = in_array($earthValue, $trueValues); |
164 | | - |
165 | | - if ($enabled && $adaptDefault) { |
166 | | - global $egMapsGoogleMapsType; |
167 | | - $egMapsGoogleMapsType = 'G_SATELLITE_3D_MAP'; |
168 | | - } |
169 | | - |
170 | | - return $enabled; |
171 | | - } |
172 | | - |
173 | | - /** |
174 | 154 | * Returns a JS items string with the provided types. The earth type will |
175 | 155 | * be added to it when it's not present and $enableEarth is true. If there are |
176 | 156 | * no types, the default will be used. |
— | — | @@ -178,13 +158,10 @@ |
179 | 159 | * @param boolean $enableEarth |
180 | 160 | * @return string |
181 | 161 | */ |
182 | | - public static function createTypesString(array &$types, $enableEarth = false) { |
| 162 | + public static function createTypesString(array &$types) { |
183 | 163 | global $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid; |
184 | 164 | |
185 | 165 | $types = MapsMapper::getValidTypes($types, $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid, array(__CLASS__, 'getGMapType')); |
186 | | - |
187 | | - // This is to ensure backwards compatibility with 0.1 and 0.2. |
188 | | - if ($enableEarth && ! in_array('G_SATELLITE_3D_MAP', $types)) $types[] = 'G_SATELLITE_3D_MAP'; |
189 | 166 | |
190 | 167 | return MapsMapper::createJSItemsString($types, null, false, false); |
191 | 168 | } |
— | — | @@ -202,11 +179,12 @@ |
203 | 180 | } |
204 | 181 | |
205 | 182 | /** |
| 183 | + * Adds the needed output for the overlays control. |
206 | 184 | * |
207 | | - * |
208 | 185 | * @param string $output |
209 | 186 | * @param string $mapName |
210 | | - * @return unknown_type |
| 187 | + * @param string $overlays |
| 188 | + * @param string $controls |
211 | 189 | */ |
212 | 190 | public static function addOverlayOutput(&$output, $mapName, $overlays, $controls) { |
213 | 191 | global $egMapsGMapOverlays, $egMapsGoogleOverlLoaded, $wgJsMimeType; |
— | — | @@ -223,7 +201,7 @@ |
224 | 202 | MapsMapper::enforceArrayValues($overlays); |
225 | 203 | $validOverlays = array(); |
226 | 204 | foreach ($overlays as $overlay) { |
227 | | - $segements = split('-', $overlay); |
| 205 | + $segements = explode('-', $overlay); |
228 | 206 | $name = $segements[0]; |
229 | 207 | |
230 | 208 | if (in_array($name, $overlayNames)) { |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Class for handling the display_point(s) parser functions with Google Maps |
| 5 | + * File holding the MapsGoogleMapsDispPoint class. |
6 | 6 | * |
7 | 7 | * @file Maps_GoogleMapsDispPoint.php |
8 | 8 | * @ingroup MapsGoogleMaps |
— | — | @@ -13,6 +13,11 @@ |
14 | 14 | die( 'Not an entry point.' ); |
15 | 15 | } |
16 | 16 | |
| 17 | +/** |
| 18 | + * Class for handling the display_point(s) parser functions with Google Maps. |
| 19 | + * |
| 20 | + * @author Jeroen De Dauw |
| 21 | + */ |
17 | 22 | final class MapsGoogleMapsDispPoint extends MapsBasePointMap { |
18 | 23 | |
19 | 24 | public $serviceName = MapsGoogleMapsUtils::SERVICE_NAME; |
— | — | @@ -28,6 +33,8 @@ |
29 | 34 | |
30 | 35 | $this->elementNamePrefix = $egMapsGoogleMapsPrefix; |
31 | 36 | $this->defaultZoom = $egMapsGoogleMapsZoom; |
| 37 | + |
| 38 | + $this->markerStringFormat = 'getGMarkerData(lat, lon, "title", "label", "icon")'; |
32 | 39 | } |
33 | 40 | |
34 | 41 | /** |
— | — | @@ -48,10 +55,8 @@ |
49 | 56 | * |
50 | 57 | */ |
51 | 58 | public function addSpecificMapHTML() { |
52 | | - global $wgJsMimeType, $wgOut; |
| 59 | + global $wgJsMimeType; |
53 | 60 | |
54 | | - $enableEarth = MapsGoogleMapsUtils::getEarthValue($this->earth); |
55 | | - |
56 | 61 | $this->type = MapsGoogleMapsUtils::getGMapType($this->type, true); |
57 | 62 | |
58 | 63 | $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls); |
— | — | @@ -60,28 +65,9 @@ |
61 | 66 | |
62 | 67 | $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom); |
63 | 68 | |
64 | | - $markerItems = array(); |
65 | | - |
66 | | - // TODO: Refactor up |
67 | | - foreach ($this->markerData as $markerData) { |
68 | | - $lat = $markerData['lat']; |
69 | | - $lon = $markerData['lon']; |
70 | | - |
71 | | - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title; |
72 | | - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label; |
73 | | - |
74 | | - $title = str_replace("'", "\'", $title); |
75 | | - $label = str_replace("'", "\'", $label); |
76 | | - |
77 | | - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : ''; |
78 | | - $markerItems[] = "getGMarkerData($lat, $lon, '$title', '$label', '$icon')"; |
79 | | - } |
80 | | - |
81 | | - $markersString = implode(',', $markerItems); |
82 | | - |
83 | 69 | $this->types = explode(",", $this->types); |
84 | 70 | |
85 | | - $typesString = MapsGoogleMapsUtils::createTypesString($this->types, $enableEarth); |
| 71 | + $typesString = MapsGoogleMapsUtils::createTypesString($this->types); |
86 | 72 | |
87 | 73 | $this->output .=<<<END |
88 | 74 | |
— | — | @@ -100,7 +86,7 @@ |
101 | 87 | controls: [$this->controls], |
102 | 88 | scrollWheelZoom: $this->autozoom |
103 | 89 | }, |
104 | | - [$markersString] |
| 90 | + [$this->markerString] |
105 | 91 | ) |
106 | 92 | ); |
107 | 93 | /*]]>*/ </script> |
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Class for handling the display_point(s) parser functions with Yahoo! Maps |
| 5 | + * File holding the MapsYahooMapsDispPoint class. |
6 | 6 | * |
7 | 7 | * @file Maps_YahooMapsDispPoint.php |
8 | 8 | * @ingroup MapsYahooMaps |
— | — | @@ -13,6 +13,11 @@ |
14 | 14 | die( 'Not an entry point.' ); |
15 | 15 | } |
16 | 16 | |
| 17 | +/** |
| 18 | + * Class for handling the display_point(s) parser functions with Yahoo! Maps. |
| 19 | + * |
| 20 | + * @author Jeroen De Dauw |
| 21 | + */ |
17 | 22 | class MapsYahooMapsDispPoint extends MapsBasePointMap { |
18 | 23 | |
19 | 24 | public $serviceName = MapsYahooMapsUtils::SERVICE_NAME; |
— | — | @@ -28,6 +33,8 @@ |
29 | 34 | |
30 | 35 | $this->elementNamePrefix = $egMapsYahooMapsPrefix; |
31 | 36 | $this->defaultZoom = $egMapsYahooMapsZoom; |
| 37 | + |
| 38 | + $this->markerStringFormat = 'getYMarkerData(lat, lon, "title", "label", "icon")'; |
32 | 39 | } |
33 | 40 | |
34 | 41 | /** |
— | — | @@ -55,25 +62,6 @@ |
56 | 63 | $this->controls = MapsYahooMapsUtils::createControlsString($this->controls); |
57 | 64 | |
58 | 65 | $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom); |
59 | | - |
60 | | - $markerItems = array(); |
61 | | - |
62 | | - // TODO: Refactor up |
63 | | - foreach ($this->markerData as $markerData) { |
64 | | - $lat = $markerData['lat']; |
65 | | - $lon = $markerData['lon']; |
66 | | - |
67 | | - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title; |
68 | | - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label; |
69 | | - |
70 | | - $title = str_replace("'", "\'", $title); |
71 | | - $label = str_replace("'", "\'", $label); |
72 | | - |
73 | | - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : ''; |
74 | | - $markerItems[] = "getYMarkerData($lat, $lon, '$title', '$label', '$icon')"; |
75 | | - } |
76 | | - |
77 | | - $markersString = implode(',', $markerItems); |
78 | 66 | |
79 | 67 | $this->types = explode(",", $this->types); |
80 | 68 | |
— | — | @@ -84,7 +72,7 @@ |
85 | 73 | |
86 | 74 | <script type="$wgJsMimeType">/*<![CDATA[*/ |
87 | 75 | addOnloadHook( |
88 | | - initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$markersString]) |
| 76 | + initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$this->markerString]) |
89 | 77 | ); |
90 | 78 | /*]]>*/</script> |
91 | 79 | END; |