Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | echo '<b>Warning:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.'; |
38 | 38 | } |
39 | 39 | else { |
40 | | - define( 'Maps_VERSION', '0.7.2' ); |
| 40 | + define( 'Maps_VERSION', '0.7.3 alpha' ); |
41 | 41 | |
42 | 42 | // The different coordinate notations. |
43 | 43 | define( 'Maps_COORDS_FLOAT', 'float' ); |
— | — | @@ -113,7 +113,7 @@ |
114 | 114 | $wgAutoloadClasses['MapsGeodistance'] = $phDir . 'Maps_Geodistance.php'; |
115 | 115 | |
116 | 116 | // To ensure Maps remains compatible with pre 1.16. |
117 | | - if ( !array_key_exists( 'Html', $wgAutoloadClasses ) ) { |
| 117 | + if ( !class_exists( 'Html' ) ) { |
118 | 118 | $wgAutoloadClasses['Html'] = $egMapsDir . 'compat/Html.php'; |
119 | 119 | } |
120 | 120 | |
Index: trunk/extensions/Maps/Maps_Settings.php |
— | — | @@ -406,8 +406,11 @@ |
407 | 407 | 'yahoo' => "<style type='text/css'> #controls {width: 512px;}</style><script src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers'></script>", |
408 | 408 | 'bing' => "<script type='$wgJsMimeType' src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1'></script>", |
409 | 409 | 'ol-wms' => "<script type='$wgJsMimeType' src='http://clients.multimap.com/API/maps/1.1/metacarta_04'></script>", |
410 | | - 'osm' => "<script type='$wgJsMimeType' src='$egMapsScriptPath/includes/services/OpenLayers/OSM/OpenStreetMap.js?$egMapsStyleVersion'></script>", |
411 | 410 | ); |
| 411 | + |
| 412 | + if ( !method_exists( 'OutputPage', 'addModules' ) ) { |
| 413 | + $egMapsOLLayerDependencies['osm'] = "<script type='$wgJsMimeType' src='$egMapsScriptPath/includes/services/OpenLayers/OSM/OpenStreetMap.js?$egMapsStyleVersion'></script>"; |
| 414 | + } |
412 | 415 | |
413 | 416 | |
414 | 417 | |
Index: trunk/extensions/Maps/includes/Maps_MappingService.php |
— | — | @@ -108,14 +108,24 @@ |
109 | 109 | $dependencies = $this->getDependencyHtml(); |
110 | 110 | |
111 | 111 | // Only add a head item when there are dependencies. |
112 | | - if ( $dependencies ) { |
113 | | - if ( $parserOrOut instanceof Parser ) { |
| 112 | + if ( $parserOrOut instanceof Parser ) { |
| 113 | + if ( $dependencies ) { |
114 | 114 | $parserOrOut->getOutput()->addHeadItem( $dependencies ); |
115 | | - } |
116 | | - else if ( $parserOrOut instanceof OutputPage ) { |
| 115 | + } |
| 116 | + |
| 117 | + if ( method_exists( $parserOrOut->getOutput(), 'addModules' ) ) { |
| 118 | + $parserOrOut->getOutput()->addModules( $this->getResourceModules() ); |
| 119 | + } |
| 120 | + } |
| 121 | + else if ( $parserOrOut instanceof OutputPage ) { |
| 122 | + if ( $dependencies ) { |
117 | 123 | $parserOrOut->addHeadItem( md5( $dependencies ), $dependencies ); |
118 | | - } |
119 | | - } |
| 124 | + } |
| 125 | + |
| 126 | + if ( method_exists( $parserOrOut, 'addModules' ) ) { |
| 127 | + $parserOrOut->addModules( $this->getResourceModules() ); |
| 128 | + } |
| 129 | + } |
120 | 130 | } |
121 | 131 | |
122 | 132 | /** |
— | — | @@ -210,4 +220,26 @@ |
211 | 221 | return array(); |
212 | 222 | } |
213 | 223 | |
| 224 | + /** |
| 225 | + * Returns the resource modules that need to be loaded to use this mapping service. |
| 226 | + * |
| 227 | + * @since 0.7.3 |
| 228 | + * |
| 229 | + * @return array of string |
| 230 | + */ |
| 231 | + protected function getResourceModules() { |
| 232 | + return array(); |
| 233 | + } |
| 234 | + |
| 235 | + /** |
| 236 | + * Returns the modules definitions for the resources of this mapping service. |
| 237 | + * |
| 238 | + * @since 0.7.3 |
| 239 | + * |
| 240 | + * @return array of arrays |
| 241 | + */ |
| 242 | + public function getResourceModuleDefinitions() { |
| 243 | + return array(); |
| 244 | + } |
| 245 | + |
214 | 246 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/includes/services/GoogleMaps3/Maps_GoogleMaps3DispMap.php |
— | — | @@ -1,31 +1,18 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Class for handling the display_map parser function with Google Maps v3. |
| 5 | + * Class for handling the display_map parser hook with Google Maps v3. |
6 | 6 | * |
7 | | - * @file Maps_GoogleMaps3DispMap.php |
8 | 7 | * @ingroup MapsGoogleMaps3 |
9 | 8 | * |
10 | 9 | * @author Jeroen De Dauw |
11 | 10 | */ |
12 | | - |
13 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
14 | | - die( 'Not an entry point.' ); |
15 | | -} |
16 | | - |
17 | | -/** |
18 | | - * Class for handling the display_map parser functions with Google Maps v3. |
19 | | - * |
20 | | - * @ingroup MapsGoogleMaps3 |
21 | | - * |
22 | | - * @author Jeroen De Dauw |
23 | | - */ |
24 | 11 | final class MapsGoogleMaps3DispMap extends MapsBaseMap { |
25 | 12 | |
26 | 13 | /** |
27 | | - * @see MapsBaseMap::addSpecificMapHTML() |
| 14 | + * @see MapsBaseMap::getMapHTML() |
28 | 15 | */ |
29 | | - public function addSpecificMapHTML( Parser $parser ) { |
| 16 | + public function getMapHTML( array $params, Parser $parser ) { |
30 | 17 | $mapName = $this->service->getMapId(); |
31 | 18 | |
32 | 19 | $this->output .= Html::element( |
Index: trunk/extensions/Maps/includes/services/YahooMaps/Maps_YahooMapsDispMap.php |
— | — | @@ -1,24 +1,19 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Class for handling the display_map parser function with Yahoo! Maps |
| 5 | + * Class for handling the display_map parser hook with Yahoo! Maps |
6 | 6 | * |
7 | 7 | * @file Maps_YahooMapsDispMap.php |
8 | 8 | * @ingroup MapsYahooMaps |
9 | 9 | * |
10 | 10 | * @author Jeroen De Dauw |
11 | 11 | */ |
12 | | - |
13 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
14 | | - die( 'Not an entry point.' ); |
15 | | -} |
16 | | - |
17 | 12 | class MapsYahooMapsDispMap extends MapsBaseMap { |
18 | 13 | |
19 | 14 | /** |
20 | | - * @see MapsBaseMap::addSpecificMapHTML() |
| 15 | + * @see MapsBaseMap::getMapHTML() |
21 | 16 | */ |
22 | | - public function addSpecificMapHTML( Parser $parser ) { |
| 17 | + public function getMapHTML( array $params, Parser $parser ) { |
23 | 18 | $mapName = $this->service->getMapId(); |
24 | 19 | |
25 | 20 | $this->output .= Html::element( |
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_ParamOLLayers.php |
— | — | @@ -87,11 +87,10 @@ |
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | | - |
92 | | - $parameter->setValue( array( |
93 | | - '[' . implode( ',', $layerDefs ) . ']', |
94 | | - $this->getDependencies( $layerNames ) |
95 | | - ) ); |
| 91 | + |
| 92 | + $parameter->setValue( method_exists( 'OutputPage', 'addModules' ) ? $layerDefs : '[' . implode( ',', $layerDefs ) . ']' ); |
| 93 | + |
| 94 | + MapsOpenLayers::addLayerDependencies( $this->getDependencies( $layerNames ) ); |
96 | 95 | } |
97 | 96 | |
98 | 97 | /** |
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayerFunctions.js |
— | — | @@ -1,5 +1,7 @@ |
2 | 2 | /** |
3 | | - * Javascript functions for Open Layers functionality in Maps and its extensions |
| 3 | + * Javascript functions for Open Layers functionality in Maps and its extensions. |
| 4 | + * |
| 5 | + * Note: This file is for backward compatibility with MediaWiki <=1.16. |
4 | 6 | * |
5 | 7 | * @file OpenLayerFunctions.js |
6 | 8 | * @ingroup MapsOpenLayers |
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_OpenLayersDispMap.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Class for handling the display_map parser function with OpenLayers. |
| 5 | + * Class for handling the display_map parser hook with OpenLayers. |
6 | 6 | * |
7 | 7 | * @file Maps_OpenLayersDispMap.php |
8 | 8 | * @ingroup MapsOpenLayers |
— | — | @@ -11,39 +11,60 @@ |
12 | 12 | class MapsOpenLayersDispMap extends MapsBaseMap { |
13 | 13 | |
14 | 14 | /** |
15 | | - * @see MapsBaseMap::addSpecificMapHTML() |
| 15 | + * @see MapsBaseMap::getJSONObject |
| 16 | + * |
| 17 | + * @since 0.7.3 |
| 18 | + * |
| 19 | + * @param array $params |
| 20 | + * @param Parser $parser |
| 21 | + * |
| 22 | + * @return mixed |
| 23 | + */ |
| 24 | + protected function getJSONObject( array $params, Parser $parser ) { |
| 25 | + global $wgLang; |
| 26 | + $params['langCode'] = $wgLang->getCode(); |
| 27 | + return $params; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @see MapsBaseMap::getMapHTML |
| 32 | + * |
| 33 | + * @since 0.7.3 |
16 | 34 | */ |
17 | | - public function addSpecificMapHTML( Parser $parser ) { |
| 35 | + public function getMapHTML( array $params, Parser $parser ) { |
18 | 36 | global $wgLang; |
19 | 37 | |
20 | | - $this->service->addLayerDependencies( $this->layers[1] ); |
21 | | - |
22 | 38 | $mapName = $this->service->getMapId(); |
23 | 39 | |
24 | | - $this->output .= Html::element( |
| 40 | + if ( !method_exists( 'OutputPage', 'addModules' ) ) { |
| 41 | + $langCode = $wgLang->getCode(); |
| 42 | + $centreLat = MapsMapper::encodeJsVar( $params['centre']['lat'] ); |
| 43 | + $centreLon = MapsMapper::encodeJsVar( $params['centre']['lon'] ); |
| 44 | + $zoom = MapsMapper::encodeJsVar( $params['zoom'] ); |
| 45 | + |
| 46 | + MapsMapper::addInlineScript( $this->service, <<<EOT |
| 47 | + initOpenLayer( |
| 48 | + "$mapName", |
| 49 | + $centreLon, |
| 50 | + $centreLat, |
| 51 | + $zoom, |
| 52 | + {$params['layers'][0]}, |
| 53 | + [{$params['controls']}], |
| 54 | + [], |
| 55 | + "$langCode" |
| 56 | + ); |
| 57 | +EOT |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + return Html::element( |
25 | 62 | 'div', |
26 | 63 | array( |
27 | 64 | 'id' => $mapName, |
28 | | - 'style' => "width: $this->width; height: $this->height; background-color: #cccccc; overflow: hidden;", |
| 65 | + 'style' => "width: {$params['width']}; height: {$params['height']}; background-color: #cccccc; overflow: hidden;", |
29 | 66 | ), |
30 | 67 | wfMsg( 'maps-loading-map' ) |
31 | | - ); |
32 | | - |
33 | | - $langCode = $wgLang->getCode(); |
34 | | - |
35 | | - MapsMapper::addInlineScript( $this->service, <<<EOT |
36 | | - initOpenLayer( |
37 | | - "$mapName", |
38 | | - $this->centreLon, |
39 | | - $this->centreLat, |
40 | | - $this->zoom, |
41 | | - {$this->layers[0]}, |
42 | | - [$this->controls], |
43 | | - [], |
44 | | - "$langCode" |
45 | | - ); |
46 | | -EOT |
47 | | - ); |
| 68 | + ); |
48 | 69 | } |
49 | 70 | |
50 | 71 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_OpenLayers.php |
— | — | @@ -40,10 +40,15 @@ |
41 | 41 | $params['controls']->setDefault( $egMapsOLControls ); |
42 | 42 | $params['controls']->addCriteria( new CriterionInArray( self::getControlNames() ) ); |
43 | 43 | $params['controls']->addManipulations( |
44 | | - new ParamManipulationFunctions( 'strtolower' ), |
45 | | - new ParamManipulationImplode( ',', "'" ) |
| 44 | + new ParamManipulationFunctions( 'strtolower' ) |
46 | 45 | ); |
47 | 46 | |
| 47 | + if ( !method_exists( 'OutputPage', 'addModules' ) ) { |
| 48 | + $params['controls']->addManipulations( |
| 49 | + new ParamManipulationImplode( ',', "'" ) |
| 50 | + ); |
| 51 | + } |
| 52 | + |
48 | 53 | $params['layers'] = new ListParameter( 'layers' ); |
49 | 54 | $params['layers']->addManipulations( new MapsParamOLLayers() ); |
50 | 55 | $params['layers']->setDoManipulationOfDefault( true ); |
— | — | @@ -86,7 +91,7 @@ |
87 | 92 | public function createMarkersJs( array $markers ) { |
88 | 93 | $markerItems = array(); |
89 | 94 | $defaultGroup = wfMsg( 'maps-markers' ); |
90 | | - //.// TODO |
| 95 | + |
91 | 96 | foreach ( $markers as $marker ) { |
92 | 97 | $markerItems[] = MapsMapper::encodeJsVar( (object)array( |
93 | 98 | 'lat' => $marker[0], |
— | — | @@ -109,12 +114,17 @@ |
110 | 115 | protected function getDependencies() { |
111 | 116 | global $egMapsStyleVersion, $egMapsScriptPath; |
112 | 117 | |
113 | | - return array( |
114 | | - Html::linkedStyle( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayers/theme/default/style.css" ), |
115 | | - Html::linkedScript( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayers/OpenLayers.js?$egMapsStyleVersion" ), |
116 | | - Html::linkedScript( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayerFunctions.js?$egMapsStyleVersion" ), |
117 | | - Html::inlineScript( 'initOLSettings(200, 100); var msgMarkers = ' . Xml::encodeJsVar( wfMsg( 'maps-markers' ) ) . ';' ) |
118 | | - ); |
| 118 | + if ( method_exists( 'OutputPage', 'addModules' ) ) { |
| 119 | + return array(); |
| 120 | + } |
| 121 | + else { |
| 122 | + return array( |
| 123 | + Html::linkedStyle( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayers/theme/default/style.css" ), |
| 124 | + Html::linkedScript( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayers/OpenLayers.js?$egMapsStyleVersion" ), |
| 125 | + Html::linkedScript( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayerFunctions.js?$egMapsStyleVersion" ), |
| 126 | + Html::inlineScript( 'initOLSettings(200, 100); var msgMarkers = ' . Xml::encodeJsVar( wfMsg( 'maps-markers' ) ) . ';' ) |
| 127 | + ); |
| 128 | + } |
119 | 129 | } |
120 | 130 | |
121 | 131 | /** |
— | — | @@ -167,4 +177,43 @@ |
168 | 178 | } |
169 | 179 | } |
170 | 180 | |
| 181 | + /** |
| 182 | + * @see MapsMappingService::getResourceModules |
| 183 | + * |
| 184 | + * @since 0.7.3 |
| 185 | + * |
| 186 | + * @return array of string |
| 187 | + */ |
| 188 | + protected function getResourceModules() { |
| 189 | + return array( 'ext.maps.openlayers', 'ext.maps.osm' ); |
| 190 | + } |
| 191 | + |
| 192 | + /** |
| 193 | + * @see MapsMappingService::getResourceModuleDefinitions |
| 194 | + * |
| 195 | + * @since 0.7.3 |
| 196 | + * |
| 197 | + * @return array of arrays |
| 198 | + */ |
| 199 | + public function getResourceModuleDefinitions() { |
| 200 | + return array( |
| 201 | + 'ext.maps.openlayers' => array( |
| 202 | + 'scripts' => array( |
| 203 | + 'OpenLayers/OpenLayers.js', |
| 204 | + 'ext.maps.openlayers.js' |
| 205 | + ), |
| 206 | + 'styles' => array( |
| 207 | + 'OpenLayers/theme/default/style.css' |
| 208 | + ), |
| 209 | + 'dependencies' => 'ext.maps.common' |
| 210 | + ), |
| 211 | + 'ext.maps.osm' => array( |
| 212 | + 'scripts' => array( |
| 213 | + 'OSM/OpenStreetMap.js', |
| 214 | + ), |
| 215 | + 'dependencies' => 'ext.maps.openlayers' |
| 216 | + ) |
| 217 | + ); |
| 218 | + } |
| 219 | + |
171 | 220 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/includes/services/OpenLayers/ext.maps.openlayers.js |
— | — | @@ -0,0 +1,203 @@ |
| 2 | +/** |
| 3 | + * JavasSript for OpenLayers maps in the Maps extension. |
| 4 | + * @see http://www.mediawiki.org/wiki/Extension:Maps |
| 5 | + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
| 6 | + */ |
| 7 | + |
| 8 | +$( document ).ready( function() { |
| 9 | + |
| 10 | + OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; |
| 11 | + OpenLayers.Util.onImageLoadErrorColor = 'transparent'; |
| 12 | + OpenLayers.Feature.prototype.popupClass = OpenLayers.Class( |
| 13 | + OpenLayers.Popup.FramedCloud, |
| 14 | + { |
| 15 | + 'autoSize': true, |
| 16 | + 'minSize': new OpenLayers.Size( 200, 100 ) |
| 17 | + } |
| 18 | + ); |
| 19 | + |
| 20 | + for ( i = 0, n = window.maps['openlayers'].length; i < n; i++ ) { |
| 21 | + initiateMap( window.maps['openlayers'][i] ); |
| 22 | + } |
| 23 | + |
| 24 | + function initiateMap( params ) { |
| 25 | + OpenLayers.Lang.setCode( params.langCode ); |
| 26 | + |
| 27 | + var hasImageLayer = false; |
| 28 | + for ( i = 0, n = params.layers.length; i < n; i++ ) { |
| 29 | + // Idieally this would check if the objecct is of type OpenLayers.layer.image |
| 30 | + if ( params.layers[i].options && params.layers[i].options.isImage === true ) { |
| 31 | + hasImageLayer = true; |
| 32 | + break; |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + // Create a new OpenLayers map with without any controls on it. |
| 37 | + var mapOptions = { |
| 38 | + controls: [] |
| 39 | + }; |
| 40 | + |
| 41 | + if ( !hasImageLayer ) { |
| 42 | + mapOptions.projection = new OpenLayers.Projection("EPSG:900913"); |
| 43 | + mapOptions.displayProjection = new OpenLayers.Projection("EPSG:4326"); |
| 44 | + mapOptions.units = "m"; |
| 45 | + mapOptions.numZoomLevels = 18; |
| 46 | + mapOptions.maxResolution = 156543.0339; |
| 47 | + mapOptions.maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34); |
| 48 | + } |
| 49 | + |
| 50 | + // TODO |
| 51 | + var mapElement = document.getElementById( 'open_layer_1' ); |
| 52 | + |
| 53 | + // Remove the loading map message. |
| 54 | + mapElement.innerHTML = ''; |
| 55 | + alert(''); |
| 56 | + // TODO |
| 57 | + var map = new OpenLayers.Map( 'open_layer_1', mapOptions ); |
| 58 | + alert(''); |
| 59 | + addControls( map, params.controls, mapElement ); |
| 60 | + |
| 61 | + // Add the base layers. |
| 62 | + for ( i = 0, n = params.layers.length; i < n; i++ ) map.addLayer( params.layers[i] ); |
| 63 | + |
| 64 | + // Layer to hold the markers. |
| 65 | + var markerLayer = new OpenLayers.Layer.Markers( 'Markers' ); // TODO |
| 66 | + markerLayer.id= 'markerLayer'; |
| 67 | + map.addLayer( markerLayer ); |
| 68 | + |
| 69 | + var centerIsSet = params.centre.lon != null && params.centre.lat != null; |
| 70 | + |
| 71 | + addMarkers( map, params, markerLayer, centerIsSet ); |
| 72 | + |
| 73 | + if ( centerIsSet ) { // When the center is provided, set it. |
| 74 | + var centre = new OpenLayers.LonLat( params.centre.lon, params.centre.lat ); |
| 75 | + |
| 76 | + if ( !hasImageLayer ) { |
| 77 | + centre.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")); |
| 78 | + } |
| 79 | + |
| 80 | + map.setCenter( centre ); |
| 81 | + } |
| 82 | + |
| 83 | + if (params.zoom != null) map.zoomTo(params.zoom); // When the zoom is provided, set it. |
| 84 | + } |
| 85 | + |
| 86 | + function addControls( map, controls, mapElement ) { |
| 87 | + // Add the controls. |
| 88 | + for ( var i = controls.length - 1; i >= 0; i-- ) { |
| 89 | + |
| 90 | + // If a string is provided, find the correct name for the control, and use eval to create the object itself. |
| 91 | + if ( typeof controls[i] == 'string' ) { |
| 92 | + if ( controls[i].toLowerCase() == 'autopanzoom' ) { |
| 93 | + if ( mapElement.offsetHeight > 140 ) controls[i] = mapElement.offsetHeight > 320 ? 'panzoombar' : 'panzoom'; |
| 94 | + } |
| 95 | + |
| 96 | + control = getValidControlName( controls[i] ); |
| 97 | + |
| 98 | + if ( control ) { |
| 99 | + eval(' map.addControl( new OpenLayers.Control.' + control + '() ); '); |
| 100 | + } |
| 101 | + } |
| 102 | + else { |
| 103 | + map.addControl(controls[i]); // If a control is provided, instead a string, just add it. |
| 104 | + controls[i].activate(); // And activate it. |
| 105 | + } |
| 106 | + |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + function addMarkers( map, params, markerLayer, centerIsSet ) { |
| 111 | + var bounds = null; |
| 112 | + |
| 113 | + if ( params.markers.length > 1 && ( !centerIsSet || params.zoom == null ) ) { |
| 114 | + bounds = new OpenLayers.Bounds(); |
| 115 | + } |
| 116 | + |
| 117 | + for ( i = params.markers.length - 1; i >= 0; i-- ) { |
| 118 | + params.markers[i].lonlat = new OpenLayers.LonLat( params.markers[i].lon, params.markers[i].lat ); |
| 119 | + |
| 120 | + if ( !hasImageLayer ) { |
| 121 | + params.markers[i].lonlat.transform( new OpenLayers.Projection( "EPSG:4326" ), new OpenLayers.Projection( "EPSG:900913" ) ); |
| 122 | + } |
| 123 | + |
| 124 | + if ( bounds != null ) bounds.extend( params.markers[i].lonlat ); // Extend the bounds when no center is set. |
| 125 | + markerLayer.addMarker( getOLMarker( markerLayer, params.markers[i], map.getProjectionObject() ) ); // Create and add the marker. |
| 126 | + } |
| 127 | + |
| 128 | + if ( bounds != null ) map.zoomToExtent( bounds ); // If a bounds object has been created, use it to set the zoom and center. |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Gets a valid control name (with excat lower and upper case letters), |
| 133 | + * or returns false when the control is not allowed. |
| 134 | + */ |
| 135 | + function getValidControlName( control ) { |
| 136 | + var OLControls = [ |
| 137 | + 'ArgParser', 'Attribution', 'Button', 'DragFeature', 'DragPan', |
| 138 | + 'DrawFeature', 'EditingToolbar', 'GetFeature', 'KeyboardDefaults', 'LayerSwitcher', |
| 139 | + 'Measure', 'ModifyFeature', 'MouseDefaults', 'MousePosition', 'MouseToolbar', |
| 140 | + 'Navigation', 'NavigationHistory', 'NavToolbar', 'OverviewMap', 'Pan', |
| 141 | + 'Panel', 'PanPanel', 'PanZoom', 'PanZoomBar', 'Permalink', |
| 142 | + 'Scale', 'ScaleLine', 'SelectFeature', 'Snapping', 'Split', |
| 143 | + 'WMSGetFeatureInfo', 'ZoomBox', 'ZoomIn', 'ZoomOut', 'ZoomPanel', |
| 144 | + 'ZoomToMaxExtent' |
| 145 | + ]; |
| 146 | + |
| 147 | + for ( var i = OLControls.length - 1; i >= 0; i-- ) { |
| 148 | + if ( control == OLControls[i].toLowerCase() ) { |
| 149 | + return OLControls[i]; |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + return false; |
| 154 | + } |
| 155 | + |
| 156 | + function getOLMarker(markerLayer, markerData, projectionObject) { |
| 157 | + var marker; |
| 158 | + |
| 159 | + if (markerData.icon != "") { |
| 160 | + //var iconSize = new OpenLayers.Size(10,17); |
| 161 | + //var iconOffset = new OpenLayers.Pixel(-(iconSize.w/2), -iconSize.h); |
| 162 | + marker = new OpenLayers.Marker(markerData.lonlat, new OpenLayers.Icon(markerData.icon)); // , iconSize, iconOffset |
| 163 | + } else { |
| 164 | + marker = new OpenLayers.Marker(markerData.lonlat); |
| 165 | + } |
| 166 | + |
| 167 | + if ( markerData.title.length + markerData.label.length > 0 ) { |
| 168 | + |
| 169 | + // This is the handler for the mousedown event on the marker, and displays the popup. |
| 170 | + marker.events.register('mousedown', marker, |
| 171 | + function(evt) { |
| 172 | + var popup = new OpenLayers.Feature(markerLayer, markerData.lonlat).createPopup(true); |
| 173 | + |
| 174 | + if (markerData.title.length > 0 && markerData.label.length > 0) { // Add the title and label to the popup text. |
| 175 | + popup.setContentHTML('<b>' + markerData.title + '</b><hr />' + markerData.label); |
| 176 | + } |
| 177 | + else { |
| 178 | + popup.setContentHTML(markerData.title + markerData.label); |
| 179 | + } |
| 180 | + |
| 181 | + popup.setOpacity(0.85); |
| 182 | + markerLayer.map.addPopup(popup); |
| 183 | + OpenLayers.Event.stop(evt); // Stop the event. |
| 184 | + } |
| 185 | + ); |
| 186 | + |
| 187 | + } |
| 188 | + |
| 189 | + return marker; |
| 190 | + } |
| 191 | + |
| 192 | + function initOLSettings(minWidth, minHeight) { |
| 193 | + OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; |
| 194 | + OpenLayers.Util.onImageLoadErrorColor = 'transparent'; |
| 195 | + OpenLayers.Feature.prototype.popupClass = OpenLayers.Class( |
| 196 | + OpenLayers.Popup.FramedCloud, |
| 197 | + { |
| 198 | + 'autoSize': true, |
| 199 | + 'minSize': new OpenLayers.Size(minWidth, minHeight) |
| 200 | + } |
| 201 | + ); |
| 202 | + } |
| 203 | + |
| 204 | +} ); |
\ No newline at end of file |
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/ext.maps.openlayers.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 205 | + native |
Index: trunk/extensions/Maps/includes/services/GoogleMaps/Maps_GoogleMapsDispMap.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Class for handling the display_map parser functions with Google Maps. |
| 5 | + * Class for handling the display_map parser hook with Google Maps. |
6 | 6 | * |
7 | 7 | * @file Maps_GoogleMapsDispMap.php |
8 | 8 | * @ingroup MapsGoogleMaps |
— | — | @@ -10,13 +10,10 @@ |
11 | 11 | */ |
12 | 12 | final class MapsGoogleMapsDispMap extends MapsBaseMap { |
13 | 13 | |
14 | | - protected function initSpecificParamInfo( array &$parameters ) { |
15 | | - } |
16 | | - |
17 | 14 | /** |
18 | | - * @see MapsBaseMap::addSpecificMapHTML() |
| 15 | + * @see MapsBaseMap::getMapHTML() |
19 | 16 | */ |
20 | | - public function addSpecificMapHTML( Parser $parser ) { |
| 17 | + public function getMapHTML( array $params, Parser $parser ) { |
21 | 18 | $mapName = $this->service->getMapId(); |
22 | 19 | |
23 | 20 | $this->service->addOverlayOutput( $this->output, $mapName, $this->overlays, $this->controls ); |
Index: trunk/extensions/Maps/includes/services/OSM/Maps_OSMDispMap.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Class for handling the display_map parser function with OSM. |
| 5 | + * Class for handling the display_map parser hook with OSM. |
6 | 6 | * |
7 | 7 | * @since 0.6.4 |
8 | 8 | * |
— | — | @@ -13,11 +13,9 @@ |
14 | 14 | class MapsOSMDispMap extends MapsBaseMap { |
15 | 15 | |
16 | 16 | /** |
17 | | - * @see MapsBaseMap::addSpecificMapHTML() |
18 | | - * |
19 | | - * @since 0.6.4 |
| 17 | + * @see MapsBaseMap::getMapHTML() |
20 | 18 | */ |
21 | | - public function addSpecificMapHTML( Parser $parser ) { |
| 19 | + public function getMapHTML( array $params, Parser $parser ) { |
22 | 20 | global $wgLang; |
23 | 21 | |
24 | 22 | $thumbs = $this->thumbs ? 'yes' : 'no'; |
Index: trunk/extensions/Maps/includes/parserHooks/Maps_DisplayMap.php |
— | — | @@ -102,7 +102,7 @@ |
103 | 103 | // Get an instance of the class handling the current parser hook and service. |
104 | 104 | $mapClass = $service->getFeatureInstance( $this->getName() ); |
105 | 105 | |
106 | | - return $mapClass->getMapHtml( $parameters, $this->parser ); |
| 106 | + return $mapClass->renderMap( $parameters, $this->parser ); |
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
Index: trunk/extensions/Maps/includes/Maps_MappingServices.php |
— | — | @@ -204,7 +204,7 @@ |
205 | 205 | * |
206 | 206 | * @since 0.6.6 |
207 | 207 | * |
208 | | - * @return array |
| 208 | + * @return array of string |
209 | 209 | */ |
210 | 210 | public static function getAllServiceValues() { |
211 | 211 | global $egMapsAvailableServices; |
— | — | @@ -217,6 +217,23 @@ |
218 | 218 | } |
219 | 219 | |
220 | 220 | return $allServiceValues; |
221 | | - } |
| 221 | + } |
222 | 222 | |
| 223 | + /** |
| 224 | + * Returns an array with an instance of a MappingService object for every available mapping service. |
| 225 | + * |
| 226 | + * @since 0.7.3 |
| 227 | + * |
| 228 | + * @return array of MappingService |
| 229 | + */ |
| 230 | + public static function getAllObjects() { |
| 231 | + $objects = array(); |
| 232 | + |
| 233 | + foreach ( self::$registeredServices as $service => $class ) { |
| 234 | + $objects[] = self::getServiceInstance( $service ); |
| 235 | + } |
| 236 | + |
| 237 | + return $objects; |
| 238 | + } |
| 239 | + |
223 | 240 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/includes/features/Maps_BaseMap.php |
— | — | @@ -13,87 +13,72 @@ |
14 | 14 | abstract class MapsBaseMap { |
15 | 15 | |
16 | 16 | /** |
| 17 | + * @since 0.6.x |
| 18 | + * |
17 | 19 | * @var iMappingService |
18 | 20 | */ |
19 | 21 | protected $service; |
20 | | - |
21 | | - protected $centreLat, $centreLon; |
22 | 22 | |
23 | | - protected $output = ''; |
24 | | - |
25 | | - private $specificParameters = false; |
26 | 23 | /** |
27 | | - * Constructor. |
| 24 | + * @since 0.7.3 |
28 | 25 | * |
29 | | - * @param MapsMappingService $service |
| 26 | + * @var array |
30 | 27 | */ |
31 | | - public function __construct( iMappingService $service ) { |
32 | | - $this->service = $service; |
33 | | - } |
| 28 | + protected $properties = array(); |
34 | 29 | |
35 | 30 | /** |
36 | | - * Sets the map properties as class fields. |
| 31 | + * Returns the HTML to display the map. |
37 | 32 | * |
38 | | - * @param array $mapProperties |
| 33 | + * @since 0.7.3 |
| 34 | + * |
| 35 | + * @param array $params |
| 36 | + * @param $parser |
| 37 | + * |
| 38 | + * @return string |
39 | 39 | */ |
40 | | - protected function setMapProperties( array $mapProperties ) { |
41 | | - foreach ( $mapProperties as $paramName => $paramValue ) { |
42 | | - if ( !property_exists( __CLASS__, $paramName ) ) { |
43 | | - $this-> { $paramName } = $paramValue; |
44 | | - } |
45 | | - else { |
46 | | - // If this happens in any way, it could be a big vunerability, so throw an exception. |
47 | | - throw new Exception( 'Attempt to override a class field during map property assignment. Field name: ' . $paramName ); |
48 | | - } |
49 | | - } |
50 | | - } |
| 40 | + protected abstract function getMapHTML( array $params, Parser $parser ); |
51 | 41 | |
52 | 42 | /** |
53 | | - * Returns the specific parameters by first checking if they have been initialized yet, |
54 | | - * doing to work if this is not the case, and then returning them. |
| 43 | + * Constructor. |
55 | 44 | * |
56 | | - * @return array |
| 45 | + * @param MapsMappingService $service |
57 | 46 | */ |
58 | | - public final function getSpecificParameterInfo() { |
59 | | - if ( $this->specificParameters === false ) { |
60 | | - $this->specificParameters = array(); |
61 | | - $this->initSpecificParamInfo( $this->specificParameters ); |
62 | | - } |
63 | | - |
64 | | - return $this->specificParameters; |
| 47 | + public function __construct( iMappingService $service ) { |
| 48 | + $this->service = $service; |
65 | 49 | } |
66 | 50 | |
67 | 51 | /** |
68 | | - * Initializes the specific parameters. |
| 52 | + * @see |
69 | 53 | * |
70 | | - * Override this method to set parameters specific to a feature service comibination in |
71 | | - * the inheriting class. |
72 | | - * |
73 | | - * @param array $parameters |
74 | | - */ |
75 | | - protected function initSpecificParamInfo( array &$parameters ) { |
| 54 | + * @since 0.7.3 |
| 55 | + */ |
| 56 | + public function addParameterInfo( array &$params ) { |
76 | 57 | } |
77 | 58 | |
78 | 59 | /** |
79 | 60 | * Handles the request from the parser hook by doing the work that's common for all |
80 | 61 | * mapping services, calling the specific methods and finally returning the resulting output. |
81 | 62 | * |
| 63 | + * @since 0.7.3 |
| 64 | + * |
82 | 65 | * @param array $params |
83 | 66 | * @param Parser $parser |
84 | 67 | * |
85 | 68 | * @return html |
86 | 69 | */ |
87 | | - public final function getMapHtml( array $params, Parser $parser ) { |
88 | | - $this->setMapProperties( $params ); |
| 70 | + public final function renderMap( array $params, Parser $parser ) { |
| 71 | + $this->setCentre( $params ); |
89 | 72 | |
90 | | - $this->setCentre(); |
| 73 | + if ( $params['zoom'] == 'null' ) { |
| 74 | + $params['zoom'] = $this->service->getDefaultZoom(); |
| 75 | + } |
91 | 76 | |
92 | | - if ( $this->zoom == 'null' ) { |
93 | | - $this->zoom = $this->service->getDefaultZoom(); |
| 77 | + $output = $this->getMapHTML( $params, $parser ); |
| 78 | + |
| 79 | + if ( method_exists( 'OutputPage', 'addModules' ) ) { |
| 80 | + $output .= $this->getJSON( $params, $parser ); |
94 | 81 | } |
95 | 82 | |
96 | | - $this->addSpecificMapHTML( $parser ); |
97 | | - |
98 | 83 | global $wgTitle; |
99 | 84 | if ( $wgTitle->getNamespace() == NS_SPECIAL ) { |
100 | 85 | global $wgOut; |
— | — | @@ -103,48 +88,66 @@ |
104 | 89 | $this->service->addDependencies( $parser ); |
105 | 90 | } |
106 | 91 | |
107 | | - return $this->output; |
| 92 | + return $output; |
108 | 93 | } |
109 | 94 | |
110 | 95 | /** |
111 | | - * Sets the $centreLat and $centreLon fields. |
112 | | - */ |
113 | | - protected function setCentre() { |
114 | | - if ( empty( $this->coordinates ) ) { // If centre is not set, use the default latitude and longitutde. |
115 | | - $this->setCentreToDefault(); |
| 96 | + * Returns the JSON with the maps data. |
| 97 | + * |
| 98 | + * @since 0.7.3 |
| 99 | + * |
| 100 | + * @param array $params |
| 101 | + * @param Parser $parser |
| 102 | + * |
| 103 | + * @return string |
| 104 | + */ |
| 105 | + protected function getJSON( array $params, Parser $parser ) { |
| 106 | + $object = $this->getJSONObject( $params, $parser ); |
| 107 | + |
| 108 | + if ( $object === false ) { |
| 109 | + return ''; |
116 | 110 | } |
117 | | - else { // If a centre value is set, geocode when needed and use it. |
118 | | - $this->coordinates = MapsGeocoders::attemptToGeocode( $this->coordinates, $this->geoservice, $this->service->getName() ); |
119 | | - |
120 | | - // If the centre is not false, it will be a valid coordinate, which can be used to set the latitude and longitutde. |
121 | | - if ( $this->coordinates ) { |
122 | | - $this->centreLat = Xml::escapeJsString( $this->coordinates['lat'] ); |
123 | | - $this->centreLon = Xml::escapeJsString( $this->coordinates['lon'] ); |
124 | | - } |
125 | | - else { // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used. |
126 | | - $this->setCentreToDefault(); |
127 | | - } |
128 | | - } |
| 111 | + |
| 112 | + // TODO |
| 113 | + return Html::inlineScript( "maps=[]; maps['{$this->service->getName()}']=[]; maps['{$this->service->getName()}'].push(" . json_encode( $object ) . ')' ); |
129 | 114 | } |
130 | 115 | |
131 | 116 | /** |
132 | | - * Attempts to set the centreLat and centreLon fields to the Maps default. |
133 | | - * When this fails (aka the default is not valid), an exception is thrown. |
| 117 | + * Returns a PHP object to encode to JSON with the map data. |
| 118 | + * |
| 119 | + * @since 0.7.3 |
| 120 | + * |
| 121 | + * @param array $params |
| 122 | + * @param Parser $parser |
134 | 123 | * |
135 | | - * @since 0.7 |
| 124 | + * @return mixed |
| 125 | + */ |
| 126 | + protected function getJSONObject( array $params, Parser $parser ) { |
| 127 | + return $params; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Translates the coordinates field to the centre field and makes sure it's set to it's default when invalid. |
136 | 132 | */ |
137 | | - protected function setCentreToDefault() { |
138 | | - global $egMapsDefaultMapCentre; |
| 133 | + protected function setCentre( array &$params ) { |
| 134 | + // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used. |
| 135 | + if ( $params['coordinates'] === false ) { |
| 136 | + global $egMapsDefaultMapCentre; |
139 | 137 | |
140 | | - $centre = MapsGeocoders::attemptToGeocode( $egMapsDefaultMapCentre, $this->geoservice, $this->service->getName() ); |
141 | | - |
142 | | - if ( $centre === false ) { |
143 | | - throw new Exception( 'Failed to parse the default centre for the map. Please check the value of $egMapsDefaultMapCentre.' ); |
| 138 | + $centre = MapsGeocoders::attemptToGeocode( $egMapsDefaultMapCentre, $params['geoservice'], $this->service->getName() ); |
| 139 | + |
| 140 | + if ( $centre === false ) { |
| 141 | + throw new Exception( 'Failed to parse the default centre for the map. Please check the value of $egMapsDefaultMapCentre.' ); |
| 142 | + } |
| 143 | + else { |
| 144 | + $params['centre'] = $centre; |
| 145 | + } |
144 | 146 | } |
145 | 147 | else { |
146 | | - $this->centreLat = Xml::escapeJsString( $centre['lat'] ); |
147 | | - $this->centreLon = Xml::escapeJsString( $centre['lon'] ); |
| 148 | + $params['centre'] = MapsCoordinateParser::parseCoordinates( $params['coordinates'] ); |
148 | 149 | } |
149 | | - } |
| 150 | + |
| 151 | + unset( $params['coordinates'] ); |
| 152 | + } |
150 | 153 | |
151 | 154 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/Maps.hooks.php |
— | — | @@ -69,15 +69,24 @@ |
70 | 70 | * @return true |
71 | 71 | */ |
72 | 72 | public static function registerResourceLoaderModules( ResourceLoader &$resourceLoader ) { |
73 | | - global $wgExtensionAssetsPath; |
| 73 | + global $egMapsScriptPath; |
74 | 74 | |
75 | | - $modules = array( |
| 75 | + $modules = array( |
| 76 | + 'ext.maps.common' => array( |
| 77 | + |
| 78 | + ), |
76 | 79 | ); |
77 | 80 | |
| 81 | + // TODO: makes more sense to have a seperate hook for each service |
| 82 | + foreach ( MapsMappingServices::getAllObjects() as $service ) { |
| 83 | + $modules = array_merge( $modules, $service->getResourceModuleDefinitions() ); |
| 84 | + } |
| 85 | + |
78 | 86 | foreach ( $modules as $name => $resources ) { |
79 | 87 | $resourceLoader->register( $name, new ResourceLoaderFileModule( |
80 | 88 | array_merge_recursive( $resources, array( 'group' => 'ext.maps' ) ), |
81 | | - dirname( __FILE__ ), "$wgExtensionAssetsPath/Maps" |
| 89 | + dirname( __FILE__ ) . '/includes/services/OpenLayers/', |
| 90 | + $egMapsScriptPath . '/includes/services/OpenLayers/' |
82 | 91 | ) ); |
83 | 92 | } |
84 | 93 | |