From a30f6761e059135e69e0bb77647141c2afb6b5b7 Mon Sep 17 00:00:00 2001 From: hydromoll Date: Tue, 2 Jun 2026 12:28:36 +0300 Subject: [PATCH] =?UTF-8?q?feat(=F0=9F=8D=8F):=20add=20getMapObjectCount?= =?UTF-8?q?=20API=20and=20guard=20circle=20overlays?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/Components/Yamap.swift | 35 ++++++++++++++++++++++++++++++++--- ios/YamapUtils.mm | 13 +++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/ios/Components/Yamap.swift b/ios/Components/Yamap.swift index d0fe64d..cbfaa69 100644 --- a/ios/Components/Yamap.swift +++ b/ios/Components/Yamap.swift @@ -340,6 +340,13 @@ public class YamapView: UIView { return result } + @objc public func getMapObjectCount() -> NSNumber { + guard let map = mapView?.mapWindow?.map else { return 0 } + let visitor = MapObjectCountVisitor() + map.mapObjects.traverse(with: visitor) + return NSNumber(value: visitor.count) + } + @objc public func getVisibleRegion() -> [String: Any]? { guard let mapWindow = mapView?.mapWindow else { return nil } let region = mapWindow.map.visibleRegion @@ -504,9 +511,14 @@ public class YamapView: UIView { else if let circleContainer = subview as? UIView, let circleView = circleContainer.value(forKey: "contentView") as? YamapLiteCircle { - let nativeMapObjects = mapView.mapWindow.map.mapObjects - let circleObject = nativeMapObjects.addCircle(with: circleView.circle) - circleView.setMapObject(object: circleObject) + if circleView.radius > 0, + circleView.circleCenter.latitude.isFinite, + circleView.circleCenter.longitude.isFinite + { + let nativeMapObjects = mapView.mapWindow.map.mapObjects + let circleObject = nativeMapObjects.addCircle(with: circleView.circle) + circleView.setMapObject(object: circleObject) + } } else if let polygonContainer = subview as? UIView, let polygonView = polygonContainer.value(forKey: "contentView") as? YamapLitePolygon { @@ -554,3 +566,20 @@ public class YamapView: UIView { if Thread.isMainThread { block() } else { DispatchQueue.main.async { block() } } } } + +private final class MapObjectCountVisitor: NSObject, YMKMapObjectVisitor { + var count = 0 + + func onPlacemarkVisited(withPlacemark placemark: YMKPlacemarkMapObject) { count += 1 } + func onPolylineVisited(withPolyline polyline: YMKPolylineMapObject) { count += 1 } + func onPolygonVisited(withPolygon: YMKPolygonMapObject) { count += 1 } + func onCircleVisited(withCircle: YMKCircleMapObject) { count += 1 } + + func onCollectionVisitStart(with collection: YMKMapObjectCollection) -> Bool { true } + func onCollectionVisitEnd(with collection: YMKMapObjectCollection) {} + func onClusterizedCollectionVisitStart(with collection: YMKClusterizedPlacemarkCollection) -> Bool + { + true + } + func onClusterizedCollectionVisitEnd(with collection: YMKClusterizedPlacemarkCollection) {} +} diff --git a/ios/YamapUtils.mm b/ios/YamapUtils.mm index 5d6483c..d3f3145 100644 --- a/ios/YamapUtils.mm +++ b/ios/YamapUtils.mm @@ -107,6 +107,19 @@ - (void)fitAllMarkers:(double)viewId }); } +- (void)getMapObjectCount:(double)viewId + resolve:(nonnull RCTPromiseResolveBlock)resolve + reject:(nonnull RCTPromiseRejectBlock)reject { + RCTExecuteOnMainQueue(^{ + YamapView *view = [self getView:viewId]; + if (view) { + resolve([view getMapObjectCount]); + } else { + [self rejecter:reject name:@"getMapObjectCount"]; + } + }); +} + - (void)getScreenPoints:(double)viewId points:(NSArray *> *)points resolve:(nonnull RCTPromiseResolveBlock)resolve