diff --git a/assets/js/map.js b/assets/js/map.js index dcac0e78..257dc1be 100644 --- a/assets/js/map.js +++ b/assets/js/map.js @@ -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, diff --git a/lib/basemap/constants.ex b/lib/basemap/constants.ex index 1a27e9ba..ba4db5ea 100644 --- a/lib/basemap/constants.ex +++ b/lib/basemap/constants.ex @@ -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 diff --git a/lib/basemap/static/runner.ex b/lib/basemap/static/runner.ex index 16bb64ed..ac8eba5f 100644 --- a/lib/basemap/static/runner.ex +++ b/lib/basemap/static/runner.ex @@ -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, diff --git a/lib/veloroute_web/components/various_helpers.ex b/lib/veloroute_web/components/various_helpers.ex index 78497b5e..a9f6f677 100644 --- a/lib/veloroute_web/components/various_helpers.ex +++ b/lib/veloroute_web/components/various_helpers.ex @@ -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