DEPRECATED-mapbox-ios-sdk icon indicating copy to clipboard operation
DEPRECATED-mapbox-ios-sdk copied to clipboard

RMMapTiledLayerView SnapshotRenderer should not be limited by tileSource.minZoom && zoom <= tileSource.maxZoom

Open jvieten opened this issue 11 years ago • 2 comments

I could provide a patch but do not know how to submit it?

RMMapTiledLayerView should use code from the "tries to return lower zoom level tiles if a tile cannot be found" section (RMMapTiledLayerView line 208) to provide an image even if the zoom factor is beyond the saved tileSource 's maxZoom

jvieten avatar Feb 16 '14 10:02 jvieten

This functionality is called overzooming and adding it to snapshotting is an enhancement. Relatively low priority right now but will track in this ticket.

incanus avatar Feb 18 '14 23:02 incanus

Thank you so much! Its fun to have one's comments being at least considered. just in case here is what I am trying out:

diff --git a/MapView/Map/RMMapTiledLayerView.m b/MapView/Map/RMMapTiledLayerView.m
index f898f31..62d8ffa 100644
--- a/MapView/Map/RMMapTiledLayerView.m
+++ b/MapView/Map/RMMapTiledLayerView.m
@@ -91,6 +91,53 @@
     self.contentScaleFactor = 1.0f;
 }

+-(UIImage*) overzoomTileImage:(short) zoom column:(int) x row:(int)y
+{
+       UIImage *tileImage = nil;
+       int currentTileDepth = 1, currentZoom = zoom - currentTileDepth;
+       while(currentZoom >_tileSource.maxZoom)
+       {
+               currentZoom = zoom - ++currentTileDepth;
+       }
+               
+       
+       // tries to return lower zoom level tiles if a tile cannot be found
+       while ( !tileImage && currentZoom >= _tileSource.minZoom && currentTileDepth <= _mapView.missingTilesDepth)
+       {
+               float nextX = x / powf(2.0, (float)currentTileDepth),
+               nextY = y / powf(2.0, (float)currentTileDepth);
+               float nextTileX = floor(nextX),
+               nextTileY = floor(nextY);
+               tileImage = [_tileSource imageForTile:RMTileMake((int)nextTileX, (int)nextTileY, currentZoom) inCache:[_mapView tileCache]];
+               
+               if (IS_VALID_TILE_IMAGE(tileImage))
+               {
+                       // crop
+                       float cropSize = 1.0 / powf(2.0, (float)currentTileDepth);
+                       
+                       CGRect cropBounds = CGRectMake(tileImage.size.width * (nextX - nextTileX),
+                                                                                  tileImage.size.height * (nextY - nextTileY),
+                                                                                  tileImage.size.width * cropSize,
+                                                                                  tileImage.size.height * cropSize);
+                       
+                       CGImageRef imageRef = CGImageCreateWithImageInRect([tileImage CGImage], cropBounds);
+                       tileImage = [UIImage imageWithCGImage:imageRef];
+                       CGImageRelease(imageRef);
+                       
+                       break;
+               }
+               else
+               {
+                       tileImage = nil;
+               }
+               
+               currentTileDepth++;
+               currentZoom = zoom - currentTileDepth;
+       }
+       return tileImage;
+
+}
+
 - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context
 {
     CGRect rect   = CGContextGetClipBoundingBox(context);
@@ -111,7 +158,7 @@

 //        NSLog(@"Tiles from x1:%d, y1:%d to x2:%d, y2:%d @ zoom %d", x1, y1, x2, y2, zoom);

-        if (zoom >= _tileSource.minZoom && zoom <= _tileSource.maxZoom)
+        if (zoom >= _tileSource.minZoom)
         {
             UIGraphicsPushContext(context);
 - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context
 {
     CGRect rect   = CGContextGetClipBoundingBox(context);
@@ -111,7 +158,7 @@

 //        NSLog(@"Tiles from x1:%d, y1:%d to x2:%d, y2:%d @ zoom %d", x1, y1, x2, y2, zoom);

-        if (zoom >= _tileSource.minZoom && zoom <= _tileSource.maxZoom)
+        if (zoom >= _tileSource.minZoom)
         {
             UIGraphicsPushContext(context);

@@ -119,8 +166,12 @@
             {
                 for (int y=y1; y<=y2; ++y)
                 {
-                    UIImage *tileImage = [_tileSource imageForTile:RMTileMake(x, y, zoom) inCache:[_mapView tileCache]];
-
+                    UIImage *tileImage =  nil;
+                                       if(zoom <= _tileSource.maxZoom)
+                                               tileImage = [_tileSource imageForTile:RMTileMake(x, y, zoom) inCache:[_mapView tileCache]];
+                                       else
+                                               tileImage = [self overzoomTileImage:zoom column:x row:y];
+                                       
                     if (IS_VALID_TILE_IMAGE(tileImage))
                         [tileImage drawInRect:CGRectMake(x * rectSize, y * rectSize, rectSize, rectSize)];
                 }
@@ -203,42 +254,7 @@
             }
             else
             {
-                NSUInteger currentTileDepth = 1, currentZoom = zoom - currentTileDepth;
-
-                // tries to return lower zoom level tiles if a tile cannot be found
-                while ( !tileImage && currentZoom >= _tileSource.minZoom && currentTileDepth <= _mapView.missingTilesDepth)
-                {
-                    float nextX = x / powf(2.0, (float)currentTileDepth),
-                          nextY = y / powf(2.0, (float)currentTileDepth);
-                    float nextTileX = floor(nextX),
-                          nextTileY = floor(nextY);
-
-                    tileImage = [_tileSource imageForTile:RMTileMake((int)nextTileX, (int)nextTileY, currentZoom) inCache:[_mapView tileCache]];
-
-                    if (IS_VALID_TILE_IMAGE(tileImage))
-                    {
-                        // crop
-                        float cropSize = 1.0 / powf(2.0, (float)currentTileDepth);
-
-                        CGRect cropBounds = CGRectMake(tileImage.size.width * (nextX - nextTileX),
-                                                       tileImage.size.height * (nextY - nextTileY),
-                                                       tileImage.size.width * cropSize,
-                                                       tileImage.size.height * cropSize);
-
-                        CGImageRef imageRef = CGImageCreateWithImageInRect([tileImage CGImage], cropBounds);
-                        tileImage = [UIImage imageWithCGImage:imageRef];
-                        CGImageRelease(imageRef);
-
-                        break;
-                    }
-                    else
-                    {
-                        tileImage = nil;
-                    }
-
-                    currentTileDepth++;
-                    currentZoom = zoom - currentTileDepth;
-                }
+                tileImage = [self overzoomTileImage:zoom column:x row:y];

jvieten avatar Feb 19 '14 15:02 jvieten