Page MenuHomePhabricator

Add "fullscreen" parameter to googlemaps display format
Closed, DeclinedPublic

Description

"The Fullscreen control offers the option to open the map in fullscreen mode. This control is enabled by default on mobile devices, and is disabled by default on desktop. Note: iOS doesn't support the fullscreen feature. The fullscreen control is therefore not visible on iOS devices." (Google)

The patch below lets the user add |fullscreen=true to enable the fullscreen control, or |fullscreen=false to disable it (I've not tested the latter as the only mobile device I have is iOS).

In hindsight it should probably be called enablefullscreen as in (Semantic) Maps.

diff --git a/formats/CargoMapsFormat.php b/formats/CargoMapsFormat.php
index af7f9ce..00a6a18 100644
--- a/formats/CargoMapsFormat.php
+++ b/formats/CargoMapsFormat.php
@@ -10,7 +10,7 @@ class CargoMapsFormat extends CargoDisplayFormat {
 	public static $mapNumber = 1;
 
 	function allowedParameters() {
-		return array( 'height', 'width', 'icon', 'zoom' );
+		return array( 'height', 'width', 'icon', 'zoom', 'fullscreen' );
 	}
 
 	/**
@@ -157,6 +157,11 @@ class CargoMapsFormat extends CargoDisplayFormat {
 		if ( array_key_exists( 'zoom', $displayParams ) ) {
 			$mapDataAttrs['zoom'] = $displayParams['zoom'];
 		}
+		
+		if ( array_key_exists( 'fullscreen', $displayParams ) ) {
+			$mapDataAttrs['fullscreen'] = ( strtolower( $displayParams['fullscreen'] ) === 'true' );
+		}
+		
 		$mapDataDiv = Html::element( 'div', $mapDataAttrs, $jsonData );
 
 		$text = <<<END
diff --git a/libs/ext.cargo.maps.js b/libs/ext.cargo.maps.js
index 240d186..76a5f2e 100644
--- a/libs/ext.cargo.maps.js
+++ b/libs/ext.cargo.maps.js
@@ -10,10 +10,11 @@
  * (also written by Yaron Koren)
  */
 
-function CargoMap( allItemValues, divID, zoomLevel ) {
+function CargoMap( allItemValues, divID, zoomLevel, fullscreen ) {
 	this.allItemValues = allItemValues;
 	this.divID = divID;
 	this.zoomLevel = zoomLevel;
+	this.fullscreen = fullscreen;
 
 	// Calculate center, and bounds, of map
 	var numItems = allItemValues.length;
@@ -90,6 +91,11 @@ CargoMap.prototype.displayWithGoogleMaps = function( doMarkerClustering ) {
 	if ( this.zoomLevel != null ) {
 		mapOptions['zoom'] = parseInt( this.zoomLevel );
 	}
+	
+	if ( this.fullscreen != null) {
+		mapOptions['fullscreenControl'] = true;
+	}
+
 	var map = new google.maps.Map(document.getElementById(this.divID), mapOptions);
 	if ( this.zoomLevel == null ) {
 		map.fitBounds( mapBounds );
@@ -211,8 +217,9 @@ jQuery(document).ready( function() {
 		var valuesForMap = jQuery.parseJSON(mapDataText);
 		var mappingService = $(this).find(".cargoMapData").attr('mappingService');
 		var zoomLevel = $(this).find(".cargoMapData").attr('zoom');
+		var fullscreen = $(this).find(".cargoMapData").attr('fullscreen');
 		var doMarkerClustering = valuesForMap.length >= mw.config.get( 'wgCargoMapClusteringMinimum' );
-		var cargoMap = new CargoMap( valuesForMap, $(this).attr('id'), zoomLevel );
+		var cargoMap = new CargoMap( valuesForMap, $(this).attr('id'), zoomLevel, fullscreen );
 		cargoMap.display( mappingService, doMarkerClustering );
 	});
 });
diff --git a/parserfunctions/CargoDisplayMap.php b/parserfunctions/CargoDisplayMap.php
index b3fe308..27186a6 100644
--- a/parserfunctions/CargoDisplayMap.php
+++ b/parserfunctions/CargoDisplayMap.php
@@ -45,6 +45,8 @@ class CargoDisplayMap {
 				$widthStr = $value;
 			} elseif ( $key == 'zoom' ) {
 				$zoomStr = $value;
+			} elseif ( $key == 'fullscreen' ) {
+				$fullscreenStr = $value;
 			}
 		}
 
@@ -86,6 +88,11 @@ class CargoDisplayMap {
 		if ( $zoomStr != null ) {
 			$displayParams['zoom'] = $zoomStr;
 		}
+		if ( $fullscreenStr != null ) {
+			$displayParams['fullscreen'] = $fullscreenStr;
+		}
+		
+		
 
 		$text = $mappingFormat->display( $valuesTable, $formattedValuesTable, $fieldDescriptions,
 			$displayParams );

Event Timeline

@Jonathan3 - sorry for the long delay on this. I just finally looked into adding this capability - probably via a "controls" parameter, instead of a "fullscreen" parameter, but no matter - when I realized that the Google maps are all already showing a "fullscreen" control! I don't know if the default changed at some point between then and now, or what, but the problem seems to have been solved on its own. Would you agree?

I have just removed mapOptions['fullscreenControl'] = true; from my code and the fullscreen control remains.

I guess you are right that the default has changed - even though the documentation hasn't.

I agree that it's all sorted for now - but it would be useful to be able to have control over this sort of thing (e.g. if the default changes again) so maybe it's something to keep in mind for the future.

Alright - I'm glad you see the same thing I do! I wonder when that new control was added... it looks like some other controls have been added too. Anyway, I see your point about having control over it, but for the moment the default behavior, and no one has complained about too many controls on the map, so I'm marking this as "Declined" - though there's always the option to bring it back.