Skip to content

Commit

Permalink
Merge branch 'release/v0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
valnoc committed Aug 23, 2017
2 parents b76a97b + 0dace12 commit 55b2a51
Show file tree
Hide file tree
Showing 42 changed files with 2,128 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
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
15 changes: 15 additions & 0 deletions TerraIncognita/AMaps/Manager/AMapsManager.swift
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 {
}
12 changes: 12 additions & 0 deletions TerraIncognita/AMaps/Manager/AMapsManagerConfig.swift
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 {
}
35 changes: 35 additions & 0 deletions TerraIncognita/AMaps/Manager/AMapsManagerObj.swift
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!
}

}
27 changes: 27 additions & 0 deletions TerraIncognita/AMaps/Other/TerraRegion+AMaps.swift
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))
}
}
42 changes: 42 additions & 0 deletions TerraIncognita/AMaps/View/AMapsView.swift
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 {

}
24 changes: 24 additions & 0 deletions TerraIncognita/AMaps/View/AMapsViewMarker.swift
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
}
}
}
21 changes: 21 additions & 0 deletions TerraIncognita/AMaps/View/AMapsViewObjectsPool.swift
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
}
}
24 changes: 24 additions & 0 deletions TerraIncognita/Core/Manager/TerraManager.swift
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
}
87 changes: 87 additions & 0 deletions TerraIncognita/Core/Manager/TerraManagerBase.swift
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
}
}
12 changes: 12 additions & 0 deletions TerraIncognita/Core/Manager/TerraManagerConfig.swift
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 {
}
22 changes: 22 additions & 0 deletions TerraIncognita/Core/Objects/TerraMarker.swift
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
}
}
Loading

0 comments on commit 55b2a51

Please sign in to comment.