-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from mapbox/1ec5-geojson-collection-conform-150
Compliant, codable, equatable GeoJSON
- Loading branch information
Showing
31 changed files
with
1,265 additions
and
582 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import Foundation | ||
|
||
|
||
public struct FeatureCollection: GeoJSONObject { | ||
public let type: FeatureType = .featureCollection | ||
public var identifier: FeatureIdentifier? | ||
/** | ||
A [FeatureCollection object](https://datatracker.ietf.org/doc/html/rfc7946#section-3.3) is a collection of Feature objects. | ||
*/ | ||
public struct FeatureCollection: Equatable { | ||
public var features: Array<Feature> = [] | ||
public var properties: [String : Any?]? | ||
|
||
public init(features: [Feature]) { | ||
self.features = features | ||
} | ||
} | ||
|
||
extension FeatureCollection: Codable { | ||
private enum CodingKeys: String, CodingKey { | ||
case type | ||
case properties | ||
case kind = "type" | ||
case features | ||
} | ||
|
||
public init(features: [Feature]) { | ||
self.features = features | ||
enum Kind: String, Codable { | ||
case FeatureCollection | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
self.features = try container.decode([Feature].self, forKey: .features) | ||
self.properties = try container.decodeIfPresent([String: Any?].self, forKey: .properties) | ||
_ = try container.decode(Kind.self, forKey: .kind) | ||
features = try container.decode([Feature].self, forKey: .features) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(type, forKey: .type) | ||
try container.encode(Kind.FeatureCollection, forKey: .kind) | ||
try container.encode(features, forKey: .features) | ||
try container.encodeIfPresent(properties, forKey: .properties) | ||
} | ||
} |
Oops, something went wrong.