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