Skip to content

Commit 1027dda

Browse files
authored
Merge pull request #86 from mapbox/1ec5-landmark-get-81
Fix landmark roundtripping
2 parents bb92ae7 + bd30bdc commit 1027dda

File tree

6 files changed

+63
-27
lines changed

6 files changed

+63
-27
lines changed

MapboxGeocoder.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
DA2E03F21CB0FE0200D1269A /* MBRectangularRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2E03F11CB0FE0200D1269A /* MBRectangularRegion.swift */; };
2121
DA2EC05C1CED72E900D4BA5D /* MBPlacemarkScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2EC05B1CED72E900D4BA5D /* MBPlacemarkScope.swift */; };
2222
DA2EC05E1CED732F00D4BA5D /* MBGeocodeOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2EC05D1CED732F00D4BA5D /* MBGeocodeOptions.swift */; };
23+
DA4D90071DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA4D90061DD63AEC006EC71A /* PlacemarkScopeTests.swift */; };
24+
DA4D90081DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA4D90061DD63AEC006EC71A /* PlacemarkScopeTests.swift */; };
25+
DA4D90091DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA4D90061DD63AEC006EC71A /* PlacemarkScopeTests.swift */; };
2326
DA5170AD1CF1B1DB00CD6DCF /* MapboxGeocoder.h in Headers */ = {isa = PBXBuildFile; fileRef = DDC229581A36073B006BE405 /* MapboxGeocoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
2427
DA5170AE1CF1B1E000CD6DCF /* MBGeocodeOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2EC05D1CED732F00D4BA5D /* MBGeocodeOptions.swift */; };
2528
DA5170AF1CF1B1E000CD6DCF /* MBGeocoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC229591A36073B006BE405 /* MBGeocoder.swift */; };
@@ -171,6 +174,7 @@
171174
DA2E03F11CB0FE0200D1269A /* MBRectangularRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBRectangularRegion.swift; sourceTree = "<group>"; };
172175
DA2EC05B1CED72E900D4BA5D /* MBPlacemarkScope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBPlacemarkScope.swift; sourceTree = "<group>"; };
173176
DA2EC05D1CED732F00D4BA5D /* MBGeocodeOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBGeocodeOptions.swift; sourceTree = "<group>"; };
177+
DA4D90061DD63AEC006EC71A /* PlacemarkScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlacemarkScopeTests.swift; sourceTree = "<group>"; };
174178
DA5170961CF1B18F00CD6DCF /* MapboxGeocoder.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MapboxGeocoder.framework; sourceTree = BUILT_PRODUCTS_DIR; };
175179
DA51709F1CF1B18F00CD6DCF /* MapboxGeocoderTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MapboxGeocoderTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
176180
DA5170C11CF253EE00CD6DCF /* MapboxGeocoder.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MapboxGeocoder.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -402,6 +406,7 @@
402406
DA701C001CB1292C00B0E520 /* GeocoderTests.swift */,
403407
DA210BAA1CB4BE73008088FD /* ForwardGeocodingTests.swift */,
404408
DDF1E84C1BD6F7BA00C40C78 /* ReverseGeocodingTests.swift */,
409+
DA4D90061DD63AEC006EC71A /* PlacemarkScopeTests.swift */,
405410
DDF1E84E1BD6F7BA00C40C78 /* Info.plist */,
406411
DDF1E8571BD700EB00C40C78 /* Fixtures */,
407412
);
@@ -1043,6 +1048,7 @@
10431048
buildActionMask = 2147483647;
10441049
files = (
10451050
DA5170B61CF1B1EF00CD6DCF /* ReverseGeocodingTests.swift in Sources */,
1051+
DA4D90081DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */,
10461052
DA5170B41CF1B1EF00CD6DCF /* GeocoderTests.swift in Sources */,
10471053
DA5170B51CF1B1EF00CD6DCF /* ForwardGeocodingTests.swift in Sources */,
10481054
);
@@ -1065,6 +1071,7 @@
10651071
buildActionMask = 2147483647;
10661072
files = (
10671073
DA5170E11CF2542800CD6DCF /* ReverseGeocodingTests.swift in Sources */,
1074+
DA4D90091DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */,
10681075
DA5170DF1CF2542800CD6DCF /* GeocoderTests.swift in Sources */,
10691076
DA5170E01CF2542800CD6DCF /* ForwardGeocodingTests.swift in Sources */,
10701077
);
@@ -1118,6 +1125,7 @@
11181125
buildActionMask = 2147483647;
11191126
files = (
11201127
DDF1E84D1BD6F7BA00C40C78 /* ReverseGeocodingTests.swift in Sources */,
1128+
DA4D90071DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */,
11211129
DA210BAB1CB4BE73008088FD /* ForwardGeocodingTests.swift in Sources */,
11221130
DA701C011CB1292C00B0E520 /* GeocoderTests.swift in Sources */,
11231131
);

