Index: trunk/extensions/Maps/Maps.i18n.php |
— | — | @@ -28,6 +28,9 @@ |
29 | 29 | 'maps-layer-value' => 'Value', |
30 | 30 | 'maps-layer-errors' => 'Errors', |
31 | 31 | 'maps-error-invalid-layerdef' => 'This layer definition is not valid.', |
| 32 | + 'maps-error-invalid-layertype' => 'There are no layers of type "$1". Only {{PLURAL:$3|this type is|these types are}} supported: $2', |
| 33 | + 'validation-error-invalid-layer' => 'Parameter $1 must be a valid layer.', |
| 34 | + 'validation-error-invalid-layers' => 'Parameter $1 must be one or more valid layers.', |
32 | 35 | |
33 | 36 | // Validation |
34 | 37 | 'validation-error-invalid-location' => 'Parameter $1 must be a valid location.', |
— | — | @@ -41,8 +44,6 @@ |
42 | 45 | |
43 | 46 | 'validation-error-invalid-goverlay' => 'Parameter $1 must be a valid overlay.', |
44 | 47 | 'validation-error-invalid-goverlays' => 'Parameter $1 must be one or more valid overlays.', |
45 | | - 'validation-error-invalid-ollayer' => 'Parameter $1 must be a valid layer.', |
46 | | - 'validation-error-invalid-ollayers' => 'Parameter $1 must be one or more valid layers.', |
47 | 48 | |
48 | 49 | // Coordinate handling |
49 | 50 | 'maps-abb-north' => 'N', |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -61,8 +61,10 @@ |
62 | 62 | $wgAutoloadClasses['MapsGeoFunctions'] = $incDir . 'Maps_GeoFunctions.php'; |
63 | 63 | $wgAutoloadClasses['MapsGeocoders'] = $incDir . 'Maps_Geocoders.php'; |
64 | 64 | $wgAutoloadClasses['MapsGeocoder'] = $incDir . 'Maps_Geocoder.php'; |
| 65 | + $wgAutoloadClasses['MapsImageLayer'] = $incDir . 'Maps_ImageLayer.php'; |
65 | 66 | $wgAutoloadClasses['MapsLayer'] = $incDir . 'Maps_Layer.php'; |
66 | 67 | $wgAutoloadClasses['MapsLayerPage'] = $incDir . 'Maps_LayerPage.php'; |
| 68 | + $wgAutoloadClasses['MapsLayers'] = $incDir . 'Maps_Layers.php'; |
67 | 69 | $wgAutoloadClasses['iMappingFeature'] = $incDir . 'iMappingFeature.php'; |
68 | 70 | $wgAutoloadClasses['iMappingService'] = $incDir . 'iMappingService.php'; |
69 | 71 | $wgAutoloadClasses['MapsMappingServices'] = $incDir . 'Maps_MappingServices.php'; |
— | — | @@ -74,6 +76,7 @@ |
75 | 77 | $wgAutoloadClasses['CriterionIsImage'] = $criDir . 'CriterionIsImage.php'; |
76 | 78 | $wgAutoloadClasses['CriterionIsLocation'] = $criDir . 'CriterionIsLocation.php'; |
77 | 79 | $wgAutoloadClasses['CriterionMapDimension'] = $criDir . 'CriterionMapDimension.php'; |
| 80 | + $wgAutoloadClasses['CriterionMapLayer'] = $criDir . 'CriterionMapLayer.php'; |
78 | 81 | |
79 | 82 | // Autoload the "includes/features/" classes. |
80 | 83 | $ftDir = $incDir . '/features/'; |
— | — | @@ -133,6 +136,9 @@ |
134 | 137 | // Since 0.7.1 |
135 | 138 | $wgHooks['ArticleFromTitle'][] = 'MapsHooks::onArticleFromTitle'; |
136 | 139 | |
| 140 | + // Since 0.7.2 |
| 141 | + $wgHooks['MappingLayersInitialization'][] = 'MapsImageLayer::register'; |
| 142 | + |
137 | 143 | $egMapsFeatures = array(); |
138 | 144 | |
139 | 145 | // Include the settings file. |
Index: trunk/extensions/Maps/includes/Maps_LayerPage.php |
— | — | @@ -9,6 +9,8 @@ |
10 | 10 | * @ingroup Maps |
11 | 11 | * |
12 | 12 | * @author Jeroen De Dauw |
| 13 | + * |
| 14 | + * TODO: check for the page being not created yet (then it's not invalid if there is nothing there...) |
13 | 15 | */ |
14 | 16 | class MapsLayerPage extends Article { |
15 | 17 | |
— | — | @@ -22,6 +24,15 @@ |
23 | 25 | protected $cachedLayer = false; |
24 | 26 | |
25 | 27 | /** |
| 28 | + * Cached key-value pairs or false. |
| 29 | + * |
| 30 | + * @since 0.7.2 |
| 31 | + * |
| 32 | + * @var false or array |
| 33 | + */ |
| 34 | + protected $keyValuePairs = false; |
| 35 | + |
| 36 | + /** |
26 | 37 | * Constructor. |
27 | 38 | * |
28 | 39 | * @since 0.7.1 |
— | — | @@ -42,8 +53,33 @@ |
43 | 54 | |
44 | 55 | $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); |
45 | 56 | |
46 | | - $layer = $this->getLayer(); |
47 | | - |
| 57 | + if ( MapsLayers::hasLayer( $this->getLayerType() ) ) { |
| 58 | + $this->displayLayerDefinition( MapsLayers::getLayer( $this->getLayerType() ) ); |
| 59 | + } |
| 60 | + else { |
| 61 | + $availableLayerTypes = MapsLayers::getAvailableLayers(); |
| 62 | + $wgOut->addHTML( |
| 63 | + '<span class="errorbox">' . |
| 64 | + htmlspecialchars( wfMsgExt( |
| 65 | + 'maps-error-invalid-layertype', |
| 66 | + 'parsemag', |
| 67 | + $this->getLayerType(), |
| 68 | + $availableLayerTypes, |
| 69 | + count( $availableLayerTypes ) |
| 70 | + ) ) . |
| 71 | + '</span><br />' |
| 72 | + ); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Displays the layer definition as a table. |
| 78 | + * |
| 79 | + * @since 0.7.2 |
| 80 | + * |
| 81 | + * @param MapsLayer $layer |
| 82 | + */ |
| 83 | + protected function displayLayerDefinition( MapsLayer $layer ) { |
48 | 84 | $errorHeader = ''; |
49 | 85 | |
50 | 86 | if ( !$layer->isValid() ) { |
— | — | @@ -121,7 +157,7 @@ |
122 | 158 | ); |
123 | 159 | } |
124 | 160 | |
125 | | - $wgOut->addHTML( Html::rawElement( 'table', array( 'width' => '100%', 'class' => 'wikitable sortable' ), implode( "\n", $rows ) ) ); |
| 161 | + $wgOut->addHTML( Html::rawElement( 'table', array( 'width' => '100%', 'class' => 'wikitable sortable' ), implode( "\n", $rows ) ) ); |
126 | 162 | } |
127 | 163 | |
128 | 164 | /** |
— | — | @@ -131,9 +167,14 @@ |
132 | 168 | * |
133 | 169 | * @return boolean |
134 | 170 | */ |
135 | | - public function hasValidDefinition() { |
136 | | - $layer = $this->getLayer(); |
137 | | - return $layer->isValid(); |
| 171 | + public function hasValidDefinition( $service = null ) { |
| 172 | + if ( MapsLayers::hasLayer( $this->getLayerType(), $service ) ) { |
| 173 | + $layer = $this->getLayer(); |
| 174 | + return $layer->isValid(); |
| 175 | + } |
| 176 | + else { |
| 177 | + return false; |
| 178 | + } |
138 | 179 | } |
139 | 180 | |
140 | 181 | /** |
— | — | @@ -145,7 +186,7 @@ |
146 | 187 | */ |
147 | 188 | public function getLayer() { |
148 | 189 | if ( $this->cachedLayer === false ) { |
149 | | - $this->cachedLayer = new MapsLayer( $this->getProperties() ); |
| 190 | + $this->cachedLayer = MapsLayers::getLayer( $this->getLayerType(), $this->getProperties() ); |
150 | 191 | } |
151 | 192 | |
152 | 193 | return $this->cachedLayer; |
— | — | @@ -158,24 +199,53 @@ |
159 | 200 | * |
160 | 201 | * @return array |
161 | 202 | */ |
162 | | - protected function getProperties() { |
163 | | - $properties = array(); |
| 203 | + final protected function getProperties() { |
| 204 | + $properties = $this->getKeyValuePairs(); |
164 | 205 | |
165 | | - if ( is_null( $this->mContent ) ) { |
166 | | - $this->loadContent(); |
| 206 | + if ( array_key_exists( 'type', $properties ) ) { |
| 207 | + unset( $properties['type'] ); |
167 | 208 | } |
168 | 209 | |
169 | | - foreach ( explode( "\n", $this->mContent ) as $line ) { |
170 | | - $parts = explode( '=', $line, 2 ); |
| 210 | + return $properties; |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * Gets the layer type of false if none is set. |
| 215 | + * |
| 216 | + * @since 0.7.2 |
| 217 | + * |
| 218 | + * @return string or false |
| 219 | + */ |
| 220 | + final protected function getLayerType() { |
| 221 | + $properties = $this->getKeyValuePairs(); |
| 222 | + return array_key_exists( 'type' , $properties ) ? $properties['type'] : false; |
| 223 | + } |
| 224 | + |
| 225 | + /** |
| 226 | + * Returns all key-value pairs stored in the page. |
| 227 | + * |
| 228 | + * @since 0.7.2 |
| 229 | + * |
| 230 | + * @return array |
| 231 | + */ |
| 232 | + final protected function getKeyValuePairs() { |
| 233 | + if ( $this->keyValuePairs === false ) { |
| 234 | + $this->keyValuePairs = array(); |
171 | 235 | |
172 | | - if ( count( $parts ) == 2 ) { |
173 | | - $properties[strtolower( str_replace( ' ', '', $parts[0] ) )] = $parts[1]; |
| 236 | + if ( is_null( $this->mContent ) ) { |
| 237 | + $this->loadContent(); |
174 | 238 | } |
| 239 | + |
| 240 | + foreach ( explode( "\n", $this->mContent ) as $line ) { |
| 241 | + $parts = explode( '=', $line, 2 ); |
| 242 | + |
| 243 | + if ( count( $parts ) == 2 ) { |
| 244 | + $this->keyValuePairs[strtolower( str_replace( ' ', '', $parts[0] ) )] = $parts[1]; |
| 245 | + } |
| 246 | + } |
175 | 247 | } |
176 | | - |
177 | | - $properties['type'] = array_key_exists( 'type', $properties ) ? $properties['type'] : MapsLayer::getDefaultType(); |
178 | 248 | |
179 | | - return $properties; |
| 249 | + return $this->keyValuePairs; |
180 | 250 | } |
181 | 251 | |
182 | 252 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/includes/Maps_Layer.php |
— | — | @@ -9,23 +9,29 @@ |
10 | 10 | * @ingroup Maps |
11 | 11 | * |
12 | 12 | * @author Jeroen De Dauw |
13 | | - * |
14 | | - * TODO: this should be probebly integrated into the mapping service system. |
15 | 13 | */ |
16 | | -class MapsLayer { |
| 14 | +abstract class MapsLayer { |
| 15 | + |
| 16 | + /** |
| 17 | + * Returns an array of parameter definitions. |
| 18 | + * |
| 19 | + * @since 0.7.2 |
| 20 | + * |
| 21 | + * @param array $params Array that can already hold definitions for common parameters. |
| 22 | + * |
| 23 | + * @return array |
| 24 | + */ |
| 25 | + protected abstract function getParameterDefinitions( array $params ); |
17 | 26 | |
18 | 27 | /** |
19 | | - * List of layer type definitions. |
| 28 | + * Returns a string containing the JavaScript definition of this layer. |
| 29 | + * Only call this function when you are sure the layer is valid! |
20 | 30 | * |
21 | 31 | * @since 0.7.1 |
22 | 32 | * |
23 | | - * @var array |
| 33 | + * @return string |
24 | 34 | */ |
25 | | - protected static $types = array( |
26 | | - 'image' => array( |
27 | | - 'class' => 'OpenLayers.Layer.Image', |
28 | | - ) |
29 | | - ); |
| 35 | + public abstract function getJavaScriptDefinition(); |
30 | 36 | |
31 | 37 | /** |
32 | 38 | * @since 0.7.1 |
— | — | @@ -51,17 +57,6 @@ |
52 | 58 | protected $hasValidated = false; |
53 | 59 | |
54 | 60 | /** |
55 | | - * Returns the default layer type. |
56 | | - * |
57 | | - * @since 0.7.1 |
58 | | - * |
59 | | - * @return string |
60 | | - */ |
61 | | - public static function getDefaultType() { |
62 | | - return 'image'; |
63 | | - } |
64 | | - |
65 | | - /** |
66 | 61 | * Constructor. |
67 | 62 | * |
68 | 63 | * @since 0.7.1 |
— | — | @@ -73,17 +68,6 @@ |
74 | 69 | } |
75 | 70 | |
76 | 71 | /** |
77 | | - * Returns the type of the layer. |
78 | | - * |
79 | | - * @since 0.7.1 |
80 | | - * |
81 | | - * @param string |
82 | | - */ |
83 | | - public function getType() { |
84 | | - return array_key_exists( 'type', $this->properties ) ? $this->properties['type'] : self::getDefaultType(); |
85 | | - } |
86 | | - |
87 | | - /** |
88 | 72 | * Returns the error messages, optionaly filtered by an error tag. |
89 | 73 | * |
90 | 74 | * @since 0.7.1 |
— | — | @@ -116,38 +100,6 @@ |
117 | 101 | } |
118 | 102 | |
119 | 103 | /** |
120 | | - * Returns an array of parameter definitions. |
121 | | - * |
122 | | - * @since 0.7.1 |
123 | | - * |
124 | | - * @return array |
125 | | - */ |
126 | | - protected function getParameterDefinitions() { |
127 | | - $params = array(); |
128 | | - |
129 | | - $params[] = new Parameter( 'lowerbound', Parameter::TYPE_FLOAT ); |
130 | | - $params[] = new Parameter( 'upperbound', Parameter::TYPE_FLOAT ); |
131 | | - $params[] = new Parameter( 'leftbound', Parameter::TYPE_FLOAT ); |
132 | | - $params[] = new Parameter( 'rightbound', Parameter::TYPE_FLOAT ); |
133 | | - $params[] = new Parameter( 'width', Parameter::TYPE_FLOAT ); |
134 | | - $params[] = new Parameter( 'height', Parameter::TYPE_FLOAT ); |
135 | | - |
136 | | - $params['type'] = new Parameter( 'type' ); |
137 | | - $params['type']->addCriteria( New CriterionInArray( array_keys( self::$types ) ) ); |
138 | | - $params['type']->addManipulations( new ParamManipulationFunctions( 'strtolower' ) ); |
139 | | - |
140 | | - $params[] = new Parameter( 'zoomlevels', Parameter::TYPE_INTEGER, false ); |
141 | | - |
142 | | - $params['label'] = new Parameter( 'label' ); |
143 | | - |
144 | | - $params['source'] = new Parameter( 'source' ); |
145 | | - $params['source']->addCriteria( new CriterionIsImage() ); |
146 | | - $params['source']->addManipulations( new MapsParamImage() ); |
147 | | - |
148 | | - return $params; |
149 | | - } |
150 | | - |
151 | | - /** |
152 | 104 | * Validates the layer. |
153 | 105 | * |
154 | 106 | * @since 0.7.1 |
— | — | @@ -155,7 +107,7 @@ |
156 | 108 | protected function validate() { |
157 | 109 | $validator = new Validator(); |
158 | 110 | |
159 | | - $validator->setParameters( $this->properties, $this->getParameterDefinitions() ); |
| 111 | + $validator->setParameters( $this->properties, $this->getParameterDefinitions( array() ) ); |
160 | 112 | $validator->validateParameters(); |
161 | 113 | |
162 | 114 | if ( $validator->hasFatalError() !== false ) { |
— | — | @@ -181,38 +133,4 @@ |
182 | 134 | return count( $this->errors ) == 0; |
183 | 135 | } |
184 | 136 | |
185 | | - /** |
186 | | - * Returns a string containing the JavaScript definition of this layer. |
187 | | - * Only call this function when you are sure the layer is valid! |
188 | | - * |
189 | | - * @since 0.7.1 |
190 | | - * |
191 | | - * @return string |
192 | | - */ |
193 | | - public function getJavaScriptDefinition() { |
194 | | - foreach ( $this->properties as $name => $value ) { |
195 | | - ${ $name } = MapsMapper::encodeJsVar( $value ); |
196 | | - } |
197 | | - |
198 | | - $class = self::$types[$this->getType()]['class']; |
199 | | - |
200 | | - $options = array( 'isImage' => true ); |
201 | | - |
202 | | - if ( $this->properties !== false ) { |
203 | | - $options['numZoomLevels'] = $zoomlevels; |
204 | | - } |
205 | | - |
206 | | - $options = Xml::encodeJsVar( (object)$options ); |
207 | | - |
208 | | - return <<<EOT |
209 | | - new $class( |
210 | | - $label, |
211 | | - $source, |
212 | | - new OpenLayers.Bounds($leftbound, $lowerbound, $rightbound, $upperbound), |
213 | | - new OpenLayers.Size($width, $height), |
214 | | - {$options} |
215 | | - ) |
216 | | -EOT; |
217 | | - } |
218 | | - |
219 | 137 | } |
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_ParamOLLayers.php |
— | — | @@ -70,9 +70,9 @@ |
71 | 71 | |
72 | 72 | if ( $title->getNamespace() == Maps_NS_LAYER && $title->exists() ) { |
73 | 73 | $layerPage = new MapsLayerPage( $title ); |
74 | | - $layer = $layerPage->getLayer(); |
75 | 74 | |
76 | | - if ( $layer->isValid() ) { |
| 75 | + if ( $layerPage->hasValidDefinition( 'openlayers' ) ) { |
| 76 | + $layer = $layerPage->getLayer(); |
77 | 77 | if ( !in_array( $layerOrGroup, $layerNames ) ) { |
78 | 78 | $layerDefs[] = $layer->getJavaScriptDefinition(); |
79 | 79 | $layerNames[] = $layerOrGroup; |
Index: trunk/extensions/Maps/includes/services/OpenLayers/CriterionOLLayer.php |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | /** |
5 | 5 | * Parameter criterion stating that the value must be an OpenLayers layer. |
6 | 6 | * |
7 | | - * @since 0.7 |
| 7 | + * @since 0.7.1 |
8 | 8 | * |
9 | 9 | * @file CriterionOLLayer.php |
10 | 10 | * @ingroup Maps |
— | — | @@ -12,52 +12,28 @@ |
13 | 13 | * |
14 | 14 | * @author Jeroen De Dauw |
15 | 15 | */ |
16 | | -class CriterionOLLayer extends ItemParameterCriterion { |
| 16 | +class CriterionOLLayer extends CriterionMapLayer { |
17 | 17 | |
| 18 | + |
18 | 19 | /** |
19 | 20 | * Constructor. |
20 | 21 | * |
21 | 22 | * @since 0.7 |
22 | 23 | */ |
23 | 24 | public function __construct() { |
24 | | - parent::__construct(); |
25 | | - } |
| 25 | + parent::__construct( 'openlayers' ); |
| 26 | + } |
26 | 27 | |
27 | 28 | /** |
28 | 29 | * @see ItemParameterCriterion::validate |
29 | 30 | */ |
30 | 31 | protected function doValidation( $value, Parameter $parameter, array $parameters ) { |
31 | | - $dynamicLayers = MapsOpenLayers::getLayerNames( true ); |
32 | | - |
33 | 32 | // Dynamic layers, defined in the settings file or localsettings. |
34 | | - if ( in_array( strtolower( $value ), $dynamicLayers ) ) { |
| 33 | + if ( in_array( strtolower( $value ), MapsOpenLayers::getLayerNames( true ) ) ) { |
35 | 34 | return true; |
36 | 35 | } |
37 | | - |
38 | | - // Image layers. |
39 | | - $title = Title::newFromText( $value, Maps_NS_LAYER ); |
40 | 36 | |
41 | | - if ( $title->getNamespace() == Maps_NS_LAYER && $title->exists() ) { |
42 | | - $layerPage = new MapsLayerPage( $title ); |
43 | | - $layer = $layerPage->getLayer(); |
44 | | - return $layer->isValid(); |
45 | | - } |
46 | | - |
47 | | - return false; |
| 37 | + return parent::doValidation( $value, $parameter, $parameters ); |
48 | 38 | } |
49 | 39 | |
50 | | - /** |
51 | | - * @see ItemParameterCriterion::getItemErrorMessage |
52 | | - */ |
53 | | - protected function getItemErrorMessage( Parameter $parameter ) { |
54 | | - return wfMsgExt( 'validation-error-invalid-ollayer', 'parsemag', $parameter->getOriginalName() ); |
55 | | - } |
56 | | - |
57 | | - /** |
58 | | - * @see ItemParameterCriterion::getFullListErrorMessage |
59 | | - */ |
60 | | - protected function getFullListErrorMessage( Parameter $parameter ) { |
61 | | - return wfMsgExt( 'validation-error-invalid-ollayers', 'parsemag', $parameter->getOriginalName() ); |
62 | | - } |
63 | | - |
64 | 40 | } |
Index: trunk/extensions/Maps/includes/Maps_ImageLayer.php |
— | — | @@ -0,0 +1,82 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class for describing image layers. |
| 6 | + * |
| 7 | + * @since 0.7.2 |
| 8 | + * |
| 9 | + * @file Maps_ImageLayer.php |
| 10 | + * @ingroup Maps |
| 11 | + * |
| 12 | + * @author Jeroen De Dauw |
| 13 | + */ |
| 14 | +class MapsImageLayer extends MapsLayer { |
| 15 | + |
| 16 | + /** |
| 17 | + * Registeres the layer. |
| 18 | + * |
| 19 | + * @since 0.7.2 |
| 20 | + */ |
| 21 | + public static function register() { |
| 22 | + MapsLayers::registerLayer( 'image', __CLASS__, 'openlayers' ); |
| 23 | + return true; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @see MapsLayer::getParameterDefinitions |
| 28 | + * |
| 29 | + * @since 0.7.2 |
| 30 | + * |
| 31 | + * @return array |
| 32 | + */ |
| 33 | + protected function getParameterDefinitions( array $params ) { |
| 34 | + $params[] = new Parameter( 'lowerbound', Parameter::TYPE_FLOAT ); |
| 35 | + $params[] = new Parameter( 'upperbound', Parameter::TYPE_FLOAT ); |
| 36 | + $params[] = new Parameter( 'leftbound', Parameter::TYPE_FLOAT ); |
| 37 | + $params[] = new Parameter( 'rightbound', Parameter::TYPE_FLOAT ); |
| 38 | + $params[] = new Parameter( 'width', Parameter::TYPE_FLOAT ); |
| 39 | + $params[] = new Parameter( 'height', Parameter::TYPE_FLOAT ); |
| 40 | + |
| 41 | + $params[] = new Parameter( 'zoomlevels', Parameter::TYPE_INTEGER, false ); |
| 42 | + |
| 43 | + $params['label'] = new Parameter( 'label' ); |
| 44 | + |
| 45 | + $params['source'] = new Parameter( 'source' ); |
| 46 | + $params['source']->addCriteria( new CriterionIsImage() ); |
| 47 | + $params['source']->addManipulations( new MapsParamImage() ); |
| 48 | + |
| 49 | + return $params; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @see MapsLayer::getJavaScriptDefinition |
| 54 | + * |
| 55 | + * @since 0.7.1 |
| 56 | + * |
| 57 | + * @return string |
| 58 | + */ |
| 59 | + public function getJavaScriptDefinition() { |
| 60 | + foreach ( $this->properties as $name => $value ) { |
| 61 | + ${ $name } = MapsMapper::encodeJsVar( $value ); |
| 62 | + } |
| 63 | + |
| 64 | + $options = array( 'isImage' => true ); |
| 65 | + |
| 66 | + if ( $this->properties !== false ) { |
| 67 | + $options['numZoomLevels'] = $zoomlevels; |
| 68 | + } |
| 69 | + |
| 70 | + $options = Xml::encodeJsVar( (object)$options ); |
| 71 | + |
| 72 | + return <<<EOT |
| 73 | + new OpenLayers.Layer.Image( |
| 74 | + $label, |
| 75 | + $source, |
| 76 | + new OpenLayers.Bounds($leftbound, $lowerbound, $rightbound, $upperbound), |
| 77 | + new OpenLayers.Size($width, $height), |
| 78 | + {$options} |
| 79 | + ) |
| 80 | +EOT; |
| 81 | + } |
| 82 | + |
| 83 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Maps/includes/Maps_ImageLayer.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 84 | + native |
Index: trunk/extensions/Maps/includes/criteria/CriterionMapLayer.php |
— | — | @@ -0,0 +1,57 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Parameter criterion stating that the value must be a layer. |
| 6 | + * |
| 7 | + * @since 0.7.2 |
| 8 | + * |
| 9 | + * @file CriterionmapLayer.php |
| 10 | + * @ingroup Maps |
| 11 | + * @ingroup Criteria |
| 12 | + * |
| 13 | + * @author Jeroen De Dauw |
| 14 | + */ |
| 15 | +class CriterionMapLayer extends ItemParameterCriterion { |
| 16 | + |
| 17 | + protected $service; |
| 18 | + |
| 19 | + /** |
| 20 | + * Constructor. |
| 21 | + * |
| 22 | + * @since 0.7 |
| 23 | + */ |
| 24 | + public function __construct( $service ) { |
| 25 | + parent::__construct(); |
| 26 | + |
| 27 | + $this->service = $service; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @see ItemParameterCriterion::validate |
| 32 | + */ |
| 33 | + protected function doValidation( $value, Parameter $parameter, array $parameters ) { |
| 34 | + $title = Title::newFromText( $value, Maps_NS_LAYER ); |
| 35 | + |
| 36 | + if ( $title->getNamespace() == Maps_NS_LAYER && $title->exists() ) { |
| 37 | + $layerPage = new MapsLayerPage( $title ); |
| 38 | + return $layerPage->hasValidDefinition( $this->service ); |
| 39 | + } |
| 40 | + |
| 41 | + return false; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @see ItemParameterCriterion::getItemErrorMessage |
| 46 | + */ |
| 47 | + protected function getItemErrorMessage( Parameter $parameter ) { |
| 48 | + return wfMsgExt( 'validation-error-invalid-layer', 'parsemag', $parameter->getOriginalName() ); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @see ItemParameterCriterion::getFullListErrorMessage |
| 53 | + */ |
| 54 | + protected function getFullListErrorMessage( Parameter $parameter ) { |
| 55 | + return wfMsgExt( 'validation-error-invalid-layers', 'parsemag', $parameter->getOriginalName() ); |
| 56 | + } |
| 57 | + |
| 58 | +} |
Property changes on: trunk/extensions/Maps/includes/criteria/CriterionMapLayer.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 59 | + native |
Index: trunk/extensions/Maps/includes/Maps_Layers.php |
— | — | @@ -12,7 +12,22 @@ |
13 | 13 | */ |
14 | 14 | class MapsLayers { |
15 | 15 | |
| 16 | + /** |
| 17 | + * List that maps layer types (keys) to their classes (values). |
| 18 | + * |
| 19 | + * @since 0.7.2 |
| 20 | + * |
| 21 | + * @var array of string |
| 22 | + */ |
16 | 23 | protected static $classes = array(); |
| 24 | + |
| 25 | + /** |
| 26 | + * List that maps layer types (keys) to the services that support them (values). |
| 27 | + * |
| 28 | + * @since 0.7.2 |
| 29 | + * |
| 30 | + * @var array of array of string |
| 31 | + */ |
17 | 32 | protected static $services = array(); |
18 | 33 | |
19 | 34 | /** |
— | — | @@ -20,29 +35,64 @@ |
21 | 36 | * |
22 | 37 | * @since 0.7.2 |
23 | 38 | * |
24 | | - * @param $string $type |
| 39 | + * @param string $type |
| 40 | + * @param array $properties |
25 | 41 | * |
26 | 42 | * @return MapsLayer |
27 | 43 | */ |
28 | | - public static function getLayer( $type ) { |
| 44 | + public static function getLayer( $type, array $properties ) { |
| 45 | + self::initializeLayers(); |
| 46 | + |
29 | 47 | if ( self::hasLayer( $type ) ) { |
30 | | - return new self::$classes[$type](); |
| 48 | + return new self::$classes[$type]( $properties ); |
31 | 49 | } |
32 | 50 | else { |
33 | 51 | throw new exception( "There is no layer class for layer of type $type." ); |
34 | 52 | } |
35 | 53 | } |
| 54 | + |
| 55 | + /** |
| 56 | + * Returns the available layer types, optionaly filtered by them requiring the |
| 57 | + * support of the $service parameter. |
| 58 | + * |
| 59 | + * @since 0.7.2 |
| 60 | + * |
| 61 | + * @param string $service |
| 62 | + * |
| 63 | + * @return array |
| 64 | + */ |
| 65 | + public static function getAvailableLayers( $service = null ) { |
| 66 | + self::initializeLayers(); |
| 67 | + |
| 68 | + if ( is_null( $service ) ) { |
| 69 | + return array_keys( self::$classes ); |
| 70 | + } |
| 71 | + else { |
| 72 | + $layers = array(); |
| 73 | + |
| 74 | + foreach ( self::$services as $layerType => $supportedServices ) { |
| 75 | + if ( in_array( $service, $supportedServices ) ) { |
| 76 | + $layers[] = $layerType; |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + return $layers; |
| 81 | + } |
| 82 | + } |
36 | 83 | |
37 | 84 | /** |
38 | 85 | * Returns if there is a layer class for the provided layer type. |
39 | 86 | * |
40 | 87 | * @since 0.7.2 |
41 | 88 | * |
42 | | - * @param $string $type |
| 89 | + * @param string $type |
| 90 | + * @param string $service |
43 | 91 | * |
44 | 92 | * @return boolean |
45 | 93 | */ |
46 | 94 | public static function hasLayer( $type, $service = null ) { |
| 95 | + self::initializeLayers(); |
| 96 | + |
47 | 97 | if ( array_key_exists( $type, self::$classes ) && array_key_exists( $type, self::$services ) ) { |
48 | 98 | return is_null( $service ) || in_array( $service, self::$services[$type] ); |
49 | 99 | } |
— | — | @@ -54,6 +104,10 @@ |
55 | 105 | /** |
56 | 106 | * Register a layer. |
57 | 107 | * |
| 108 | + * @param string $type |
| 109 | + * @param string $layerClass |
| 110 | + * @param $serviceIdentifier |
| 111 | + * |
58 | 112 | * @since 0.7.2 |
59 | 113 | */ |
60 | 114 | public static function registerLayer( $type, $layerClass, $serviceIdentifier ) { |