1 //= require querystring
3 OSM.initializeContextMenu = function (map) {
4 var querystring = require("querystring-component");
6 map.contextmenu.addItem({
7 text: I18n.t("javascripts.context.directions_from"),
8 callback: function directionsFromHere(e) {
9 var precision = OSM.zoomPrecision(map.getZoom()),
10 latlng = e.latlng.wrap(),
11 lat = latlng.lat.toFixed(precision),
12 lng = latlng.lng.toFixed(precision);
14 OSM.router.route("/directions?" + querystring.stringify({
15 from: lat + "," + lng,
16 to: $("#route_to").val()
21 map.contextmenu.addItem({
22 text: I18n.t("javascripts.context.directions_to"),
23 callback: function directionsToHere(e) {
24 var precision = OSM.zoomPrecision(map.getZoom()),
25 latlng = e.latlng.wrap(),
26 lat = latlng.lat.toFixed(precision),
27 lng = latlng.lng.toFixed(precision);
29 OSM.router.route("/directions?" + querystring.stringify({
30 from: $("#route_from").val(),
36 map.contextmenu.addItem({
37 text: I18n.t("javascripts.context.add_note"),
38 callback: function addNoteHere(e) {
39 var precision = OSM.zoomPrecision(map.getZoom()),
40 latlng = e.latlng.wrap(),
41 lat = latlng.lat.toFixed(precision),
42 lng = latlng.lng.toFixed(precision);
44 OSM.router.route("/note/new?lat=" + lat + "&lon=" + lng);
48 map.contextmenu.addItem({
49 text: I18n.t("javascripts.context.show_address"),
50 callback: function describeLocation(e) {
51 var precision = OSM.zoomPrecision(map.getZoom()),
52 latlng = e.latlng.wrap(),
53 lat = latlng.lat.toFixed(precision),
54 lng = latlng.lng.toFixed(precision);
56 OSM.router.route("/search?whereami=1&query=" + encodeURIComponent(lat + "," + lng));
60 map.contextmenu.addItem({
61 text: I18n.t("javascripts.context.query_features"),
62 callback: function queryFeatures(e) {
63 var precision = OSM.zoomPrecision(map.getZoom()),
64 latlng = e.latlng.wrap(),
65 lat = latlng.lat.toFixed(precision),
66 lng = latlng.lng.toFixed(precision);
68 OSM.router.route("/query?lat=" + lat + "&lon=" + lng);
72 map.contextmenu.addItem({
73 text: I18n.t("javascripts.context.centre_map"),
74 callback: function centreMap(e) {
79 map.on("mousedown", function (e) {
80 if (e.originalEvent.shiftKey) map.contextmenu.disable();
81 else map.contextmenu.enable();
84 var updateMenu = function updateMenu() {
85 map.contextmenu.setDisabled(2, map.getZoom() < 12);
86 map.contextmenu.setDisabled(4, map.getZoom() < 14);
89 map.on("zoomend", updateMenu);