r82998 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82997‎ | r82998 | r82999 >
Date:01:37, 1 March 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r82991
Modified paths:
  • /branches/Maps0.8/Maps.i18n.php (modified) (history)
  • /branches/Maps0.8/Maps.php (modified) (history)
  • /branches/Maps0.8/includes/services/GoogleMaps/GoogleMaps.php (modified) (history)
  • /branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMaps.php (modified) (history)
  • /branches/Maps0.8/includes/services/GoogleMaps/ext.maps.googlemaps2.js (modified) (history)

Diff [purge]

Index: branches/Maps0.8/Maps.i18n.php
@@ -20,6 +20,7 @@
2121 Available mapping services: $1",
2222 'maps_map' => 'Map',
2323 'maps-loading-map' => 'Loading map...',
 24+ 'maps-load-failed' => 'Could not load the map!',
2425 'maps-markers' => 'Markers',
2526 'maps-others' => 'others',
2627 'maps-ns-layer' => 'Layer',
@@ -150,7 +151,8 @@
151152 'maps_click_to_activate' => 'Click to activate map',
152153 'maps_centred_on' => 'Map centered on $1, $2.',
153154
154 - // Google Maps v2 overlays
 155+ // Google Maps v2
 156+ 'maps-googlemaps2-incompatbrowser' => 'Your browser is not compatible with Google Maps v2.',
