Completed
Push — leaflet-attribution ( 0121c0 )
by Peter
04:35
created

MapsOpenLayers::getControlNames()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

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