1 OSM.initializeContextMenu = function (map) {
 
   2   map.contextmenu.addItem({
 
   3     text: I18n.t("javascripts.context.directions_from"),
 
   4     callback: function directionsFromHere(e) {
 
   5       const latlng = OSM.cropLocation(e.latlng, map.getZoom());
 
   7       OSM.router.route("/directions?" + new URLSearchParams({
 
   8         from: latlng.join(","),
 
   9         to: getDirectionsEndpointCoordinatesFromInput($("#route_to"))
 
  14   map.contextmenu.addItem({
 
  15     text: I18n.t("javascripts.context.directions_to"),
 
  16     callback: function directionsToHere(e) {
 
  17       const latlng = OSM.cropLocation(e.latlng, map.getZoom());
 
  19       OSM.router.route("/directions?" + new URLSearchParams({
 
  20         from: getDirectionsEndpointCoordinatesFromInput($("#route_from")),
 
  26   map.contextmenu.addItem({
 
  27     text: I18n.t("javascripts.context.add_note"),
 
  28     callback: function addNoteHere(e) {
 
  29       const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
 
  31       OSM.router.route("/note/new?" + new URLSearchParams({ lat, lon }));
 
  35   map.contextmenu.addItem({
 
  36     text: I18n.t("javascripts.context.show_address"),
 
  37     callback: function describeLocation(e) {
 
  38       const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
 
  40       OSM.router.route("/search?" + new URLSearchParams({ lat, lon }));
 
  44   map.contextmenu.addItem({
 
  45     text: I18n.t("javascripts.context.query_features"),
 
  46     callback: function queryFeatures(e) {
 
  47       const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
 
  49       OSM.router.route("/query?" + new URLSearchParams({ lat, lon }));
 
  53   map.contextmenu.addItem({
 
  54     text: I18n.t("javascripts.context.centre_map"),
 
  55     callback: function centreMap(e) {
 
  60   map.on("mousedown", function (e) {
 
  61     if (e.originalEvent.shiftKey) map.contextmenu.disable();
 
  62     else map.contextmenu.enable();
 
  65   function getDirectionsEndpointCoordinatesFromInput(input) {
 
  66     if (input.attr("data-lat") && input.attr("data-lon")) {
 
  67       return input.attr("data-lat") + "," + input.attr("data-lon");
 
  69       return $(input).val();
 
  73   var updateMenu = function updateMenu() {
 
  74     map.contextmenu.setDisabled(2, map.getZoom() < 12);
 
  75     map.contextmenu.setDisabled(4, map.getZoom() < 14);
 
  78   map.on("zoomend", updateMenu);