简体   繁体   中英

AGSMAPView callout not showing on touch point

I am new to ARCGIS. Any help will be appreciated. I am showing callout on didtap delegate Like this

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)

    }
    
}

在此处输入图像描述

Everything is Working fine first time. But User can also search for places using REST API and then mapview is moves to that point and show callout

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

It returns Site and I create ViewPoint using Latitude and Longitude and show callout with zoom out and zoom in animation Code is given below

        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)

            }
        }

After that when I tap on map any point Callout always shows to top Left Corner While first time didtap delegate was working fine When I debug code and print callout frame it always shows zero x and zero y

在此处输入图像描述

There are a few things going on here:

Firstly, I think you've got the wrong spatial reference. You're using 4236 but WGS84 is 4326.

Note, you can avoid this type of typo by just referencing AGSSpatialReference.wgs84() , so you could say this:

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

But look closely at that: you're also using latitude as X and longitude as Y. It's unfortunately confusing, but when you create an x,y point you need to specify longitude,latitude , not latitude,longitude :

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

It's a common mistake. We have a helper function to simplify working with lat/lon source data:

AGSPointMakeWGS84(center.latitude, center.longitude)

You're also doing a bit more work than you need to (especially in forcing spatial reference conversions) and are introducing a few potential areas where errors could creep in.

So, assuming you actually need to set the map scale twice (I guess you are zooming to the location, and then zooming in a bit to focus attention), you could try something like this, which seems much less prone to errors:

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)
        
    }
}

I confess I'm not entirely sure what your callout screenOffset calculation is doing, but I've left that as is.

I might also suggest adding the graphic before you animate the view, or after the first animation and before the second one (ie you're looking at the right location but have yet to zoom in a bit), but that's up to you.

Also, could I suggest that you post questions like this over at the ArcGIS Runtime SDK for iOS forum ? We do monitor this space if you use the right tags, but you'll generally get more eyes on your questions over there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM