https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114598

Revision: 114598
Author:   netbrain
Date:     2012-03-29 11:16:40 +0000 (Thu, 29 Mar 2012)
Log Message:
-----------
added polygons parameter, can draw polygons on map

Added Paths:
-----------
    trunk/extensions/Maps/includes/Maps_Polygon.php
    trunk/extensions/Maps/includes/criteria/CriterionPolygon.php
    trunk/extensions/Maps/includes/manipulations/Maps_ParamPolygon.php

Added: trunk/extensions/Maps/includes/Maps_Polygon.php
===================================================================
--- trunk/extensions/Maps/includes/Maps_Polygon.php                             
(rev 0)
+++ trunk/extensions/Maps/includes/Maps_Polygon.php     2012-03-29 11:16:40 UTC 
(rev 114598)
@@ -0,0 +1,76 @@
+<?php
+/**
+ * Class that holds metadata on polygons made up by locations on map.
+ *
+ * @since 0.7.2
+ *
+ * @file Maps_Polygon.php
+ * @ingroup Maps
+ *
+ * @licence GNU GPL v3
+ * @author Kim Eik < [email protected] >
+ */
+class MapsPolygon extends MapsLine{
+
+
+    /**
+     * @var
+     */
+    protected $fillColor;
+
+    /**
+     * @var
+     */
+    protected $fillOpacity;
+
+
+    public function getJSONObject( $defText = '', $defTitle = '') {
+        $parentArray = parent::getJSONObject($defText,$defTitle);
+        $array = array(
+            'fillColor' => $this->hasFillColor() ? $this->getFillColor() : 
'#FF0000',
+            'fillOpacity' => $this->hasFillOpacity() ? $this->getFillOpacity() 
: 0.5
+        );
+        return array_merge($parentArray,$array);
+    }
+
+    private function hasFillColor(){
+        return $this->fillColor !== '';
+    }
+
+    private function hasFillOpacity(){
+        return $this->fillOpacity !== '';
+    }
+
+    /**
+     * @return
+     */
+    public function getFillOpacity()
+    {
+        return $this->fillOpacity;
+    }
+
+    /**
+     * @param  $fillOpacity
+     */
+    public function setFillOpacity($fillOpacity)
+    {
+        $this->fillOpacity = $fillOpacity;
+    }
+
+    /**
+     * @return
+     */
+    public function getFillColor()
+    {
+        return $this->fillColor;
+    }
+
+    /**
+     * @param  $fillColor
+     */
+    public function setFillColor($fillColor)
+    {
+        $this->fillColor = $fillColor;
+    }
+
+}

Added: trunk/extensions/Maps/includes/criteria/CriterionPolygon.php
===================================================================
--- trunk/extensions/Maps/includes/criteria/CriterionPolygon.php                
                (rev 0)
+++ trunk/extensions/Maps/includes/criteria/CriterionPolygon.php        
2012-03-29 11:16:40 UTC (rev 114598)
@@ -0,0 +1,90 @@
+<?php
+
+/**
+ * Parameter criterion stating that the value must be a set of coordinates or 
an address.
+ *
+ * @since 0.7
+ *
+ * @file CriterionLine.php
+ * @ingroup Maps
+ * @ingroup Criteria
+ *
+ * @author Kim Eik
+ */
+
+class CriterionPolygon extends ItemParameterCriterion
+{
+
+    /**
+     * Returns true if the parameter value contains atleast 1 colon
+     * meaning that there are atleast two enpoints on which to draw a polygon.
+     * And if the first and last coordinates are the same, indicating that 
there is a loop.
+     *
+     * @param string $value
+     * @param Parameter $parameter
+     * @param array $parameters
+     *
+     * @since 0.4
+     *
+     * @return boolean
+     */
+    protected function doValidation($value, Parameter $parameter, array 
$parameters)
+    {
+        //need atleast two points to create a polygon
+        $valid = strpos($value, ':') != false;
+        if (!$valid) {
+            return $valid;
+        }
+
+        //setup geocode deps
+        $canGeoCode = MapsGeocoders::canGeocode();
+        if ($canGeoCode) {
+            $geoService = $parameter->hasDependency('geoservice') ? 
$parameters['geoservice']->getValue() : '';
+            $mappingService = $parameter->hasDependency('mappingservice') ? 
$parameters['mappingservice']->getValue() : false;
+        }
+
+        //strip away line parameters and check for valid locations
+        $parts = preg_split('/[:]/', $value);
+        foreach ($parts as $part) {
+            $toIndex = strpos($part, '|');
+            if ($toIndex != false) {
+                $part = substr($part, 0, $toIndex);
+            }
+
+            if($canGeoCode){
+                $valid = MapsGeocoders::isLocation(
+                    $part,
+                    $geoService,
+                    $mappingService
+                );
+            } else {
+                $valid = MapsCoordinateParser::areCoordinates($part);
+            }
+
+            if(!$valid){
+                break;
+            }
+        }
+
+        if(MapsCoordinateParser::parseAndFormat($parts[0]) != 
MapsCoordinateParser::parseAndFormat($parts[sizeof($parts)-1])){
+            $valid = false;
+        }
+
+        return $valid;
+    }
+
+    /**
+     * Gets an internationalized error message to construct a ValidationError 
with
+     * when the criteria validation failed. (for non-list values)
+     *
+     * @param Parameter $parameter
+     *
+     * @since 0.4
+     *
+     * @return string
+     */
+    protected function getItemErrorMessage(Parameter $parameter)
+    {
+        return wfMsgExt('validation-error-invalid-polyline-param', 'parsemag', 
$parameter->getOriginalName());
+    }
+}
\ No newline at end of file

Added: trunk/extensions/Maps/includes/manipulations/Maps_ParamPolygon.php
===================================================================
--- trunk/extensions/Maps/includes/manipulations/Maps_ParamPolygon.php          
                (rev 0)
+++ trunk/extensions/Maps/includes/manipulations/Maps_ParamPolygon.php  
2012-03-29 11:16:40 UTC (rev 114598)
@@ -0,0 +1,38 @@
+<?php
+class MapsParamPolygon extends ItemParameterManipulation {
+
+    /**
+     * Constructor
+     */
+    public function __construct() {
+        parent::__construct();
+    }
+
+    /**
+     * Manipulate an actual value.
+     *
+     * @param string $value
+     * @param Parameter $parameter
+     * @param array $parameters
+     *
+     * @since 0.4
+     *
+     * @return mixed
+     */
+    public function doManipulation(&$value, Parameter $parameter, array 
&$parameters)
+    {
+      $parts = preg_split('/[\|]+/',$value);
+      $polygonCoords = preg_split('/[:]/',$parts[0]);
+
+      $value = new MapsPolygon($polygonCoords);
+      $value->setTitle( isset($parts[1]) ? $parts[1] : '' );
+      $value->setText( isset($parts[2]) ? $parts[2] : '' );
+      $value->setStrokeColor( isset($parts[3]) ? $parts[3] : '' );
+      $value->setStrokeOpacity( isset($parts[4]) ? $parts[4] : '' );
+      $value->setStrokeWeight( isset($parts[5]) ? $parts[5] : '' );
+      $value->setFillColor(isset($parts[6]) ? $parts[6] : '');
+      $value->setFillOpacity(isset($parts[7]) ? $parts[7] : '');
+
+      $value = $value->getJSONObject();
+    }
+}
\ No newline at end of file


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to