/** * @see ParameterManipulation::manipulate * * @since 0.7 */ public function manipulate(Parameter &$parameter, array &$parameters) { global $egMapsOLLayerGroups, $egMapsOLAvailableLayers; $layerDefs = array(); $usedLayers = array(); foreach ($parameter->getValue() as $layerOrGroup) { $lcLayerOrGroup = strtolower($layerOrGroup); // Layer groups. Loop over all items and add them if not present yet. if (array_key_exists($lcLayerOrGroup, $egMapsOLLayerGroups)) { foreach ($egMapsOLLayerGroups[$lcLayerOrGroup] as $layerName) { if (!in_array($layerName, $usedLayers)) { if (is_array($egMapsOLAvailableLayers[$layerName])) { $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$layerName][0]; } else { $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$layerName]; } $usedLayers[] = $layerName; } } } elseif (array_key_exists($lcLayerOrGroup, $egMapsOLAvailableLayers)) { if (!in_array($lcLayerOrGroup, $usedLayers)) { if (is_array($egMapsOLAvailableLayers[$lcLayerOrGroup])) { $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$lcLayerOrGroup][0]; } else { $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$lcLayerOrGroup]; } $usedLayers[] = $lcLayerOrGroup; } } else { $layerParts = explode($this->groupNameSep, $layerOrGroup, 2); $layerGroup = $layerParts[0]; $layerName = count($layerParts) > 1 ? $layerParts[1] : null; $title = Title::newFromText($layerGroup, Maps_NS_LAYER); if ($title !== null && $title->getNamespace() == Maps_NS_LAYER) { /** * TODO/FIXME: This shouldn't be here and using $wgParser, instead it should * be somewhere around MapsBaseMap::renderMap. But since we do a lot more than * 'parameter manipulation' in here, we already diminish the information needed * for this which will never arrive there. Perhaps the whole * MapsLayer::getJavaScriptDefinition() shouldn't be done here. */ global $wgParser; // add dependency to the layer page so if the layer definition gets updated, // the page where it is used will be updated as well: $rev = Revision::newFromTitle($title); $wgParser->getOutput()->addTemplate($title, $title->getArticleID(), $rev->getId()); // if the whole layer group is not yet loaded into the map and the group exists: if (!in_array($layerGroup, $usedLayers) && $title->exists()) { $layerPage = new MapsLayerPage($title); if ($layerName !== null) { // load specific layer with name: $layer = MapsLayers::loadLayer($title, $layerName); $layers = new MapsLayerGroup($layer); $usedLayer = $layerOrGroup; } else { // load all layers from group: $layers = MapsLayers::loadLayerGroup($title); $usedLayer = $layerGroup; } foreach ($layers->getLayers() as $layer) { if (($layer->getName() === null || !in_array($layerGroup . $this->groupNameSep . $layer->getName(), $usedLayers)) && $layer->isOk()) { $layerDefs[] = $layer->getJavaScriptDefinition(); } } $usedLayers[] = $usedLayer; // have to add this after loop of course! } } else { wfWarn("Invalid layer ({$layerOrGroup}) encountered after validation."); } } } $parameter->setValue($layerDefs); MapsMappingServices::getServiceInstance('openlayers')->addLayerDependencies($this->getDependencies($usedLayers)); }
/** * Returns if the layer page has any layer defined which has a definition that is 'ok', * meaning, the layer can be used in a map. * * @since 3.0 * * @param string $name if set, only for the layer definition with this name will be searched. * @param string $service if set, only layers supporthing this service will be taken in account. * * @return boolean */ public function hasUsableLayer($name = null, $service = null) { // if name is given, get only that layer to check on, otherwise all: if ($name !== null) { $layer = MapsLayers::loadLayer($this->getTitle(), $name); if ($layer === null) { return false; } $layers = array($layer); } else { $layers = MapsLayers::loadLayerGroup($this->getTitle()); $layers = $layers->getLayers(); } // datermine whether any layer is usable: foreach ($layers as $layerName => $layer) { if ($layer->isOk() && ($service === null || $layer->isSupportingService($service))) { return true; } } return false; }