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; }
protected function shortArrayFromPlacemark(Placemark $placemark) { $result = array('title' => $placemark->getTitle(), 'subtitle' => $placemark->getSubtitle(), 'id' => $placemark->getId(), 'categories' => $placemark->getCategoryIds(), 'url' => $this->urlForPlacemark($placemark)); $geometry = $placemark->getGeometry(); if ($geometry) { $center = $geometry->getCenterCoordinate(); if (isset($this->mapProjector)) { $center = $this->mapProjector->projectPoint($center); } $result['lat'] = $center['lat']; $result['lon'] = $center['lon']; } return $result; }
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; }
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); } }