forked from bensquire/php-static-maps-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
googlestaticmapfeature.php
162 lines (143 loc) · 3.51 KB
/
googlestaticmapfeature.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* @author Ben Squire <[email protected]>
* @license Apache 2.0
*
* @package GoogleStaticMap
*
* @abstract This class abstracts the map feature part of the Google
* Static map API. i.e: Determine those map features that are visible
* and how they are styled.
*
* @see https://github.com/bensquire/php-static-maps-generator
*/
class GoogleStaticMapFeature {
const SEPERATOR = '|';
protected $aFeatures = array(
'administrative',
'administrative.country',
'administrative.land_parcel',
'administrative.locality',
'administrative.neighborhood',
'administrative.province',
'all',
'landscape',
'landscape.man_made',
'landscape.natural',
'poi',
'poi.attraction',
'poi.business',
'poi.government',
'poi.medical',
'poi.park',
'poi.place_of_worship',
'poi.school',
'poi.sports_complex',
'road',
'road.arterial',
'road.highway',
'road.highway.controlled_access',
'road.local',
'transit',
'transit.line',
'transit.station',
'transit.station.airport',
'transit.station.bus',
'transit.station.rail',
'water'
);
protected $aElements = array('all', 'geometry', 'labels');
protected $sFeature = null;
protected $sElement = null;
protected $oStyle = null;
public function __construct($aParams = array()) {
if (isset($aParams['feature'])) {
$this->setFeature($aParams['feature']);
}
if (isset($aParams['element'])) {
$this->setElement($aParams['element']);
}
if (isset($aParams['style'])) {
$this->setStyle($aParams['style']);
}
}
/**
* Sets the type of feature the object represents
*
* @param string $sFeature
* @return GoogleStaticMapFeature
*/
public function setFeature($sFeature) {
if (!in_array($sFeature, $this->aFeatures)) {
throw new Exception('Unknown Map Feature');
}
$this->sFeature = $sFeature;
return $this;
}
/**
* Creates the feature styling object either using an associative array of
* values or by passing in an instance of _GoogleStaticMapFeatureStyling.
*
* @param GoogleStaticMapFeatureStyling $mStyle
* @return GoogleStaticMapFeature
*/
public function setStyle($mStyle) {
if ($mStyle instanceof GoogleStaticMapFeatureStyling) {
$this->oStyle = $mStyle;
} elseif (is_array($mStyle)) {
$this->oStyle = new GoogleStaticMapFeatureStyling($mStyle);
} else {
throw new Exception('Invalid type passed to Map Feature Styling.');
}
return $this;
}
/**
* Sets the element of the feature you are styling, 'all', 'geometry', 'labels'.
*
* @param string $sElement
* @return GoogleStaticMapFeature
*/
public function setElement($sElement) {
if (!in_array($sElement, $this->aElements)) {
throw new Exception('Unknown Map Element');
}
$this->sElement = $sElement;
return $this;
}
/**
* Returns the feature being editted
*
* @return string
*/
public function getFeature() {
return $this->sFeature;
}
/**
* Returns the features styling object.
*
* @return GoogleStaticMapFeatureStyling
*/
public function getStyle() {
return $this->oStyle;
}
/**
* Returns the element of the feature thats being styled
*
* @return string
*/
public function getElement() {
return $this->sElement;
}
/**
* Builds the url string of the feature styling
*
* @return string
*/
public function build() {
if ($this->oStyle instanceOf GoogleStaticMapFeatureStyling) {
$styles = $this->oStyle->build();
}
return 'style=feature:' . $this->sFeature . $this::SEPERATOR . 'element:' . $this->sElement . ((isset($styles) ? $this::SEPERATOR . $styles : ''));
}
}
?>