1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class for describing image layers. |
5
|
|
|
* |
6
|
|
|
* @since 0.7.2 |
7
|
|
|
* |
8
|
|
|
* @file Maps_ImageLayer.php |
9
|
|
|
* @ingroup Maps |
10
|
|
|
* |
11
|
|
|
* @licence GNU GPL v2+ |
12
|
|
|
* @author Jeroen De Dauw < [email protected] > |
13
|
|
|
* @author Daniel Werner |
14
|
|
|
*/ |
15
|
|
|
class MapsImageLayer extends MapsLayer { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Registers the layer. |
19
|
|
|
* |
20
|
|
|
* @since 0.7.2 |
21
|
|
|
*/ |
22
|
|
|
public static function register() { |
23
|
|
|
MapsLayerTypes::registerLayerType( 'image', __CLASS__, 'openlayers' ); |
24
|
|
|
return true; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @see MapsLayer::getParameterDefinitions |
29
|
|
|
* |
30
|
|
|
* @since 0.7.2 |
31
|
|
|
* |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
|
|
protected function getParameterDefinitions() { |
35
|
|
|
$params = parent::getParameterDefinitions(); |
36
|
|
|
|
37
|
|
|
// map extent for extents bound object: |
38
|
|
|
$params['topextent'] = [ |
39
|
|
|
'type' => 'float', |
40
|
|
|
'aliases' => [ 'upperbound', 'topbound' ], |
41
|
|
|
'message' => 'maps-displaymap-par-coordinates', // TODO-customMaps: create a message |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
$params['rightextent'] = [ |
45
|
|
|
'type' => 'float', |
46
|
|
|
'aliases' => [ 'rightbound' ], |
47
|
|
|
'message' => 'maps-displaymap-par-coordinates', // TODO-customMaps: create a message |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
$params['bottomextent'] = [ |
51
|
|
|
'type' => 'float', |
52
|
|
|
'aliases' => [ 'lowerbound', 'bottombound' ], |
53
|
|
|
'message' => 'maps-displaymap-par-coordinates', // TODO-customMaps: create a message |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
$params['leftextent'] = [ |
57
|
|
|
'type' => 'float', |
58
|
|
|
'aliases' => [ 'leftbound' ], |
59
|
|
|
'message' => 'maps-displaymap-par-coordinates', // TODO-customMaps: create a message |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
// image-source information: |
63
|
|
|
$params['source'] = [ |
64
|
|
|
// TODO-customMaps: addCriteria( new CriterionIsImage() ) |
65
|
|
|
'message' => 'maps-displaymap-par-coordinates', // TODO-customMaps: create a message |
66
|
|
|
'post-format' => function( $source ) { |
67
|
|
|
$imageUrl = MapsMapper::getFileUrl( $source ); |
|
|
|
|
68
|
|
|
|
69
|
|
|
global $egMapsAllowExternalImages; |
70
|
|
|
if( $imageUrl === '' && $egMapsAllowExternalImages ) { |
71
|
|
|
return $source; |
72
|
|
|
} |
73
|
|
|
return $imageUrl; |
74
|
|
|
} |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
$params['width'] = [ |
78
|
|
|
'type' => 'float', |
79
|
|
|
'message' => 'maps-displaymap-par-coordinates', // TODO-customMaps: create a message |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
$params['height'] = [ |
83
|
|
|
'type' => 'float', |
84
|
|
|
'message' => 'maps-displaymap-par-coordinates', // TODO-customMaps: create a message |
85
|
|
|
]; |
86
|
|
|
|
87
|
|
|
return $params; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @see MapsLayer::getPropertyHtmlRepresentation |
92
|
|
|
* |
93
|
|
|
* @since 3.0 |
94
|
|
|
* |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
protected function getPropertyHtmlRepresentation( $name, &$parser ) { |
98
|
|
|
$value = $this->properties[ $name ]; |
|
|
|
|
99
|
|
|
|
100
|
|
|
switch( $name ) { |
101
|
|
|
case 'source': |
102
|
|
|
$value = $this->originalPropertyValues['source']; // get original, non-modified value |
103
|
|
|
|
104
|
|
|
$title = Title::newFromText( $value, NS_FILE ); |
105
|
|
|
|
106
|
|
|
// if title has invalid characters or doesn't exist and has url-style |
107
|
|
|
if( $title === null |
108
|
|
|
|| ( !$title->exists() && preg_match( '|^.+\://.+\..+$|', $value ) ) |
109
|
|
|
) { |
110
|
|
|
// url link: |
111
|
|
|
$value = $parser->recursiveTagParse( "[$value $value]" ); |
112
|
|
|
} else { |
113
|
|
|
// wikilink (can be red link to non-existant file): |
114
|
|
|
$imgName = $title->getPrefixedText(); |
115
|
|
|
$value = $parser->recursiveTagParse( "[[$imgName|thumb|[[:$imgName]]|left]]" ); |
116
|
|
|
} |
117
|
|
|
return $value; // html already |
118
|
|
|
|
119
|
|
|
default: |
120
|
|
|
// if we don't have any special handling here, leave it to base class: |
121
|
|
|
return parent::getPropertyHtmlRepresentation( $name, $parser ); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
return htmlspecialchars( $value );; |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @see MapsLayer::doPropertiesHtmlTransform |
128
|
|
|
* |
129
|
|
|
* @since 3.0 |
130
|
|
|
* |
131
|
|
|
* @return array |
132
|
|
|
*/ |
133
|
|
|
protected function doPropertiesHtmlTransform( &$properties ) { |
134
|
|
|
parent::doPropertiesHtmlTransform( $properties ); |
135
|
|
|
|
136
|
|
|
$sp = ' '; // non-breaking thin space |
137
|
|
|
|
138
|
|
|
// image-size: |
139
|
|
|
$properties['image-size'] = "<b>width:</b> {$properties['width']}{$sp}pixel, <b>height:</b> {$properties['height']}{$sp}pixel"; |
140
|
|
|
unset( $properties['width'], $properties['height'] ); |
141
|
|
|
|
142
|
|
|
// extent: |
143
|
|
|
$unit = $properties['units']; |
144
|
|
|
$properties['extent'] = |
145
|
|
|
"<b>left:</b> {$properties['leftextent']}{$sp}$unit, " . |
146
|
|
|
"<b>bottom:</b> {$properties['bottomextent']}{$sp}$unit, " . |
147
|
|
|
"<b>right:</b> {$properties['rightextent']}{$sp}$unit, " . |
148
|
|
|
"<b>top:</b> {$properties['topextent']}{$sp}$unit"; |
149
|
|
|
unset( $properties['leftextent'], $properties['bottomextent'], $properties['rightextent'], $properties['topextent'] ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @see MapsLayer::getJavaScriptDefinition |
154
|
|
|
* |
155
|
|
|
* @since 0.7.2 |
156
|
|
|
* |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
|
|
public function getJavaScriptDefinition() { |
160
|
|
|
$this->validate(); |
161
|
|
|
|
162
|
|
|
// do image layer options: |
163
|
|
|
|
164
|
|
|
$options = [ |
165
|
|
|
'isImage' => true, |
166
|
|
|
'units' => $this->properties['units'], |
167
|
|
|
]; |
168
|
|
|
|
169
|
|
|
if( $this->properties['zoomlevels'] !== false ) { |
170
|
|
|
$options['numZoomLevels'] = $this->properties['zoomlevels']; |
171
|
|
|
} |
172
|
|
|
if( $this->properties['minscale'] !== false ) { |
173
|
|
|
$options['minScale'] = $this->properties['minscale']; |
174
|
|
|
} |
175
|
|
|
if( $this->properties['maxscale'] !== false ) { |
176
|
|
|
$options['maxScale'] = $this->properties['maxscale']; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$options = Xml::encodeJsVar( (object)$options ); //js-encode all options ); |
180
|
|
|
|
181
|
|
|
// for non-option params, get JavaScript-encoded config values: |
182
|
|
|
foreach( $this->properties as $name => $value ) { |
183
|
|
|
${ $name } = MapsMapper::encodeJsVar( $value ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
return <<<JavaScript |
187
|
|
|
new OpenLayers.Layer.Image( |
188
|
|
|
$label, |
|
|
|
|
189
|
|
|
$source, |
|
|
|
|
190
|
|
|
new OpenLayers.Bounds($leftextent, $bottomextent, $rightextent, $topextent), |
|
|
|
|
191
|
|
|
new OpenLayers.Size($width, $height), |
|
|
|
|
192
|
|
|
$options |
193
|
|
|
); |
194
|
|
|
JavaScript; |
195
|
|
|
die(); |
|
|
|
|
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
} |
199
|
|
|
|
This method has been deprecated.