2 //= require index/browse
3 //= require index/export
6 $(document).ready(function () {
7 var permalinks = $("#permalink").detach().html();
9 var params = OSM.mapParams();
10 var map = createMap("map");
12 L.control.scale().addTo(map);
14 map.attributionControl.setPrefix(permalinks);
16 map.on("moveend baselayerchange", updateLocation);
18 if (!params.object_zoom) {
20 var bbox = L.latLngBounds([params.minlat, params.minlon],
21 [params.maxlat, params.maxlon]);
29 map.setView([params.lat, params.lon], params.zoom);
34 setMapLayers(params.layers);
38 marker = L.marker([params.mlat, params.mlon], {icon: getUserIcon()}).addTo(map);
42 addObjectToMap(params.object, params.object_zoom);
47 $("body").on("click", "a.set_position", function (e) {
50 var data = $(this).data();
51 var centre = L.latLng(data.lat, data.lon);
53 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
54 map.fitBounds([[data.minLat, data.minLon],
55 [data.maxLat, data.maxLon]]);
57 map.setView(centre, data.zoom);
61 map.removeLayer(marker);
64 marker = L.marker(centre, {icon: getUserIcon()}).addTo(map);
67 function updateLocation() {
68 var center = map.getCenter();
69 var zoom = map.getZoom();
70 var layers = getMapLayers();
71 var extents = map.getBounds();
73 updatelinks(center.lng,
78 extents.getSouthLat(),
80 extents.getNorthLat(),
83 var expiry = new Date();
84 expiry.setYear(expiry.getFullYear() + 10);
85 $.cookie("_osm_location", [center.lng, center.lat, zoom, layers].join("|"), {expires: expiry});
88 function remoteEditHandler() {
89 var extent = map.getBounds();
92 $("#linkloader").load(function () { loaded = true; });
93 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.getWestLng()
94 + "&bottom=" + extent.getSouthLat()
95 + "&right=" + extent.getEastLng()
96 + "&top=" + extent.getNorthLat());
98 setTimeout(function () {
99 if (!loaded) alert(I18n.t('site.index.remote_failed'));
105 $("a[data-editor=remote]").click(remoteEditHandler);
107 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
111 $(window).resize(handleResize);
113 $("#search_form").submit(function () {
114 var bounds = map.getBounds();
116 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
117 $("#sidebar_content").load($(this).attr("action"), {
118 query: $("#query").val(),
119 minlon: bounds.getWestLng(),
120 minlat: bounds.getSouthLat(),
121 maxlon: bounds.getEastLng(),
122 maxlat: bounds.getNorthLat()
128 if ($("#query").val()) {
129 $("#search_form").submit();
132 // Focus the search field for browsers that don't support
133 // the HTML5 'autofocus' attribute
134 if (!("autofocus" in document.createElement("input"))) {