美文网首页
ArcGIS for iOS 系列教程 之 AGSMapView

ArcGIS for iOS 系列教程 之 AGSMapView

作者: 拉酷大王 | 来源:发表于2021-06-13 10:24 被阅读0次

前言

AGSMapView是用于展示2D地理信息的一个类,暴露了mapScale、rotation等常用属性,也提供了设置视角,设置比例尺,监听用户行为等事件的接口。

加载底图

加载底图需要赋值一个AGSMap对象给AGSMapView


        let amapUrl = "http://webst03.is.autonavi.com/appmaptile?x={col}&y={row}&z={level}&lang=zh_cn&size=1&scale=1&style=7"
    
        let tiledLayer = AGSWebTiledLayer(urlTemplate: amapUrl);
        
        let map = AGSMap(basemap: AGSBasemap(baseLayer: tiledLayer))
        
        mapView.map = map

添加数据层

上文讲到,数据层也叫操作层,是用户主要接触的图层,改图层采用自上而下的顺序进行绘制

let featureTable = AGSServiceFeatureTable(url: URL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0")!)
let featureLayer = AGSFeatureLayer(featureTable: featureTable)
map.operationalLayers.add(featureLayer)

添加图形层

图形、绘制层内容较多,会单独拿出来说

监听用户点击事件并且获取相关属性信息

  1. 设置代理
mapView.touchDelegate = self
  1. 实现代理方法
extension ViewController: AGSGeoViewTouchDelegate{
    
    func geoView(_ geoView: AGSGeoView, didTouchUpAtScreenPoint screenPoint: CGPoint, mapPoint: AGSPoint) {
        
    }
}
  1. 代理方法中Tap、Touch、Double Tap、Long Press、Force Touch都有对应方法

定位+显示当前位置

  1. 定位ArcGIS本身有封装好的api提供使用
    自动获取定位并且把地图视角设置到当前位置:
        self.mapView.locationDisplay.start { error in
            if let e = error{
                
            }
        }
        self.mapView.locationDisplay.autoPanMode = AGSLocationDisplayAutoPanMode.compassNavigation
        self.mapView.locationDisplay.navigationPointHeightFactor = 0.5

ps:iOS需要在plist文件中添加相应的权限字段

  1. 也可以通过系统api或者第三方提供的定位api来获取经纬度,然后手动设置视角。这里要记得做不同坐标系的转换工作

通过不同方式设置视角

        mapView.setViewpoint(AGSViewpoint(latitude: 34.752965,longitude: 113.665911,scale: scale)) { result in
            
        }

获取当前的比例尺

有相应的get方法直接获取

mapView.mapScale

设置地图的比例尺

mapView.setViewpointScale(mapView.mapScale * 2, completion: nil)

监听地图视角变化

/** Block that gets invoked whenever the viewpoint changes.
 @note This handler may get invoked up to 60 times per second, for example, when a pan or zoom animation is in progress. Do not perform any heavy-lifting in this handler as it may adversely impact the rendering performance.
 @note The block will be invoked on the same thread on which the event occured, which could be any arbitrary thread. You need to dispatch any UI related work to the main thread.
 @since 100
 */
@property (nullable, nonatomic, copy, readwrite) void (^viewpointChangedHandler)(void);

相关文章

网友评论

      本文标题:ArcGIS for iOS 系列教程 之 AGSMapView

      本文链接:https://www.haomeiwen.com/subject/hlrasltx.html