Sha256: 728d0a1e0472c54fb699fda47d2c38d2e0f56c01d56f5d6f7e305cfa4dfade0e

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

require "addressable/uri"

module GeoblacklightAdmin
  class ImageService
    module Tms
      ##
      # 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.
      # @param [SolrDocument]
      # @param [Integer] thumbnail size
      # @return [String] tms thumbnail url
      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geoblacklight_admin-0.5.1 app/services/geoblacklight_admin/image_service/tms.rb