r106031 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106030‎ | r106031 | r106032 >
Date:15:46, 13 December 2011
Author:danwe
Status:deferred (Comments)
Tags:
Comment:
Implemented marker groups for display_point parser function/tag
Modified paths:
  • /trunk/extensions/Maps/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_Location.php (modified) (history)
  • /trunk/extensions/Maps/includes/manipulations/Maps_ParamLocation.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker0.png (added) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker1.png (added) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker2.png (added) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker3.png (added) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker4.png (added) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker5.png (added) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker6.png (added) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker7.png (added) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker8.png (added) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker9.png (added) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/jquery.openlayers.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/RELEASE-NOTES
@@ -14,6 +14,8 @@
1515 * Changed minimun MediaWiki version from 1.17 to 1.18.
1616 * Removed support for the deprecated Google Maps v2 API.
1717
 18+* 'display_points' locations have a fifth parameter for defining a group for the location.
 19+
1820 === Maps 1.0.5 ===
1921 (2011-11-30)
2022
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker0.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker0.png
___________________________________________________________________
Added: svn:mime-type
2123 + image/png
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker1.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker1.png
___________________________________________________________________
Added: svn:mime-type
2224 + image/png
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker2.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker2.png
___________________________________________________________________
Added: svn:mime-type
2325 + image/png
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker3.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker3.png
___________________________________________________________________
Added: svn:mime-type
2426 + image/png
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker4.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker4.png
___________________________________________________________________
Added: svn:mime-type
2527 + image/png
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker5.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker5.png
___________________________________________________________________
Added: svn:mime-type
2628 + image/png
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker6.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker6.png
___________________________________________________________________
Added: svn:mime-type
2729 + image/png
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker7.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker7.png
___________________________________________________________________
Added: svn:mime-type
2830 + image/png
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker8.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker8.png
___________________________________________________________________
Added: svn:mime-type
2931 + image/png
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker9.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayers/img/marker9.png
___________________________________________________________________
Added: svn:mime-type
3032 + image/png
Index: trunk/extensions/Maps/includes/services/OpenLayers/jquery.openlayers.js
@@ -3,6 +3,7 @@
44 * @see http://www.mediawiki.org/wiki/Extension:Maps
55 *
66 * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
 7+ * @author Daniel Werner
