/**
  * @see ValueFormatter::format
  *
  * @since 0.1
  *
  * @param GlobeCoordinateValue $value The value to format
  *
  * @return string
  * @throws InvalidArgumentException
  */
 public function format($value)
 {
     if (!$value instanceof GlobeCoordinateValue) {
         throw new InvalidArgumentException('The GlobeCoordinateFormatter can only format instances of GlobeCoordinateValue.');
     }
     $formatter = new GeoCoordinateFormatter($this->options);
     return $formatter->formatLatLongValue($value->getLatLong(), $value->getPrecision());
 }
Esempio n. 2
0
 /**
  * @see ValueFormatter::format
  *
  * @since 0.1
  *
  * @param GlobeCoordinateValue $value The value to format
  *
  * @return string
  * @throws InvalidArgumentException
  */
 public function format($value)
 {
     if (!$value instanceof GlobeCoordinateValue) {
         throw new InvalidArgumentException('Data value type mismatch. Expected a GlobeCoordinateValue.');
     }
     $formatter = new GeoCoordinateFormatter($this->options);
     return $formatter->formatLatLongValue($value->getLatLong(), $value->getPrecision());
 }
 /**
  * @dataProvider validProvider
  */
 public function testFormatterRoundTrip(GlobeCoordinateValue $coord, $expectedValue, FormatterOptions $options)
 {
     $formatter = new GlobeCoordinateFormatter($options);
     $parser = new GlobeCoordinateParser(new ParserOptions(array('precision' => $coord->getPrecision())));
     $formatted = $formatter->format($coord);
     $parsed = $parser->parse($formatted);
     // NOTE: $parsed may be != $coord, because of rounding, so we can't compare directly.
     $formattedParsed = $formatter->format($parsed);
     $this->assertEquals($formatted, $formattedParsed);
 }
Esempio n. 4
0
 /**
  * Normalizes latitude to [-90°..+90°]. Normalizes longitude to [-180°..+180°[ on Earth and
  * Moon and to [0°..+360°[ on all other globes.
  * @see http://planetarynames.wr.usgs.gov/TargetCoordinates
  *
  * @param GlobeCoordinateValue $value
  *
  * @return GlobeCoordinateValue
  */
 public function normalizeGlobeCoordinate(GlobeCoordinateValue $value)
 {
     return new GlobeCoordinateValue($this->normalizeGlobeLatLong($value->getLatLong(), $value->getGlobe()), $value->getPrecision(), $value->getGlobe());
 }
Esempio n. 5
0
 /**
  * @dataProvider instanceProvider
  * @param GlobeCoordinateValue $globeCoordinate
  * @param array $arguments
  */
 public function testGetPrecision(GlobeCoordinateValue $globeCoordinate, array $arguments)
 {
     $actual = $globeCoordinate->getPrecision();
     $this->assertTrue(is_float($actual) || is_int($actual) || is_null($actual), 'Precision is int or float or null');
     $this->assertEquals($arguments[1], $actual);
 }