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);
10 OSM.router.route("/directions?" + querystring.stringify({
11 route: lat + "," + lng + ";" + $("#route_to").val()
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);
24 OSM.router.route("/directions?" + querystring.stringify({
25 route: $("#route_from").val() + ";" + lat + "," + lng
30 map.contextmenu.addItem({
31 text: I18n.t("javascripts.context.add_note"),
32 callback: function addNoteHere(e) {
33 // I'd like this, instead of panning, to pass a query parameter about where to place the marker
34 map.panTo(e.latlng.wrap(), {animate: false});
35 OSM.router.route("/note/new");
39 map.contextmenu.addItem({
40 text: I18n.t("javascripts.context.show_address"),
41 callback: function describeLocation(e) {
42 var precision = OSM.zoomPrecision(map.getZoom()),
43 latlng = e.latlng.wrap(),
44 lat = latlng.lat.toFixed(precision),
45 lng = latlng.lng.toFixed(precision);
47 OSM.router.route("/search?query=" + encodeURIComponent(lat + "," + lng));
51 map.contextmenu.addItem({
52 text: I18n.t("javascripts.context.query_features"),
53 callback: function queryFeatures(e) {
54 var precision = OSM.zoomPrecision(map.getZoom()),
55 latlng = e.latlng.wrap(),
56 lat = latlng.lat.toFixed(precision),
57 lng = latlng.lng.toFixed(precision);
59 OSM.router.route("/query?lat=" + lat + "&lon=" + lng);
63 map.contextmenu.addItem({
64 text: I18n.t("javascripts.context.centre_map"),
65 callback: function centreMap(e) {
70 map.on("mousedown", function (e) {
71 if (e.shiftKey) map.contextmenu.disable();
72 }).on("mouseup", function () {
73 map.contextmenu.enable();
76 var updateMenu = function updateMenu () {
77 map.contextmenu.setDisabled(2, map.getZoom() < 12);
78 map.contextmenu.setDisabled(4, map.getZoom() < 14);
81 map.on("zoomend", updateMenu);