155157 'maps_overlays' => 'Overlays',
156158 'maps_photos' => 'Photos',
157159 'maps_videos' => 'Videos',
Index: branches/Maps0.8/Maps.php
@@ -39,118 +39,130 @@
4040 if ( ! defined( 'Validator_VERSION' ) ) {
4141 die( '<b>Error:</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>.<br />' );
4242 }
43 -else {
44 - define( 'Maps_VERSION', '0.8 alpha' );
4543
46 - // The different coordinate notations.
47 - define( 'Maps_COORDS_FLOAT', 'float' );
48 - define( 'Maps_COORDS_DMS', 'dms' );
49 - define( 'Maps_COORDS_DM', 'dm' );
50 - define( 'Maps_COORDS_DD', 'dd' );
51 -
52 - $egMapsScriptPath = ( $wgExtensionAssetsPath === false ? '/extensions' : $wgExtensionAssetsPath ) . '/Maps';
53 - $egMapsDir = dirname( __FILE__ ) . '/';
 44+define( 'Maps_VERSION', '0.8 alpha' );
5445
55 - $egMapsStyleVersion = $wgStyleVersion . '-' . Maps_VERSION;
 46+// The different coordinate notations.
 47+define( 'Maps_COORDS_FLOAT', 'float' );
 48+define( 'Maps_COORDS_DMS', 'dms' );
 49+define( 'Maps_COORDS_DM', 'dm' );
 50+define( 'Maps_COORDS_DD', 'dd' );
5651
57 - $wgAutoloadClasses['MapsHooks'] = dirname( __FILE__ ) . '/Maps.hooks.php';
 52+$egMapsScriptPath = ( $wgExtensionAssetsPath === false ? '/extensions' : $wgExtensionAssetsPath ) . '/Maps';
 53+$egMapsDir = dirname( __FILE__ ) . '/';
 54+
 55+$egMapsStyleVersion = $wgStyleVersion . '-' . Maps_VERSION;
 56+
 57+$wgAutoloadClasses['MapsHooks'] = dirname( __FILE__ ) . '/Maps.hooks.php';
 58+
 59+// Autoload the "includes/" classes and interfaces.
 60+$incDir = dirname( __FILE__ ) . '/includes/';
 61+$wgAutoloadClasses['MapsMapper'] = $incDir . 'Maps_Mapper.php';
 62+$wgAutoloadClasses['MapsCoordinateParser'] = $incDir . 'Maps_CoordinateParser.php';
 63+$wgAutoloadClasses['MapsDistanceParser'] = $incDir . 'Maps_DistanceParser.php';
 64+$wgAutoloadClasses['MapsGeoFunctions'] = $incDir . 'Maps_GeoFunctions.php';
 65+$wgAutoloadClasses['MapsGeocoders'] = $incDir . 'Maps_Geocoders.php';
 66+$wgAutoloadClasses['MapsGeocoder'] = $incDir . 'Maps_Geocoder.php';
 67+$wgAutoloadClasses['MapsKMLFormatter'] = $incDir . 'Maps_KMLFormatter.php';
 68+$wgAutoloadClasses['MapsLayer'] = $incDir . 'Maps_Layer.php';
 69+$wgAutoloadClasses['MapsLayerPage'] = $incDir . 'Maps_LayerPage.php';
 70+$wgAutoloadClasses['MapsLayers'] = $incDir . 'Maps_Layers.php';
 71+$wgAutoloadClasses['MapsLocation'] = $incDir . 'Maps_Location.php';
 72+$wgAutoloadClasses['iMappingFeature'] = $incDir . 'iMappingFeature.php';
 73+$wgAutoloadClasses['iMappingService'] = $incDir . 'iMappingService.php';
 74+$wgAutoloadClasses['MapsMappingServices'] = $incDir . 'Maps_MappingServices.php';
 75+$wgAutoloadClasses['MapsMappingService'] = $incDir . 'Maps_MappingService.php';
 76+$wgAutoloadClasses['MapsSettings'] = $incDir . 'Maps_Settings.php';
 77+
 78+// Autoload the "includes/criteria/" classes.
 79+$criDir = $incDir . 'criteria/';
 80+$wgAutoloadClasses['CriterionIsDistance'] = $criDir . 'CriterionIsDistance.php';
 81+$wgAutoloadClasses['CriterionIsImage'] = $criDir . 'CriterionIsImage.php';
 82+$wgAutoloadClasses['CriterionIsLocation'] = $criDir . 'CriterionIsLocation.php';
 83+$wgAutoloadClasses['CriterionMapDimension'] = $criDir . 'CriterionMapDimension.php';
 84+$wgAutoloadClasses['CriterionMapLayer'] = $criDir . 'CriterionMapLayer.php';
 85+unset( $criDir );
 86+
 87+// Autoload the "includes/features/" classes.
 88+$ftDir = $incDir . '/features/';
 89+$wgAutoloadClasses['MapsBaseMap'] = $ftDir . 'Maps_BaseMap.php';
 90+$wgAutoloadClasses['MapsBasePointMap'] = $ftDir . 'Maps_BasePointMap.php';
 91+unset( $ftDir );
 92+
 93+// Autoload the "includes/geocoders/" classes.
 94+$geoDir = $incDir . 'geocoders/';
 95+$wgAutoloadClasses['MapsGeonamesGeocoder'] = $geoDir . 'Maps_GeonamesGeocoder.php';
 96+$wgAutoloadClasses['MapsGoogleGeocoder'] = $geoDir . 'Maps_GoogleGeocoder.php';
 97+$wgAutoloadClasses['MapsYahooGeocoder'] = $geoDir . 'Maps_YahooGeocoder.php';
 98+unset( $geoDir );
 99+
 100+// Autoload the "includes/layers/" classes.
 101+$lyrDir = $incDir . 'layers/';
 102+$wgAutoloadClasses['MapsImageLayer'] = $lyrDir . 'Maps_ImageLayer.php';
 103+$wgAutoloadClasses['MapsKMLLayer'] = $lyrDir . 'Maps_KMLLayer.php';
 104+unset( $lyrDir );
 105+
 106+// Autoload the "includes/manipulations/" classes.
 107+$manDir = $incDir . 'manipulations/';
 108+$wgAutoloadClasses['MapsParamDimension'] = $manDir . 'Maps_ParamDimension.php';
 109+$wgAutoloadClasses['MapsParamImage'] = $manDir . 'Maps_ParamImage.php';
 110+$wgAutoloadClasses['MapsParamLocation'] = $manDir . 'Maps_ParamLocation.php';
 111+$wgAutoloadClasses['MapsParamService'] = $manDir . 'Maps_ParamService.php';
 112+$wgAutoloadClasses['MapsParamZoom'] = $manDir . 'Maps_ParamZoom.php';
 113+unset( $manDir );
 114+
 115+// Autoload the "includes/parserHooks/" classes.
 116+$phDir = $incDir . '/parserHooks/';
 117+$wgAutoloadClasses['MapsCoordinates'] = $phDir . 'Maps_Coordinates.php';
 118+$wgAutoloadClasses['MapsDisplayMap'] = $phDir . 'Maps_DisplayMap.php';
 119+$wgAutoloadClasses['MapsDisplayPoint'] = $phDir . 'Maps_DisplayPoint.php';
 120+$wgAutoloadClasses['MapsDistance'] = $phDir . 'Maps_Distance.php';
 121+$wgAutoloadClasses['MapsFinddestination'] = $phDir . 'Maps_Finddestination.php';
 122+$wgAutoloadClasses['MapsGeocode'] = $phDir . 'Maps_Geocode.php';
 123+$wgAutoloadClasses['MapsGeodistance'] = $phDir . 'Maps_Geodistance.php';
 124+unset( $phDir );
 125+unset( $incDir );
58126
59 - // Autoload the "includes/" classes and interfaces.
60 - $incDir = dirname( __FILE__ ) . '/includes/';
61 - $wgAutoloadClasses['MapsMapper'] = $incDir . 'Maps_Mapper.php';
62 - $wgAutoloadClasses['MapsCoordinateParser'] = $incDir . 'Maps_CoordinateParser.php';
63 - $wgAutoloadClasses['MapsDistanceParser'] = $incDir . 'Maps_DistanceParser.php';
64 - $wgAutoloadClasses['MapsGeoFunctions'] = $incDir . 'Maps_GeoFunctions.php';
65 - $wgAutoloadClasses['MapsGeocoders'] = $incDir . 'Maps_Geocoders.php';
66 - $wgAutoloadClasses['MapsGeocoder'] = $incDir . 'Maps_Geocoder.php';
67 - $wgAutoloadClasses['MapsKMLFormatter'] = $incDir . 'Maps_KMLFormatter.php';
68 - $wgAutoloadClasses['MapsLayer'] = $incDir . 'Maps_Layer.php';
69 - $wgAutoloadClasses['MapsLayerPage'] = $incDir . 'Maps_LayerPage.php';
70 - $wgAutoloadClasses['MapsLayers'] = $incDir . 'Maps_Layers.php';
71 - $wgAutoloadClasses['MapsLocation'] = $incDir . 'Maps_Location.php';
72 - $wgAutoloadClasses['iMappingFeature'] = $incDir . 'iMappingFeature.php';
73 - $wgAutoloadClasses['iMappingService'] = $incDir . 'iMappingService.php';
74 - $wgAutoloadClasses['MapsMappingServices'] = $incDir . 'Maps_MappingServices.php';
75 - $wgAutoloadClasses['MapsMappingService'] = $incDir . 'Maps_MappingService.php';
76 - $wgAutoloadClasses['MapsSettings'] = $incDir . 'Maps_Settings.php';
 127+$wgExtensionMessagesFiles['MapsMagic'] = $egMapsDir . 'Maps.i18n.magic.php';
77128
78 - // Autoload the "includes/criteria/" classes.
79 - $criDir = $incDir . 'criteria/';
80 - $wgAutoloadClasses['CriterionIsDistance'] = $criDir . 'CriterionIsDistance.php';
81 - $wgAutoloadClasses['CriterionIsImage'] = $criDir . 'CriterionIsImage.php';
82 - $wgAutoloadClasses['CriterionIsLocation'] = $criDir . 'CriterionIsLocation.php';
83 - $wgAutoloadClasses['CriterionMapDimension'] = $criDir . 'CriterionMapDimension.php';
84 - $wgAutoloadClasses['CriterionMapLayer'] = $criDir . 'CriterionMapLayer.php';
85 - unset( $criDir );
86 -
87 - // Autoload the "includes/features/" classes.
88 - $ftDir = $incDir . '/features/';
89 - $wgAutoloadClasses['MapsBaseMap'] = $ftDir . 'Maps_BaseMap.php';
90 - $wgAutoloadClasses['MapsBasePointMap'] = $ftDir . 'Maps_BasePointMap.php';
91 - unset( $ftDir );
92 -
93 - // Autoload the "includes/geocoders/" classes.
94 - $geoDir = $incDir . 'geocoders/';
95 - $wgAutoloadClasses['MapsGeonamesGeocoder'] = $geoDir . 'Maps_GeonamesGeocoder.php';
96 - $wgAutoloadClasses['MapsGoogleGeocoder'] = $geoDir . 'Maps_GoogleGeocoder.php';
97 - $wgAutoloadClasses['MapsYahooGeocoder'] = $geoDir . 'Maps_YahooGeocoder.php';
98 - unset( $geoDir );
99 -
100 - // Autoload the "includes/layers/" classes.
101 - $lyrDir = $incDir . 'layers/';
102 - $wgAutoloadClasses['MapsImageLayer'] = $lyrDir . 'Maps_ImageLayer.php';
103 - $wgAutoloadClasses['MapsKMLLayer'] = $lyrDir . 'Maps_KMLLayer.php';
104 - unset( $lyrDir );
105 -
106 - // Autoload the "includes/manipulations/" classes.
107 - $manDir = $incDir . 'manipulations/';
108 - $wgAutoloadClasses['MapsParamDimension'] = $manDir . 'Maps_ParamDimension.php';
109 - $wgAutoloadClasses['MapsParamImage'] = $manDir . 'Maps_ParamImage.php';
110 - $wgAutoloadClasses['MapsParamLocation'] = $manDir . 'Maps_ParamLocation.php';
111 - $wgAutoloadClasses['MapsParamService'] = $manDir . 'Maps_ParamService.php';
112 - $wgAutoloadClasses['MapsParamZoom'] = $manDir . 'Maps_ParamZoom.php';
113 - unset( $manDir );
114 -
115 - // Autoload the "includes/parserHooks/" classes.
116 - $phDir = $incDir . '/parserHooks/';
117 - $wgAutoloadClasses['MapsCoordinates'] = $phDir . 'Maps_Coordinates.php';
118 - $wgAutoloadClasses['MapsDisplayMap'] = $phDir . 'Maps_DisplayMap.php';
119 - $wgAutoloadClasses['MapsDisplayPoint'] = $phDir . 'Maps_DisplayPoint.php';
120 - $wgAutoloadClasses['MapsDistance'] = $phDir . 'Maps_Distance.php';
121 - $wgAutoloadClasses['MapsFinddestination'] = $phDir . 'Maps_Finddestination.php';
122 - $wgAutoloadClasses['MapsGeocode'] = $phDir . 'Maps_Geocode.php';
123 - $wgAutoloadClasses['MapsGeodistance'] = $phDir . 'Maps_Geodistance.php';
124 - unset( $phDir );
125 - unset( $incDir );
126 -
127 - $wgExtensionMessagesFiles['MapsMagic'] = $egMapsDir . 'Maps.i18n.magic.php';
128 -
129 - $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php';
 129+$wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php';
130130
131 - // Register the initialization function of Maps.
132 - $wgExtensionFunctions[] = 'efMapsSetup';
 131+// Register the initialization function of Maps.
 132+$wgExtensionFunctions[] = 'efMapsSetup';
133133
134 - // Since 0.2
135 - $wgHooks['AdminLinks'][] = 'MapsHooks::addToAdminLinks';
 134+// Since 0.2
 135+$wgHooks['AdminLinks'][] = 'MapsHooks::addToAdminLinks';
 136+
 137+// Since 0.6.5
 138+$wgHooks['UnitTestsList'][] = 'MapsHooks::registerUnitTests';
136139
137 - // Since 0.6.5
138 - $wgHooks['UnitTestsList'][] = 'MapsHooks::registerUnitTests';
139 -
140 - // Since 0.7
141 - $wgHooks['SkinAfterBottomScripts'][] = 'MapsHooks::addOnloadFunction';
142 -
143 - // Since 0.7.1
144 - $wgHooks['ArticleFromTitle'][] = 'MapsHooks::onArticleFromTitle';
145 -
146 - $egMapsFeatures = array();
147 -
148 - // Include the settings file.
149 - require_once $egMapsDir . 'Maps_Settings.php';
150 -
151 - define( 'Maps_NS_LAYER', $egMapsNamespaceIndex + 0 );
152 - define( 'Maps_NS_LAYER_TALK', $egMapsNamespaceIndex + 1 );
153 -}
 140+// Since 0.7
 141+$wgHooks['SkinAfterBottomScripts'][] = 'MapsHooks::addOnloadFunction';
