Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline map #251

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "approved.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "original"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "unchecked.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "original"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions mapkit-samples/Common/Utils/UserStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation

final class UserStorage {
private enum Keys {
static let isCellularNetwork = "Is cellular network"
static let isAutoUpdate = "Is auto update"
}

static var isCellularNetwork: Bool {
get {
return UserDefaults.standard.bool(forKey: Keys.isCellularNetwork)
}
set {
UserDefaults.standard.set(newValue, forKey: Keys.isCellularNetwork)
}
}

static var isAutoUpdate: Bool {
get {
return UserDefaults.standard.bool(forKey: Keys.isAutoUpdate)
}
set {
UserDefaults.standard.set(newValue, forKey: Keys.isAutoUpdate)
}
}
}
33 changes: 33 additions & 0 deletions mapkit-samples/MapOffline/DataMoveListener.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// MapCameraListener.swift
// MapSearch
//

import YandexMapsMobile

class DataMoveListener: NSObject, YMKOfflineCacheDataMoveListener {

// MARK: - Constructor

init(optionViewModel: OptionsViewModel) {
self.optionViewModel = optionViewModel
}

// MARK: - Public methods

func onDataMoveProgress(withPercent percent: Int) {
optionViewModel.progress = Float(percent)
}

func onDataMoveCompleted() {
optionViewModel.isSuccessMove = true
}

func onDataMoveErrorWithError(_ error: any Error) {
optionViewModel.errorText = error.localizedDescription
}

// MARK: - Private properties

private let optionViewModel: OptionsViewModel
}
31 changes: 31 additions & 0 deletions mapkit-samples/MapOffline/MapCameraListener.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// MapCameraListener.swift
// MapSearch
//

import YandexMapsMobile

class MapCameraListener: NSObject, YMKMapCameraListener {
// MARK: - Constructor

init(searchViewModel: SearchViewModel) {
self.searchViewModel = searchViewModel
}

// MARK: - Public methods

func onCameraPositionChanged(
with map: YMKMap,
cameraPosition: YMKCameraPosition,
cameraUpdateReason: YMKCameraUpdateReason,
finished: Bool
) {
if cameraUpdateReason == .gestures {
searchViewModel.setVisibleRegion(with: map.visibleRegion)
}
}

// MARK: - Private properties

private let searchViewModel: SearchViewModel
}
35 changes: 35 additions & 0 deletions mapkit-samples/MapOffline/MapUIState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// MapUIState.swift
// MapSearch
//

import YandexMapsMobile

struct MapUIState {
let query: String
let searchState: SearchState
let regionListState: RegionListState

init(query: String = String(), searchState: SearchState, regionListState: RegionListState) {
self.query = query
self.searchState = searchState
self.regionListState = regionListState
}
}

struct SearchResponseItem {
let point: YMKPoint
let geoObject: YMKGeoObject?
}

enum SearchState {
case idle
case loading
case error
case success(items: [SearchResponseItem], zoomToItems: Bool, itemsBoundingBox: YMKBoundingBox)
}

enum RegionListState {
case idle
case success
}
Loading