Skip to content

Commit

Permalink
start work on gps macro
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermeindl committed Dec 24, 2024
1 parent 8e34d31 commit 185c193
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/additionals/wiki_macros/gmap_macro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module WikiMacros
module GmapMacro
Redmine::WikiFormatting::Macros.register do
desc <<-DESCRIPTION
Display a google map. Examples:
Display a google map.
Syntax:
Expand Down
66 changes: 66 additions & 0 deletions lib/additionals/wiki_macros/gps_macro.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# frozen_string_literal: true

module Additionals
module WikiMacros
module GpsMacro
Redmine::WikiFormatting::Macros.register do
desc <<-DESCRIPTION
Display a GPS coordinates and link it to Google or Openstreetmap.
Syntax:
{{gps([q=QUERY, mode=MODE, width=216, height=368])}}
Parameters:
:param string lat: latitude of location
:param string log: longitude of location
:param string service: google (default) or osm
:param int zoom: zoom level (only use for osm)
:param string name: if specified, name is used as link name
Examples:
{{gps(49.56083,11.56018)}}
{{gps(lat=49.56083,lon=11.56018)}}
DESCRIPTION

macro :gps do |_obj, args|
args, options = extract_macro_options(args,
:lat,
:lon,
:service,
:name,
:zoom)

lat = options[:lat].presence || args&.first
lon = options[:lon].presence || args&.second
service = options[:service].presence || 'both'
zoom = options[:zoom].presence || 17

raise 'The correct usage is {{gmap([q=QUERY, mode=MODE, widths=x, height=y])}}' if lat.empty? || lon.empty?

google_link = "https://www.google.com/maps/dir/?api=1&destination=#{lat},#{lon}"
osm_link = "https://www.openstreetmap.org/?mlat=#{lat}&mlon=#{lon}#map=#{zoom}/#{lat}/#{lon}"

case service
when 'google'
return link_to_external options[:name], src if options[:name].present?

return tag.span safe_join(['GPS:', link_to_external("#{lat},#{lon}", google_link)], ' '), class: 'gps'
when 'osm'
return link_to_external options[:name], src if options[:name].present?

return tag.span safe_join(['GPS:', link_to_external("#{lat},#{lon}", osm_link)], ' '), class: 'gps'
else
prefix = options[:name].presence || 'GPS'

return tag.span safe_join(["#{prefix}:",
link_to_external('OSM', osm_link),
link_to_external('Gmap', google_link)], ' '), class: 'gps'
end
end
end
end
end
end

0 comments on commit 185c193

Please sign in to comment.