`BaseItemPlacemarkManager` for single placemark managers added

This commit is contained in:
Vladimir Makarov 2023-03-12 19:37:03 +01:00
parent 511c2b9653
commit 9dca21afd9
6 changed files with 59 additions and 24 deletions

View File

@ -23,7 +23,7 @@
import TIMapUtils
import MapKit
open class ApplePlacemarkManager<Model>: BasePlacemarkManager<MKAnnotationView, Model, CLLocationCoordinate2D>,
open class ApplePlacemarkManager<Model>: BaseItemPlacemarkManager<MKAnnotationView, Model, CLLocationCoordinate2D>,
MKAnnotation {
// MARK: - MKAnnotation
@ -36,12 +36,9 @@ open class ApplePlacemarkManager<Model>: BasePlacemarkManager<MKAnnotationView,
/// Point (coordinates) itself of the current placemark manager
public var coordinate: CLLocationCoordinate2D {
placemarkPosition ?? .init()
placemarkPosition
}
/// Placemark itself of the current placemark manager
public private(set) var placemark: MKAnnotationView?
/// The current state of a manager's placemark
override public var state: MarkerState {
didSet {
@ -80,8 +77,9 @@ open class ApplePlacemarkManager<Model>: BasePlacemarkManager<MKAnnotationView,
// MARK: - PlacemarkManager
override open func configure(placemark: MKAnnotationView) {
// Setting initial values in cluster configuration and each placemark respectively
self.placemark = placemark
super.configure(placemark: placemark)
// Setting required values of the current manager and placemark respectively
self.placemark?.clusteringIdentifier = clusteringIdentifier
self.state = .default
}

View File

@ -114,7 +114,7 @@ open class GoogleClusterPlacemarkManager<Model>: BaseClusterPlacemarkManager<GMS
return false
}
return tapHandler?(placemarkManagers, .from(coordinates: placemarkManagers.compactMap { $0.position }) ?? .init()) ?? false
return tapHandler?(placemarkManagers, .from(coordinates: placemarkManagers.map(\.placemarkPosition)) ?? .init()) ?? false
}
open func clusterManager(_ clusterManager: GMUClusterManager, didTap clusterItem: GMUClusterItem) -> Bool {

View File

@ -24,19 +24,16 @@ import TIMapUtils
import GoogleMaps
import GoogleMapsUtils
open class GooglePlacemarkManager<Model>: BasePlacemarkManager<GMSMarker, Model, CLLocationCoordinate2D>,
open class GooglePlacemarkManager<Model>: BaseItemPlacemarkManager<GMSMarker, Model, CLLocationCoordinate2D>,
GMUClusterItem {
// MARK: - GMUClusterItem
/// Point (coordinates) itself of the current placemark manager
public var position: CLLocationCoordinate2D {
placemarkPosition ?? .init()
placemarkPosition
}
/// Placemark itself of the current placemark manager
public private(set) var placemark: GMSMarker?
/// The current state of a manager's placemark
override public var state: MarkerState {
didSet {
@ -62,8 +59,7 @@ open class GooglePlacemarkManager<Model>: BasePlacemarkManager<GMSMarker, Model,
// MARK: - PlacemarkManager
override open func configure(placemark: GMSMarker) {
// Setting initial values in cluster configuration and each placemark respectively
self.placemark = placemark
super.configure(placemark: placemark)
/*
Note: it is required not to just resetting a state but setting a value depending

View File

@ -24,9 +24,9 @@
Base cluster placemark manager
- Parameters:
- `ClusterPlacemark`: a generic parameter describing a cluster placemark itself
- `ItemPlacemarkManager`: a single placemarks manager element of array for a cluster
- `ClusterBounds`: a collection of cluster placemark objects
- ClusterPlacemark: a generic parameter describing a cluster placemark itself
- ItemPlacemarkManager: a single placemarks manager element of array for a cluster
- ClusterBounds: a rectangle area of the current cluster or a collection of cluster placemark objects
*/
open class BaseClusterPlacemarkManager<ClusterPlacemark, ItemPlacemarkManager: PlacemarkManager, ClusterBounds>:
BasePlacemarkManager<ClusterPlacemark, [ItemPlacemarkManager], ClusterBounds> where ItemPlacemarkManager.Position : Equatable {

View File

@ -0,0 +1,43 @@
//
// Copyright (c) 2023 Touch Instinct
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the Software), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
/**
Base single item placemark manager
Contains all properties of `BasePlacemarkManager` and adds a `placemark` property to use
- Parameters:
- Placemark: a placemark itself managed by an item placemark manager
- DataModel: a data model of a placemark which is used for configuration etc.
- Location: latitude and longitude of a placemark
*/
open class BaseItemPlacemarkManager<Placemark, DataModel, Location>: BasePlacemarkManager<Placemark, DataModel, Location> {
/// Placemark itself of the current placemark manager
public private(set) var placemark: Placemark?
override open func configure(placemark: Placemark) {
super.configure(placemark: placemark)
self.placemark = placemark
}
}

View File

@ -23,12 +23,9 @@
import TIMapUtils
import YandexMapsMobile
open class YandexPlacemarkManager<Model>: BasePlacemarkManager<YMKPlacemarkMapObject, Model, YMKPoint>,
open class YandexPlacemarkManager<Model>: BaseItemPlacemarkManager<YMKPlacemarkMapObject, Model, YMKPoint>,
YMKMapObjectTapListener {
/// Placemark itself of the current placemark manager
public private(set) var placemark: YMKPlacemarkMapObject?
/// The current state of a manager's placemark
override public var state: MarkerState {
didSet {
@ -71,8 +68,9 @@ open class YandexPlacemarkManager<Model>: BasePlacemarkManager<YMKPlacemarkMapOb
// MARK: - PlacemarkManager
override open func configure(placemark: YMKPlacemarkMapObject) {
// Setting initial values in cluster configuration and each placemark respectively
self.placemark = placemark
super.configure(placemark: placemark)
// Setting initial value of the current placemark state
self.state = .default
// Setting tap listener for a pin tap handling