ios - 如何将 Mapkit 限制在某些缩放级别?
<p><p>目前我们正在使用 wms 服务而不是苹果 map 。我们重写 <code>LoadTileAtPath</code> 以从服务器返回图 block 。</p>
<p>我们的问题是,由于应用程序在网络连接非常弱的偏远地区加载 map 图 block 需要花费大量时间,因此我们计划将缩放级别限制在以下级别</p>
<p><strong>级别</strong></p>
<pre><code>1:1,250
1:25,000
1:250,000
</code></pre>
<p>借助关于 <a href="http://wiki.openstreetmap.org/wiki/Zoom_levels" rel="noreferrer noopener nofollow">zoom levels</a> 的文档我将 z 值限制为 19 或 15 或 11</p>
<p>这里方法</p>
<pre><code>nuint ClampedZ(nuint z)
{
//19,15,11
List<nuint> supportedLayers = new List<nuint>(){ 11, 15, 19 };
nuint toRet = z;
nuint min = supportedLayers; //supportedLayers[];
nuint Prevmin = min;
nuint max = supportedLayers; //supportedLayers;
if (z > min && z < max)
{
foreach (nuint ZoomSupported in supportedLayers)
{
if (z < ZoomSupported)
{
toRet = Prevmin;
break;
}
else
{
Prevmin = ZoomSupported;
}
}
}
return toRet;
}
</code></pre>
<p>我只是想知道这是否是限制缩放级别的正确方法</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在你的 <code>MKMapViewDelegate</code> 中试试这个:</p>
<pre><code>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)
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何将 Mapkit 限制在某些缩放级别?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/41700881/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/41700881/
</a>
</p>
页:
[1]