From 2cef5b13976ff6fa7457e29a66b60fdda03ce297 Mon Sep 17 00:00:00 2001 From: Aleksei Sapitskii <45671572+aleksproger@users.noreply.github.com> Date: Thu, 10 Oct 2024 10:55:11 +0300 Subject: [PATCH] MAPSIOS-1581: Geofence integration (#2319) --- .../Geofencing/Geofencing+Turf.swift | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Sources/MapboxMaps/Foundation/Extensions/Geofencing/Geofencing+Turf.swift diff --git a/Sources/MapboxMaps/Foundation/Extensions/Geofencing/Geofencing+Turf.swift b/Sources/MapboxMaps/Foundation/Extensions/Geofencing/Geofencing+Turf.swift new file mode 100644 index 000000000000..8ee572975879 --- /dev/null +++ b/Sources/MapboxMaps/Foundation/Extensions/Geofencing/Geofencing+Turf.swift @@ -0,0 +1,40 @@ +@_spi(Experimental) @_spi(Internal) import MapboxCommon + +@_spi(Experimental) +extension GeofenceState { + /// Create `GeofenceState` + @_spi(Experimental) + public init(feature: Turf.Feature, timestamp: Date?) { + self.init(_feature: MapboxCommon.Feature(feature), timestamp: timestamp) + } + + /// The feature linked to this state + @_spi(Experimental) + public var feature: Turf.Feature { Turf.Feature(_feature) } +} + +@_spi(Experimental) +extension GeofencingEvent { + /// Create `GeofenceEvent` + @_spi(Experimental) + public init(feature: Turf.Feature, timestamp: Date) { + self.init(_feature: MapboxCommon.Feature(feature), timestamp: timestamp) + } + + /// The feature linked to this event + @_spi(Experimental) + public var feature: Turf.Feature { Turf.Feature(_feature) } +} + +@_spi(Experimental) +extension GeofencingService { + /// Adds a feature to be monitored for geofencing activities. + /// You can add extra properties (see GeofencingPropertiesKeys) to the Feature to configure how geofencing engine behaves per each specific feature. + /// If a feature with the same ID already exist it will be overwritten and its state reset + @_spi(Experimental) + public func addFeature(feature: Turf.Feature, callback: @escaping (Result) -> Void) { + self.addFeature(feature: MapboxCommon.Feature(feature)) { result in + callback(result) + } + } +}