Пример #1
0
 protected function shortArrayFromPlacemark(Placemark $placemark)
 {
     $result = array('title' => $placemark->getTitle(), 'subtitle' => $placemark->getSubtitle(), 'id' => $placemark->getId(), 'categories' => $placemark->getCategoryIds());
     $geometry = $placemark->getGeometry();
     if ($geometry) {
         $center = $geometry->getCenterCoordinate();
         $result['lat'] = $center['lat'];
         $result['lon'] = $center['lon'];
     }
     return $result;
 }
Пример #2
0
 public function addPlacemark(Placemark $placemark)
 {
     // only GoogleJSMap, ArcGISJSMap, and GoogleStaticMap support overlays
     $geometry = $placemark->getGeometry();
     if ($geometry instanceof MapPolygon) {
         $this->addPolygon($placemark);
     } elseif ($geometry instanceof MapPolyline) {
         $this->addPath($placemark);
     } else {
         $this->addPoint($placemark);
     }
 }
Пример #3
0
function shortArrayFromMapFeature(Placemark $feature)
{
    $category = current($feature->getCategoryIds());
    $result = array('category' => $category);
    $id = $feature->getId();
    if ($id) {
        $result['featureindex'] = $id;
    } else {
        $geometry = $feature->getGeometry();
        if ($geometry) {
            $coords = $geometry->getCenterCoordinate();
            $result['lat'] = $coords['lat'];
            $result['lon'] = $coords['lon'];
        }
        $result['title'] = $feature->getTitle();
    }
    return $result;
}
Пример #4
0
 public static function updateFeature(Placemark $feature, $parentCategoryId, $projector = null)
 {
     $style = $feature->getStyle();
     if (method_exists($style, 'getId')) {
         $styleId = $style->getId();
     } else {
         $styleId = null;
     }
     $geometry = $feature->getGeometry();
     if ($geometry) {
         if ($projector) {
             $geometry = $projector->projectGeometry($geometry);
         }
         $centroid = $geometry->getCenterCoordinate();
         $wkt = WKTParser::wktFromGeometry($geometry);
     } else {
         // TODO: handle this instead of throwing exception
         throw new KurogoDataException("feature has no geometry");
     }
     $placemarkId = $feature->getId();
     // placemark table
     $isStored = $feature instanceof MapDBPlacemark && $feature->isStored();
     if (!$isStored) {
         $sql = 'SELECT * FROM ' . self::PLACEMARK_TABLE . ' WHERE placemark_id=? AND lat=? AND lon=?';
         $params = array($placemarkId, $centroid['lat'], $centroid['lon']);
         $results = self::connection()->query($sql, $params);
         if ($results->fetch()) {
             $isStored = true;
         }
     }
     $params = array($feature->getTitle(), $feature->getAddress(), $styleId, $wkt, $placemarkId, $centroid['lat'], $centroid['lon']);
     if ($isStored) {
         $sql = 'UPDATE ' . self::PLACEMARK_TABLE . '   SET name=?, address=?, style_id=?, geometry=?' . ' WHERE placemark_id=? AND lat=? AND lon=?';
     } else {
         $sql = 'INSERT INTO ' . self::PLACEMARK_TABLE . ' (name, address, style_id, geometry, placemark_id, lat, lon)' . ' VALUES (?, ?, ?, ?, ?, ?, ?)';
     }
     self::connection()->query($sql, $params);
     if ($placemarkId === null) {
         // TODO: check db compatibility for this function
         $placemarkId = self::connection()->lastInsertId();
     }
     // categories
     $categories = $feature->getCategoryIds();
     if (!is_array($categories)) {
         $categories = array();
     }
     if (!in_array($parentCategoryId, $categories)) {
         $categories[] = $parentCategoryId;
     }
     foreach ($categories as $categoryId) {
         $sql = 'INSERT INTO ' . self::PLACEMARK_CATEGORY_TABLE . ' (placemark_id, lat, lon, category_id)' . ' VALUES (?, ?, ?, ?)';
         $params = array($placemarkId, $centroid['lat'], $centroid['lon'], $categoryId);
         self::connection()->query($sql, $params, db::IGNORE_ERRORS);
     }
     // properties
     $sql = 'DELETE FROM ' . self::PLACEMARK_PROPERTIES_TABLE . ' WHERE placemark_id=?';
     $params = array($placemarkId);
     self::connection()->query($sql, $params);
     $properties = $feature->getFields();
     foreach ($properties as $name => $value) {
         $sql = 'INSERT INTO ' . self::PLACEMARK_PROPERTIES_TABLE . ' (placemark_id, lat, lon, property_name, property_value)' . ' VALUES (?, ?, ?, ?, ?)';
         $params = array($placemarkId, $centroid['lat'], $centroid['lon'], $name, $value);
         self::connection()->query($sql, $params);
     }
 }
 protected function getProjectedFeature(Placemark $placemark)
 {
     if ($placemark instanceof BasePlacemark) {
         // generic Placemark does not implement setGeometry
         $this->setupProjector();
         if ($this->projector !== null) {
             $geometry = $placemark->getGeometry();
             if ($geometry) {
                 $placemark->setGeometry($this->projector->projectGeometry($geometry));
             }
         }
     }
     return $placemark;
 }
Пример #6
0
 protected function getProjectedFeature(Placemark $placemark)
 {
     if ($placemark instanceof BasePlacemark) {
         // generic Placemark does not implement setGeometry
         $this->setupProjector();
         if ($this->projector !== null) {
             $geometry = $placemark->getGeometry();
             if ($geometry) {
                 $placemark->setGeometry($this->projector->projectGeometry($geometry));
             }
         }
     }
     $placemark->setURLParam('feed', $this->categoryId);
     $placemark->setURLParam('group', $this->feedGroup);
     return $placemark;
 }