MapboxGeocoder/MBPlacemark.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,9 @@ public class Placemark: NSObject, NSCopying, NSSecureCoding {
161161
The scope offers a general indication of the size or importance of the feature represented by the placemark – in other words, how local the feature is.
162162
*/
163163
public var scope: PlacemarkScope {
164-
let components = identifier.characters.split(".")
165-
assert(components.count == 2)
166-
let scopeCharacters = identifier.characters.split(".").first!
167-
return PlacemarkScope(descriptions: [String(scopeCharacters)])
164+
let components = identifier.componentsSeparatedByString(".")
165+
assert(components.count > 0)
166+
return PlacemarkScope(descriptions: [components.prefix(2).joinWithSeparator(".")]) ?? PlacemarkScope(descriptions: [components.first!]) ?? []
168167
}
169168

170169
/**

MapboxGeocoder/MBPlacemarkScope.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ typedef NS_OPTIONS(NSUInteger, MBPlacemarkScope) {
2222
MBPlacemarkScopeNeighborhood = (1 << 7),
2323
/// A physical address, such as to a business or residence.
2424
MBPlacemarkScopeAddress = (1 << 8),
25-
/// A point of interest, such as a business or school.
26-
MBPlacemarkScopePointOfInterest = (1 << 9),
27-
/// Subset of regular points of interest. Landmarks are particularly notable or long-lived features like parks, museums, and places of worship.
28-
MBPlacemarkScopePointOfInterestLandmark = (1 << 10),
29-
25+
26+
/// A particularly notable or long-lived point of interest, such as a park, museum, or place of worship.
27+
MBPlacemarkScopeLandmark = (1 << 10),
28+
/// A point of interest, such as a business or store.
29+
MBPlacemarkScopePointOfInterest = MBPlacemarkScopeLandmark | (1 << 9),
30+
3031
/// All scopes.
3132
MBPlacemarkScopeAll = 0x0ffffUL,
3233
};

MapboxGeocoder/MBPlacemarkScope.swift

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extension PlacemarkScope: CustomStringConvertible {
44
/**
55
Initializes a placemark scope bitmask corresponding to the given array of string representations of scopes.
66
*/
7-
public init(descriptions: [String]) {
7+
public init?(descriptions: [String]) {
88
var scope: PlacemarkScope = []
99
for description in descriptions {
1010
switch description {
@@ -24,48 +24,46 @@ extension PlacemarkScope: CustomStringConvertible {
2424
scope.insert(.Neighborhood)
2525
case "address":
2626
scope.insert(.Address)
27+
28+
case "poi.landmark":
29+
scope.insert(.Landmark)
2730
case "poi":
2831
scope.insert(.PointOfInterest)
29-
case "poi.landmark":
30-
scope.insert(.PointOfInterestLandmark)
3132
default:
32-
break
33+
return nil
3334
}
3435
}
3536
self.init(rawValue: scope.rawValue)
3637
}
3738

3839
public var description: String {
3940
var descriptions: [String] = []
40-
if contains(PlacemarkScope.Country) {
41+
if contains(.Country) {
4142
descriptions.append("country")
4243
}
43-
if contains(PlacemarkScope.Region) {
44+
if contains(.Region) {
4445
descriptions.append("region")
4546
}
46-
if contains(PlacemarkScope.District) {
47+
if contains(.District) {
4748
descriptions.append("district")
4849
}
49-
if contains(PlacemarkScope.PostalCode) {
50+
if contains(.PostalCode) {
5051
descriptions.append("postcode")
5152
}
52-
if contains(PlacemarkScope.Place) {
53+
if contains(.Place) {
5354
descriptions.append("place")
5455
}
55-
if contains(PlacemarkScope.Locality) {
56+
if contains(.Locality) {
5657
descriptions.append("locality")
5758
}
58-
if contains(PlacemarkScope.Neighborhood) {
59+
if contains(.Neighborhood) {
5960
descriptions.append("neighborhood")
6061
}
61-
if contains(PlacemarkScope.Address) {
62+
if contains(.Address) {
6263
descriptions.append("address")
6364
}
64-
if contains(PlacemarkScope.PointOfInterest) {
65-
descriptions.append("poi")
66-
}
67-
if contains(PlacemarkScope.PointOfInterestLandmark) {
68-
descriptions.append("poi.landmark")
65+
if contains(.Landmark) {
66+
descriptions.append(contains(.PointOfInterest) ? "poi" : "poi.landmark")
6967
}
7068
return descriptions.joinWithSeparator(",")
7169
}

MapboxGeocoderTests/ForwardGeocodingTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class ForwardGeocodingTests: XCTestCase {
8282
options.allowedISOCountryCodes = ["NC"]
8383
let task = geocoder.geocode(options: options) { (placemarks, attribution, error) in
8484
XCTAssertEqual(placemarks?.count, 0, "forward geocode should return no results for invalid query")
85-
8685
XCTAssertEqual(attribution, "NOTICE: © 2016 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained.")
8786

8887
expection.fulfill()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import XCTest
2+
import MapboxGeocoder
3+
4+
class PlacemarkScopeTests: XCTestCase {
5+
func testContainment() {
6+
XCTAssert(PlacemarkScope.All.contains(.Country))
7+
XCTAssert(PlacemarkScope.All.contains(.Region))
8+
XCTAssert(PlacemarkScope.All.contains(.District))
9+
XCTAssert(PlacemarkScope.All.contains(.PostalCode))
10+
XCTAssert(PlacemarkScope.All.contains(.Place))
11+
XCTAssert(PlacemarkScope.All.contains(.Locality))
12+
XCTAssert(PlacemarkScope.All.contains(.Neighborhood))
13+
XCTAssert(PlacemarkScope.All.contains(.Address))
14+
XCTAssert(PlacemarkScope.PointOfInterest.contains(.Landmark))
15+
XCTAssert(PlacemarkScope.All.contains(.PointOfInterest))
16+
17+
XCTAssertEqual(PlacemarkScope.All.description.componentsSeparatedByString(",").count, 9, "testContainment() needs to be updated.")
18+
19+
XCTAssertLessThanOrEqual(PlacemarkScope.All.rawValue, PlacemarkScope.RawValue.max)
20+
XCTAssertLessThanOrEqual(PlacemarkScope(descriptions: PlacemarkScope.All.description.componentsSeparatedByString(","))?.rawValue ?? .max, PlacemarkScope.All.rawValue)
21+
}
22+
23+
func testDescriptions() {
24+
XCTAssertNil(PlacemarkScope(descriptions: ["neighbourhood"]))
25+
XCTAssertEqual(PlacemarkScope(descriptions: PlacemarkScope.All.description.componentsSeparatedByString(","))?.description, PlacemarkScope.All.description)
26+
27+
XCTAssertEqual(PlacemarkScope(descriptions: ["poi"]), .PointOfInterest)
28+
XCTAssertEqual(PlacemarkScope(descriptions: ["poi.landmark"]), .Landmark)
29+
XCTAssertEqual(PlacemarkScope(descriptions: ["poi", "poi.landmark"]), .PointOfInterest)
30+
}
31+
}

0 commit comments

Comments
 (0)