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);
12 OSM.router.route("/directions?" + Qs.stringify({
13 from: lat + "," + lng,
14 to: getDirectionsEndpointCoordinatesFromInput($("#route_to"))
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);
27 OSM.router.route("/directions?" + Qs.stringify({
28 from: getDirectionsEndpointCoordinatesFromInput($("#route_from")),
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);
42 OSM.router.route("/note/new?lat=" + lat + "&lon=" + lng);
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);
54 OSM.router.route("/search?lat=" + encodeURIComponent(lat) + "&lon=" + encodeURIComponent(lng));
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);
66 OSM.router.route("/query?lat=" + lat + "&lon=" + lng);
70 map.contextmenu.addItem({
71 text: I18n.t("javascripts.context.centre_map"),
72 callback: function centreMap(e) {
77 map.on("mousedown", function (e) {
78 if (e.originalEvent.shiftKey) map.contextmenu.disable();
79 else map.contextmenu.enable();
82 function getDirectionsEndpointCoordinatesFromInput(input) {
83 if (input.attr("data-lat") && input.attr("data-lon")) {
84 return input.attr("data-lat") + "," + input.attr("data-lon");
86 return $(input).val();
90 var updateMenu = function updateMenu() {
91 map.contextmenu.setDisabled(2, map.getZoom() < 12);
92 map.contextmenu.setDisabled(4, map.getZoom() < 14);
95 map.on("zoomend", updateMenu);