]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/index/contextmenu.js
Fix rubocop warning
[rails.git] / app / assets / javascripts / index / contextmenu.js
1 //= require qs/dist/qs
2
3 OSM.initializeContextMenu = function (map) {
4   map.contextmenu.addItem({
5     text: I18n.t("javascripts.context.directions_from"),
6     callback: function directionsFromHere(e) {
7       var precision = OSM.zoomPrecision(map.getZoom()),
8           latlng = e.latlng.wrap(),
9           lat = latlng.lat.toFixed(precision),
10           lng = latlng.lng.toFixed(precision);
11
12       OSM.router.route("/directions?" + Qs.stringify({
13         from: lat + "," + lng,
14         to: $("#route_to").val()
15       }));
16     }
17   });
18
19   map.contextmenu.addItem({
20     text: I18n.t("javascripts.context.directions_to"),
21     callback: function directionsToHere(e) {
22       var precision = OSM.zoomPrecision(map.getZoom()),
23           latlng = e.latlng.wrap(),
24           lat = latlng.lat.toFixed(precision),
25           lng = latlng.lng.toFixed(precision);
26
27       OSM.router.route("/directions?" + Qs.stringify({
28         from: $("#route_from").val(),
29         to: lat + "," + lng
30       }));
31     }
32   });
33
34   map.contextmenu.addItem({
35     text: I18n.t("javascripts.context.add_note"),
36     callback: function addNoteHere(e) {
37       var precision = OSM.zoomPrecision(map.getZoom()),
38           latlng = e.latlng.wrap(),
39           lat = latlng.lat.toFixed(precision),
40           lng = latlng.lng.toFixed(precision);
41
42       OSM.router.route("/note/new?lat=" + lat + "&lon=" + lng);
43     }
44   });
45
46   map.contextmenu.addItem({
47     text: I18n.t("javascripts.context.show_address"),
48     callback: function describeLocation(e) {
49       var precision = OSM.zoomPrecision(map.getZoom()),
50           latlng = e.latlng.wrap(),
51           lat = latlng.lat.toFixed(precision),
52           lng = latlng.lng.toFixed(precision);
53
54       OSM.router.route("/search?whereami=1&query=" + encodeURIComponent(lat + "," + lng));
55     }
56   });
57
58   map.contextmenu.addItem({
59     text: I18n.t("javascripts.context.query_features"),
60     callback: function queryFeatures(e) {
61       var precision = OSM.zoomPrecision(map.getZoom()),
62           latlng = e.latlng.wrap(),
63           lat = latlng.lat.toFixed(precision),
64           lng = latlng.lng.toFixed(precision);
65
66       OSM.router.route("/query?lat=" + lat + "&lon=" + lng);
67     }
68   });
69
70   map.contextmenu.addItem({
71     text: I18n.t("javascripts.context.centre_map"),
72     callback: function centreMap(e) {
73       map.panTo(e.latlng);
74     }
75   });
76
77   map.on("mousedown", function (e) {
78     if (e.originalEvent.shiftKey) map.contextmenu.disable();
79     else map.contextmenu.enable();
80   });
81
82   var updateMenu = function updateMenu() {
83     map.contextmenu.setDisabled(2, map.getZoom() < 12);
84     map.contextmenu.setDisabled(4, map.getZoom() < 14);
85   };
86
87   map.on("zoomend", updateMenu);
88   updateMenu();
89 };