1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace Maps\ParserHooks; |
6
|
|
|
|
7
|
|
|
use DataValues\Geo\Values\LatLongValue; |
8
|
|
|
use Maps\GeoFunctions; |
9
|
|
|
use Maps\MapsFactory; |
10
|
|
|
use ParserHook; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class for the 'finddestination' parser hooks, which can find a |
14
|
|
|
* destination given a starting point, an initial bearing and a distance. |
15
|
|
|
* |
16
|
|
|
* @licence GNU GPL v2+ |
17
|
|
|
* @author Jeroen De Dauw < [email protected] > |
18
|
|
|
*/ |
19
|
|
|
class FindDestinationFunction extends ParserHook { |
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Renders and returns the output. |
23
|
|
|
* |
24
|
|
|
* @see ParserHook::render |
25
|
|
|
* |
26
|
|
|
* @param array $parameters |
27
|
|
|
* |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
1 |
|
public function render( array $parameters ) { |
31
|
1 |
|
$destination = GeoFunctions::findDestination( |
32
|
1 |
|
$parameters['location']->getCoordinates(), |
33
|
1 |
|
$parameters['bearing'], |
34
|
1 |
|
$parameters['distance'] |
35
|
|
|
); |
36
|
|
|
|
37
|
1 |
|
return MapsFactory::globalInstance()->getCoordinateFormatter()->format( |
38
|
1 |
|
new LatLongValue( $destination['lat'], $destination['lon'] ), |
39
|
1 |
|
$parameters['format'], |
40
|
1 |
|
$parameters['directional'] |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @see ParserHook::getMessage() |
46
|
|
|
*/ |
47
|
|
|
public function getMessage() { |
48
|
|
|
return 'maps-finddestination-description'; |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Gets the name of the parser hook. |
53
|
|
|
* |
54
|
|
|
* @see ParserHook::getName |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
2 |
|
protected function getName() { |
59
|
2 |
|
return 'finddestination'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns an array containing the parameter info. |
64
|
|
|
* |
65
|
|
|
* @see ParserHook::getParameterInfo |
66
|
|
|
* |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
51 |
|
protected function getParameterInfo( $type ) { |
70
|
51 |
|
global $egMapsAvailableCoordNotations; |
71
|
51 |
|
global $egMapsCoordinateNotation, $egMapsCoordinateDirectional; |
72
|
|
|
|
73
|
51 |
|
$params = []; |
74
|
|
|
|
75
|
51 |
|
$params['location'] = [ |
76
|
|
|
'type' => 'mapslocation', |
77
|
|
|
]; |
78
|
|
|
|
79
|
51 |
|
$params['format'] = [ |
80
|
51 |
|
'default' => $egMapsCoordinateNotation, |
81
|
51 |
|
'values' => $egMapsAvailableCoordNotations, |
82
|
51 |
|
'aliases' => 'notation', |
83
|
|
|
'tolower' => true, |
84
|
|
|
]; |
85
|
|
|
|
86
|
51 |
|
$params['directional'] = [ |
87
|
51 |
|
'type' => 'boolean', |
88
|
51 |
|
'default' => $egMapsCoordinateDirectional, |
89
|
|
|
]; |
90
|
|
|
|
91
|
51 |
|
$params['bearing'] = [ |
92
|
|
|
'type' => 'float', |
93
|
|
|
]; |
94
|
|
|
|
95
|
51 |
|
$params['distance'] = [ |
96
|
|
|
'type' => 'distance', |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
// Give grep a chance to find the usages: |
100
|
|
|
// maps-finddestination-par-location, maps-finddestination-par-format, |
101
|
|
|
// maps-finddestination-par-directional, maps-finddestination-par-bearing, |
102
|
|
|
// maps-finddestination-par-distance, maps-finddestination-par-mappingservice, |
103
|
|
|
// maps-finddestination-par-geoservice, maps-finddestination-par-allowcoordinates |
104
|
51 |
|
foreach ( $params as $name => &$param ) { |
105
|
51 |
|
$param['message'] = 'maps-finddestination-par-' . $name; |
106
|
|
|
} |
107
|
|
|
|
108
|
51 |
|
return $params; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns the list of default parameters. |
113
|
|
|
* |
114
|
|
|
* @see ParserHook::getDefaultParameters |
115
|
|
|
* |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
1 |
|
protected function getDefaultParameters( $type ) { |
119
|
1 |
|
return [ 'location', 'bearing', 'distance' ]; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.