78 */
89
910 (function( $ ){ $.fn.openlayers = function( mapElementId, options ) {
@@ -13,7 +14,7 @@
1415 if ( markerData.icon != "" ) {
1516 marker = new OpenLayers.Marker( markerData.lonlat, new OpenLayers.Icon( markerData.icon ) );
1617 } else {
17 - marker = new OpenLayers.Marker( markerData.lonlat );
 18+ marker = new OpenLayers.Marker( markerData.lonlat, new OpenLayers.Icon( markerLayer.defaultIcon ) );
1819 }
1920
2021 if ( markerData.text !== '' ) {
@@ -36,26 +37,44 @@
3738 options.locations = [];
3839 }
3940
 41+ var locations = options.locations;
4042 var bounds = null;
41 -
42 - // Layer to hold the markers.
43 - var markerLayer = new OpenLayers.Layer.Markers( mediaWiki.msg( 'maps-markers' ) );
44 - markerLayer.id= 'markerLayer';
45 - map.addLayer( markerLayer );
46 -
47 - if ( options.locations.length > 1 && ( options.centre === false || options.zoom === false ) ) {
 43+
 44+ if ( locations.length > 1 && ( options.centre === false || options.zoom === false ) ) {
4845 bounds = new OpenLayers.Bounds();
4946 }
5047
51 - for ( i = options.locations.length - 1; i >= 0; i-- ) {
52 - options.locations[i].lonlat = new OpenLayers.LonLat( options.locations[i].lon, options.locations[i].lat );
 48+ var groupLayers = new Object();
 49+ var groups = 0;
 50+
 51+ for ( i = locations.length - 1; i >= 0; i-- ) {
5352
 53+ var location = locations[i];
 54+
 55+ // Create a own marker-layer for the marker group:
 56+ if( ! groupLayers[ location.group ] ) {
 57+ // in case no group is specified, use default marker layer:
 58+ var layerName = location.group != '' ? location.group : mediaWiki.msg( 'maps-markers' );
 59+ var curLayer = new OpenLayers.Layer.Markers( layerName );
 60+ groups++;
 61+ curLayer.id = 'markerLayer' + groups;
 62+ // define default icon, one of ten in different colors, if more than ten layers, colors will repeat:
 63+ curLayer.defaultIcon = egMapsScriptPath + '/includes/services/OpenLayers/OpenLayers/img/marker' + ( ( groups + 10 ) % 10 ) + '.png';
 64+ map.addLayer( curLayer );
 65+ groupLayers[ location.group ] = curLayer;
 66+ } else {
 67+ // if markers of this group exist already, they have an own layer already
 68+ var curLayer = groupLayers[ location.group ];
 69+ }
 70+
 71+ location.lonlat = new OpenLayers.LonLat( location.lon, location.lat );
 72+
5473 if ( !hasImageLayer ) {
55 - options.locations[i].lonlat.transform( new OpenLayers.Projection( "EPSG:4326" ), new OpenLayers.Projection( "EPSG:900913" ) );
 74+ location.lonlat.transform( new OpenLayers.Projection( "EPSG:4326" ), new OpenLayers.Projection( "EPSG:900913" ) );
5675 }
5776
58 - if ( bounds != null ) bounds.extend( options.locations[i].lonlat ); // Extend the bounds when no center is set.
59 - markerLayer.addMarker( this.getOLMarker( markerLayer, options.locations[i] ) ); // Create and add the marker.
 77+ if ( bounds != null ) bounds.extend( location.lonlat ); // Extend the bounds when no center is set.
 78+ curLayer.addMarker( this.getOLMarker( curLayer, location ) ); // Create and add the marker.
6079 }
6180
6281 if ( bounds != null ) map.zoomToExtent( bounds ); // If a bounds object has been created, use it to set the zoom and center.
Index: trunk/extensions/Maps/includes/manipulations/Maps_ParamLocation.php
@@ -10,6 +10,7 @@
1111 * @ingroup ParameterManipulations
1212 *
1313 * @author Jeroen De Dauw
 14+ * @author Daniel Werner
1415 */
1516 class MapsParamLocation extends ItemParameterManipulation {
1617
@@ -65,6 +66,10 @@
6667 $value->setIcon( $icon );
6768 }
6869
 70+ if ( $group = array_shift( $parts ) ) {
 71+ $value->setGroup( $group );
 72+ }
 73+
6974 if ( $this->toJSONObj ) {
7075 $value = $value->getJSONObject();
7176 }
Index: trunk/extensions/Maps/includes/Maps_Location.php
@@ -9,6 +9,7 @@
1010 * @ingroup Maps
1111 *
1212 * @author Jeroen De Dauw
 13+ * @author Daniel Werner
1314 */
1415 class MapsLocation {
1516
@@ -61,6 +62,12 @@
6263 */
6364 protected $icon = '';
6465
 66+ /**
 67+ * @since 1.1
 68+ *
 69+ * @var string
 70+ */
 71+ protected $group = '';
6572
6673 /**
6774 * @since 0.7.1
@@ -295,7 +302,7 @@
296303 * @param string $title
297304 */
298305 public function setTitle( $title ) {
299 - $this->title = $title;
 306+ $this->title = trim( $title );
300307 }
301308
302309 /**
@@ -306,7 +313,7 @@
307314 * @param string $text
308315 */
309316 public function setText( $text ) {
310 - $this->text = $text;
 317+ $this->text = trim( $text );
311318 }
312319
313320 /**
@@ -328,10 +335,21 @@
329336 * @param string $icon
330337 */
331338 public function setIcon( $icon ) {
332 - $this->icon = $icon;
333 - }
 339+ $this->icon = trim( $icon );
 340+ }
334341
335342 /**
 343+ * Sets the group
 344+ *
 345+ * @since 1.1
 346+ *
 347+ * @param string $group
 348+ */
 349+ public function setGroup( $group ) {
 350+ $this->group = trim( $group );
 351+ }
 352+
 353+ /**
336354 * Returns if there is any title.
337355 *
338356 * @since 1.0
@@ -387,13 +405,35 @@
388406 }
389407
390408 /**
 409+ * Returns the group.
 410+ *
 411+ * @since 1.1
 412+ *
 413+ * @return string
 414+ */
 415+ public function getGroup() {
 416+ return $this->group;
 417+ }
 418+
 419+ /**
 420+ * Returns whether Location is asigned to a group.
 421+ *
 422+ * @since 1.1
 423+ *
 424+ * @return string
 425+ */
 426+ public function hasGroup() {
 427+ return $this->group != '';
 428+ }
 429+
 430+ /**
391431 * Returns an object that can directly be converted to JS using json_encode or similar.
392432 *
393433 * @since 1.0
394434 *
395435 * @return object
396436 */
397 - public function getJSONObject( $defText = '', $defTitle = '', $defIconUrl = '' ) {
 437+ public function getJSONObject( $defText = '', $defTitle = '', $defIconUrl = '', $defGroup = '' ) {
398438 return array(
399439 'lat' => $this->getLatitude(),
400440 'lon' => $this->getLongitude(),
@@ -401,7 +441,8 @@
402442 'text' => $this->hasText() ? $this->getText() : $defText,
403443 'title' => $this->hasTitle() ? $this->getTitle() : $defTitle,
404444 'address' => $this->getAddress( false ),
405 - 'icon' => $this->hasIcon() ? MapsMapper::getFileUrl( $this->getIcon() ) : $defIconUrl
 445+ 'icon' => $this->hasIcon() ? MapsMapper::getFileUrl( $this->getIcon() ) : $defIconUrl,
 446+ 'group' => $this->hasGroup() ? $this->getGroup() : $defGroup
406447 );
407448 }
408449

Comments

#Comment by Nikerabbit (talk | contribs)   21:33, 13 December 2011

Group essentially means the marker color here, am I correct?

Typo: asigned -> assigned

#Comment by Danwe (talk | contribs)   22:04, 13 December 2011

changed to 'assigned' in my local copy ;)

#Comment by Danwe (talk | contribs)   22:01, 13 December 2011

Group first of all shows the group names as overlays, so you can display / hide all markers of a group. As additional gimmick, the default icons color will visualize group affiliation for up to ten groups, then the colors will be start from index 1 again. This only works with OpenLayers currently.