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 baselayerchange", 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);
62 map.removeLayer(marker);
65 marker = L.marker(centre, {icon: getUserIcon()}).addTo(map);
68 function updateLocation() {
69 var center = map.getCenter().wrap();
70 var zoom = map.getZoom();
71 var layers = getMapLayers();
72 var extents = map.getBounds().wrap();
74 updatelinks(center.lng,
79 extents.getSouthLat(),
81 extents.getNorthLat(),
84 var expiry = new Date();
85 expiry.setYear(expiry.getFullYear() + 10);
86 $.cookie("_osm_location", [center.lng, center.lat, zoom, layers].join("|"), {expires: expiry});
89 function remoteEditHandler() {
90 var extent = map.getBounds();
93 $("#linkloader").load(function () { loaded = true; });
94 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.getWestLng()
95 + "&bottom=" + extent.getSouthLat()
96 + "&right=" + extent.getEastLng()
97 + "&top=" + extent.getNorthLat());
99 setTimeout(function () {
100 if (!loaded) alert(I18n.t('site.index.remote_failed'));
106 $("a[data-editor=remote]").click(remoteEditHandler);
108 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
112 $(window).resize(handleResize);
114 $("#search_form").submit(function () {
115 var bounds = map.getBounds();
117 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
118 $("#sidebar_content").load($(this).attr("action"), {
119 query: $("#query").val(),
120 minlon: bounds.getWestLng(),
121 minlat: bounds.getSouthLat(),
122 maxlon: bounds.getEastLng(),
123 maxlat: bounds.getNorthLat()
129 if ($("#query").val()) {
130 $("#search_form").submit();
133 // Focus the search field for browsers that don't support
134 // the HTML5 'autofocus' attribute
135 if (!("autofocus" in document.createElement("input"))) {