/** * Decode string and generate a full SVG document. * * @uses DOMDocument * @param string $encoded - Encoded polyline * @return string - SVG document */ public static function DecodeToSVG($encoded) { // Create list of points $points = parent::Decode($encoded); // Grab first pair list($x, $y) = self::shiftPoint($points); // Path will need to start by moving to first coordinate. $path = sprintf('M %f %f L ', $x, $y); // Init bounding box's min & max. $minX = $maxX = $x; $minY = $maxY = $y; while ($points) { // This can be simplified with php-5.5's generators. list($x, $y) = self::shiftPoint($points); $path .= sprintf('%f %f, ', $x, $y); // Grow MBR if ($x < $minX) { $minX = $x; } if ($y < $minY) { $minY = $y; } if ($x > $maxX) { $maxX = $x; } if ($y > $maxY) { $maxY = $y; } } // Close poylgon $path = rtrim($path, ', ') . ' Z'; // Create viewBox from MBR points $mbr = sprintf("%f %f %f %f", $minX, $minY, abs($maxX - $minX), abs($maxY - $minY)); return self::generateSVG($path, $mbr); }
public function addPath($placemark) { parent::addPath($placemark); $pointArr = array(); foreach ($placemark->getGeometry()->getPoints() as $point) { $pointArr[] = array($point['lat'], $point['lon']); } $polyline = Polyline::encodeFromArray($pointArr); $style = $placemark->getStyle(); if ($style === null) { // color can be 0xRRGGBB or // {black, brown, green, purple, yellow, blue, gray, orange, red, white} $styleArgs = array('color:red'); } else { $styleArgs = array(); $color = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::COLOR); if ($color) { $styleArgs[] = 'color:0x' . htmlColorForColorString($color); } $weight = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::WEIGHT); if ($weight) { $styleArgs[] = 'weight:' . $weight; } } $this->paths[] = implode('|', $styleArgs) . '|enc:' . $polyline; }
/** * Test rounding issues report by issue #10 * * @return NULL */ public function testRounding() { $originalPoints = array(48.000006, 2.000004, 48.00001, 2.0); $encoded = Polyline::encode($originalPoints); $this->assertEquals('a_~cH_seK??', $encoded); $decodedPoints = Polyline::decode($encoded); $this->assertTrue($decodedPoints[0] === $decodedPoints[2]); $this->assertTrue($decodedPoints[1] === $decodedPoints[3]); }
/** * Encoded WKB from blob * * This method will copy the given blob to memory descriptor. There's better * ways to do this. * * @param string $blob - Binary safe string * @return string */ public function encodeFromBlob($blob) { $this->fd = fopen('php://memory', 'wb'); fwrite($this->fd, $blob); fseek($this->fd, 0); $points = $this->parseWkb(); fclose($this->fd); return parent::Encode($points); }
/** * @covers Polyline::Pair */ public function testPairBadInput() { $this->assertEquals(array(), Polyline::Pair('not a list')); }
public function addPath($points, $style=null) { $polyline = Polyline::encodeFromArray($points); if ($style === null) { // color can be 0xRRGGBB or // {black, brown, green, purple, yellow, blue, gray, orange, red, white} $styleArgs = array('color:red'); } else { $styleArgs = array(); $color = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::COLOR); if ($color) $styleArgs[] = 'color:0x'.$color; $weight = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::WEIGHT); if ($weight) $styleArgs[] = 'weight:'.$weight; } $this->paths[] = implode('|', $styleArgs).'|enc:'.$polyline; }
/** * Static instance method * * @return Polyline * @deprecated * @codeCoverageIgnore * @ignore */ public static function Singleton() { trigger_error('Polyline::Singleton deprecated.', E_USER_DEPRECATED); return self::$instance instanceof self ? self::$instance : (self::$instance = new self()); }