@exterio/react-native-yamap-lite 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +510 -0
- package/YamapLite.podspec +21 -0
- package/android/build.gradle +101 -0
- package/android/gradle.properties +14 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/yamaplite/ClusteredYamapLiteViewManager.kt +181 -0
- package/android/src/main/java/com/yamaplite/Components/ClusteredYamapLiteView.kt +169 -0
- package/android/src/main/java/com/yamaplite/Components/YamapLiteCircleView.kt +145 -0
- package/android/src/main/java/com/yamaplite/Components/YamapLiteMarkerView.kt +214 -0
- package/android/src/main/java/com/yamaplite/Components/YamapLitePolygon.kt +149 -0
- package/android/src/main/java/com/yamaplite/Components/YamapLitePolyline.kt +171 -0
- package/android/src/main/java/com/yamaplite/Components/YamapLiteView.kt +678 -0
- package/android/src/main/java/com/yamaplite/Events/CameraPositionChangeEvent.kt +38 -0
- package/android/src/main/java/com/yamaplite/Events/MapLoadEvent.kt +34 -0
- package/android/src/main/java/com/yamaplite/Events/PressEvent.kt +24 -0
- package/android/src/main/java/com/yamaplite/Utils/ImageCache.kt +45 -0
- package/android/src/main/java/com/yamaplite/Utils/PointParser.kt +39 -0
- package/android/src/main/java/com/yamaplite/Utils/ResolveImageHelper.kt +122 -0
- package/android/src/main/java/com/yamaplite/Utils/YamapUtils.kt +169 -0
- package/android/src/main/java/com/yamaplite/YamapLiteCircleViewManager.kt +67 -0
- package/android/src/main/java/com/yamaplite/YamapLiteMarkerViewManager.kt +82 -0
- package/android/src/main/java/com/yamaplite/YamapLitePackage.kt +41 -0
- package/android/src/main/java/com/yamaplite/YamapLitePolygonViewManager.kt +61 -0
- package/android/src/main/java/com/yamaplite/YamapLitePolylineViewManager.kt +75 -0
- package/android/src/main/java/com/yamaplite/YamapLiteViewManager.kt +176 -0
- package/ios/ClusteredYamapLiteView.h +15 -0
- package/ios/ClusteredYamapLiteView.mm +325 -0
- package/ios/ClusteredYamapLiteViewManager.mm +17 -0
- package/ios/Components/Circle.swift +108 -0
- package/ios/Components/ClusteredYamap.swift +190 -0
- package/ios/Components/Marker.swift +187 -0
- package/ios/Components/Polygon.swift +108 -0
- package/ios/Components/Polyline.swift +125 -0
- package/ios/Components/Yamap.swift +585 -0
- package/ios/Listeners/CameraListener.swift +54 -0
- package/ios/Listeners/ClusterListener.swift +38 -0
- package/ios/Listeners/MapInputListener.swift +35 -0
- package/ios/Listeners/MapLoadListener.swift +35 -0
- package/ios/Listeners/MapObjectTap.swift +12 -0
- package/ios/Listeners/UserLocationObjectListener.swift +29 -0
- package/ios/Models/YamapModels.swift +77 -0
- package/ios/Utils/ImageCache.swift +20 -0
- package/ios/Utils/PointsEqual.h +45 -0
- package/ios/Utils/ResolveImageHelper.swift +142 -0
- package/ios/YamapLiteCircleView.h +15 -0
- package/ios/YamapLiteCircleView.mm +102 -0
- package/ios/YamapLiteMarkerView.h +15 -0
- package/ios/YamapLiteMarkerView.mm +102 -0
- package/ios/YamapLitePolygonView.h +15 -0
- package/ios/YamapLitePolygonView.mm +120 -0
- package/ios/YamapLitePolylineView.h +15 -0
- package/ios/YamapLitePolylineView.mm +115 -0
- package/ios/YamapLiteView.h +15 -0
- package/ios/YamapLiteView.mm +361 -0
- package/ios/YamapLiteViewManager.mm +17 -0
- package/ios/YamapUtils.h +5 -0
- package/ios/YamapUtils.mm +205 -0
- package/lib/module/@types/index.js +8 -0
- package/lib/module/@types/index.js.map +1 -0
- package/lib/module/ClusteredYamapLiteViewNativeComponent.ts +98 -0
- package/lib/module/Components/Circle.js +20 -0
- package/lib/module/Components/Circle.js.map +1 -0
- package/lib/module/Components/ClusteredYamap.js +133 -0
- package/lib/module/Components/ClusteredYamap.js.map +1 -0
- package/lib/module/Components/Marker.js +40 -0
- package/lib/module/Components/Marker.js.map +1 -0
- package/lib/module/Components/Polygon.js +25 -0
- package/lib/module/Components/Polygon.js.map +1 -0
- package/lib/module/Components/Polyline.js +25 -0
- package/lib/module/Components/Polyline.js.map +1 -0
- package/lib/module/Components/Yamap.js +124 -0
- package/lib/module/Components/Yamap.js.map +1 -0
- package/lib/module/Components/index.js +9 -0
- package/lib/module/Components/index.js.map +1 -0
- package/lib/module/NativeYamapUtils.js +5 -0
- package/lib/module/NativeYamapUtils.js.map +1 -0
- package/lib/module/Utils/YamapUtils.js +14 -0
- package/lib/module/Utils/YamapUtils.js.map +1 -0
- package/lib/module/YamapCircleViewNativeComponent.ts +28 -0
- package/lib/module/YamapLiteViewNativeComponent.ts +93 -0
- package/lib/module/YamapMarkerViewNativeComponent.ts +32 -0
- package/lib/module/YamapPolygonViewNativeComponent.ts +28 -0
- package/lib/module/YamapPolylineViewNativeComponent.ts +31 -0
- package/lib/module/index.js +7 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/@types/index.d.ts +257 -0
- package/lib/typescript/src/@types/index.d.ts.map +1 -0
- package/lib/typescript/src/ClusteredYamapLiteViewNativeComponent.d.ts +82 -0
- package/lib/typescript/src/ClusteredYamapLiteViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/Components/Circle.d.ts +4 -0
- package/lib/typescript/src/Components/Circle.d.ts.map +1 -0
- package/lib/typescript/src/Components/ClusteredYamap.d.ts +3 -0
- package/lib/typescript/src/Components/ClusteredYamap.d.ts.map +1 -0
- package/lib/typescript/src/Components/Marker.d.ts +3 -0
- package/lib/typescript/src/Components/Marker.d.ts.map +1 -0
- package/lib/typescript/src/Components/Polygon.d.ts +4 -0
- package/lib/typescript/src/Components/Polygon.d.ts.map +1 -0
- package/lib/typescript/src/Components/Polyline.d.ts +4 -0
- package/lib/typescript/src/Components/Polyline.d.ts.map +1 -0
- package/lib/typescript/src/Components/Yamap.d.ts +3 -0
- package/lib/typescript/src/Components/Yamap.d.ts.map +1 -0
- package/lib/typescript/src/Components/index.d.ts +7 -0
- package/lib/typescript/src/Components/index.d.ts.map +1 -0
- package/lib/typescript/src/NativeYamapUtils.d.ts +30 -0
- package/lib/typescript/src/NativeYamapUtils.d.ts.map +1 -0
- package/lib/typescript/src/Utils/YamapUtils.d.ts +27 -0
- package/lib/typescript/src/Utils/YamapUtils.d.ts.map +1 -0
- package/lib/typescript/src/YamapCircleViewNativeComponent.d.ts +20 -0
- package/lib/typescript/src/YamapCircleViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/YamapLiteViewNativeComponent.d.ts +80 -0
- package/lib/typescript/src/YamapLiteViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/YamapMarkerViewNativeComponent.d.ts +25 -0
- package/lib/typescript/src/YamapMarkerViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/YamapPolygonViewNativeComponent.d.ts +20 -0
- package/lib/typescript/src/YamapPolygonViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/YamapPolylineViewNativeComponent.d.ts +23 -0
- package/lib/typescript/src/YamapPolylineViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +189 -0
- package/src/@types/index.ts +314 -0
- package/src/ClusteredYamapLiteViewNativeComponent.ts +98 -0
- package/src/Components/Circle.tsx +22 -0
- package/src/Components/ClusteredYamap.tsx +194 -0
- package/src/Components/Marker.tsx +50 -0
- package/src/Components/Polygon.tsx +27 -0
- package/src/Components/Polyline.tsx +27 -0
- package/src/Components/Yamap.tsx +176 -0
- package/src/Components/index.ts +6 -0
- package/src/NativeYamapUtils.ts +47 -0
- package/src/Utils/YamapUtils.ts +63 -0
- package/src/YamapCircleViewNativeComponent.ts +28 -0
- package/src/YamapLiteViewNativeComponent.ts +93 -0
- package/src/YamapMarkerViewNativeComponent.ts +32 -0
- package/src/YamapPolygonViewNativeComponent.ts +28 -0
- package/src/YamapPolylineViewNativeComponent.ts +31 -0
- package/src/index.tsx +5 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import React
|
|
3
|
+
import YandexMapsMobile
|
|
4
|
+
|
|
5
|
+
class MapInputListener: NSObject, YMKMapInputListener {
|
|
6
|
+
private weak var delegate: YamapViewComponentDelegate?
|
|
7
|
+
|
|
8
|
+
init(delegate: YamapViewComponentDelegate?) {
|
|
9
|
+
self.delegate = delegate
|
|
10
|
+
super.init()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
func onMapTap(with map: YMKMap, point: YMKPoint) {
|
|
14
|
+
let coords: [String: Any] = [
|
|
15
|
+
"lat": point.latitude,
|
|
16
|
+
"lon": point.longitude
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
DispatchQueue.main.async { [weak self] in
|
|
20
|
+
self?.delegate?.handleOnMapPress(coords: coords)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func onMapLongTap(with map: YMKMap, point: YMKPoint) {
|
|
25
|
+
let coords: [String: Any] = [
|
|
26
|
+
"lat": point.latitude,
|
|
27
|
+
"lon": point.longitude
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
DispatchQueue.main.async { [weak self] in
|
|
31
|
+
self?.delegate?.handleOnMapLongPress(coords: coords)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import React
|
|
3
|
+
import YandexMapsMobile
|
|
4
|
+
|
|
5
|
+
class MapLoadListener: NSObject, YMKMapLoadedListener {
|
|
6
|
+
private var callback: RCTDirectEventBlock?
|
|
7
|
+
private weak var mapDelegate: YamapViewComponentDelegate?
|
|
8
|
+
init(callback: RCTDirectEventBlock?, mapDelegate: YamapViewComponentDelegate?) {
|
|
9
|
+
self.callback = callback
|
|
10
|
+
self.mapDelegate = mapDelegate
|
|
11
|
+
super.init()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
func onMapLoaded(with statistics: YMKMapLoadStatistics) {
|
|
15
|
+
let params: [String: Any] = [
|
|
16
|
+
"renderObjectCount": statistics.renderObjectCount,
|
|
17
|
+
"curZoomModelsLoaded": statistics.curZoomModelsLoaded,
|
|
18
|
+
"curZoomPlacemarksLoaded": statistics.curZoomPlacemarksLoaded,
|
|
19
|
+
"curZoomLabelsLoaded": statistics.curZoomLabelsLoaded,
|
|
20
|
+
"curZoomGeometryLoaded": statistics.curZoomGeometryLoaded,
|
|
21
|
+
"tileMemoryUsage": statistics.tileMemoryUsage,
|
|
22
|
+
"delayedGeometryLoaded": statistics.delayedGeometryLoaded,
|
|
23
|
+
"fullyAppeared": statistics.fullyAppeared,
|
|
24
|
+
"fullyLoaded": statistics.fullyLoaded,
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
DispatchQueue.main.async { [weak self] in
|
|
28
|
+
if let callback = self?.callback {
|
|
29
|
+
callback(params)
|
|
30
|
+
} else if let delegate = self?.mapDelegate {
|
|
31
|
+
delegate.handleOnMapLoaded(result: params)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import YandexMapsMobile
|
|
3
|
+
|
|
4
|
+
@objc class MarkerTapListener: NSObject, YMKMapObjectTapListener {
|
|
5
|
+
func onMapObjectTap(with mapObject: YMKMapObject, point: YMKPoint) -> Bool {
|
|
6
|
+
if let handler = mapObject.userData as? MapObjectTapHandler {
|
|
7
|
+
handler.onMapObjectTap(point: point)
|
|
8
|
+
return handler.handled
|
|
9
|
+
}
|
|
10
|
+
return false
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import React
|
|
3
|
+
import YandexMapsMobile
|
|
4
|
+
|
|
5
|
+
@objc(UserLocationObjectListener)
|
|
6
|
+
class UserLocationObjectListener: NSObject, YMKUserLocationObjectListener {
|
|
7
|
+
var userLocationView: YMKUserLocationView?
|
|
8
|
+
|
|
9
|
+
var cb: (() -> Void)?
|
|
10
|
+
|
|
11
|
+
init(callback: @escaping () -> Void) {
|
|
12
|
+
cb = callback
|
|
13
|
+
super.init()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
func onObjectAdded(with view: YMKUserLocationView) {
|
|
17
|
+
userLocationView = view
|
|
18
|
+
cb?()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func onObjectRemoved(with _: YMKUserLocationView) {
|
|
22
|
+
//
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func onObjectUpdated(with view: YMKUserLocationView, event _: YMKObjectEvent) {
|
|
26
|
+
userLocationView = view
|
|
27
|
+
cb?()
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import YandexMapsMobile
|
|
3
|
+
|
|
4
|
+
@objc public protocol MapObject {
|
|
5
|
+
var zIndex: Float { get }
|
|
6
|
+
var handled: Bool { get }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@objc public protocol MapObjectTapHandler: AnyObject {
|
|
10
|
+
var handled: Bool { get }
|
|
11
|
+
var mapObject: YMKMapObject? { get }
|
|
12
|
+
func setMapObject(object: YMKMapObject)
|
|
13
|
+
var zIndex: Float { get }
|
|
14
|
+
func onMapObjectTap(point: YMKPoint)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
struct Point {
|
|
18
|
+
let lat: Double
|
|
19
|
+
let lon: Double
|
|
20
|
+
|
|
21
|
+
init(lat: Double = 0.0, lon: Double = 0.0) {
|
|
22
|
+
self.lat = lat
|
|
23
|
+
self.lon = lon
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
struct Anchor {
|
|
28
|
+
let x: Double
|
|
29
|
+
let y: Double
|
|
30
|
+
|
|
31
|
+
init(x: Double = 0.5, y: Double = 0.5) {
|
|
32
|
+
self.x = x
|
|
33
|
+
self.y = y
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
struct Coordinate {
|
|
38
|
+
let latitude: Double
|
|
39
|
+
let longitude: Double
|
|
40
|
+
let zoom: Float?
|
|
41
|
+
let azimuth: Float?
|
|
42
|
+
let tilt: Float?
|
|
43
|
+
|
|
44
|
+
init(latitude: Double = 0.0, longitude: Double = 0.0, zoom: Float?, azimuth: Float?, tilt: Float?) {
|
|
45
|
+
self.latitude = latitude
|
|
46
|
+
self.longitude = longitude
|
|
47
|
+
self.zoom = zoom
|
|
48
|
+
self.azimuth = azimuth
|
|
49
|
+
self.tilt = tilt
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
struct LogoPosition {
|
|
54
|
+
var horizontal = YMKLogoHorizontalAlignment.right
|
|
55
|
+
var vertical = YMKLogoVerticalAlignment.bottom
|
|
56
|
+
init(position: NSObject) {
|
|
57
|
+
guard let horizontalPosition = position.value(forKey: "horizontal") as? String,
|
|
58
|
+
let verticalPosition = position.value(forKey: "vertical") as? String
|
|
59
|
+
else {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
switch horizontalPosition {
|
|
63
|
+
case "left":
|
|
64
|
+
horizontal = YMKLogoHorizontalAlignment.left
|
|
65
|
+
case "center":
|
|
66
|
+
horizontal = YMKLogoHorizontalAlignment.center
|
|
67
|
+
default:
|
|
68
|
+
horizontal = YMKLogoHorizontalAlignment.right
|
|
69
|
+
}
|
|
70
|
+
switch verticalPosition {
|
|
71
|
+
case "top":
|
|
72
|
+
vertical = YMKLogoVerticalAlignment.top
|
|
73
|
+
default:
|
|
74
|
+
vertical = YMKLogoVerticalAlignment.bottom
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
public class ImageCache {
|
|
5
|
+
static let shared = ImageCache()
|
|
6
|
+
private let cache = NSCache<NSString, UIImage>()
|
|
7
|
+
private let cacheSize = 50 * 1024 * 1024 // 50 МБ в байтах
|
|
8
|
+
|
|
9
|
+
private init() {
|
|
10
|
+
cache.totalCostLimit = cacheSize
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
func setObject(_ image: UIImage, forKey key: NSString, cost: Int) {
|
|
14
|
+
cache.setObject(image, forKey: key, cost: cost)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
func objectForKey(_ key: NSString) -> UIImage? {
|
|
18
|
+
return cache.object(forKey: key)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#ifdef __cplusplus
|
|
4
|
+
|
|
5
|
+
#include <cstddef>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
namespace yamaplite {
|
|
9
|
+
|
|
10
|
+
template <typename Coord>
|
|
11
|
+
inline bool latLonEqual(const Coord &a, const Coord &b) {
|
|
12
|
+
return a.lat == b.lat && a.lon == b.lon;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
template <typename Coord>
|
|
16
|
+
inline bool pointsEqual(const std::vector<Coord> &lhs,
|
|
17
|
+
const std::vector<Coord> &rhs) {
|
|
18
|
+
if (lhs.size() != rhs.size()) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
for (size_t i = 0; i < lhs.size(); ++i) {
|
|
22
|
+
if (!latLonEqual(lhs[i], rhs[i])) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
template <typename Coord>
|
|
30
|
+
inline bool ringsEqual(const std::vector<std::vector<Coord>> &lhs,
|
|
31
|
+
const std::vector<std::vector<Coord>> &rhs) {
|
|
32
|
+
if (lhs.size() != rhs.size()) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
for (size_t i = 0; i < lhs.size(); ++i) {
|
|
36
|
+
if (!pointsEqual(lhs[i], rhs[i])) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
} // namespace yamaplite
|
|
44
|
+
|
|
45
|
+
#endif
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
import YandexMapsMobile
|
|
4
|
+
import os.log
|
|
5
|
+
|
|
6
|
+
private let logger = OSLog(subsystem: "com.yamaplite", category: "ResolveImageHelper")
|
|
7
|
+
|
|
8
|
+
public class ResolveImageHelper {
|
|
9
|
+
// MARK: - Singleton
|
|
10
|
+
public static let shared = ResolveImageHelper()
|
|
11
|
+
|
|
12
|
+
// MARK: - Properties
|
|
13
|
+
var iconSize: NSNumber?
|
|
14
|
+
var source: String?
|
|
15
|
+
var lastSource: String?
|
|
16
|
+
|
|
17
|
+
private let session: URLSession = {
|
|
18
|
+
let config = URLSessionConfiguration.default
|
|
19
|
+
config.timeoutIntervalForRequest = 30.0
|
|
20
|
+
config.timeoutIntervalForResource = 60.0
|
|
21
|
+
config.requestCachePolicy = .reloadIgnoringLocalCacheData
|
|
22
|
+
return URLSession(configuration: config)
|
|
23
|
+
}()
|
|
24
|
+
|
|
25
|
+
private init() {}
|
|
26
|
+
|
|
27
|
+
func resolveUIImage(uri: NSString, completion: ((UIImage?) -> Void)? = nil) -> UIImage? {
|
|
28
|
+
guard !uri.isEqual(to: "") else {
|
|
29
|
+
os_log("URI is nil or empty", log: logger, type: .error)
|
|
30
|
+
completion?(nil)
|
|
31
|
+
return nil
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if uri.hasPrefix("file://") || uri.hasPrefix("/") {
|
|
35
|
+
var url = URL(string: uri as String)
|
|
36
|
+
if url == nil {
|
|
37
|
+
url = URL(fileURLWithPath: uri as String)
|
|
38
|
+
}
|
|
39
|
+
guard let fileURL = url else {
|
|
40
|
+
os_log("Failed to create URL from URI: %@", log: logger, type: .error, uri)
|
|
41
|
+
completion?(nil)
|
|
42
|
+
return nil
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
guard let imageData = try? Data(contentsOf: fileURL) else {
|
|
46
|
+
os_log("Failed to load image data from URL: %@", log: logger, type: .error, uri)
|
|
47
|
+
completion?(nil)
|
|
48
|
+
return nil
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
guard let icon = UIImage(data: imageData) else {
|
|
52
|
+
os_log("Failed to create image from data: %@", log: logger, type: .error, uri)
|
|
53
|
+
completion?(nil)
|
|
54
|
+
return nil
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let width: CGFloat =
|
|
58
|
+
(iconSize?.floatValue ?? 0) > 0 ? CGFloat(iconSize!.floatValue) : icon.size.width
|
|
59
|
+
let resized = self.resizeImage(icon, toWidth: width)
|
|
60
|
+
|
|
61
|
+
let cost = Int(resized.size.width * resized.size.height * resized.scale * resized.scale * 4)
|
|
62
|
+
ImageCache.shared.setObject(resized, forKey: uri, cost: cost)
|
|
63
|
+
completion?(resized)
|
|
64
|
+
return resized
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if let cached = ImageCache.shared.objectForKey(uri) {
|
|
68
|
+
completion?(cached)
|
|
69
|
+
return cached
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
var url = URL(string: uri as String)
|
|
73
|
+
if url == nil {
|
|
74
|
+
url = URL(fileURLWithPath: uri as String)
|
|
75
|
+
}
|
|
76
|
+
guard let imageURL = url else {
|
|
77
|
+
os_log("Failed to create URL from URI: %@", log: logger, type: .error, uri)
|
|
78
|
+
completion?(nil)
|
|
79
|
+
return nil
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
loadImageAsync(uri: uri, withURL: imageURL, completion: completion)
|
|
83
|
+
return nil
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func loadImageAsync(uri: NSString, withURL url: URL, completion: ((UIImage?) -> Void)? = nil) {
|
|
87
|
+
guard !uri.isEqual(to: "") else {
|
|
88
|
+
completion?(nil)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
if let cached = ImageCache.shared.objectForKey(uri) {
|
|
92
|
+
completion?(cached)
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let task = session.dataTask(with: url) { data, response, error in
|
|
97
|
+
if let error = error {
|
|
98
|
+
os_log("Network error loading image %@: %@", log: logger, type: .error, uri, error.localizedDescription)
|
|
99
|
+
completion?(nil)
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode < 200 || httpResponse.statusCode >= 300 {
|
|
104
|
+
os_log("HTTP %d while loading image %@", log: logger, type: .error, httpResponse.statusCode, uri)
|
|
105
|
+
completion?(nil)
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
guard let imageData = data else {
|
|
110
|
+
os_log("No data received from URL: %@", log: logger, type: .error, uri)
|
|
111
|
+
completion?(nil)
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
guard let image = UIImage(data: imageData) else {
|
|
116
|
+
os_log("Failed to decode image data (%d bytes) from: %@", log: logger, type: .error, imageData.count, uri)
|
|
117
|
+
completion?(nil)
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let cost = Int(image.size.width * image.size.height * image.scale * image.scale * 4)
|
|
122
|
+
ImageCache.shared.setObject(image, forKey: uri, cost: cost)
|
|
123
|
+
|
|
124
|
+
DispatchQueue.main.async {
|
|
125
|
+
completion?(image)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
task.resume()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
func resizeImage(_ image: UIImage, toWidth width: CGFloat) -> UIImage {
|
|
133
|
+
guard image.size.width > 0 && image.size.height > 0 else { return image }
|
|
134
|
+
let scaleFactor = width / image.size.width
|
|
135
|
+
let newSize = CGSize(width: width, height: image.size.height * scaleFactor)
|
|
136
|
+
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
|
|
137
|
+
image.draw(in: CGRect(origin: .zero, size: newSize))
|
|
138
|
+
let newImage = UIGraphicsGetImageFromCurrentImageContext()
|
|
139
|
+
UIGraphicsEndImageContext()
|
|
140
|
+
return newImage ?? image
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#import <React/RCTViewComponentView.h>
|
|
2
|
+
#import <React/RCTViewManager.h>
|
|
3
|
+
#import <UIKit/UIKit.h>
|
|
4
|
+
|
|
5
|
+
#ifndef YamapLiteCircleViewNativeComponent_h
|
|
6
|
+
#define YamapLiteCircleViewNativeComponent_h
|
|
7
|
+
|
|
8
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
9
|
+
|
|
10
|
+
@interface YamapLiteCircleView : RCTViewComponentView
|
|
11
|
+
@end
|
|
12
|
+
|
|
13
|
+
NS_ASSUME_NONNULL_END
|
|
14
|
+
|
|
15
|
+
#endif /* YamapLiteViewNativeComponent_h */
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#import "YamapLiteCircleView.h"
|
|
2
|
+
#include "ReactCodegen/react/renderer/components/YamapLiteViewSpec/EventEmitters.h"
|
|
3
|
+
#include "react/renderer/components/YamapLiteViewSpec/EventEmitters.h"
|
|
4
|
+
#include <Foundation/Foundation.h>
|
|
5
|
+
#include <objc/NSObject.h>
|
|
6
|
+
|
|
7
|
+
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
|
8
|
+
#import <React/RCTConversions.h>
|
|
9
|
+
#import <react/renderer/components/YamapLiteViewSpec/ComponentDescriptors.h>
|
|
10
|
+
#import <react/renderer/components/YamapLiteViewSpec/EventEmitters.h>
|
|
11
|
+
#import <react/renderer/components/YamapLiteViewSpec/Props.h>
|
|
12
|
+
#import <react/renderer/components/YamapLiteViewSpec/RCTComponentViewHelpers.h>
|
|
13
|
+
#import <react/renderer/graphics/Color.h>
|
|
14
|
+
|
|
15
|
+
#import "RCTFabricComponentsPlugins.h"
|
|
16
|
+
#import "YamapLite-Swift.h"
|
|
17
|
+
|
|
18
|
+
using namespace facebook::react;
|
|
19
|
+
|
|
20
|
+
@interface YamapLiteCircleView () <RCTYamapLiteCircleViewViewProtocol,
|
|
21
|
+
YamapLiteCircleComponentDelegate>
|
|
22
|
+
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
@implementation YamapLiteCircleView {
|
|
26
|
+
YamapLiteCircle *_view;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
30
|
+
return concreteComponentDescriptorProvider<
|
|
31
|
+
YamapLiteCircleViewComponentDescriptor>();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
35
|
+
if (self = [super initWithFrame:frame]) {
|
|
36
|
+
static const auto defaultProps =
|
|
37
|
+
std::make_shared<const YamapLiteCircleViewProps>();
|
|
38
|
+
_props = defaultProps;
|
|
39
|
+
_view = [[YamapLiteCircle alloc] init];
|
|
40
|
+
_view.delegate = self;
|
|
41
|
+
self.contentView = _view;
|
|
42
|
+
}
|
|
43
|
+
return self;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
- (void)updateProps:(Props::Shared const &)props
|
|
47
|
+
oldProps:(Props::Shared const &)oldProps {
|
|
48
|
+
const auto &oldViewProps =
|
|
49
|
+
*std::static_pointer_cast<YamapLiteCircleViewProps const>(_props);
|
|
50
|
+
const auto &newViewProps =
|
|
51
|
+
*std::static_pointer_cast<YamapLiteCircleViewProps const>(props);
|
|
52
|
+
|
|
53
|
+
if (oldViewProps.radius != newViewProps.radius) {
|
|
54
|
+
_view.radius = newViewProps.radius;
|
|
55
|
+
}
|
|
56
|
+
if (oldViewProps.fillColor != newViewProps.fillColor) {
|
|
57
|
+
UIColor *uiColor = RCTUIColorFromSharedColor(newViewProps.fillColor);
|
|
58
|
+
if (uiColor) {
|
|
59
|
+
_view.fillColor = uiColor;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (oldViewProps.strokeColor != newViewProps.strokeColor) {
|
|
63
|
+
UIColor *uiColor = RCTUIColorFromSharedColor(newViewProps.strokeColor);
|
|
64
|
+
if (uiColor) {
|
|
65
|
+
_view.strokeColor = uiColor;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (oldViewProps.strokeWidth != newViewProps.strokeWidth) {
|
|
69
|
+
_view.strokeWidth = newViewProps.strokeWidth;
|
|
70
|
+
}
|
|
71
|
+
if (oldViewProps.zIndex != newViewProps.zIndex) {
|
|
72
|
+
_view.zIndex = newViewProps.zInd;
|
|
73
|
+
}
|
|
74
|
+
if (oldViewProps.center.lat != newViewProps.center.lat ||
|
|
75
|
+
oldViewProps.center.lon != newViewProps.center.lon) {
|
|
76
|
+
[_view setCircleCenterWithLatitude:newViewProps.center.lat
|
|
77
|
+
longitude:newViewProps.center.lon];
|
|
78
|
+
}
|
|
79
|
+
if (oldViewProps.handled != newViewProps.handled) {
|
|
80
|
+
_view.handled = newViewProps.handled;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[super updateProps:props oldProps:oldProps];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
- (void)onCirclePressWithPoint:
|
|
87
|
+
(NSDictionary<NSString *, NSNumber *> *_Nonnull)point {
|
|
88
|
+
if (_eventEmitter != nil) {
|
|
89
|
+
YamapLiteCircleViewEventEmitter::OnCirclePress event = {};
|
|
90
|
+
event.lat = [[point objectForKey:@"lat"] doubleValue];
|
|
91
|
+
event.lon = [[point objectForKey:@"lon"] doubleValue];
|
|
92
|
+
std::dynamic_pointer_cast<const YamapLiteCircleViewEventEmitter>(
|
|
93
|
+
_eventEmitter)
|
|
94
|
+
->onCirclePress(event);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
Class<RCTComponentViewProtocol> YamapLiteCircleViewCls(void) {
|
|
99
|
+
return YamapLiteCircleView.class;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#import <React/RCTViewManager.h>
|
|
2
|
+
#import <React/RCTViewComponentView.h>
|
|
3
|
+
#import <UIKit/UIKit.h>
|
|
4
|
+
|
|
5
|
+
#ifndef YamapLiteMarkerViewNativeComponent_h
|
|
6
|
+
#define YamapLiteMarkerViewNativeComponent_h
|
|
7
|
+
|
|
8
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
9
|
+
|
|
10
|
+
@interface YamapLiteMarkerView : RCTViewComponentView
|
|
11
|
+
@end
|
|
12
|
+
|
|
13
|
+
NS_ASSUME_NONNULL_END
|
|
14
|
+
|
|
15
|
+
#endif /* YamapLiteViewNativeComponent_h */
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#import "YamapLiteMarkerView.h"
|
|
2
|
+
#include "ReactCodegen/react/renderer/components/YamapLiteViewSpec/EventEmitters.h"
|
|
3
|
+
#include "react/renderer/components/YamapLiteViewSpec/EventEmitters.h"
|
|
4
|
+
#include <Foundation/Foundation.h>
|
|
5
|
+
#include <objc/NSObject.h>
|
|
6
|
+
|
|
7
|
+
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
|
8
|
+
#import <React/RCTConversions.h>
|
|
9
|
+
|
|
10
|
+
#import "RCTFabricComponentsPlugins.h"
|
|
11
|
+
#import "YamapLite-Swift.h"
|
|
12
|
+
#import <react/renderer/components/YamapLiteViewSpec/ComponentDescriptors.h>
|
|
13
|
+
#import <react/renderer/components/YamapLiteViewSpec/EventEmitters.h>
|
|
14
|
+
#import <react/renderer/components/YamapLiteViewSpec/Props.h>
|
|
15
|
+
#import <react/renderer/components/YamapLiteViewSpec/RCTComponentViewHelpers.h>
|
|
16
|
+
|
|
17
|
+
using namespace facebook::react;
|
|
18
|
+
|
|
19
|
+
@interface YamapLiteMarkerView () <RCTYamapLiteMarkerViewViewProtocol,
|
|
20
|
+
YamapLiteMarkerComponentDelegate>
|
|
21
|
+
|
|
22
|
+
@end
|
|
23
|
+
|
|
24
|
+
@implementation YamapLiteMarkerView {
|
|
25
|
+
YamapLiteMarker *_view;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
29
|
+
return concreteComponentDescriptorProvider<
|
|
30
|
+
YamapLiteMarkerViewComponentDescriptor>();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
34
|
+
if (self = [super initWithFrame:frame]) {
|
|
35
|
+
static const auto defaultProps =
|
|
36
|
+
std::make_shared<const YamapLiteMarkerViewProps>();
|
|
37
|
+
_props = defaultProps;
|
|
38
|
+
_view = [[YamapLiteMarker alloc] init];
|
|
39
|
+
_view.delegate = self;
|
|
40
|
+
self.contentView = _view;
|
|
41
|
+
}
|
|
42
|
+
return self;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
- (void)updateProps:(Props::Shared const &)props
|
|
46
|
+
oldProps:(Props::Shared const &)oldProps {
|
|
47
|
+
const auto &oldViewProps =
|
|
48
|
+
*std::static_pointer_cast<YamapLiteMarkerViewProps const>(_props);
|
|
49
|
+
const auto &newViewProps =
|
|
50
|
+
*std::static_pointer_cast<YamapLiteMarkerViewProps const>(props);
|
|
51
|
+
if (oldViewProps.scale != newViewProps.scale) {
|
|
52
|
+
_view.scale = newViewProps.scale;
|
|
53
|
+
}
|
|
54
|
+
if (oldViewProps.zInd != newViewProps.zInd) {
|
|
55
|
+
_view.zIndex = newViewProps.zInd;
|
|
56
|
+
}
|
|
57
|
+
if (oldViewProps.visible != newViewProps.visible) {
|
|
58
|
+
_view.visible = newViewProps.visible;
|
|
59
|
+
}
|
|
60
|
+
if (oldViewProps.handled != newViewProps.handled) {
|
|
61
|
+
_view.handled = newViewProps.handled;
|
|
62
|
+
}
|
|
63
|
+
if (oldViewProps.point.lat != newViewProps.point.lat ||
|
|
64
|
+
oldViewProps.point.lon != newViewProps.point.lon) {
|
|
65
|
+
[_view setPointWithLat:newViewProps.point.lat lon:newViewProps.point.lon];
|
|
66
|
+
}
|
|
67
|
+
if (oldViewProps.anchor.x != newViewProps.anchor.x ||
|
|
68
|
+
oldViewProps.anchor.y != newViewProps.anchor.y) {
|
|
69
|
+
[_view setAnchorWithX:newViewProps.anchor.x y:newViewProps.anchor.y];
|
|
70
|
+
}
|
|
71
|
+
if (RCTNSStringFromString(oldViewProps.source) !=
|
|
72
|
+
RCTNSStringFromString(newViewProps.source)) {
|
|
73
|
+
[_view setIconWithUri:RCTNSStringFromString(newViewProps.source)];
|
|
74
|
+
}
|
|
75
|
+
if (oldViewProps.rotated != newViewProps.rotated) {
|
|
76
|
+
_view.rotated = newViewProps.rotated;
|
|
77
|
+
}
|
|
78
|
+
if (oldViewProps.size != newViewProps.size) {
|
|
79
|
+
_view.size = newViewProps.size;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
[super updateProps:props oldProps:oldProps];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
- (void)onMarkerPressWithPoint:
|
|
86
|
+
(NSDictionary<NSString *, NSNumber *> *_Nonnull)point {
|
|
87
|
+
if (_eventEmitter != nil) {
|
|
88
|
+
YamapLiteMarkerViewEventEmitter::OnMarkerPress event = {};
|
|
89
|
+
event.lat = [[point objectForKey:@"lat"] doubleValue];
|
|
90
|
+
event.lon = [[point objectForKey:@"lon"] doubleValue];
|
|
91
|
+
|
|
92
|
+
std::dynamic_pointer_cast<const YamapLiteMarkerViewEventEmitter>(
|
|
93
|
+
_eventEmitter)
|
|
94
|
+
->onMarkerPress(event);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
Class<RCTComponentViewProtocol> YamapLiteMarkerViewCls(void) {
|
|
99
|
+
return YamapLiteMarkerView.class;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#import <React/RCTViewComponentView.h>
|
|
2
|
+
#import <React/RCTViewManager.h>
|
|
3
|
+
#import <UIKit/UIKit.h>
|
|
4
|
+
|
|
5
|
+
#ifndef YamapLitePolygonViewNativeComponent_h
|
|
6
|
+
#define YamapLitePolygonViewNativeComponent_h
|
|
7
|
+
|
|
8
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
9
|
+
|
|
10
|
+
@interface YamapLitePolygonView : RCTViewComponentView
|
|
11
|
+
@end
|
|
12
|
+
|
|
13
|
+
NS_ASSUME_NONNULL_END
|
|
14
|
+
|
|
15
|
+
#endif /* YamapLiteViewNativeComponent_h */
|