如何将Mapkit限制为某些缩放级别?

时间:2017-01-17 15:23:26

标签: ios mapkit mkoverlay wms

目前我们正在使用wms服务而不是苹果地图。我们重写LoadTileAtPath以从服务器返回切片。

我们的问题是,由于应用程序在偏远地区占用大量时间,我们计划将缩放级别限制在以下级别

水平

1:1,250

1:25,000

1:250,000

在关于zoom levels的文档的帮助下,我将z值限制为19或15或11

这里的方法

nuint ClampedZ(nuint z)
        {
            //19,15,11

            List<nuint> supportedLayers = new List<nuint>(){ 11, 15, 19 };
            nuint toRet = z;
            nuint min = supportedLayers[0]; //supportedLayers[];
            nuint Prevmin = min;
            nuint max = supportedLayers[supportedLayers.Count - 1]; //supportedLayers[supportedLayers.Length - 1];
            if (z > min && z < max)
            {
                foreach (nuint ZoomSupported in supportedLayers)
                {

                    if (z < ZoomSupported)
                    {
                        toRet = Prevmin;
                        break;
                    }
                    else
                    {
                        Prevmin = ZoomSupported;
                    }
                }
            }
            return toRet;
        }

我只是想知道这是否是限制缩放级别的正确方法

1 个答案:

答案 0 :(得分:0)

MKMapViewDelegate

中试试这个
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
    let maxLatitudeDelta: CLLocationDegrees = 1.0 //put in appropriate value for your zoom levels
    let maxLongitudeDelta: CLLocationDegrees = 1.0 //put in appropriate value for your zoom levels
    let center = mapView.centerCoordinate
    let region = MKCoordinateRegionMake(center, MKCoordinateSpan(latitudeDelta: maxLatitudeDelta, longitudeDelta: maxLongitudeDelta))
    let adjustedRegion = mapView.regionThatFits(region)
    mapView.setRegion(adjustedRegion, animated: true)
}