r94132 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94131‎ | r94132 | r94133 >
Date:18:54, 9 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed types parameter for google maps 3
Modified paths:
  • /trunk/extensions/Maps/includes/services/GoogleMaps3/GoogleMaps3.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/GoogleMaps3/Maps_GoogleMaps3.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/GoogleMaps3/Maps_ParamGMap3Types.php (added) (history)
  • /trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/includes/services/GoogleMaps3/Maps_ParamGMap3Types.php
@@ -0,0 +1,37 @@
 2+<?php
 3+
 4+/**
 5+ * Parameter manipulation ensuring that the map types list contains the map type.
 6+ *
 7+ * @since 1.0.1
 8+ *
 9+ * @file Maps_ParamGMap3Types.php
 10+ * @ingroup Maps
 11+ * @ingroup ParameterManipulations
 12+ * @ingroup MapsGoogleMaps
 13+ *
 14+ * @licence GNU GPL v3
 15+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 16+ */
 17+class MapsParamGMap3Types extends ListParameterManipulation {
 18+
 19+ /**
 20+ * @see ParameterManipulation::manipulate
 21+ *
 22+ * @since 1.0.1
 23+ */
 24+ public function manipulate( Parameter &$parameter, array &$parameters ) {
 25+ if ( !in_array( $parameters['type']->getValue(), $parameter->getValue() ) ) {
 26+ if ( $parameters['type']->wasSetToDefault() ) {
 27+ if ( count( $parameter->getValue() ) > 0 ) {
 28+ $types = $parameter->getValue();
 29+ $parameters['type']->setValue( $types[0] );
 30+ }
 31+ }
 32+ else {
 33+ array_unshift( $parameter->getValue(), $parameters['type']->getValue() );
 34+ }
 35+ }
 36+ }
 37+
 38+}
\ No newline at end of file
Property changes on: trunk/extensions/Maps/includes/services/GoogleMaps3/Maps_ParamGMap3Types.php
___________________________________________________________________
Added: svn:eol-style
139 + native
Index: trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js
@@ -83,6 +83,44 @@
8484 this.markers = [];
8585 };
8686
 87+ var showEarth = $.inArray( 'earth', options.types );
 88+
 89+ // If there are any non-Google KML/KMZ layers, load the geoxml library and use it to add these layers.
 90+ if ( showEarth ) {
 91+ // Yay, IE seriously fails. Compat code for IE < 9.
 92+ if (!Array.prototype.filter)
 93+ {
 94+ Array.prototype.filter = function(fun /*, thisp */)
 95+ {
 96+ "use strict";
 97+
 98+ if (this === void 0 || this === null)
 99+ throw new TypeError();
 100+
 101+ var t = Object(this);
 102+ var len = t.length >>> 0;
 103+ if (typeof fun !== "function")
 104+ throw new TypeError();
 105+
 106+ var res = [];
 107+ var thisp = arguments[1];
 108+ for (var i = 0; i < len; i++)
 109+ {
 110+ if (i in t)
 111+ {
 112+ var val = t[i]; // in case fun mutates this
 113+ if (fun.call(thisp, val, i, t))
 114+ res.push(val);
 115+ }
 116+ }
 117+
 118+ return res;
 119+ };
 120+ }
 121+
 122+ options.types.filter( function( element, index, array ) { return element != 'earth'; } );
 123+ }
 124+
