You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cartodb/lib/static_maps_url_helper.rb

44 lines
1.5 KiB

module Carto
class StaticMapsURLHelper
def url_for_static_map(request, visualization, map_width, map_height)
username = CartoDB.extract_subdomain(request)
request_protocol = request.protocol.sub('://', '')
static_maps_base_url(username, request_protocol) +
static_maps_image_url_fragment(visualization.id, map_width, map_height)
end
def url_for_static_map_without_request(username, request_protocol, visualization, map_width, map_height)
static_maps_base_url(username, request_protocol) +
static_maps_image_url_fragment(visualization.id, map_width, map_height)
end
private
# INFO: Assumes no trailing '/' comes inside, so returned string doesn't has it either
def static_maps_base_url(username, request_protocol)
9 years ago
config = get_cdn_config
if !config.nil? && !config.empty?
9 years ago
"#{request_protocol}://#{config[request_protocol]}/#{username}"
else
9 years ago
# sample format: {protocol}://{user}.{maps_domain}:{port}/
# All parameters except {user} come already replaced
ApplicationHelper.maps_api_template('public').sub('{user}', username)
end
end
# INFO: To ease testing while we keep the config in a global array...
9 years ago
def get_cdn_config
Cartodb.config[:cdn_url]
end
def static_maps_image_url_fragment(visualization_id, width, height)
template_name = Carto::NamedMaps::Template.new(Carto::Visualization.find(visualization_id)).name
"/api/v1/map/static/named/#{template_name}/#{width}/#{height}.png"
end
end
end