コード例 #1
0
ファイル: map_object.cpp プロジェクト: MasoudAjorlo/omim
void MapObject::SetFromFeatureType(FeatureType const & ft)
{
  m_mercator = feature::GetCenter(ft);
  m_name = ft.GetNames();
  m_types = feature::TypesHolder(ft);
  m_metadata = ft.GetMetadata();
  m_featureID = ft.GetID();
  ASSERT(m_featureID.IsValid(), ());
  m_geomType = ft.GetFeatureType();
}
コード例 #2
0
// Functions ---------------------------------------------------------------------------------------
void ProcessMetadata(FeatureType & ft, Result::Metadata & meta)
{
  if (meta.m_isInitialized)
    return;

  feature::Metadata const & src = ft.GetMetadata();

  auto const cuisinesMeta = src.Get(feature::Metadata::FMD_CUISINE);
  if (cuisinesMeta.empty())
  {
    meta.m_cuisine = "";
  }
  else
  {
    vector<string> cuisines;
    osm::Cuisines::Instance().ParseAndLocalize(cuisinesMeta, cuisines);
    meta.m_cuisine = strings::JoinStrings(cuisines, " • ");
  }

  meta.m_airportIata = src.Get(feature::Metadata::FMD_AIRPORT_IATA);
  meta.m_brand = src.Get(feature::Metadata::FMD_BRAND);

  string const openHours = src.Get(feature::Metadata::FMD_OPEN_HOURS);
  if (!openHours.empty())
  {
    osmoh::OpeningHours const oh(openHours);
    // TODO: We should check closed/open time for specific feature's timezone.
    time_t const now = time(nullptr);
    if (oh.IsValid() && !oh.IsUnknown(now))
      meta.m_isOpenNow = oh.IsOpen(now) ? osm::Yes : osm::No;
    // In else case value us osm::Unknown, it's set in preview's constructor.
  }

  if (strings::to_int(src.Get(feature::Metadata::FMD_STARS), meta.m_stars))
    meta.m_stars = base::clamp(meta.m_stars, 0, 5);
  else
    meta.m_stars = 0;

  bool const isSponsoredHotel = ftypes::IsBookingChecker::Instance()(ft);
  meta.m_isSponsoredHotel = isSponsoredHotel;
  meta.m_isHotel = ftypes::IsHotelChecker::Instance()(ft);

  if (isSponsoredHotel)
  {
    auto const r = src.Get(feature::Metadata::FMD_RATING);
    if (!r.empty())
    {
      float raw;
      if (strings::to_float(r.c_str(), raw))
        meta.m_hotelRating = raw;
    }


    int pricing;
    if (!strings::to_int(src.Get(feature::Metadata::FMD_PRICE_RATE), pricing))
      pricing = 0;
    string pricingStr;
    CHECK_GREATER_OR_EQUAL(pricing, 0, ("Pricing must be positive!"));
    for (auto i = 0; i < pricing; i++)
      pricingStr.append(kPricingSymbol);

    meta.m_hotelPricing = pricing;
    meta.m_hotelApproximatePricing = pricingStr;
  }

  meta.m_isInitialized = true;
}