2 //= require index/browse
3 //= require index/export
5 //= require index/notes
7 $(document).ready(function () {
8 var permalinks = $("#permalink").detach().html();
10 var params = OSM.mapParams();
11 var map = createMap("map");
13 L.control.scale().addTo(map);
15 map.attributionControl.setPrefix(permalinks);
17 map.on("moveend layeradd layerremove", updateLocation);
19 if (!params.object_zoom) {
21 var bbox = L.latLngBounds([params.minlat, params.minlon],
22 [params.maxlat, params.maxlon]);
30 map.setView([params.lat, params.lon], params.zoom);
35 setMapLayers(params.layers);
39 marker = L.marker([params.mlat, params.mlon], {icon: getUserIcon()}).addTo(map);
43 addObjectToMap(params.object, params.object_zoom);
48 $("body").on("click", "a.set_position", function (e) {
51 var data = $(this).data();
52 var centre = L.latLng(data.lat, data.lon);
54 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
55 map.fitBounds([[data.minLat, data.minLon],
56 [data.maxLat, data.maxLon]]);
58 map.setView(centre, data.zoom);
61 if (data.type && data.id) {
62 addObjectToMap(data, true);
66 map.removeLayer(marker);
69 marker = L.marker(centre, {icon: getUserIcon()}).addTo(map);
72 function updateLocation() {
73 var center = map.getCenter().wrap();
74 var zoom = map.getZoom();
75 var layers = getMapLayers();
76 var extents = map.getBounds().wrap();
78 updatelinks(center.lng,
88 var expiry = new Date();
89 expiry.setYear(expiry.getFullYear() + 10);
90 $.cookie("_osm_location", [center.lng, center.lat, zoom, layers].join("|"), {expires: expiry});
93 function remoteEditHandler() {
94 var extent = map.getBounds();
97 $("#linkloader").load(function () { loaded = true; });
98 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.getWest()
99 + "&bottom=" + extent.getSouth()
100 + "&right=" + extent.getEast()
101 + "&top=" + extent.getNorth());
103 setTimeout(function () {
104 if (!loaded) alert(I18n.t('site.index.remote_failed'));
110 $("a[data-editor=remote]").click(remoteEditHandler);
112 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
116 $(window).resize(handleResize);
118 $("#search_form").submit(function () {
119 var bounds = map.getBounds();
121 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
122 $("#sidebar_content").load($(this).attr("action"), {
123 query: $("#query").val(),
124 minlon: bounds.getWest(),
125 minlat: bounds.getSouth(),
126 maxlon: bounds.getEast(),
127 maxlat: bounds.getNorth()
133 if ($("#query").val()) {
134 $("#search_form").submit();
137 // Focus the search field for browsers that don't support
138 // the HTML5 'autofocus' attribute
139 if (!("autofocus" in document.createElement("input"))) {