154142
 143+// Since 0.7.1
 144+$wgHooks['ArticleFromTitle'][] = 'MapsHooks::onArticleFromTitle';
 145+
 146+$egMapsFeatures = array();
 147+
 148+// Include the settings file.
 149+require_once $egMapsDir . 'Maps_Settings.php';
 150+
 151+define( 'Maps_NS_LAYER', $egMapsNamespaceIndex + 0 );
 152+define( 'Maps_NS_LAYER_TALK', $egMapsNamespaceIndex + 1 );
 153+
 154+$wgResourceModules['ext.maps.common'] = array(
 155+ 'localBasePath' => dirname( __FILE__ ) . '/includes',
 156+ 'remoteBasePath' => $egMapsScriptPath . '/includes',
 157+ 'group' => 'ext.maps',
 158+ 'messages' => array(
 159+ 'maps-load-failed',
 160+ ),
 161+ 'scripts' => array(
 162+ 'ext.maps.common.js'
 163+ )
 164+);
 165+
 166+
155167 /**
156168 * Initialization function for the Maps extension.
157169 *
Index: branches/Maps0.8/includes/services/GoogleMaps/GoogleMaps.php
@@ -21,6 +21,7 @@
2222 }
2323
2424 $wgResourceModules['ext.maps.googlemaps2'] = array(
 25+ 'dependencies' => array( 'ext.maps.common' ),
2526 'localBasePath' => dirname( __FILE__ ),
2627 'remoteBasePath' => $egMapsScriptPath . '/includes/services/GoogleMaps',
2728 'group' => 'ext.maps',
@@ -36,7 +37,8 @@
3738 'maps_photos',
3839 'maps_videos',
3940 'maps_wikipedia',
40 - 'maps_webcams'
 41+ 'maps_webcams',
 42+ 'maps-googlemaps2-incompatbrowser'
4143 )
4244 );
4345
Index: branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMaps.php
@@ -51,10 +51,7 @@
5252 $params['controls'] = new ListParameter( 'controls' );
5353 $params['controls']->setDefault( $egMapsGMapControls );
5454 $params['controls']->addCriteria( new CriterionInArray( self::getControlNames() ) );
55 - $params['controls']->addManipulations(
56 - new ParamManipulationFunctions( 'strtolower' ),
57 - new ParamManipulationImplode( ',', "'" )
58 - );
 55+ $params['controls']->addManipulations( new ParamManipulationFunctions( 'strtolower' ) );
5956
6057 $params['type'] = new Parameter(
6158 'type',
@@ -78,14 +75,13 @@
7976 new CriterionInArray( array_keys( self::$mapTypes ) ),
8077 )
8178 );
82 - $params['types']->addManipulations( new MapsParamGMapType(), new ParamManipulationImplode( ',' ) );
 79+ $params['types']->addManipulations( new MapsParamGMapType() );
8380
8481 $params['autozoom'] = new Parameter(
8582 'autozoom',
8683 Parameter::TYPE_BOOLEAN,
8784 $egMapsGoogleAutozoom
8885 );
89 - $params['autozoom']->addManipulations( new ParamManipulationBoolstr() );
9086
9187 $params['kml'] = new ListParameter( 'kml' );
9288 $params['kml']->setDefault( array() );
Index: branches/Maps0.8/includes/services/GoogleMaps/ext.maps.googlemaps2.js
@@ -15,19 +15,29 @@
1616 setTimeout( function() { loadGoogleMaps(); }, 100 );
1717 }
1818 else {
19 - window.unload = GUnload;
20 -
21 - window.GOverlays = [
22 - new GLayer("com.panoramio.all"),
23 - new GLayer("com.youtube.all"),
24 - new GLayer("org.wikipedia.en"),
25 - new GLayer("com.google.webcams")
26 - ];
27 -
28 - for ( i in window.maps.googlemaps2 ) {
29 - var map = new GoogleMap( jQuery, window.maps.googlemaps2[i] );
30 - map.initiate( i );
 19+ if ( GBrowserIsCompatible() ) {
 20+ window.unload = GUnload;
 21+
 22+ window.GOverlays = [
 23+ new GLayer("com.panoramio.all"),
 24+ new GLayer("com.youtube.all"),
 25+ new GLayer("org.wikipedia.en"),
 26+ new GLayer("com.google.webcams")
 27+ ];
 28+
 29+ for ( i in window.maps.googlemaps2 ) {
 30+ var map = new GoogleMap( jQuery, window.maps.googlemaps2[i] );
 31+ map.initiate( i );
 32+ }
3133 }
 34+ else {
 35+ alert( mediaWiki.msg( 'maps-googlemaps2-incompatbrowser' ) );
 36+
 37+ for ( i in window.maps.googlemaps2 ) {
 38+ // FIXME: common module with message not getting loaded for some reason
 39+ jQuery( '#' + i ).text( mediaWiki.msg( 'maps-load-failed' ) );
 40+ }
 41+ }
3242 }
3343 }
3444
@@ -38,111 +48,52 @@
3949 );
4050
4151 var GoogleMap = function( $, args ) {
 52+ var args = cleanParameters( args );
4253
43 - var args = args;
44 -
4554 this.initiate = function( mapName ) {
46 - //alert( mapName );
 55+ createGoogleMap( mapName, args );
4756 }
4857
49 - /**
50 - * Returns GMarker object on the provided location. It will show a popup baloon
51 - * with title and label when clicked, if either of these is set.
52 - */
53 - function createGMarker( markerData ) {
54 - var marker;
55 -
56 - if ( markerData.icon != '' ) {
57 - var iconObj = new GIcon( G_DEFAULT_ICON );
58 - iconObj.image = markerData.icon;
59 -
60 - var newimg = new Image();
61 - newimg.src = markerData.icon;
62 -
63 - // Only do these things when there is an actual width, which there won,t the first time the image is loaded.
64 - // FIXME: this means the image won't have it's correct size when it differs from the default on first load!
65 - if ( newimg.width > 0 ) {
66 - /* Determine size of icon and pass it in */
67 - iconObj.iconSize.width = newimg.width;
68 - iconObj.iconSize.height = newimg.height;
69 - iconObj.shadow = null;
70 -
71 - /* Anchor the icon on bottom middle */
72 - var anchor = new GPoint();
73 - anchor.x = Math.floor( newimg.width / 2 );
74 - anchor.y = newimg.height;
75 - iconObj.iconAnchor = anchor;
76 - }
77 -
78 - marker = new GMarker( markerData.point, { icon: iconObj } );
79 - } else {
80 - marker = new GMarker( markerData.point );
 58+ function cleanParameters( args ) {
 59+
 60+ args.type = eval( args.type );
 61+ var ts=[];
 62+ var t;
 63+ while ( t = args.types.shift() ) {
 64+ ts.unshift( eval( t ) );
8165 }
 66+ args.types = ts;
8267
83 - if ( ( markerData.title + markerData.label ).length != '' ) {
84 - var bothTxtAreSet = markerData.title.length != '' && markerData.label.length != '';
85 - var popupText = bothTxtAreSet ? '<b>' + markerData.title + '</b><hr />' + markerData.label : markerData.title + markerData.label;
86 - popupText = '<div style="overflow:auto;max-height:130px;">' + popupText + '</div>';
 68+ args.types = ensureTypeIsSelectable( args.type, args.types );
 69+
 70+ return args;
 71+ }
8772
88 - GEvent.addListener(marker, 'click',
89 - function() {
90 - marker.openInfoWindowHtml(popupText, {maxWidth:350});
91 - }
92 - );
93 - }
94 -
95 - return marker;
96 - }
97 -
9873 /**
99 - * Returns GMap2 object with the provided properties and markers.
100 - * This is done by setting the map centre and size, and passing the arguments to function createGoogleMap.
101 - */
102 - this.initializeGoogleMap = function(mapName, mapOptions, markers) {
103 - if (GBrowserIsCompatible()) {
104 - mapOptions.centre = (mapOptions.lat != null && mapOptions.lon != null) ? new GLatLng(mapOptions.lat, mapOptions.lon) : null;
105 - //mapOptions.size = new GSize(mapOptions.width, mapOptions.height);
106 - return createGoogleMap(mapName, mapOptions, markers);
107 - }
108 - else {
109 - return false;
110 - }
111 - }
112 -
113 - /**
11474 * Returns GMap2 object with the provided properties.
11575 */
116 - function createGoogleMap(mapName, mapOptions, markers) {
117 - var mapElement = document.getElementById(mapName);
118 - var typesContainType = false;
119 -
120 - for (var i = 0; i < mapOptions.types.length; i++) {
121 - if (mapOptions.types[i] == mapOptions.type) typesContainType = true;
122 - }
123 -
124 - if (! typesContainType) mapOptions.types.push(mapOptions.type);
125 -
126 - var map = new GMap2(mapElement, {mapTypes: mapOptions.types});
 76+ function createGoogleMap( mapName, args ) {
 77+ var mapElement = document.getElementById( mapName );
 78+ var map = new GMap2( mapElement, { mapTypes: args.types } );
12779 map.name = mapName;
 80+ map.setMapType( args.type );
12881
129 - map.setMapType(mapOptions.type);
130 -
13182 var hasSearchBar = false;
13283
133 - for ( i = mapOptions.controls.length - 1; i >= 0; i-- ) {
134 - if ( mapOptions.controls[i] == 'searchbar' ) {
 84+ for ( i = args.controls.length - 1; i >= 0; i-- ) {
 85+ if ( args.controls[i] == 'searchbar' ) {
13586 hasSearchBar = true;
13687 break;
13788 }
13889 }
13990
14091 // List of GControls: http://code.google.com/apis/maps/documentation/reference.html#GControl
141 - for ( i = 0; i < mapOptions.controls.length; i++ ) {
142 - if ( mapOptions.controls[i].toLowerCase() == 'auto' ) {
143 - if ( mapElement.offsetHeight > 75 ) mapOptions.controls[i] = mapElement.offsetHeight > 320 ? 'large' : 'small';
 92+ for ( var i = 0, n = args.controls.length; i < n; i++ ) {
 93+ if ( args.controls[i] == 'auto' ) {
 94+ if ( mapElement.offsetHeight > 75 ) args.controls[i] = mapElement.offsetHeight > 320 ? 'large' : 'small';
14495 }
145 -
146 - switch ( mapOptions.controls[i] ) {
 96+
 97+ switch ( args.controls[i] ) {
14798 case 'large' :
14899 map.addControl( new GLargeMapControl3D() );
149100 break;
@@ -186,7 +137,8 @@
187138 break;
188139 }
189140 }
190 -
 141+
 142+/*
191143 var bounds = ((mapOptions.zoom == null || mapOptions.centre == null) && markers.length > 1) ? new GLatLngBounds() : null;
192144
193145 for ( i = markers.length - 1; i >= 0; i-- ) {
@@ -219,8 +171,75 @@
220172 eval("window.GMaps." + mapName + " = map;");
221173
222174 return map;
 175+ */
223176 }
 177+
 178+ function ensureTypeIsSelectable( type, types ) {
 179+ var typesContainType = false;
224180
 181+ for ( var i = 0, n = types.length; i < n; i++ ) {
 182+ if ( types[i] == type ) {
 183+ typesContainType = true;
 184+ break;
 185+ }
 186+ }
 187+
 188+ if ( !typesContainType ) {
 189+ types.push( type );
 190+ }
 191+
 192+ return types;
 193+ }
 194+
 195+ /**
 196+ * Returns GMarker object on the provided location. It will show a popup baloon
 197+ * with title and label when clicked, if either of these is set.
 198+ */
 199+ function createGMarker( markerData ) {
 200+ var marker;
 201+
 202+ if ( markerData.icon != '' ) {
 203+ var iconObj = new GIcon( G_DEFAULT_ICON );
 204+ iconObj.image = markerData.icon;
 205+
 206+ var newimg = new Image();
 207+ newimg.src = markerData.icon;
 208+
 209+ // Only do these things when there is an actual width, which there won,t the first time the image is loaded.
 210+ // FIXME: this means the image won't have it's correct size when it differs from the default on first load!
 211+ if ( newimg.width > 0 ) {
 212+ /* Determine size of icon and pass it in */
 213+ iconObj.iconSize.width = newimg.width;
 214+ iconObj.iconSize.height = newimg.height;
 215+ iconObj.shadow = null;
 216+
 217+ /* Anchor the icon on bottom middle */
 218+ var anchor = new GPoint();
 219+ anchor.x = Math.floor( newimg.width / 2 );
 220+ anchor.y = newimg.height;
 221+ iconObj.iconAnchor = anchor;
 222+ }
 223+
 224+ marker = new GMarker( markerData.point, { icon: iconObj } );
 225+ } else {
 226+ marker = new GMarker( markerData.point );
 227+ }
 228+
 229+ if ( ( markerData.title + markerData.label ).length != '' ) {
 230+ var bothTxtAreSet = markerData.title.length != '' && markerData.label.length != '';
 231+ var popupText = bothTxtAreSet ? '<b>' + markerData.title + '</b><hr />' + markerData.label : markerData.title + markerData.label;
 232+ popupText = '<div style="overflow:auto;max-height:130px;">' + popupText + '</div>';
 233+
 234+ GEvent.addListener(marker, 'click',
 235+ function() {
 236+ marker.openInfoWindowHtml(popupText, {maxWidth:350});
 237+ }
 238+ );
 239+ }
 240+
 241+ return marker;
 242+ }
 243+
225244 function setupCheckboxShiftClick() { return true; }
226245
227246 function MoreControl() {};
@@ -240,7 +259,7 @@
241260 var textDiv = document.createElement("div");
242261 textDiv.id = map.name + "-inner-more";
243262 textDiv.setAttribute('class', 'inner-more');
244 - textDiv.appendChild(document.createTextNode( msgOverlays ));
 263+ textDiv.appendChild(document.createTextNode( mediaWiki.msg( 'maps_overlays' ) ));
245264
246265 buttonDiv.appendChild(textDiv);
247266

Follow-up revisions

RevisionCommit summaryAuthorDate
r82999follow up to r82998jeroendedauw01:37, 1 March 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r82991follow up to r82988jeroendedauw00:14, 1 March 2011

Status & tagging log