使用swift在OpenLayers中缩放到层范围



我已经创建了一个具有不同层的imap,并且我有一个下拉列表,在其中我选择了一个场代码。

现在我想添加一个功能,如果选择了农场代码,地图应该缩放到地图上输入的搜索结果。目前,搜索结果已输入到图层中,但不会缩放到结果。

我还编写了一个api来获取geojson数据,下面是我从我的api中获得的geojson:

{data=";{"类型":"特征集合","特征":[{"型":"特性","几何":{"类":"多重多边形"}},"坐标":[[[390656.789.999999804731.230000001],[390679.7804719.67000002],[309682.359999998804705.86],[309682.691804705.47000001],[309681.85804705.271],[306682.998999999804705.00000001],[390683.14804704.840000002],[3390683.26899999804704.61],]]},";属性":{"gid":144589,"fid_lpis_d":1,"farm_code":"001/0004","objectid_1":77898,"objectid":310098,"category":"Woodland","ift_ioa":"Broadlead","country":"Scotland","质心_x":390578.864868,"质心_y":804684.433405,"形状面积":1.556981124281313;area_in_hectare":0.1446488296835173}}

如有任何帮助,我们将不胜感激
谢谢
Rutupana Panda

还有一件事你得到的是错误的

纬度和经度是一对用于描述地理坐标系平面上的位置。这些数字采用十进制度数格式,范围从-90到90纬度和-180到180表示经度。

位置数组将填充latlong例如

var locations = [CLLocationCoordinate2DMake(23.16, 77.36),
CLLocationCoordinate2DMake(25.16, 72.36),
CLLocationCoordinate2DMake(24.16, 75.36),
CLLocationCoordinate2DMake(22.16, 74.36)]

从中获取corinates阵列的位置并绘制MKPolygon

var locations = //location cordinates array.
let polygon = MKPolygon(coordinates: &locations, count: locations.count)
mapView?.add(polygon)

而不是使用mapViewrendererFor委托方法

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKPolygon {
let renderer = MKPolygonRenderer(polygon: overlay as! MKPolygon)
renderer.fillColor = UIColor.black.withAlphaComponent(0.5)
renderer.strokeColor = UIColor.green
renderer.lineWidth = 1
return renderer
}

return MKOverlayRenderer()
}

最新更新