| 520 | } |
| 521 | |
| 522 | GeocoderResult geocoderResultFromJson(const rapidjson::Document& json) { |
| 523 | GeocoderResult result; |
| 524 | |
| 525 | const rapidjson::Pointer labelPointer = |
| 526 | rapidjson::Pointer("/properties/label"); |
| 527 | const rapidjson::Pointer coordinatesPointer = |
| 528 | rapidjson::Pointer("/geometry/coordinates"); |
| 529 | |
| 530 | auto featuresMember = json.FindMember("features"); |
| 531 | if (featuresMember != json.MemberEnd() && featuresMember->value.IsArray()) { |
| 532 | auto featuresIt = featuresMember->value.GetArray(); |
| 533 | for (auto& feature : featuresIt) { |
| 534 | const rapidjson::Value* pLabel = labelPointer.Get(feature); |
| 535 | |
| 536 | std::string label; |
| 537 | if (pLabel) { |
| 538 | label = JsonHelpers::getStringOrDefault(*pLabel, ""); |
| 539 | } |
| 540 | |
| 541 | std::optional<std::vector<double>> bboxItems = |
| 542 | JsonHelpers::getDoubles(feature, 4, "bbox"); |
| 543 | if (!bboxItems) { |
| 544 | // Could be a point value. |
| 545 | const rapidjson::Value* pCoordinates = coordinatesPointer.Get(feature); |
| 546 | |
| 547 | CesiumGeospatial::Cartographic point(0, 0); |
| 548 | if (pCoordinates && pCoordinates->IsArray() && |
| 549 | pCoordinates->Size() == 2) { |
| 550 | auto coordinatesArray = pCoordinates->GetArray(); |
| 551 | |
| 552 | point = CesiumGeospatial::Cartographic::fromDegrees( |
| 553 | JsonHelpers::getDoubleOrDefault(coordinatesArray[0], 0), |
| 554 | JsonHelpers::getDoubleOrDefault(coordinatesArray[1], 0)); |
| 555 | } |
| 556 | |
| 557 | result.features.emplace_back(GeocoderFeature{label, point}); |
| 558 | } else { |
| 559 | std::vector<double>& values = bboxItems.value(); |
| 560 | CesiumGeospatial::GlobeRectangle rect = |
| 561 | CesiumGeospatial::GlobeRectangle::fromDegrees( |
| 562 | values[0], |
| 563 | values[1], |
| 564 | values[2], |
| 565 | values[3]); |
| 566 | |
| 567 | result.features.emplace_back(GeocoderFeature{label, rect}); |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | auto attributionMemberIt = json.FindMember("attributions"); |
| 573 | if (attributionMemberIt != json.MemberEnd() && |
| 574 | attributionMemberIt->value.IsArray()) { |
| 575 | const auto& valueJson = attributionMemberIt->value; |
| 576 | |
| 577 | result.attributions.reserve(valueJson.Size()); |
| 578 | |
| 579 | for (rapidjson::SizeType i = 0; i < valueJson.Size(); ++i) { |
no test coverage detected