Skip to content

Commit

Permalink
honor minimal zoom when rendering map preview
Browse files Browse the repository at this point in the history
  • Loading branch information
breunigs committed Jan 21, 2024
1 parent 44b3800 commit 3341304
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions assets/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ function setup() {
center: initial.slice(0, 2),
zoom: initial[2],
fitBoundsOptions: fitBoundsOpt,
// keep in sync with basemap/constants.ex
minZoom: 9,
maxZoom: 19,
style: style,
Expand Down
11 changes: 10 additions & 1 deletion lib/basemap/constants.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
defmodule Basemap.Constants do
def bounds_fitting_max_zoom, do: 17
# keep in sync with map.js
def min_zoom, do: 9

@max_zoom 19
def max_zoom, do: @max_zoom

@bounds_fitting_max_zoom 17
def bounds_fitting_max_zoom, do: @bounds_fitting_max_zoom

if @bounds_fitting_max_zoom > @max_zoom, do: raise("invalid config")
end
7 changes: 6 additions & 1 deletion lib/basemap/static/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ defmodule Basemap.Static.Runner do
@spec render(render_task(), non_neg_integer()) ::
{:ok, content_type :: binary(), image :: binary()} | {:error, reason :: binary()}
def render(task, timeout \\ 5000) do
zoom =
task.zoom
|> max(Basemap.Constants.min_zoom())
|> min(Basemap.Constants.bounds_fitting_max_zoom())

line =
Enum.join(
[
task.lon,
task.lat,
task.zoom,
zoom,
task.pixelRatio,
task.width,
task.height,
Expand Down
7 changes: 6 additions & 1 deletion lib/veloroute_web/components/various_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ defmodule VelorouteWeb.VariousHelpers do
"""
def to_string_center_zoom(bounds) do
cz = Geo.CheapRuler.bounds_to_center_zoom(bounds)
zoom = min(Basemap.Constants.bounds_fitting_max_zoom(), round(cz.zoom))

zoom =
round(cz.zoom)
|> max(Basemap.Constants.min_zoom())
|> min(Basemap.Constants.bounds_fitting_max_zoom())

Enum.join([cz.lon, cz.lat, zoom], ",")
end
end

0 comments on commit 3341304

Please sign in to comment.