/**
  * @see ValueFormatter::format
  *
  * Generates HTML representing the details of a GlobeCoordinateValue,
  * as an itemized list.
  *
  * @param GlobeCoordinateValue $value
  *
  * @throws InvalidArgumentException
  * @return string HTML
  */
 public function format($value)
 {
     if (!$value instanceof GlobeCoordinateValue) {
         throw new InvalidArgumentException('Data value type mismatch. Expected a GlobeCoordinateValue.');
     }
     $html = '';
     $html .= Html::element('h4', array('class' => 'wb-details wb-globe-details wb-globe-rendered'), $this->coordinateFormatter->format($value));
     $html .= Html::openElement('table', array('class' => 'wb-details wb-globe-details'));
     //TODO: nicer formatting and localization of numbers.
     $html .= $this->renderLabelValuePair('latitude', htmlspecialchars($value->getLatitude()));
     $html .= $this->renderLabelValuePair('longitude', htmlspecialchars($value->getLongitude()));
     $html .= $this->renderLabelValuePair('precision', htmlspecialchars($value->getPrecision()));
     $html .= $this->renderLabelValuePair('globe', htmlspecialchars($value->getGlobe()));
     $html .= Html::closeElement('table');
     return $html;
 }
 public function testFormatWithInvalidPrecision_fallsBackToDefaultPrecision()
 {
     $options = new FormatterOptions();
     $options->setOption(GeoCoordinateFormatter::OPT_PRECISION, 0);
     $formatter = new GlobeCoordinateFormatter($options);
     $formatted = $formatter->format(new GlobeCoordinateValue(new LatLongValue(1.2, 3.4), null));
     $this->assertEquals('1.2, 3.4', $formatted);
 }
예제 #3
0
 /**
  * @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);
 }