DEPRECATED-mapbox-ios-sdk
DEPRECATED-mapbox-ios-sdk copied to clipboard
Changing tileSource unsets zoom settings
Setting theMapView.tileSource to a new source after creation seems to work fine, except minimum and maximum zoom levels (and/or bounding height) seem to get corrupted.
For example, our map is set up so you can't zoom out further than the whole world (mapView.boundingMask = RMMapMinHeightBound), but after changing the tileSource, you can then zoom out too far (so the map is smaller than the containing view.) Resetting min/max zoom and bounding height doesn't fix it.
There are some issues with boundingMask
still as documented in #12. Your best bet right now is probably to set a minimum zoom post-changing tileSource
which corresponds to your minimum desired size. For example, if your map view is 500x300
, then take 300
and set minZoom
to 0.228
(log2(300 / 256)
). Then you will never be able to zoom smaller than 300
in either direction.
I couldn't get this to work. Sorry, what's the 256 in the equation?
The 256 is the pixel size for normal tiles (i.e., adjustTilesForRetinaDisplay = NO
, otherwise they get doubled to 512px to remain legible). So this is saying figure out the smallest zoom that will still allow a single-tile map (i.e., z0
) to cover the complete view.
Aaaaaannnnd now that I look at this, I realize it should be 500
, not 300
above, so that the longer side is the limiter, not the shorter. Try 0.966
? (log2(500 / 256)
)
Right, I've got this working now. You also need to manually reset the zoom level if it falls under the new minZoomLevel.
I call my resetMapMinimiumZoom after the mapView is initially created, in layoutSubviews (to handle rotations and other map resizing we do) and if I change the tileSource later on.
- (void)resetMapMinimumZoom
{
CGFloat tileSize = mapView.adjustedZoomForRetinaDisplay == YES ? 512.0f : 256.0f;
mapView.minZoom = log2(mapView.bounds.size.width / tileSize);
if (mapView.zoom < mapView.minZoom)
{
mapView.zoom = mapView.minZoom;
}
}
Cool. That seems as though it could essentially become the new zoom
clamping code when I address this natively post-0.4.0. Thanks for the report and sorry for the hack-for-now.
BTW this ties into #12.
The max/min zoom are also incorrect on mapView:initWith...Source. You have to reset them immediately afterwards.
These are overwritten with the values from your tile source settings I believe, but yeah, the setup process is confusing.
On Sep 12, 2012, at 9:55, Tracy Harton [email protected] wrote:
The max/min zoom are also incorrect on mapView:initWith...Source. You have to reset them immediately afterwards.
— Reply to this email directly or view it on GitHub.
The map minZoom/maxZoom are separate from the tilesource minZoom/maxZoom. Atleast that's the way it used to work in route-me, which I'd say is preferable as you may want to allow zooming past your tileSource, etc..
/tracy
I'm pretty sure the code in the above resetMapMinimumZoom function worked, but either it didn't or something changed, and it no longer works in portrait mode (or when the mapView's height is longer than its width). The obvious answer is that the function should use height or width, whichever is larger, in its calculation — but this doesn't work either. Any thoughts?
Am I correct in understanding that the real problem here is still the #12 bounding mask issue, so that the map can't be zoomed out beyond viewable coverage (unless desired).
i.e. the map view zoom min/max should get updated upon tile source changes to cover most use cases. If you want to preserve a certain zoom range, you should record it and re-set it after the tile source change.
I think that's desired behavior for the majority of cases. If so, we can close in favor of just #12.
Let me know if I'm missing something.
I still consider resetting the min/max zoom incorrect, and it breaks from the route-me behavior. The was some discussion about it years ago, and was eventually fixed...
The tile source has a min/max, and the mapView has a separate min/max. IMO, The min/max of the tilesource should control the range of tiles fetched from the server/db, and the min/max of the mapView controls what the user is allow to zoom to / what is displayed. Data vs. presentation.
I guess I'm not seeing why you'd want it to change just because you've selected a different map?
/tracy
Makes sense, @tracyharton. I'll leave open and think about this.
sorry, is this issue fixed? i'm still having issues with min zoom - horizontal scroll is disabled at some point until you zoom in the map view... thanks