-
Notifications
You must be signed in to change notification settings - Fork 1
issue #54: Adjust zoom levels to screen size #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
|
|
||
| import UIKit | ||
|
|
||
| enum Model {} // namespace only | ||
|
|
||
| extension Model { | ||
| struct Image { | ||
| var cid: Int | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,26 +6,35 @@ | |||||||
| // | ||||||||
|
|
||||||||
| import MapKit | ||||||||
|
|
||||||||
| enum Model {} // namespace only | ||||||||
| import VGSL | ||||||||
|
|
||||||||
| // https://leafletjs.com/examples/zoom-levels/ | ||||||||
| private func zoom(delta: Double) -> Int { | ||||||||
| Int((2 + log2(180 / delta)).rounded(.toNearestOrAwayFromZero)) | ||||||||
| func zoom(region: Region, mapSize: CGSize) -> Int { | ||||||||
| let delta = min(region.span.latitudeDelta, region.span.longitudeDelta) | ||||||||
| return Int( | ||||||||
| log2(360 / delta).rounded(.toNearestOrAwayFromZero) | ||||||||
| + adjustment(mapSize: mapSize) | ||||||||
| ).clamp(3...19) | ||||||||
| } | ||||||||
|
|
||||||||
| func delta(zoom: Int) -> Double { | ||||||||
| 180 / pow(2, Double(zoom - 2)) | ||||||||
| func delta(zoom: Int, mapSize: CGSize) -> Double { | ||||||||
| 360 / pow(2, Double(zoom) - adjustment(mapSize: mapSize)) | ||||||||
| } | ||||||||
|
|
||||||||
| extension Region { | ||||||||
| var zoom: Int { | ||||||||
| let delta = min(span.latitudeDelta, span.longitudeDelta) | ||||||||
| return Rewind.zoom(delta: delta).clamped(in: minZoom...maxZoom) | ||||||||
| } | ||||||||
| private func adjustment(mapSize: CGSize) -> Double { | ||||||||
| let x = min(mapSize.width, mapSize.height) | ||||||||
| let (x1, y1) = (375.0, 0.7) // min adjustment for small screens | ||||||||
| let (x2, y2) = (1024.0, 1.5) // max adjustment for large screens | ||||||||
| return (y2 - y1) / (x2 - x1) * (x - x1) + y1 | ||||||||
|
||||||||
| return (y2 - y1) / (x2 - x1) * (x - x1) + y1 | |
| let value = (y2 - y1) / (x2 - x1) * (x - x1) + y1 | |
| return max(y1, min(y2, value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the screen size is smaller than 375 pixels (x1), the function will return values less than 0.7. Similarly, for screens larger than 1024 pixels (x2), it will return values greater than 1.5.
sounds ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The adjustment function implements a linear interpolation formula but lacks documentation explaining the rationale behind the chosen screen size thresholds (375px and 1024px) and adjustment values (0.7 and 1.5). Adding a comment to explain why these specific values were chosen would improve code maintainability and help future developers understand the zoom adjustment logic.