-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
2,128 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,28 @@ | ||
# TerraIncognita | ||
One map library to rule them all. | ||
|
||
The idea of TerraIncognita is to provide a common API for several maps libraries. | ||
|
||
## Roadmap | ||
### v1.0 (MVP) | ||
#### v0.1 | ||
1. Core Objects: | ||
* configurable map manager | ||
* add/remove markers | ||
* markers storage | ||
1. AMaps core objects | ||
1. GMaps core objects | ||
#### v0.2 | ||
1. markers filtering according to map view region change | ||
1. markers customization (image) | ||
1. markers clustering | ||
#### v0.3 | ||
1. map interaction delegate | ||
* markers selection | ||
* user location change | ||
#### v0.4 | ||
1. shapes | ||
* line | ||
* polygon | ||
* circle | ||
1. shapes customization |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// AMapsManager.swift | ||
// TerraIncognitaExample | ||
// | ||
// Created by Valeriy Bezuglyy on 29/07/2017. | ||
// Copyright © 2017 Valeriy Bezuglyy. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol AMapsManagerDelegate:TerraManagerDelegate { | ||
} | ||
|
||
protocol AMapsManager: TerraManager { | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// AMapsManagerConfig.swift | ||
// TerraIncognitaExample | ||
// | ||
// Created by Valeriy Bezuglyy on 29/07/2017. | ||
// Copyright © 2017 Valeriy Bezuglyy. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol AMapsManagerConfig: TerraManagerConfig { | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// AMapsManagerBase.swift | ||
// TerraIncognitaExample | ||
// | ||
// Created by Valeriy Bezuglyy on 29/07/2017. | ||
// Copyright © 2017 Valeriy Bezuglyy. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class AMapsManagerObj: TerraManagerBase { | ||
|
||
weak var aMapsDelegate: AMapsManagerDelegate? { | ||
get{ | ||
return delegate as? AMapsManagerDelegate | ||
} | ||
set{ | ||
delegate = newValue | ||
} | ||
} | ||
|
||
init(config: AMapsManagerConfig) { | ||
super.init(config: config) | ||
viewObjectsPool = AMapsViewObjectsPool() | ||
} | ||
|
||
//MARK: - markers | ||
|
||
//MARK: - view | ||
override func makeTerraView() -> TerraView { | ||
view = AMapsView() | ||
return view! | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// TerraRegion+AMaps.swift | ||
// TerraIncognitaExample | ||
// | ||
// Created by Valeriy Bezuglyy on 20/08/2017. | ||
// Copyright © 2017 Valeriy Bezuglyy. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import MapKit | ||
|
||
extension TerraRegion { | ||
convenience init(mkCoordinateRegion: MKCoordinateRegion) { | ||
let center = mkCoordinateRegion.center | ||
let deltaLat = mkCoordinateRegion.span.latitudeDelta | ||
let deltaLon = mkCoordinateRegion.span.longitudeDelta | ||
|
||
self.init(topLeft: CLLocationCoordinate2D(latitude: center.latitude + deltaLat, | ||
longitude: center.longitude - deltaLon), | ||
topRight: CLLocationCoordinate2D(latitude: center.latitude + deltaLat, | ||
longitude: center.longitude + deltaLon), | ||
bottomLeft: CLLocationCoordinate2D(latitude: center.latitude - deltaLat, | ||
longitude: center.longitude - deltaLon), | ||
bottomRight: CLLocationCoordinate2D(latitude: center.latitude - deltaLat, | ||
longitude: center.longitude + deltaLon)) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// TerraView.swift | ||
// TerraIncognitaExample | ||
// | ||
// Created by Valeriy Bezuglyy on 29/07/2017. | ||
// Copyright © 2017 Valeriy Bezuglyy. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import MapKit | ||
|
||
class AMapsView: MKMapView { | ||
|
||
// required init?(coder aDecoder: NSCoder) { | ||
// fatalError("init(coder:) has not been implemented") | ||
// } | ||
} | ||
|
||
extension AMapsView: TerraView { | ||
func view() -> UIView { | ||
return self | ||
} | ||
|
||
func currentRegion() -> TerraRegion { | ||
let mkRegion = region | ||
let terraRegion = TerraRegion(mkCoordinateRegion: mkRegion) | ||
return terraRegion | ||
} | ||
|
||
func updateViewMarkers(add viewMarkersToAdd: [TerraViewMarker], remove viewMarkersToRemove: [TerraViewMarker]) { | ||
DispatchQueue.main.async { [weak self] in | ||
guard let __self = self else { return } | ||
__self.delegate = __self | ||
__self.removeAnnotations(viewMarkersToRemove as! [AMapsViewMarker]) | ||
__self.addAnnotations(viewMarkersToAdd as! [AMapsViewMarker]) | ||
} | ||
} | ||
} | ||
|
||
extension AMapsView: MKMapViewDelegate { | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// TerraViewMarker.swift | ||
// TerraIncognitaExample | ||
// | ||
// Created by Valeriy Bezuglyy on 30/07/2017. | ||
// Copyright © 2017 Valeriy Bezuglyy. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import MapKit | ||
|
||
class AMapsViewMarker: NSObject, TerraViewMarker { | ||
var terra_markerId: String! | ||
var terra_reuseIdentifier: String? | ||
var terra_coordinate: CLLocationCoordinate2D! | ||
} | ||
|
||
extension AMapsViewMarker: MKAnnotation { | ||
public var coordinate: CLLocationCoordinate2D { | ||
get{ | ||
return terra_coordinate | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// TerraViewObjectsPool.swift | ||
// TerraIncognitaExample | ||
// | ||
// Created by Valeriy Bezuglyy on 30/07/2017. | ||
// Copyright © 2017 Valeriy Bezuglyy. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import MapKit | ||
|
||
class AMapsViewObjectsPool: TerraViewObjectsPool { | ||
|
||
//MARK: viewMarkers | ||
override func makeViewMarker(_ markerId: String, reuseIdentifier: String?) -> TerraViewMarker { | ||
let viewMarker = AMapsViewMarker() | ||
viewMarker.terra_markerId = markerId | ||
viewMarker.terra_reuseIdentifier = reuseIdentifier | ||
return viewMarker | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// TerraManager.swift | ||
// TerraIncognitaExample | ||
// | ||
// Created by Valeriy Bezuglyy on 29/07/2017. | ||
// Copyright © 2017 Valeriy Bezuglyy. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol TerraManagerDelegate:class { | ||
} | ||
|
||
protocol TerraManager: class { | ||
weak var delegate:TerraManagerDelegate? {get set} | ||
|
||
//MARK: - markers | ||
func reloadMarkers(_ newMarkers:[TerraMarker]) | ||
func reloadMarkers(add markersToAdd:[TerraMarker], remove markerIdsToRemove:[String]) | ||
|
||
//MARK - view | ||
var terraView: TerraView? {get} | ||
func makeTerraView() -> TerraView | ||
} |
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// TerraManagerBase.swift | ||
// TerraIncognitaExample | ||
// | ||
// Created by Valeriy Bezuglyy on 29/07/2017. | ||
// Copyright © 2017 Valeriy Bezuglyy. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class TerraManagerBase: TerraManager { | ||
|
||
weak var delegate:TerraManagerDelegate? | ||
var storage: TerraStorage | ||
var view: TerraView? | ||
var viewObjectsPool: TerraViewObjectsPool | ||
var updateViewQueue:DispatchQueue | ||
|
||
init(config:TerraManagerConfig) { | ||
storage = TerraStorage() | ||
updateViewQueue = DispatchQueue(label: "TerraManagerBase_updateViewQueue") | ||
viewObjectsPool = TerraViewObjectsPool() | ||
} | ||
|
||
//MARK: - markers | ||
func reloadMarkers(_ newMarkers:[TerraMarker]) { | ||
storage.reloadMarkers(newMarkers) { [weak self] (markers) in | ||
guard let __self = self else { return } | ||
__self.updateViewMarkersOnTerraView(markers) | ||
} | ||
} | ||
|
||
func reloadMarkers(add markersToAdd:[TerraMarker], remove markerIdsToRemove:[String]) { | ||
storage.reloadMarkers(add: markersToAdd, remove: markerIdsToRemove) { [weak self] (markers) in | ||
guard let __self = self else { return } | ||
__self.updateViewMarkersOnTerraView(markers) | ||
} | ||
} | ||
|
||
//MARK: - view | ||
var terraView: TerraView? { | ||
get{ | ||
return view | ||
} | ||
} | ||
|
||
func makeTerraView() -> TerraView { | ||
fatalError(debugMessage_notImplemented) | ||
} | ||
|
||
fileprivate func updateViewMarkersOnTerraView(_ markers:[TerraMarker]) { | ||
updateViewQueue.async { [weak self] in | ||
guard let __self = self else { return } | ||
guard let terraView = __self.terraView else { return } | ||
|
||
// let region = terraView.currentRegion() | ||
// let markersInside = markers.filter({ region.containsCoordinate($0.coordinate) }) | ||
let markersInside = markers | ||
|
||
__self.showActualViewMarkersOnTerraView(markersInside) | ||
} | ||
} | ||
|
||
fileprivate func showActualViewMarkersOnTerraView(_ actualMarkers:[TerraMarker]) { | ||
var actualViewMarkers:[TerraViewMarker] = [] | ||
for item in actualMarkers { | ||
let viewMarker = viewObjectsPool.dequeueReusableViewMarker(item._id, reuseIdentifier: item.reuseIdentifier) | ||
configure(viewMarker, with: item) | ||
actualViewMarkers.append(viewMarker) | ||
} | ||
|
||
let otherViewMarkers:[TerraViewMarker] = viewObjectsPool.otherUsedViewMarkers(actualViewMarkers) | ||
viewObjectsPool.enqueueReusableViewMarkers(otherViewMarkers) | ||
|
||
if let terraView = terraView { | ||
terraView.updateViewMarkers(add: actualViewMarkers, | ||
remove: otherViewMarkers) | ||
} | ||
} | ||
|
||
//MARK: - view marker | ||
func configure(_ viewMarker:TerraViewMarker, with terraMarker:TerraMarker) { | ||
viewMarker.terra_markerId = terraMarker._id | ||
viewMarker.terra_reuseIdentifier = terraMarker.reuseIdentifier | ||
viewMarker.terra_coordinate = terraMarker.coordinate | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// TerraManagerConfig.swift | ||
// TerraIncognitaExample | ||
// | ||
// Created by Valeriy Bezuglyy on 29/07/2017. | ||
// Copyright © 2017 Valeriy Bezuglyy. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol TerraManagerConfig { | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// TerraMarker.swift | ||
// TerraIncognitaExample | ||
// | ||
// Created by Valeriy Bezuglyy on 29/07/2017. | ||
// Copyright © 2017 Valeriy Bezuglyy. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CoreLocation | ||
|
||
class TerraMarker { | ||
var _id: String | ||
var coordinate: CLLocationCoordinate2D | ||
var reuseIdentifier: String? | ||
|
||
init(_id: String, | ||
coordinate: CLLocationCoordinate2D) { | ||
self._id = _id | ||
self.coordinate = coordinate | ||
} | ||
} |
Oops, something went wrong.