Example #1
0
 /**
  * Returns true if the parameter value contains atleast 1 comma
  * meaning that there are atleast two enpoints on which to draw a line.
  *
  * @param string $value
  * @param Parameter $parameter
  * @param array $parameters
  *
  * @since 0.4
  *
  * @return boolean
  */
 protected function doValidation($value, Parameter $parameter, array $parameters)
 {
     //fetch locations
     $value = explode($this->metaDataSeparator, $value);
     $value = $value[0];
     //need atleast two points to create a line
     $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 = explode(':', $value);
     foreach ($parts as $part) {
         $toIndex = strpos($part, $this->metaDataSeparator);
         if ($toIndex != false) {
             $part = substr($part, 0, $toIndex);
         }
         if ($canGeoCode) {
             $valid = MapsGeocoders::isLocation($part, $geoService, $mappingService);
         } else {
             $valid = MapsCoordinateParser::areCoordinates($part);
         }
         if (!$valid) {
             break;
         }
     }
     return $valid;
 }
Example #2
0
 /**
  *
  * @param string $value
  *
  * @since 2.0
  *
  * @return boolean
  */
 public function doValidation($value)
 {
     //fetch locations
     $value = explode($this->metaDataSeparator, $value);
     $value = $value[0];
     //strip away line parameters and check for valid locations
     $parts = explode(':', $value);
     if (count($parts) != 2) {
         return false;
     }
     return $parts[1] > 0 ? MapsCoordinateParser::areCoordinates($parts[0]) : false;
 }
Example #3
0
 /**
  * @see GeoValidator::doValidation
  */
 protected function doValidation($value)
 {
     //Empty string. e.g no coordinates given
     if (empty($value)) {
         return true;
     }
     if ($this->metaDataSeparator !== false) {
         $parts = explode($this->metaDataSeparator, $value);
         $value = $parts[0];
     }
     return MapsCoordinateParser::areCoordinates($value);
 }
 /**
  * @see ItemParameterCriterion::validate
  */
 protected function doValidation($value, Parameter $parameter, array $parameters)
 {
     if ($this->metaDataSeparator !== false) {
         $parts = explode($this->metaDataSeparator, $value);
         $value = $parts[0];
     }
     if (MapsGeocoders::canGeocode()) {
         $geoService = $parameter->hasDependency('geoservice') ? $parameters['geoservice']->getValue() : '';
         $mappingService = $parameter->hasDependency('mappingservice') ? $parameters['mappingservice']->getValue() : false;
         return MapsGeocoders::isLocation($value, $geoService, $mappingService);
     } else {
         return MapsCoordinateParser::areCoordinates($value);
     }
 }
Example #5
0
 /**
  * @see GeoValidator::doValidation
  */
 public function doValidation($value)
 {
     //fetch locations
     $value = explode($this->metaDataSeparator, $value);
     $value = $value[0];
     $parts = explode(':', $value);
     if (count($parts) != 2) {
         return false;
     }
     foreach ($parts as $part) {
         $valid = MapsCoordinateParser::areCoordinates($part);
         if (!$valid) {
             break;
         }
     }
     return $valid;
 }
Example #6
0
 /**
  * @see GeoValidator::doValidation
  */
 public function doValidation($value)
 {
     //fetch locations
     $value = explode($this->metaDataSeparator, $value);
     $value = $value[0];
     //need atleast two points to create a line
     $valid = strpos($value, ':') != false;
     if (!$valid) {
         return $valid;
     }
     //strip away line parameters and check for valid locations
     $parts = explode(':', $value);
     foreach ($parts as $part) {
         $toIndex = strpos($part, $this->metaDataSeparator);
         if ($toIndex != false) {
             $part = substr($part, 0, $toIndex);
         }
         $valid = MapsCoordinateParser::areCoordinates($part);
         if (!$valid) {
             break;
         }
     }
     return $valid;
 }
 /**
  * Does the same as Geocode, but also formats the result into a string.
  * 
  * @since 0.7
  * 
  * @param string $coordsOrAddress
  * @param string $service
  * @param string $mappingService
  * @param coordinate type $targetFormat The notation to which they should be formatted. Defaults to floats.
  * @param boolean $directional Indicates if the target notation should be directional. Defaults to false.
  * 
  * @return formatted coordinates string or false
  */
 public static function geocodeToString($address, $service = '', $mappingService = false, $targetFormat = Maps_COORDS_FLOAT, $directional = false)
 {
     $coordinates = self::geocode($address, $service, $mappingService);
     return $coordinates ? MapsCoordinateParser::formatCoordinates($coordinates, $targetFormat, $directional) : false;
 }
