1 //= require index/browse
2 //= require index/export
5 $(document).ready(function () {
6 var permalinks = $("#permalink").html();
8 var params = OSM.mapParams();
9 var map = createMap("map");
11 L.control.scale().addTo(map);
13 map.attributionControl.setPrefix(permalinks);
15 map.on("moveend baselayerchange", updateLocation);
17 if (!params.object_zoom) {
19 var bbox = L.latLngBounds([params.minlat, params.minlon],
20 [params.maxlat, params.maxlon]);
28 map.setView([params.lat, params.lon], params.zoom);
33 setMapLayers(params.layers);
37 marker = L.marker([params.mlat, params.mlon], {icon: getUserIcon()}).addTo(map);
41 addObjectToMap(params.object, params.object_zoom);
46 $("body").on("click", "a.set_position", function (e) {
49 var data = $(this).data();
50 var centre = L.latLng(data.lat, data.lon);
52 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
53 map.fitBounds([[data.minLat, data.minLon],
54 [data.maxLat, data.maxLon]]);
56 map.setView(centre, data.zoom);
60 map.removeLayer(marker);
63 marker = L.marker(centre, {icon: getUserIcon()}).addTo(map);
66 function updateLocation() {
67 var center = map.getCenter();
68 var zoom = map.getZoom();
69 var layers = getMapLayers();
70 var extents = map.getBounds();
72 updatelinks(center.lng,
77 extents.getSouthLat(),
79 extents.getNorthLat(),
82 var expiry = new Date();
83 expiry.setYear(expiry.getFullYear() + 10);
84 $.cookie("_osm_location", [center.lng, center.lat, zoom, layers].join("|"), {expires: expiry});
87 function remoteEditHandler() {
88 var extent = map.getBounds();
91 $("#linkloader").load(function () { loaded = true; });
92 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.getWestLng()
93 + "&bottom=" + extent.getSouthLat()
94 + "&right=" + extent.getEastLng()
95 + "&top=" + extent.getNorthLat());
97 setTimeout(function () {
98 if (!loaded) alert(I18n.t('site.index.remote_failed'));
104 $("a[data-editor=remote]").click(remoteEditHandler);
106 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
110 $(window).resize(handleResize);
112 $("#search_form").submit(function () {
113 var bounds = map.getBounds();
115 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
116 $("#sidebar_content").load($(this).attr("action"), {
117 query: $("#query").val(),
118 minlon: bounds.getWestLng(),
119 minlat: bounds.getSouthLat(),
120 maxlon: bounds.getEastLng(),
121 maxlat: bounds.getNorthLat()
127 if ($("#query").val()) {
128 $("#search_form").submit();