Completed
Push — address-as-title ( 9b6eeb...601934 )
by Peter
11:07
created

MapsOpenLayers::getLayerNames()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Class holding information and functionality specific to OpenLayers.
5
 * This information and features can be used by any mapping feature.
6
 * 
7
 * @since 0.1
8
 * 
9
 * @licence GNU GPL v2+
10
 * @author Jeroen De Dauw < [email protected] >
11
 */
12
class MapsOpenLayers extends MapsMappingService {
13
	
14
	/**
15
	 * Constructor.
16
	 * 
17
	 * @since 0.6.6
18
	 */	
19
	public function __construct( $serviceName ) {
20
		parent::__construct(
21
			$serviceName,
22
			[ 'layers', 'openlayer' ]
23
		);
24
	}	
25
	
26
	/**
27
	 * @see MapsMappingService::addParameterInfo
28
	 * 
29
	 * @since 0.7
30
	 */	
31
	public function addParameterInfo( array &$params ) {
32
		global $egMapsOLLayers, $egMapsOLControls, $egMapsResizableByDefault;
33
34
		$params['zoom'] = [
35
			'type' => 'integer',
36
			'range' => [ 0, 19 ],
37
			'default' => self::getDefaultZoom(),
38
			'message' => 'maps-openlayers-par-zoom',
39
		];
40
41
		$params['controls'] = [
42
			'default' => $egMapsOLControls,
43
			'values' => self::getControlNames(),
44
			'message' =>'maps-openlayers-par-controls',
45
			'islist' => true,
46
			'tolower' => true,
47
		];
48
49
		$params['layers'] = [
50
			'default' => $egMapsOLLayers,
51
			'message' =>'maps-openlayers-par-layers',
52
			'manipulatedefault' => true,
53
			'islist' => true,
54
			'tolower' => true,
55
			// TODO-customMaps: addCriteria( new CriterionOLLayer() );
56
		];
57
		
58
		$params['resizable'] = [
59
			'type' => 'boolean',
60
			'default' => false,
61
			'manipulatedefault' => false,
62
			'message' => 'maps-par-resizable',
63
		];
64
		
65
		$params['overlays'] = [
66
			// Default empty array will end up in JS just right without manipulation.
67
			'default' => [],
68
			'manipulatedefault' => false,
69
			'message' => 'maps-openlayers-par-overlays',
70
71
			// NOTE: code has moved into @see MapsDisplayMapRenderer
72
			// TODO-customMaps: addCriteria( new CriterionOLLayer( ';' ) );
73
			// TODO-customMaps: addManipulations( new MapsParamOLLayers() );
74
		];
75
76
		$params['resizable'] = [
77
			'type' => 'boolean',
78
			'default' => $egMapsResizableByDefault,
79
			'message' => 'maps-par-resizable',
80
		];
81
82
		$params['searchmarkers'] = [
83
			'default' => '',
84
			'message' => 'maps-openlayers-par-searchmarkers',
85
			'values' => [ 'title', 'all', '' ],
86
			'tolower' => true,
87
		];
88
89
		$params['kml'] = [
90
			'default' => [],
91
			'message' => 'maps-openlayers-par-kml',
92
			'islist' => true,
93
			// new MapsParamFile() FIXME
94
		];
95
	}
96
	
97
	/**
98
	 * @see iMappingService::getDefaultZoom
99
	 * 
100
	 * @since 0.6.5
101
	 */	
102
	public function getDefaultZoom() {
103
		global $egMapsOpenLayersZoom;
104
		return $egMapsOpenLayersZoom;
105
	}		
106
	
107
	/**
108
	 * @see MapsMappingService::getMapId
109
	 * 
110
	 * @since 0.6.5
111
	 */
112
	public function getMapId( $increment = true ) {
113
		static $mapsOnThisPage = 0;
114
		
115
		if ( $increment ) {
116
			$mapsOnThisPage++;
117
		}
118
		
119
		return 'open_layer_' . $mapsOnThisPage;
120
	}		
121
	
122
	/**
123
	 * Returns the names of all supported controls. 
124
	 * This data is a copy of the one used to actually translate the names
125
	 * into the controls, since this resides client side, in OpenLayerFunctions.js. 
126
	 * 
127
	 * @return array
128
	 */
129
	public static function getControlNames() {
130
		return [
131
			'argparser', 'attribution', 'button', 'dragfeature', 'dragpan',
132
			'drawfeature', 'editingtoolbar', 'getfeature', 'keyboarddefaults', 'layerswitcher',
133
			'measure', 'modifyfeature', 'mousedefaults', 'mouseposition', 'mousetoolbar',
134
			'navigation', 'navigationhistory', 'navtoolbar', 'overviewmap', 'pan',
135
			'panel', 'panpanel', 'panzoom', 'panzoombar', 'autopanzoom', 'permalink',
136
			'scale', 'scaleline', 'selectfeature', 'snapping', 'split',
137
			'wmsgetfeatureinfo', 'zoombox', 'zoomin', 'zoomout', 'zoompanel',
138
			'zoomtomaxextent'
139
		];
140
	}
141
142
	/**
143
	 * Returns the names of all supported dynamic layers.
144
	 *
145
	 * @param boolean $includeGroups
146
	 *
147
	 * @return array
148
	 */
149
	public static function getLayerNames( $includeGroups = false ) {
150
		global $egMapsOLAvailableLayers, $egMapsOLLayerGroups;
151
		
152
		$keys = array_keys( $egMapsOLAvailableLayers );
153
		
154
		if ( $includeGroups ) {
155
			$keys = array_merge( $keys, array_keys( $egMapsOLLayerGroups ) );
156
		}
157
		
158
		return $keys;
159
	}
160
	
161
	/**
162
	 * Adds the layer dependencies. 
163
	 * 
164
	 * @since 0.7.1
165
	 * 
166
	 * @param array $dependencies
167
	 */
168
	public function addLayerDependencies( array $dependencies ) {
169
		foreach ( $dependencies as $dependency ) {
170
			$this->addDependency( $dependency );
171
		}
172
	}
173
	
174
	/**
175
	 * @see MapsMappingService::getResourceModules
176
	 * 
177
	 * @since 0.7.3
178
	 * 
179
	 * @return array of string
180
	 */
181
	public function getResourceModules() {
182
		return array_merge(
183
			parent::getResourceModules(),
184
			[ 'ext.maps.openlayers' ]
185
		);
186
	}
187
188
	/**
189
	 * Returns a list of all config variables that should be passed to the JS.
190
	 *
191
	 * @since 1.0.1
192
	 *
193
	 * @return array
194
	 */
195
	public function getConfigVariables() {
0 ignored issues
show
Coding Style introduced by
getConfigVariables uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
196
		return array_merge(
197
			parent::getConfigVariables(),
198
			[ 'egMapsScriptPath' => $GLOBALS['wgScriptPath'] . '/extensions/Maps/' ]
199
		);
200
	}
201
	
202
}
203