Example #8
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     $parsedCoords = MapsCoordinateParser::parseCoordinates($parameters['location']);
     if ($parsedCoords) {
         $output = MapsCoordinateParser::formatCoordinates($parsedCoords, $parameters['format'], $parameters['directional']);
     } else {
         // The coordinates should be valid when this method gets called.
         throw new Exception('Attempt to format an invalid set of coordinates');
     }
     return $output;
 }
Example #9
0
 /**
  * Returns the locations coordinates formatted in the specified notation.
  * 
  * @since 0.7.1
  * 
  * @param string $format Element of the Maps_COORDS_ enum
  * @param boolean $directional
  * @param string $separator
  * 
  * @return string
  */
 public function getCoordinates($format = null, $directional = null, $separator = null)
 {
     if (!$this->isValid()) {
         throw new Exception('Attempt to get the coordinates for an invalid location');
     }
     return MapsCoordinateParser::formatCoordinates(array('lat' => $this->latitude, 'lon' => $this->longitude), is_null($format) ? $this->format : $format, is_null($directional) ? $this->directional : $directional, is_null($separator) ? $this->separator : $separator);
 }
Example #10
0
 /**
  * Gets a regex group that allows only the supported separators.
  * 
  * @since 0.6.2
  * 
  * @return string
  */
 protected static function getSeparatorsRegex()
 {
     if (!self::$separatorsRegex) {
         self::$separatorsRegex = '(' . implode('|', self::$separators) . ')';
     }
     return self::$separatorsRegex;
 }
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     $canGeocode = MapsGeocoders::canGeocode();
     if ($canGeocode) {
         $location = MapsGeocoders::attemptToGeocode($parameters['location'], $parameters['geoservice'], $parameters['mappingservice']);
     } else {
         $location = MapsCoordinateParser::parseCoordinates($parameters['location']);
     }
     // TODO
     if ($location) {
         $destination = MapsGeoFunctions::findDestination($location, $parameters['bearing'], MapsDistanceParser::parseDistance($parameters['distance']));
         $output = MapsCoordinateParser::formatCoordinates($destination, $parameters['format'], $parameters['directional']);
     } else {
         // The location should be valid when this method gets called.
         throw new MWException('Attempt to find a destination from an invalid location');
     }
     return $output;
 }
Example #12
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     if (MapsGeocoders::canGeocode()) {
         $start = MapsGeocoders::attemptToGeocode($parameters['location1'], $parameters['geoservice'], $parameters['mappingservice']);
         $end = MapsGeocoders::attemptToGeocode($parameters['location2'], $parameters['geoservice'], $parameters['mappingservice']);
     } else {
         $start = MapsCoordinateParser::parseCoordinates($parameters['location1']);
         $end = MapsCoordinateParser::parseCoordinates($parameters['location2']);
     }
     if ($start && $end) {
         $output = MapsDistanceParser::formatDistance(MapsGeoFunctions::calculateDistance($start, $end), $parameters['unit'], $parameters['decimals']);
     } else {
         // The locations should be valid when this method gets called.
         throw new Exception('Attempt to find the distance between locations of at least one is invalid');
     }
     return $output;
 }
 /**
  * Tests MapsCoordinateParser::parseAndFormat()
  */
 public function testParseAndFormat()
 {
     foreach (self::$fakeCoordinates as $coord) {
         $this->assertFalse(MapsCoordinateParser::parseAndFormat($coord), "parseAndFormat did not return false for {$coord}.");
     }
     foreach (self::$coordinateMappings['float-dms'] as $destination => $sources) {
         foreach ($sources as $source) {
             $result = MapsCoordinateParser::parseAndFormat($source, Maps_COORDS_DMS, false);
             $this->assertEquals($destination, $result, "{$source} parsed to \n{$result}, not \n{$destination}.");
         }
     }
     foreach (self::$coordinateMappings['dms-float-directional'] as $destination => $sources) {
         foreach ($sources as $source) {
             $result = MapsCoordinateParser::parseAndFormat($source, Maps_COORDS_FLOAT, true);
             $this->assertEquals($destination, $result, "{$source} parsed to \n{$result}, not \n{$destination}.");
         }
     }
 }
Example #14
0
 /**
  * Create links to mapping services based on a wiki-editable message. The parameters
  * available to the message are:
  * 
  * $1: The location in non-directional float notation.
  * $2: The location in directional DMS notation.
  * $3: The latitude in non-directional float notation.
  * $4 The longitude in non-directional float notation.
  * 
  * @since 0.6.4
  * 
  * @return array
  */
 protected function getServiceLinkParams()
 {
     $coordinateSet = $this->m_dataitem->getCoordinateSet();
     return array(MapsCoordinateParser::formatCoordinates($coordinateSet, 'float', false), MapsCoordinateParser::formatCoordinates($coordinateSet, 'dms', true), $coordinateSet['lat'], $coordinateSet['lon']);
 }