Index: trunk/extensions/Maps/includes/Maps_LayerPage.php |
— | — | @@ -30,8 +30,6 @@ |
31 | 31 | */ |
32 | 32 | public function view() { |
33 | 33 | parent::view(); |
34 | | - //$layer = $this->getLayer(); |
35 | | - //var_dump($layer);exit; |
36 | 34 | } |
37 | 35 | |
38 | 36 | /** |
— | — | @@ -55,14 +53,18 @@ |
56 | 54 | protected function getProperties() { |
57 | 55 | $properties = array(); |
58 | 56 | |
| 57 | + if ( is_null( $this->mContent ) ) { |
| 58 | + $this->loadContent(); |
| 59 | + } |
| 60 | + |
59 | 61 | foreach ( explode( "\n", $this->mContent ) as $line ) { |
60 | 62 | $parts = explode( '=', $line, 2 ); |
61 | 63 | |
62 | 64 | if ( count( $parts ) == 2 ) { |
63 | | - $properties[$parts[0]] = $parts[1]; |
| 65 | + $properties[strtolower( str_replace( ' ', '', $parts[0] ) )] = $parts[1]; |
64 | 66 | } |
65 | 67 | } |
66 | | - |
| 68 | + |
67 | 69 | return $properties; |
68 | 70 | } |
69 | 71 | |
Index: trunk/extensions/Maps/includes/Maps_Layer.php |
— | — | @@ -13,13 +13,50 @@ |
14 | 14 | class MapsLayer { |
15 | 15 | |
16 | 16 | /** |
| 17 | + * List of layer type definitions. |
| 18 | + * |
17 | 19 | * @since 0.7.1 |
18 | 20 | * |
19 | 21 | * @var array |
20 | 22 | */ |
| 23 | + protected static $types = array( |
| 24 | + 'image' => array( |
| 25 | + 'class' => 'OpenLayers.Layer.Image', |
| 26 | + 'required' => array( |
| 27 | + 'label', |
| 28 | + 'source', |
| 29 | + 'lowerbound', |
| 30 | + 'upperbound', |
| 31 | + 'leftbound', |
| 32 | + 'rightbound', |
| 33 | + 'width', |
| 34 | + 'height' |
| 35 | + ), |
| 36 | + 'optional' => array( |
| 37 | + 'zoomlevels' |
| 38 | + ) |
| 39 | + ) |
| 40 | + ); |
| 41 | + |
| 42 | + /** |
| 43 | + * @since 0.7.1 |
| 44 | + * |
| 45 | + * @var array |
| 46 | + */ |
21 | 47 | protected $properties; |
22 | 48 | |
23 | 49 | /** |
| 50 | + * Returns the default layer type. |
| 51 | + * |
| 52 | + * @since 0.7.1 |
| 53 | + * |
| 54 | + * @return string |
| 55 | + */ |
| 56 | + public static function getDefaultType() { |
| 57 | + return 'image'; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
24 | 61 | * Creates and returns a new instance of an MapsLayer, based on the provided array of key value pairs. |
25 | 62 | * |
26 | 63 | * @since 0.7.1 |
— | — | @@ -54,4 +91,80 @@ |
55 | 92 | $this->properties = $properties; |
56 | 93 | } |
57 | 94 | |
58 | | -} |
\ No newline at end of file |
| 95 | + /** |
| 96 | + * Returns the type of the layer. |
| 97 | + * |
| 98 | + * @since 0.7.1 |
| 99 | + * |
| 100 | + * @param string |
| 101 | + */ |
| 102 | + public function getType() { |
| 103 | + return array_key_exists( 'type', $this->properties ) ? $this->properties['type'] : self::getDefaultType(); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Gets if the properties make up a valid layer definition. |
| 108 | + * |
| 109 | + * @since 0.7.1 |
| 110 | + * |
| 111 | + * @return boolean |
| 112 | + */ |
| 113 | + public function isValid() { |
| 114 | + if ( array_key_exists( $this->getType(), self::$types ) ) { |
| 115 | + $typeDefinition = self::$types[$this->getType()]; |
| 116 | + |
| 117 | + // Loop over the required parameters. |
| 118 | + foreach ( $typeDefinition['required'] as $paramName ) { |
| 119 | + if ( !array_key_exists( $paramName, $this->properties ) ) { |
| 120 | + return false; |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + return true; |
| 125 | + } |
| 126 | + else { |
| 127 | + return false; |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Returns a string containing the JavaScript definition of this layer. |
| 133 | + * Only call this function when you are sure the layer is valid! |
| 134 | + * |
| 135 | + * @since 0.7.1 |
| 136 | + * |
| 137 | + * @return string |
| 138 | + */ |
| 139 | + public function getJavaScriptDefinition() { |
| 140 | + // Note: this is currently hardcoded for layers of type image. |
| 141 | + $label = Xml::encodeJsVar( $this->properties['label'] ); |
| 142 | + $source = Xml::encodeJsVar( $this->properties['source'] ); |
| 143 | + $lowerBound = Xml::encodeJsVar( (int)$this->properties['lowerbound'] ); |
| 144 | + $upperBound = Xml::encodeJsVar( (int)$this->properties['upperbound'] ); |
| 145 | + $leftBound = Xml::encodeJsVar( (int)$this->properties['leftbound'] ); |
| 146 | + $rightBound = Xml::encodeJsVar( (int)$this->properties['rightbound'] ); |
| 147 | + $width = Xml::encodeJsVar( (int)$this->properties['width'] ); |
| 148 | + $height = Xml::encodeJsVar( (int)$this->properties['height'] ); |
| 149 | + |
| 150 | + $class = self::$types[$this->getType()]['class']; |
| 151 | + |
| 152 | + $options = array(); |
| 153 | + |
| 154 | + if ( array_key_exists( 'zoomlevels', $this->properties ) ) { |
| 155 | + $options['numZoomLevels'] = (int)$this->properties['zoomlevels']; |
| 156 | + } |
| 157 | + |
| 158 | + $options = Xml::encodeJsVar( (object)$options ); |
| 159 | + |
| 160 | + return <<<EOT |
| 161 | + new $class( |
| 162 | + $label, |
| 163 | + $source, |
| 164 | + new OpenLayers.Bounds($leftBound, $lowerBound, $rightBound, $upperBound), |
| 165 | + new OpenLayers.Size($width, $height), |
| 166 | + {$options} |
| 167 | + ) |
| 168 | +EOT; |
| 169 | + } |
| 170 | + |
| 171 | +} |
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_ParamOLLayers.php |
— | — | @@ -31,30 +31,93 @@ |
32 | 32 | public function manipulate( Parameter &$parameter, array &$parameters ) { |
33 | 33 | global $egMapsOLLayerGroups, $egMapsOLAvailableLayers; |
34 | 34 | |
35 | | - $unpacked = array(); |
36 | | - $imageLayers = array(); |
| 35 | + $layerDefs = array(); |
| 36 | + $layerNames = array(); |
37 | 37 | |
38 | 38 | foreach ( $parameter->getValue() as $layerOrGroup ) { |
39 | 39 | if ( array_key_exists( $layerOrGroup, $egMapsOLLayerGroups ) ) { |
40 | | - $unpacked += $egMapsOLLayerGroups[$layerOrGroup]; |
| 40 | + $layerNames += $egMapsOLLayerGroups[$layerOrGroup]; |
| 41 | + |
| 42 | + foreach ( $egMapsOLLayerGroups[$layerOrGroup] as $layerName ) { |
| 43 | + $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$layerName]; |
| 44 | + } |
41 | 45 | } |
42 | | - elseif ( in_array( $layerOrGroup, $egMapsOLAvailableLayers ) ) { |
43 | | - $unpacked[] = $layerOrGroup; |
| 46 | + elseif ( array_key_exists( $layerOrGroup, $egMapsOLAvailableLayers ) ) { |
| 47 | + $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$layerOrGroup]; |
| 48 | + $layerNames[] = $layerOrGroup; |
44 | 49 | } |
45 | 50 | else { |
46 | 51 | $title = Title::newFromText( $layerOrGroup, Maps_NS_LAYER ); |
47 | 52 | |
48 | 53 | if ( $title->getNamespace() == Maps_NS_LAYER && $title->exists() ) { |
49 | 54 | $layerPage = new MapsLayerPage( $title ); |
50 | | - $imageLayers[] = $layerPage->getLayer(); |
| 55 | + $layer = $layerPage->getLayer(); |
| 56 | + |
| 57 | + if ( $layer->isValid() ) { |
| 58 | + $layerDefs[] = $layer->getJavaScriptDefinition(); |
| 59 | + $layerNames[] = $layerOrGroup; |
| 60 | + } |
| 61 | + else { |
| 62 | + wfWarn( "Invalid layer ($layerOrGroup) encountered after validation." ); |
| 63 | + } |
51 | 64 | } |
52 | 65 | else { |
53 | 66 | wfWarn( "Invalid layer ($layerOrGroup) encountered after validation." ); |
54 | 67 | } |
55 | 68 | } |
56 | 69 | } |
| 70 | + |
| 71 | + $parameter->setValue( array( |
| 72 | + '[' . implode( ',', $layerDefs ) . ']', |
| 73 | + $this->getDependencies( $layerNames ) |
| 74 | + ) ); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Returns the depencies for the provided layers. |
| 79 | + * |
| 80 | + * @since 0.7.1 |
| 81 | + * |
| 82 | + * @param array $layerNames |
| 83 | + * |
| 84 | + * @return array |
| 85 | + */ |
| 86 | + protected function getDependencies( array $layerNames ) { |
| 87 | + global $egMapsOLLayerDependencies; |
| 88 | + static $decompressed = false; |
57 | 89 | |
58 | | - $parameter->setValue( array( $unpacked, $imageLayers ) ); |
| 90 | + if ( !$decompressed ) { |
| 91 | + $this->decompressLayerDependencies(); |
| 92 | + $decompressed = true; |
| 93 | + } |
| 94 | + |
| 95 | + $layerDependencies = array(); |
| 96 | + |
| 97 | + foreach ( $layerNames as $layerName ) { |
| 98 | + if ( array_key_exists( $layerName, $egMapsOLLayerDependencies ) ) { |
| 99 | + |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + return $layerDependencies; |
59 | 104 | } |
60 | 105 | |
| 106 | + /** |
| 107 | + * Resolves group dependencies to individual layer dependencies. |
| 108 | + * |
| 109 | + * @since 0.7.1 |
| 110 | + */ |
| 111 | + protected static function decompressLayerDependencies() { |
| 112 | + global $egMapsOLLayerDependencies, $egMapsOLLayerGroups; |
| 113 | + |
| 114 | + foreach ( $egMapsOLLayerGroups as $groupName => $groupItems ) { |
| 115 | + if ( array_key_exists( $groupName, $egMapsOLLayerDependencies ) ) { |
| 116 | + foreach ( $groupItems as $item ) { |
| 117 | + $egMapsOLLayerDependencies[$item] = $egMapsOLLayerDependencies[$groupName]; |
| 118 | + } |
| 119 | + unset($egMapsOLLayerDependencies[$groupName]); |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + |
61 | 124 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_OpenLayersDispMap.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | public function addSpecificMapHTML( Parser $parser ) { |
18 | 18 | global $wgLang; |
19 | 19 | |
20 | | - $layerItems = $this->service->createLayersStringAndLoadDependencies( $this->layers[0] ); |
| 20 | + $layerItems = $this->service->addLayerDependencies( $this->layers[1] ); |
21 | 21 | |
22 | 22 | $mapName = $this->service->getMapId(); |
23 | 23 | |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | $this->centreLon, |
39 | 39 | $this->centreLat, |
40 | 40 | $this->zoom, |
41 | | - [$layerItems], |
| 41 | + {$this->layers[0]}, |
42 | 42 | [$this->controls], |
43 | 43 | [], |
44 | 44 | "$langCode" |
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_OpenLayers.php |
— | — | @@ -14,16 +14,6 @@ |
15 | 15 | class MapsOpenLayers extends MapsMappingService { |
16 | 16 | |
17 | 17 | /** |
18 | | - * List to keep track of loaded layers. |
19 | | - * Typically this means one or more js/css files have been added. |
20 | | - * |
21 | | - * @since 0.7 |
22 | | - * |
23 | | - * @var array |
24 | | - */ |
25 | | - protected static $loadedLayers = array(); |
26 | | - |
27 | | - /** |
28 | 18 | * Constructor. |
29 | 19 | * |
30 | 20 | * @since 0.6.6 |
— | — | @@ -160,46 +150,17 @@ |
161 | 151 | |
162 | 152 | return $keys; |
163 | 153 | } |
164 | | - |
165 | | - /** |
166 | | - * Build up a csv string with the layers, to be outputted as a JS array |
167 | | - * |
168 | | - * @param array $layers |
169 | | - * |
170 | | - * @return csv string |
171 | | - */ |
172 | | - public function createLayersStringAndLoadDependencies( array $layers ) { |
173 | | - global $egMapsOLAvailableLayers; |
174 | | - |
175 | | - $layerStr = array(); |
176 | | - |
177 | | - foreach ( $layers as $layer ) { |
178 | | - $this->loadDependencyWhenNeeded( $layer ); |
179 | | - $layerStr[] = is_array( $egMapsOLAvailableLayers[$layer] ) ? $egMapsOLAvailableLayers[$layer][0] : $egMapsOLAvailableLayers[$layer]; |
180 | | - } |
181 | | - |
182 | | - return count( $layerStr ) == 0 ? '' : 'new ' . implode( ',new ', $layerStr ); |
183 | | - } |
184 | 154 | |
185 | 155 | /** |
186 | | - * Load the dependencies of a layer if they are not loaded yet. |
| 156 | + * Adds the layer dependencies. |
187 | 157 | * |
188 | | - * Note: The check if the layer has been added is redudant with the new (>=0.6.3) dependency management. |
189 | | - * |
190 | | - * @param string $layer The layer to check (and load the dependencies for |
| 158 | + * @since 0.7.1 |
| 159 | + * |
| 160 | + * @param array $dependencies |
191 | 161 | */ |
192 | | - public function loadDependencyWhenNeeded( $layer ) { |
193 | | - global $egMapsOLAvailableLayers, $egMapsOLLayerDependencies; |
194 | | - |
195 | | - // Check if there is a dependency refered by the layer definition. |
196 | | - if ( is_array( $egMapsOLAvailableLayers[$layer] ) |
197 | | - && count( $egMapsOLAvailableLayers[$layer] ) > 1 |
198 | | - && array_key_exists( $egMapsOLAvailableLayers[$layer][1], $egMapsOLLayerDependencies ) |
199 | | - && !in_array( $egMapsOLAvailableLayers[$layer][1], self::$loadedLayers ) ) { |
200 | | - // Add the dependency to the output. |
201 | | - $this->addDependency( $egMapsOLLayerDependencies[$egMapsOLAvailableLayers[$layer][1]] ); |
202 | | - // Register that it's added so it does not get done multiple times. |
203 | | - self::$loadedLayers[] = $egMapsOLAvailableLayers[$layer][1]; |
| 162 | + public function addLayerDependencies( array $dependencies ) { |
| 163 | + foreach ( $dependencies as $dependency ) { |
| 164 | + $this->addDependency( $dependency ); |
204 | 165 | } |
205 | 166 | } |
206 | 167 | |
Index: trunk/extensions/Maps/includes/services/OpenLayers/CriterionOLLayer.php |
— | — | @@ -36,8 +36,11 @@ |
37 | 37 | |
38 | 38 | // Image layers. |
39 | 39 | $title = Title::newFromText( $value, Maps_NS_LAYER ); |
| 40 | + |
40 | 41 | if ( $title->getNamespace() == Maps_NS_LAYER && $title->exists() ) { |
41 | | - return true; |
| 42 | + $layerPage = new MapsLayerPage( $title ); |
| 43 | + $layer = $layerPage->getLayer(); |
| 44 | + return $layer->isValid(); |
42 | 45 | } |
43 | 46 | |
44 | 47 | return false; |