【问题标题】:AGSMAPView callout not showing on touch pointAGSMAPView 标注未显示在触摸点上
【发布时间】:2021-03-18 22:47:33
【问题描述】:

我是 ARCGIS 的新手。任何帮助将不胜感激。 我在 didtap 代表上显示标注像这样

func geoView(_ geoView: AGSGeoView, didTapAtScreenPoint screenPoint: CGPoint, mapPoint: AGSPoint) {
    isFromSearch = false
    MBProgressHUD.showAdded(to: self.view, animated: true)
    self.mapView.identifyLayers(atScreenPoint: screenPoint, tolerance: 12, returnPopupsOnly: false, maximumResultsPerLayer: 10) { (identifyLayerResults: [AGSIdentifyLayerResult]?, error: Error?) in
             //check for errors and ensure identifyLayerResults is not nil
        MBProgressHUD.hide(for: self.view, animated: true)
        if let error = error {
            print(error)
            return
        }
        guard let identifyLayerResults = identifyLayerResults else { return }
             // iterate the identify layer results
        guard identifyLayerResults.count > 0 else {return}
        guard identifyLayerResults[0].sublayerResults.count > 0 else {return}
        guard identifyLayerResults[0].sublayerResults[0].geoElements.count > 0 else {return}

        let result = identifyLayerResults[0].sublayerResults[0].geoElements[0].attributes
        self.identifyLayerResult = identifyLayerResults[0]
        var title: String? = nil
        var subtitle: String? = nil
        if ((result["SiteCode"] as? String) != nil) &&  ((result["SiteName"] as? String) != nil){
            title = (result["SiteCode"] as? String)
            subtitle = (result["SiteName"] as? String)
        }
        else {
            title = (result["company"] as? String)
            subtitle = (result["identifier"] as? String)
        }
        self.mapView.callout.title = title
        self.mapView.callout.detail = subtitle
        self.mapView.callout.show(at: mapPoint, screenOffset: .zero, rotateOffsetWithMap: false, animated: true)

    }
    
}

第一次一切正常。但用户也可以使用 REST API 搜索地点 然后 mapview 移动到该点并显示标注

https://******/arcgis/rest/services/Google/MobileiOS3/MapServer/find?

它返回站点,我使用纬度和经度创建 ViewPoint,并显示带有缩小和放大动画的标注代码如下

        let pointView = AGSViewpoint(latitude: center.latitude, longitude: center.longitude, scale: 12E7)
        self.mapView.setViewpoint(pointView, duration: 2) { (value) in
            let pointView1 = AGSViewpoint(latitude: center.latitude, longitude: center.longitude, scale: 12E4)
            self.mapView.setViewpoint(pointView1, duration: 2) { (true) in
                let wgs84 = AGSSpatialReference(wkid: 4236)
                let point = AGSPoint(x: center.latitude, y: center.longitude, spatialReference: wgs84)
                let marker = AGSPictureMarkerSymbol(image: UIImage(named: "BluePushpin.png")!)
                marker.leaderOffsetX = 9
                marker.leaderOffsetY = -16
                let graphics = AGSGraphic(geometry: point, symbol: marker, attributes: nil)
                self.mGraphicOverlay.graphics.add(graphics)
                let cgPoint = CGPoint(x: self.mapView.center.x, y: self.mapView.center.y - (self.mapView.callout.frame.height + 33))
                
                print(cgPoint)
                self.mapView.callout.show(at: graphics.geometry as! AGSPoint, screenOffset: cgPoint, rotateOffsetWithMap: false, animated: true)

            }
        }

之后,当我在地图上点击任何点时,标注总是显示在左上角而第一次 didtap 代表工作正常 当我调试代码并打印标注框架时,它总是显示零 x 和零 y

【问题讨论】:

    标签: arcgis gmsmapview arcgis-runtime


    【解决方案1】:

    这里发生了一些事情:

    首先,我认为您使用了错误的空间参考。您使用的是 4236,但 WGS84 是 4326。

    注意,您可以通过引用 AGSSpatialReference.wgs84() 来避免这种类型的拼写错误,因此您可以这样说:

    let point = AGSPoint(x: center.latitude, y: center.longitude, spatialReference: .wgs84())

    但是仔细看一下:您还使用纬度作为 X,经度作为 Y。不幸的是,这令人困惑,但是当您创建 x,y 点时,您需要指定 longitude,latitude,而不是 latitude,longitude:

    let point = AGSPoint(x: center.longitude, y: center.latitude, spatialReference: .wgs84())

    这是一个常见的错误。我们有一个辅助函数来简化对 lat/lon 源数据的处理:

    AGSPointMakeWGS84(center.latitude, center.longitude)

    您还做了一些超出您需要的工作(尤其是在强制空间参考转换方面),并且引入了一些可能会出现错误的潜在区域。

    所以,假设您实际上需要设置两次地图比例(我猜您正在缩放到该位置,然后再放大一点以集中注意力),您可以尝试这样的事情,这似乎不太容易出错:

    let centerPoint = AGSPointMakeWGS84(center.latitude, center.longitude)
    self.mapView.setViewpoint(AGSViewpoint(center: centerPoint, scale: 12E7), duration: 2) { _ in
        self.mapView.setViewpoint(AGSViewpoint(center: centerPoint, scale: 12E4), duration: 2) { _ in
            let marker = AGSPictureMarkerSymbol(image: UIImage(named: "BluePushpin.png")!)
            marker.leaderOffsetX = 9
            marker.leaderOffsetY = -16
            let graphics = AGSGraphic(geometry: centerPoint, symbol: marker, attributes: nil)
            self.mGraphicOverlay.graphics.add(graphics)
    
            let cgPoint = CGPoint(x: self.mapView.center.x, y: self.mapView.center.y - (self.mapView.callout.frame.height + 33))
            print(cgPoint)
            self.mapView.callout.show(at: centerPoint, screenOffset: cgPoint, rotateOffsetWithMap: false, animated: true)
            
        }
    }
    

    我承认我不完全确定你的 callout screenOffset 计算在做什么,但我保持原样。

    我还建议在为视图设置动画之前添加图形,或者在第一个动画之后和第二个动画之前添加图形(即您正在查看正确的位置但尚未放大一点),但这取决于你。

    另外,我可以建议您在ArcGIS Runtime SDK for iOS forum 上发布这样的问题吗?如果您使用正确的标签,我们会监控此空间,但您通常会更多地关注您的问题。

    【讨论】:

      猜你喜欢
      • 2011-12-14
      • 2017-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 2014-07-23
      • 2012-12-03
      相关资源
      最近更新 更多