Module: GeoblacklightAdmin::ImageService::Tms

Defined in:
app/services/geoblacklight_admin/image_service/tms.rb

Class Method Summary collapse

Class Method Details

.image_url(document, size) ⇒ String

Formats and returns a thumbnail url for a TMS endpoint from a Web Map Service. This utilizes the GeoServer specific ‘reflect’ service to generate parameters like bbox that are difficult to tweak without more detailed information about the layer.

Parameters:

  • (SolrDocument)
  • thumbnail (Integer)

    size

Returns:

  • (String)

    tms thumbnail url



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/services/geoblacklight_admin/image_service/tms.rb', line 16

def self.image_url(document, size)
  # Begins with:
  # https://cugir.library.cornell.edu/geoserver/gwc/service/tms/1.0.0/cugir%3Acugir007957@EPSG%3A3857@png/{z}/{x}/{y}.png

  # Works with:
  # https://cugir.library.cornell.edu/geoserver/wms/reflect?&FORMAT=image%2Fpng&TRANSPARENT=TRUE&LAYERS=cugir007957&WIDTH=1500&HEIGHT=1500

  # Parse the URL using Addressable::URI which handles more complex URIs
  parsed_url = Addressable::URI.parse(document.viewer_endpoint)

  puts "Parsed URL: #{parsed_url.inspect}"

  # Build a hash to store the extracted components
  parsed_data = {
    base_url: "#{parsed_url.scheme}://#{parsed_url.host}#{parsed_url.port ? ":" + parsed_url.port.to_s : ""}",
    path_pattern: parsed_url.path
  }

  puts "Parsed Data: #{parsed_data.inspect}"

  endpoint = parsed_data[:base_url]
  "#{endpoint}/geoserver/wms/reflect?" \
    "&FORMAT=image%2Fpng" \
    "&TRANSPARENT=TRUE" \
    "&LAYERS=#{document["gbl_wxsIdentifier_s"]}" \
    "&WIDTH=#{size}" \
    "&HEIGHT=#{size}"
end