Index: trunk/extensions/Maps/includes/criteria/CriterionPolygon.php |
— | — | @@ -0,0 +1,90 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Parameter criterion stating that the value must be a set of coordinates or an address. |
| 6 | + * |
| 7 | + * @since 0.7 |
| 8 | + * |
| 9 | + * @file CriterionLine.php |
| 10 | + * @ingroup Maps |
| 11 | + * @ingroup Criteria |
| 12 | + * |
| 13 | + * @author Kim Eik |
| 14 | + */ |
| 15 | + |
| 16 | +class CriterionPolygon extends ItemParameterCriterion |
| 17 | +{ |
| 18 | + |
| 19 | + /** |
| 20 | + * Returns true if the parameter value contains atleast 1 colon |
| 21 | + * meaning that there are atleast two enpoints on which to draw a polygon. |
| 22 | + * And if the first and last coordinates are the same, indicating that there is a loop. |
| 23 | + * |
| 24 | + * @param string $value |
| 25 | + * @param Parameter $parameter |
| 26 | + * @param array $parameters |
| 27 | + * |
| 28 | + * @since 0.4 |
| 29 | + * |
| 30 | + * @return boolean |
| 31 | + */ |
| 32 | + protected function doValidation($value, Parameter $parameter, array $parameters) |
| 33 | + { |
| 34 | + //need atleast two points to create a polygon |
| 35 | + $valid = strpos($value, ':') != false; |
| 36 | + if (!$valid) { |
| 37 | + return $valid; |
| 38 | + } |
| 39 | + |
| 40 | + //setup geocode deps |
| 41 | + $canGeoCode = MapsGeocoders::canGeocode(); |
| 42 | + if ($canGeoCode) { |
| 43 | + $geoService = $parameter->hasDependency('geoservice') ? $parameters['geoservice']->getValue() : ''; |
| 44 | + $mappingService = $parameter->hasDependency('mappingservice') ? $parameters['mappingservice']->getValue() : false; |
| 45 | + } |
| 46 | + |
| 47 | + //strip away line parameters and check for valid locations |
| 48 | + $parts = preg_split('/[:]/', $value); |
| 49 | + foreach ($parts as $part) { |
| 50 | + $toIndex = strpos($part, '|'); |
| 51 | + if ($toIndex != false) { |
| 52 | + $part = substr($part, 0, $toIndex); |
| 53 | + } |
| 54 | + |
| 55 | + if($canGeoCode){ |
| 56 | + $valid = MapsGeocoders::isLocation( |
| 57 | + $part, |
| 58 | + $geoService, |
| 59 | + $mappingService |
| 60 | + ); |
| 61 | + } else { |
| 62 | + $valid = MapsCoordinateParser::areCoordinates($part); |
| 63 | + } |
| 64 | + |
| 65 | + if(!$valid){ |
| 66 | + break; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + if(MapsCoordinateParser::parseAndFormat($parts[0]) != MapsCoordinateParser::parseAndFormat($parts[sizeof($parts)-1])){ |
| 71 | + $valid = false; |
| 72 | + } |
| 73 | + |
| 74 | + return $valid; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Gets an internationalized error message to construct a ValidationError with |
| 79 | + * when the criteria validation failed. (for non-list values) |
| 80 | + * |
| 81 | + * @param Parameter $parameter |
| 82 | + * |
| 83 | + * @since 0.4 |
| 84 | + * |
| 85 | + * @return string |
| 86 | + */ |
| 87 | + protected function getItemErrorMessage(Parameter $parameter) |
| 88 | + { |
| 89 | + return wfMsgExt('validation-error-invalid-polyline-param', 'parsemag', $parameter->getOriginalName()); |
| 90 | + } |
| 91 | +} |
\ No newline at end of file |
Index: trunk/extensions/Maps/includes/manipulations/Maps_ParamPolygon.php |
— | — | @@ -0,0 +1,38 @@ |
| 2 | +<?php |
| 3 | +class MapsParamPolygon extends ItemParameterManipulation { |
| 4 | + |
| 5 | + /** |
| 6 | + * Constructor |
| 7 | + */ |
| 8 | + public function __construct() { |
| 9 | + parent::__construct(); |
| 10 | + } |
| 11 | + |
| 12 | + /** |
| 13 | + * Manipulate an actual value. |
| 14 | + * |
| 15 | + * @param string $value |
| 16 | + * @param Parameter $parameter |
| 17 | + * @param array $parameters |
| 18 | + * |
| 19 | + * @since 0.4 |
| 20 | + * |
| 21 | + * @return mixed |
| 22 | + */ |
| 23 | + public function doManipulation(&$value, Parameter $parameter, array &$parameters) |
| 24 | + { |
| 25 | + $parts = preg_split('/[\|]+/',$value); |
| 26 | + $polygonCoords = preg_split('/[:]/',$parts[0]); |
| 27 | + |
| 28 | + $value = new MapsPolygon($polygonCoords); |
| 29 | + $value->setTitle( isset($parts[1]) ? $parts[1] : '' ); |
| 30 | + $value->setText( isset($parts[2]) ? $parts[2] : '' ); |
| 31 | + $value->setStrokeColor( isset($parts[3]) ? $parts[3] : '' ); |
| 32 | + $value->setStrokeOpacity( isset($parts[4]) ? $parts[4] : '' ); |
| 33 | + $value->setStrokeWeight( isset($parts[5]) ? $parts[5] : '' ); |
| 34 | + $value->setFillColor(isset($parts[6]) ? $parts[6] : ''); |
| 35 | + $value->setFillOpacity(isset($parts[7]) ? $parts[7] : ''); |
| 36 | + |
| 37 | + $value = $value->getJSONObject(); |
| 38 | + } |
| 39 | +} |
\ No newline at end of file |
Index: trunk/extensions/Maps/includes/Maps_Polygon.php |
— | — | @@ -0,0 +1,76 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Class that holds metadata on polygons made up by locations on map. |
| 5 | + * |
| 6 | + * @since 0.7.2 |
| 7 | + * |
| 8 | + * @file Maps_Polygon.php |
| 9 | + * @ingroup Maps |
| 10 | + * |
| 11 | + * @licence GNU GPL v3 |
| 12 | + * @author Kim Eik < kim@heldig.org > |
| 13 | + */ |
| 14 | +class MapsPolygon extends MapsLine{ |
| 15 | + |
| 16 | + |
| 17 | + /** |
| 18 | + * @var |
| 19 | + */ |
| 20 | + protected $fillColor; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var |
| 24 | + */ |
| 25 | + protected $fillOpacity; |
| 26 | + |
| 27 | + |
| 28 | + public function getJSONObject( $defText = '', $defTitle = '') { |
| 29 | + $parentArray = parent::getJSONObject($defText,$defTitle); |
| 30 | + $array = array( |
| 31 | + 'fillColor' => $this->hasFillColor() ? $this->getFillColor() : '#FF0000', |
| 32 | + 'fillOpacity' => $this->hasFillOpacity() ? $this->getFillOpacity() : 0.5 |
| 33 | + ); |
| 34 | + return array_merge($parentArray,$array); |
| 35 | + } |
| 36 | + |
| 37 | + private function hasFillColor(){ |
| 38 | + return $this->fillColor !== ''; |
| 39 | + } |
| 40 | + |
| 41 | + private function hasFillOpacity(){ |
| 42 | + return $this->fillOpacity !== ''; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @return |
| 47 | + */ |
| 48 | + public function getFillOpacity() |
| 49 | + { |
| 50 | + return $this->fillOpacity; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @param $fillOpacity |
| 55 | + */ |
| 56 | + public function setFillOpacity($fillOpacity) |
| 57 | + { |
| 58 | + $this->fillOpacity = $fillOpacity; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @return |
| 63 | + */ |
| 64 | + public function getFillColor() |
| 65 | + { |
| 66 | + return $this->fillColor; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @param $fillColor |
| 71 | + */ |
| 72 | + public function setFillColor($fillColor) |
| 73 | + { |
| 74 | + $this->fillColor = $fillColor; |
| 75 | + } |
| 76 | + |
| 77 | +} |