Calculating tiles to display in a MapRect when “over-zoomed” beyond the overlay tile set

前端 未结 3 1146
予麋鹿
予麋鹿 2020-12-04 18:47

I am working on an app that uses MKOverlay views to layer my own custom maps on top of the Google base map. I have been using Apple\'s excellent TileMap sample code (from W

3条回答
  •  时光说笑
    2020-12-04 19:22

    A bit late to the party, but... Under iOS 7.0 and greater, you can use the maximumZ property on MKTileOverlay. From the docs:

    If you use different overlay objects to represent different tiles at different zoom levels, use this property to specify the maximum zoom level supported by this overlay’s tiles. At zoom level 0, tiles cover the entire world map; at zoom level 1, tiles cover 1/4 of the world; at zoom level 2, tiles cover 1/16 of the world, and so on. The map never tries to load tiles for a zoom level greater than the value specified by this property.

    - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id)overlay {
    
        if ([overlay isKindOfClass:[MKTileOverlay class]]) {
    
            MKTileOverlay *ovrly = (MKTileOverlay *)overlay;
            ovrly.maximumZ = 9;  // Set your maximum zoom level here
            MKTileOverlayRenderer *rndr = [[MKTileOverlayRenderer alloc] initWithTileOverlay:ovrly];
            return rndr;
    
        }
    
        return nil;
    }
    

提交回复
热议问题