87125 var mapOptions = {
88126 disableDefaultUI: true,
89127 mapTypeId: options.type == 'earth' ? google.maps.MapTypeId.SATELLITE : eval( 'google.maps.MapTypeId.' + options.type )
@@ -96,9 +134,16 @@
97135 mapOptions.scaleControl = $.inArray( 'scale', options.controls ) != -1;
98136 mapOptions.streetViewControl = $.inArray( 'streetview', options.controls ) != -1;
99137
 138+ for ( i in options.types ) {
 139+ options.types[i] = eval( 'google.maps.MapTypeId.' + options.types[i] );
 140+ }
 141+
100142 // Map control styles
101 - mapOptions.zoomControlOptions = { style: eval( 'google.maps.ZoomControlStyle.' + options.zoomstyle ) }
102 - mapOptions.mapTypeControlOptions = { style: eval( 'google.maps.MapTypeControlStyle.' + options.typestyle ) }
 143+ mapOptions.zoomControlOptions = { style: eval( 'google.maps.ZoomControlStyle.' + options.zoomstyle ) };
 144+ mapOptions.mapTypeControlOptions = {
 145+ style: eval( 'google.maps.MapTypeControlStyle.' + options.typestyle ),
 146+ mapTypeIds: options.types
 147+ };
103148
104149 var map = new google.maps.Map( this.get( 0 ), mapOptions );
105150 this.map = map;
@@ -129,48 +174,12 @@
130175 } );
131176 }
132177
133 - // If there are any non-Google KML/KMZ layers, load the geoxml library and use it to add these layers.
134 - if ( $.inArray( 'earth', options.types ) ) {
 178+ if ( showEarth ) {
135179 mw.loader.using( 'ext.maps.gm3.earth', function() {
136180 var ge = new GoogleEarth( map );
137 - } );
138 -
139 - // Yay, IE seriously fails. Compat code for IE < 9.
140 - if (!Array.prototype.filter)
141 - {
142 - Array.prototype.filter = function(fun /*, thisp */)
143 - {
144 - "use strict";
145 -
146 - if (this === void 0 || this === null)
147 - throw new TypeError();
148 -
149 - var t = Object(this);
150 - var len = t.length >>> 0;
151 - if (typeof fun !== "function")
152 - throw new TypeError();
153 -
154 - var res = [];
155 - var thisp = arguments[1];
156 - for (var i = 0; i < len; i++)
157 - {
158 - if (i in t)
159 - {
160 - var val = t[i]; // in case fun mutates this
161 - if (fun.call(thisp, val, i, t))
162 - res.push(val);
163 - }
164 - }
165 -
166 - return res;
167 - };
168 - }
169 -
170 - options.types.filter( function( element, index, array ) { return element != 'earth'; } );
 181+ } );
171182 }
172183
173 - // TODO: map types
174 -
175184 for ( i = options.fusiontables.length - 1; i >= 0; i-- ) {
176185 var ftLayer = new google.maps.FusionTablesLayer( options.fusiontables[i], { map: map } );
177186 }
Index: trunk/extensions/Maps/includes/services/GoogleMaps3/GoogleMaps3.php
@@ -13,7 +13,8 @@
1414 * @file GoogleMaps3.php
1515 * @ingroup MapsGoogleMaps3
1616 *
17 - * @author Jeroen De Dauw
 17+ * @licence GNU GPL v3
 18+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1819 */
1920
2021 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -67,6 +68,7 @@
6869
6970 $wgAutoloadClasses['MapsGoogleMaps3'] = dirname( __FILE__ ) . '/Maps_GoogleMaps3.php';
7071 $wgAutoloadClasses['MapsParamGMap3Type'] = dirname( __FILE__ ) . '/Maps_ParamGMap3Type.php';
 72+ $wgAutoloadClasses['MapsParamGMap3Types'] = dirname( __FILE__ ) . '/Maps_ParamGMap3Types.php';
7173 $wgAutoloadClasses['MapsParamGMap3Typestyle'] = dirname( __FILE__ ) . '/Maps_ParamGMap3Typestyle.php';
7274 $wgAutoloadClasses['MapsParamGMap3Zoomstyle'] = dirname( __FILE__ ) . '/Maps_ParamGMap3Zoomstyle.php';
7375
Index: trunk/extensions/Maps/includes/services/GoogleMaps3/Maps_GoogleMaps3.php
@@ -9,7 +9,8 @@
1010 * @file Maps_GoogleMaps3.php
1111 * @ingroup MapsGoogleMaps3
1212 *
13 - * @author Jeroen De Dauw
 13+ * @licence GNU GPL v3
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1415 */
1516 class MapsGoogleMaps3 extends MapsMappingService {
1617
@@ -95,9 +96,10 @@
9697 $params['type']->setMessage( 'maps-googlemaps3-par-type' );
9798
9899 $params['types'] = new ListParameter( 'types' );
 100+ $params['types']->addDependencies( 'type' );
99101 $params['types']->setDefault( $egMapsGMaps3Types );
100102 $params['types']->addCriteria( new CriterionInArray( self::getTypeNames() ) );
101 - $params['types']->addManipulations( new MapsParamGMap3Type() );
 103+ $params['types']->addManipulations( new MapsParamGMap3Type(), new MapsParamGMap3Types() );
102104 $params['types']->setMessage( 'maps-googlemaps3-par-types' );
103105
104106 $params['layers'] = new ListParameter( 'layers' );