Class: Decidim::Map::Provider::StaticMap::Here

Inherits:
StaticMap show all
Defined in:
decidim-core/lib/decidim/map/provider/static_map/here.rb

Overview

The static map utility class for the HERE maps service

Constant Summary

Constants inherited from StaticMap

StaticMap::DEFAULT_SIZE, StaticMap::DEFAULT_ZOOM

Instance Attribute Summary

Attributes inherited from Utility

#configuration, #locale, #organization

Instance Method Summary collapse

Methods inherited from StaticMap

#image_data, #link

Methods inherited from Utility

#initialize

Constructor Details

This class inherits a constructor from Decidim::Map::Utility

Instance Method Details

#url(latitude:, longitude:, options: {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'decidim-core/lib/decidim/map/provider/static_map/here.rb', line 9

def url(latitude:, longitude:, options: {})
  map_url = configuration.fetch(:url, nil)
  return super unless map_url

  return super unless map_url.include?("mia/v3")

  w = options[:width] || Decidim::Map::StaticMap::DEFAULT_SIZE
  h = options[:height] || Decidim::Map::StaticMap::DEFAULT_SIZE

  params = {
    apiKey: configuration[:api_key],
    overlay: "point:#{latitude},#{longitude};icon=cp;size=large|#{latitude},#{longitude};style=circle;width=50m;color=%231B9D2C60"
  }

  URI.parse("#{map_url}:radius=90/#{w}x#{h}/png8").tap do |uri|
    uri.query = URI.encode_www_form(params)
  end.to_s
end

#url_params(latitude:, longitude:, options: {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'decidim-core/lib/decidim/map/provider/static_map/here.rb', line 29

def url_params(latitude:, longitude:, options: {})
  ActiveSupport::Deprecation.warn(
    <<~DEPRECATION.strip
      Please use a V3 version HERE maps.
      For further information, see:
      https://www.here.com/docs/bundle/map-image-migration-guide-v3/page/README.html
      Also make sure your Decidim.maps configurations are using the
      up to date format.
      You need to change:
        static_url = "https://image.maps.ls.hereapi.com/mia/1.6/mapview" if static_provider == "here" && static_url.blank?
      to:
        static_url = "https://image.maps.hereapi.com/mia/v3/base/mc/overlay" if static_provider == "here"
      in your config/initializers/decidim.rb file.
    DEPRECATION
  )

  params = {
    c: "#{latitude}, #{longitude}",
    z: options[:zoom] || Decidim::Map::StaticMap::DEFAULT_ZOOM,
    w: options[:width] || Decidim::Map::StaticMap::DEFAULT_SIZE,
    h: options[:height] || Decidim::Map::StaticMap::DEFAULT_SIZE,
    f: 1
  }

  params[:apiKey] = configuration[:api_key]

  params
end