這是你如何可以通過只執行MapView的做到這一點:didChangeToRegion:
if (![self.bbox containsLocation:region.center] || region.zoomLevel < self.minZoom) {
SKCoordinateRegion allowedRegion = region;
if (region.center.latitude > self.bbox.topLeftCoordinate.latitude) {
allowedRegion.center.latitude = self.bbox.topLeftCoordinate.latitude;
} else if (region.center.latitude < self.bbox.bottomRightCoordinate.latitude) {
allowedRegion.center.latitude = self.bbox.bottomRightCoordinate.latitude;
}
if (region.center.longitude > self.bbox.bottomRightCoordinate.longitude) {
allowedRegion.center.longitude = self.bbox.bottomRightCoordinate.longitude;
} else if (region.center.longitude < self.bbox.topLeftCoordinate.longitude) {
allowedRegion.center.longitude = self.bbox.topLeftCoordinate.longitude;
}
if (region.zoomLevel < self.minZoom) {
allowedRegion.zoomLevel = self.minZoom;
}
mapView.visibleRegion = allowedRegion;
}
哪裏self.bbox是你想要讓邊框的SKBoundingBox。 和self.minZoom是允許的最小縮放級別。
雖然這並不理想,但出於以下兩個原因: 1.當您嘗試跨越邊界框邊界時,地圖有點來回擺動。 2.邊界框不適合封閉一個國家。簡化的多邊形會更好。