From 185c1939ae72d5f55f4d177acac7d46af18077d5 Mon Sep 17 00:00:00 2001 From: Alexander Meindl Date: Tue, 24 Dec 2024 18:27:34 +0100 Subject: [PATCH] start work on gps macro --- lib/additionals/wiki_macros/gmap_macro.rb | 2 +- lib/additionals/wiki_macros/gps_macro.rb | 66 +++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 lib/additionals/wiki_macros/gps_macro.rb diff --git a/lib/additionals/wiki_macros/gmap_macro.rb b/lib/additionals/wiki_macros/gmap_macro.rb index 8932cac0..c19ac42b 100644 --- a/lib/additionals/wiki_macros/gmap_macro.rb +++ b/lib/additionals/wiki_macros/gmap_macro.rb @@ -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: diff --git a/lib/additionals/wiki_macros/gps_macro.rb b/lib/additionals/wiki_macros/gps_macro.rb new file mode 100644 index 00000000..79525551 --- /dev/null +++ b/lib/additionals/wiki_macros/gps_macro.rb @@ -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