1

我一直在尝试在具有重叠覆盖的地图上实现 GMSOverlay。设置 zIndex 确实可以在彼此之上显示叠加层。但是当点击顶部覆盖时,它不能正常工作。后面的是超车水龙头。

有人可以帮我调试和解决这个问题:

这是覆盖实现的代码片段:

覆盖自定义类

class OrbisMapOverlayMarker: GMSGroundOverlay {
   var mapPlaceBaseColor: UIColor!
   var mapPlaceId: String!
   var placeCoordinate: CLLocationCoordinate2D!
   var lastCheckinTimeStamp: Date! 
   var radius: CLLocationDistance!
   var fixedRadius: CLLocationDistance! 
   var imageView: UIImageView!
   private var pulseMaxSize: CLLocationDistance = 100
   var increment: CLLocationDistance = 10
   private let maxSizeReference: CLLocationDistance = 100
   private let referenceRadius: CLLocationDistance = 500
   var fixedOpacity: Float = 1
   var isProgressing = true
   var imageUrlName: String = ""
   
   init(bounds: GMSCoordinateBounds, icon: UIImage?, radius: CLLocationDistance) {
       super.init()
       self.imageView = UIImageView()
       self.bounds = bounds
       self.icon = icon
       self.radius = radius
       self.fixedRadius = radius
       pulseMaxSize = (maxSizeReference / referenceRadius) * radius
       increment = (maxSizeReference * 0.1 / referenceRadius) * radius
   }
}

执行:

.
.
.
        let placeSize = orbisPlace.calculatedSize
        let clDistance = CLLocationDistance(placeSize)
        let coordinate = CLLocationCoordinate2D(latitude: orbisPlace.coordinates?.latitude ?? 0, longitude: orbisPlace.coordinates?.longitude ?? 0)
        let topLeftCoordinate = CLHelper.coordinate(from: coordinate, distance: -clDistance)
        let bottomRightCoordinate = CLHelper.coordinate(from: coordinate, distance: clDistance)
        let circleZIndex = Int32(1600 - placeSize)
        
        var color = UIColor(named: AppColors.appBlue.rawValue)
        if let colorHex = orbisPlace.placeDominantGroup?.strokeColorHexString {
            color = UIColor.hexStringToUIColor(hex: colorHex)
        }
        
        let customMarker = OrbisMapOverlayMarker(bounds: GMSCoordinateBounds(coordinate: topLeftCoordinate, coordinate: bottomRightCoordinate), icon: nil, radius: clDistance)
        let mapZoomRadius = mapView.getRadius()
        customMarker.mapPlaceId = orbisPlace.placeKey
        customMarker.position = CLLocationCoordinate2D(latitude: orbisPlace.coordinates?.latitude ?? 0, longitude: orbisPlace.coordinates?.longitude ?? 0)
        let placeOpacity = Float(getPlaceCircleOpacity(forCircle: customMarker, withSize: placeSize, mapRadius: mapZoomRadius))
        if let activeMarker = self.activeGlowOverlay {
            if activeMarker.mapPlaceId == orbisPlace.placeKey {
                customMarker.opacity = 1
                customMarker.fixedOpacity = Float(1)
            }
            else {
                customMarker.opacity = 0.1
                customMarker.fixedOpacity = Float(0.1)
            }
        }
        else {
            customMarker.opacity = placeOpacity
            customMarker.fixedOpacity = Float(placeOpacity)
        }
        customMarker.isTappable = true
        mapMarkers.append(customMarker)
        customMarker.icon = image
        customMarker.zIndex = circleZIndex
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, qos: .userInteractive, flags: .enforceQoS) {
            customMarker.map = mapView
        }
.
.
.

我还在 map sdk repo 上提交了问题: https ://github.com/googlemaps/maps-sdk-for-ios-samples/issues/118

4

0 回答 0