示例#1
0
 /**
  * @covers MultiMaps\Bounds::__get
  */
 public function test__get()
 {
     $point = new Point(123, 456);
     $this->object->extend(array($point));
     $this->assertEquals($this->object->ne, $this->object->sw);
     $this->assertEquals($this->object->ne, $this->object->center);
     $this->assertEquals($this->object->ne, $point);
     $this->assertNull($this->object->tralala);
 }
示例#2
0
 /**
  * Add circle to map
  * @param string $value
  * @return boolean
  */
 public function addElementCircle($value)
 {
     $return = true;
     $stringscircle = explode($GLOBALS['egMultiMaps_SeparatorItems'], $value);
     foreach ($stringscircle as $circlevalue) {
         if (trim($circlevalue) == '') {
             continue;
         }
         $circle = new Circle();
         if (!$circle->parse($circlevalue, $this->classname)) {
             $return = false;
             $this->errormessages = array_merge($this->errormessages, $circle->getErrorMessages());
         }
         if (!$circle->isValid()) {
             continue;
         }
         $this->circles[] = $circle;
         $circlescount = count($circle->pos);
         for ($index = 0; $index < $circlescount; $index++) {
             $ne = new Point($circle->pos[$index]->lat, $circle->pos[$index]->lon);
             $sw = new Point($circle->pos[$index]->lat, $circle->pos[$index]->lon);
             $ne->move($circle->radiuses[$index], $circle->radiuses[$index]);
             $sw->move(-$circle->radiuses[$index], -$circle->radiuses[$index]);
             $this->elementsBounds->extend(array($ne, $sw));
         }
     }
     return $return;
 }
示例#3
0
 /**
  * Returns an array with data indexed by name.
  *
  * @return array
  */
 public function toArray()
 {
     $adminLevels = [];
     foreach ($this->adminLevels as $adminLevel) {
         $adminLevels[$adminLevel->getLevel()] = ['name' => $adminLevel->getName(), 'code' => $adminLevel->getCode()];
     }
     return array('latitude' => $this->getLatitude(), 'longitude' => $this->getLongitude(), 'bounds' => $this->bounds->toArray(), 'kind' => $this->kind, 'streetNumber' => $this->streetNumber, 'streetName' => $this->streetName, 'postalCode' => $this->postalCode, 'locality' => $this->locality, 'subLocality' => $this->subLocality, 'adminLevels' => $adminLevels, 'country' => $this->country->getName(), 'countryCode' => $this->country->getCode(), 'timezone' => $this->timezone);
 }
示例#4
0
文件: Utils.php 项目: folkevil/geokit
 public static function castToBounds($input)
 {
     try {
         return Bounds::normalize($input);
     } catch (\InvalidArgumentException $e) {
     }
     try {
         $latLng = LatLng::normalize($input);
         return new Bounds($latLng, $latLng);
     } catch (\InvalidArgumentException $e) {
     }
     throw new \InvalidArgumentException(sprintf('Cannot cast to Bounds from input %s.', json_encode($input)));
 }
示例#5
0
 public function testPositiveNegative()
 {
     $min_x = -10;
     $min_y = -10;
     $max_x = -5;
     $max_y = -5;
     $b = new Bounds($max_x, $max_y, $min_x, $min_y);
     $this->assertEquals($min_x, $b->left);
     $this->assertEquals($min_y, $b->top);
     $this->assertEquals($max_x, $b->right);
     $this->assertEquals($max_y, $b->bottom);
     $this->assertEquals(5, $b->getWidth());
     $this->assertEquals(5, $b->getHeight());
     $this->assertTrue($b->contains(-9, -9));
     $this->assertTrue($b->contains(-5, -10));
     $this->assertFalse($b->contains(-1, 1));
 }
示例#6
0
 function test_creation_from_circle()
 {
     $bounds = Bounds::from_point_and_radius(array(32.939829, -96.951176), 2.5);
     $inside = new LatLng(32.969527, -96.99015900000001);
     $outside = new LatLng(32.895155, -96.958444);
     $this->assertTrue($bounds->contains($inside));
     $this->assertFalse($bounds->contains($outside));
 }
示例#7
0
 private function extract_bounds_from_options(&$options)
 {
     if (array_key_exists('bounds', $options)) {
         $bounds = $options['bounds'];
         array_delete($options, 'bounds');
         return Bounds::normalize($bounds);
     }
     return null;
 }
示例#8
0
 /**
  * @AjaxCallable=TRUE
  * @AjaxMethod=POST
  * @AjaxAsync=TRUE
  */
 function load_pois()
 {
     $this->load->library('geo/Bounds');
     $this->load->library('geo/LatLng');
     $this->load->library('geo/Polygon');
     $this->load->library('geo/Point');
     $this->load->model('POIModel');
     $sBounds = filter_input(INPUT_POST, 'bounds', FILTER_VALIDATE_FLOAT, FILTER_REQUIRE_ARRAY);
     $bounds = Bounds::deserialize($sBounds);
     return POIModel::load_by_bounds($bounds);
 }
示例#9
0
文件: Metadata.php 项目: Crayg/PHPGPX
 /**
  * @param SimpleXMLElement $xml
  * @return Metadata
  * @throws InvalidGPXException
  */
 public static function fromXML(SimpleXMLElement $xml)
 {
     $metadata = new Metadata();
     if (!empty($xml->name)) {
         $metadata->setName((string) $xml->name[0]);
     }
     if (!empty($xml->desc)) {
         $metadata->setDescription((string) $xml->desc[0]);
     }
     if (!empty($xml->author)) {
         $metadata->setAuthor(Person::fromXML($xml->author[0]));
     }
     if (!empty($xml->copyright)) {
         $metadata->setCopyright(Copyright::fromXML($xml->copyright[0]));
     }
     if (!empty($xml->link)) {
         $links = [];
         foreach ($xml->link as $link) {
             array_push($links, Link::fromXML($link));
         }
         $metadata->setLinks($links);
     }
     if (!empty($xml->time)) {
         $metadata->setTime(strtotime((string) $xml->time[0]));
     }
     if (!empty($xml->keywords)) {
         $metadata->setKeywords((string) $xml->keywords[0]);
     }
     if (!empty($xml->bounds)) {
         $metadata->setBounds(Bounds::fromXML($xml->bounds0[0]));
     }
     if (!empty($xml->extensions)) {
         $metadata->setExtensions(Extensions::fromXML($xml->extensions[0]));
     }
     return $metadata;
 }
示例#10
0
 /**
  * @param  Bounds $bounds
  * @return Bounds
  */
 public function union(Bounds $bounds)
 {
     $newBounds = $this->extend($bounds->getSouthWest());
     return $newBounds->extend($bounds->getNorthEast());
 }
示例#11
0
 private static function buildBoundsClause(Bounds $bounds)
 {
     $s = $bounds->s();
     $w = $bounds->w();
     $n = $bounds->n();
     $e = $bounds->e();
     if ($w > $e) {
         return "(`lat` < {$n} AND `lat` > {$s} AND (`lng` < {$e} OR `lng` > {$w}))";
     } else {
         return "(`lat` < {$n} AND `lat` > {$s} AND `lng` < {$e} AND `lng` > {$w})";
     }
 }
示例#12
0
 public function testNormalizeShouldThrowExceptionForInvalidObjectInput()
 {
     $this->setExpectedException('\\InvalidArgumentException', 'Cannot normalize Bounds from input {}.');
     Bounds::normalize(new \stdClass());
 }